diff options
Diffstat (limited to 'monitor/dispatch')
-rw-r--r-- | monitor/dispatch/automate_barometer_client.py | 51 | ||||
-rw-r--r-- | monitor/dispatch/automate_cadvisor_client.py | 43 | ||||
-rw-r--r-- | monitor/dispatch/automate_collectd_client.py | 50 | ||||
-rw-r--r-- | monitor/dispatch/install_clients.py | 118 |
4 files changed, 118 insertions, 144 deletions
diff --git a/monitor/dispatch/automate_barometer_client.py b/monitor/dispatch/automate_barometer_client.py deleted file mode 100644 index 3a246028..00000000 --- a/monitor/dispatch/automate_barometer_client.py +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################## -# Copyright (c) 2018 Huawei Tech and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -import logging -import yaml -import utils.infra_setup.passwordless_SSH.ssh as ssh - -logger = logging.getLogger(__name__) -barometer_client_install_sh =\ - "/home/opnfv/bottlenecks/monitor/dispatch/install_barometer_client.sh" -barometer_client_install_conf =\ - "/home/opnfv/bottlenecks/monitor/config/barometer_client.conf" - -with open('/tmp/pod.yaml') as f: - dataMap = yaml.safe_load(f) - for x in dataMap: - for y in dataMap[x]: - if (y['role'] == 'Controller') or (y['role'] == 'Compute'): - ip = str(y['ip']) - user = str(y['user']) - pwd = str(y['password']) - ssh_d = ssh.SSH(user, host=ip, password=pwd) - status, stdout, stderr = ssh_d.execute( - "cd /etc && mkdir barometer_config" - ) - if status: - print Exception( - "Command: \"mkdir barometer_config\" failed.") - logger.info(stdout.splitlines()) - with open(barometer_client_install_conf) as stdin_file: - ssh_d.run("cat > /etc/barometer_config/\ -barometer_client.conf", - stdin=stdin_file) - with open(barometer_client_install_sh) as stdin_file: - ssh_d.run("cat > /etc/barometer_config/install.sh", - stdin=stdin_file) - - status, stdout, stderr = ssh_d.execute( - "sudo apt-get install -y docker.io" - ) - if status: - raise Exception("Command for installing docker failed.") - logger.info(stdout.splitlines()) - - ssh_d.run("cd /etc/barometer_config/ && bash ./install.sh") diff --git a/monitor/dispatch/automate_cadvisor_client.py b/monitor/dispatch/automate_cadvisor_client.py deleted file mode 100644 index 3a65ff1d..00000000 --- a/monitor/dispatch/automate_cadvisor_client.py +++ /dev/null @@ -1,43 +0,0 @@ -############################################################################## -# Copyright (c) 2017 Huawei Tech and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -import logging -import yaml -import utils.infra_setup.passwordless_SSH.ssh as ssh - -logger = logging.getLogger(__name__) -cadvisor_client_install_sh =\ - "/home/opnfv/bottlenecks/monitor/dispatch/install_cadvisor_client.sh" - -with open('/tmp/pod.yaml') as f: - dataMap = yaml.safe_load(f) - for x in dataMap: - for y in dataMap[x]: - if (y['role'] == 'Controller') or (y['role'] == 'Compute'): - ip = str(y['ip']) - user = str(y['user']) - pwd = str(y['password']) - ssh_d = ssh.SSH(user, host=ip, password=pwd) - status, stdout, stderr = ssh_d.execute( - "cd /etc && mkdir cadvisor_config" - ) - if status: - print Exception( - "Command: \"mkdir cadvisor_config\" failed.") - logger.info(stdout.splitlines()) - with open(cadvisor_client_install_sh) as stdin_file: - ssh_d.run("cat > /etc/cadvisor_config/install.sh", - stdin=stdin_file) - status, stdout, stderr = ssh_d.execute( - "sudo apt-get install -y docker.io" - ) - if status: - raise Exception("Command for installing docker failed.") - logger.info(stdout.splitlines()) - ssh_d.run("cd /etc/cadvisor_config/ && bash ./install.sh") diff --git a/monitor/dispatch/automate_collectd_client.py b/monitor/dispatch/automate_collectd_client.py deleted file mode 100644 index c4346e51..00000000 --- a/monitor/dispatch/automate_collectd_client.py +++ /dev/null @@ -1,50 +0,0 @@ -############################################################################## -# Copyright (c) 2017 Huawei Tech and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -import logging -import yaml -import utils.infra_setup.passwordless_SSH.ssh as ssh - -logger = logging.getLogger(__name__) -collectd_client_install_sh =\ - "/home/opnfv/bottlenecks/monitor/dispatch/install_collectd_client.sh" -collectd_client_install_conf =\ - "/home/opnfv/bottlenecks/monitor/config/collectd_client.conf" - -with open('/tmp/pod.yaml') as f: - dataMap = yaml.safe_load(f) - for x in dataMap: - for y in dataMap[x]: - if (y['role'] == 'Controller') or (y['role'] == 'Compute'): - ip = str(y['ip']) - user = str(y['user']) - pwd = str(y['password']) - ssh_d = ssh.SSH(user, host=ip, password=pwd) - status, stdout, stderr = ssh_d.execute( - "cd /etc && mkdir collectd_config" - ) - if status: - print Exception( - "Command: \"mkdir collectd_config\" failed.") - logger.info(stdout.splitlines()) - with open(collectd_client_install_sh) as stdin_file: - ssh_d.run("cat > /etc/collectd_config/install.sh", - stdin=stdin_file) - with open(collectd_client_install_conf) as stdin_file: - ssh_d.run( - "cat > /etc/collectd_config/collectd_client.conf", - stdin=stdin_file - ) - status, stdout, stderr = ssh_d.execute( - "sudo apt-get install -y docker.io" - ) - if status: - raise Exception("Command for installing docker failed.") - logger.info(stdout.splitlines()) - ssh_d.run("cd /etc/collectd_config/ && bash ./install.sh") diff --git a/monitor/dispatch/install_clients.py b/monitor/dispatch/install_clients.py new file mode 100644 index 00000000..ab7d0f5a --- /dev/null +++ b/monitor/dispatch/install_clients.py @@ -0,0 +1,118 @@ +############################################################################## +# Copyright (c) 2018 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +''' +Currently supported installers are Apex, Compass... +Supported monitoring tools are Cadvisor, Collectd, Barometer... +Carefully, do not change the path or name of the configuration files which +are hard coded for docker volume mapping. +''' +import os +import logging +import yaml +import utils.infra_setup.passwordless_SSH.ssh as ssh +import argparse + +logger = logging.getLogger(__name__) + +parser = argparse.ArgumentParser(description='Monitoring Clients Dispatcher') +parser.add_argument("-i", "--INSTALLER_TYPE", + help="The installer for the system under monitoring") +# Barometer config and installation files +# /home/opnfv/bottlenecks/monitor/dispatch/install_barometer_client.sh +# /home/opnfv/bottlenecks/monitor/config/barometer_client.conf +# Cadvisor installation file +# /home/opnfv/bottlenecks/monitor/dispatch/install_cadvisor_client.sh +# Collectd config and installation files +# /home/opnfv/bottlenecks/monitor/dispatch/install_collectd_client.sh +# /home/opnfv/bottlenecks/monitor/config/collectd_client.conf +parser.add_argument("-s", "--INSTALlATION_SCRIPT", + help="The path of the script to install monitoring script") +parser.add_argument("-c", "--CLIENT_CONFIG", default="", + help="The path of the config of monitoring client") +parser.add_argument("-p", "--POD_DISCRIPTOR", default="/tmp/pod.yaml", + help="The path of pod discrition file") +args = parser.parse_args() + +INSTALLERS = ['apex', 'compass'] +if args.INSTALLER_TYPE not in INSTALLERS: + raise Exception("The installer is not supported.") +if not args.INSTALlATION_SCRIPT: + raise Exception("Must specify the client installation script path!") + +if "barometer" in args.INSTALlATION_SCRIPT.lower(): + CONFIG_FILE = "/etc/barometer_config/barometer_client.conf" + CONFIG_DIR = "barometer_config" + INSTALlATION_SCRIPT = "/etc/barometer_config/install.sh" +elif "collectd" in args.INSTALlATION_SCRIPT.lower(): + CONFIG_FILE = "/etc/collectd_config/collectd_client.conf" + CONFIG_DIR = "collectd_config" + INSTALlATION_SCRIPT = "/etc/collectd_config/install.sh" +elif "cadvisor" in args.INSTALlATION_SCRIPT.lower(): + CONFIG_DIR = "cadvisor_config" + INSTALlATION_SCRIPT = "/etc/cadvisor_config/install.sh" +else: + raise Exception("The monitor client is not supported") + + +def main(): + with open(args.POD_DISCRIPTOR) as f: + dataMap = yaml.safe_load(f) + for x in dataMap: + for y in dataMap[x]: + if (y['role'].lower() == 'controller') or ( + y['role'].lower() == 'compute'): + ip = str(y['ip']) + user = str(y['user']) + pwd = str(y['password']) + idkey = str(y['key_filename']) + + if pwd: + ssh_d = ssh.SSH(user, host=ip, password=pwd) + elif idkey: + idkey = "/tmp/id_rsa" + ssh_d = ssh.SSH(user, host=ip, key_filename=idkey) + status, stdout, stderr = ssh_d.execute( + "cd /etc && mkdir " + CONFIG_DIR + ) + if status: + print Exception( + "Command: \"mkdir {}\".format(CONFIG_DIR) failed.") + logger.info(stdout.splitlines()) + if args.CLIENT_CONFIG: + with open(args.CLIENT_CONFIG) as stdin_file: + ssh_d.run("cat > " + CONFIG_FILE, + stdin=stdin_file) + with open(args.INSTALlATION_SCRIPT) as stdin_file: + ssh_d.run("cat > " + INSTALlATION_SCRIPT, + stdin=stdin_file) + + for u in os.uname(): + if 'ubuntu' in u.lower(): + NODE_OS = 'ubuntu' + break + if NODE_OS == 'ubuntu': + status, stdout, stderr = ssh_d.execute( + "sudo apt-get install -y docker.io" + ) + else: + status, stdout, stderr = ssh_d.execute( + "sudo yum install -y docker-io" + ) + if status: + raise Exception( + "Command for installing docker failed.") + logger.info(stdout.splitlines()) + + ssh_d.run( + "cd /etc/{}/ && bash ./install.sh".format(CONFIG_DIR) + ) + + +if __name__ == '__main__': + main() |