1 ##############################################################################
2 # Copyright (c) 2018 Huawei Tech and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 Currently supported installers are Apex, Compass...
11 Supported monitoring tools are Cadvisor, Collectd, Barometer...
12 Carefully, do not change the path or name of the configuration files which
13 are hard coded for docker volume mapping.
18 import utils.infra_setup.passwordless_SSH.ssh as ssh
21 logger = logging.getLogger(__name__)
23 parser = argparse.ArgumentParser(description='Monitoring Clients Dispatcher')
24 parser.add_argument("-i", "--INSTALLER_TYPE",
25 help="The installer for the system under monitoring")
26 # Barometer config and installation files
27 # /home/opnfv/bottlenecks/monitor/dispatch/install_barometer_client.sh
28 # /home/opnfv/bottlenecks/monitor/config/barometer_client.conf
29 # Cadvisor installation file
30 # /home/opnfv/bottlenecks/monitor/dispatch/install_cadvisor_client.sh
31 # Collectd config and installation files
32 # /home/opnfv/bottlenecks/monitor/dispatch/install_collectd_client.sh
33 # /home/opnfv/bottlenecks/monitor/config/collectd_client.conf
34 parser.add_argument("-s", "--INSTALlATION_SCRIPT",
35 help="The path of the script to install monitoring script")
36 parser.add_argument("-c", "--CLIENT_CONFIG", default="",
37 help="The path of the config of monitoring client")
38 parser.add_argument("-p", "--POD_DISCRIPTOR", default="/tmp/pod.yaml",
39 help="The path of pod discrition file")
40 args = parser.parse_args()
42 INSTALLERS = ['apex', 'compass']
43 if args.INSTALLER_TYPE not in INSTALLERS:
44 raise Exception("The installer is not supported.")
45 if not args.INSTALlATION_SCRIPT:
46 raise Exception("Must specify the client installation script path!")
48 if "barometer" in args.INSTALlATION_SCRIPT.lower():
49 CONFIG_FILE = "/etc/barometer_config/barometer_client.conf"
50 CONFIG_DIR = "barometer_config"
51 INSTALlATION_SCRIPT = "/etc/barometer_config/install.sh"
52 elif "collectd" in args.INSTALlATION_SCRIPT.lower():
53 CONFIG_FILE = "/etc/collectd_config/collectd_client.conf"
54 CONFIG_DIR = "collectd_config"
55 INSTALlATION_SCRIPT = "/etc/collectd_config/install.sh"
56 elif "cadvisor" in args.INSTALlATION_SCRIPT.lower():
57 CONFIG_DIR = "cadvisor_config"
58 INSTALlATION_SCRIPT = "/etc/cadvisor_config/install.sh"
60 raise Exception("The monitor client is not supported")
64 with open(args.POD_DISCRIPTOR) as f:
65 dataMap = yaml.safe_load(f)
68 if (y['role'].lower() == 'controller') or (
69 y['role'].lower() == 'compute'):
72 pwd = str(y['password'])
73 idkey = str(y['key_filename'])
76 ssh_d = ssh.SSH(user, host=ip, password=pwd)
79 ssh_d = ssh.SSH(user, host=ip, key_filename=idkey)
80 status, stdout, stderr = ssh_d.execute(
81 "cd /etc && mkdir " + CONFIG_DIR
85 "Command: \"mkdir {}\".format(CONFIG_DIR) failed.")
86 logger.info(stdout.splitlines())
87 if args.CLIENT_CONFIG:
88 with open(args.CLIENT_CONFIG) as stdin_file:
89 ssh_d.run("cat > " + CONFIG_FILE,
91 with open(args.INSTALlATION_SCRIPT) as stdin_file:
92 ssh_d.run("cat > " + INSTALlATION_SCRIPT,
96 if 'ubuntu' in u.lower():
99 if NODE_OS == 'ubuntu':
100 status, stdout, stderr = ssh_d.execute(
101 "sudo apt-get install -y docker.io"
104 status, stdout, stderr = ssh_d.execute(
105 "sudo yum install -y docker-io"
109 "Command for installing docker failed.")
110 logger.info(stdout.splitlines())
113 "cd /etc/{}/ && bash ./install.sh".format(CONFIG_DIR)
117 if __name__ == '__main__':