1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
##############################################################################
# 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]:
print("Installing {} in: {}".format(INSTALlATION_SCRIPT, y))
pwd = idkey = ''
if (y['role'].lower() == 'controller') or (
y['role'].lower() == 'compute'):
ip = str(y['ip'])
user = str(y['user'])
if 'password' in y.keys():
pwd = str(y['password'])
if 'key_filename' in y.keys():
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 && if [ ! -d " + CONFIG_DIR +
" ]; then sudo mkdir " + CONFIG_DIR + "; fi"
)
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("sudo sh -c \"cat > " + CONFIG_FILE +
"\"",
stdin=stdin_file)
with open(args.INSTALlATION_SCRIPT) as stdin_file:
ssh_d.run("sudo sh -c \"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 service docker start"
)
if status:
raise Exception(
"Command for installing docker failed.")
logger.info(stdout.splitlines())
ssh_d.run(
"cd /etc/{}/ && bash ./install.sh".format(CONFIG_DIR),
raise_on_error=False
)
if __name__ == '__main__':
main()
|