6dd70676f6bb709a314916ecbc02cb06c38f74d7
[bottlenecks.git] / monitor / automate_collectd_client.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Tech and others.
3 #
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 ##############################################################################
9
10 import logging
11 import sys
12 import yaml
13 sys.path.insert(0, '/home/opnfv/bottlenecks/utils/infra_setup/passwordless_SSH/')
14 import ssh
15
16 logger = logging.getLogger(__name__)
17 with open('/tmp/pod.yaml') as f:
18     dataMap = yaml.safe_load(f)
19     for x in dataMap:
20         for y in dataMap[x]:
21             if (y['role']=='Controller') or (y['role']=='Compute'):
22                 ip = str(y['ip'])
23                 user = str(y['user'])
24                 pwd = str(y['password'])
25                 ssh_d = ssh.SSH(user, host= ip, password= pwd)
26                 status, stdout, stderr = ssh_d.execute("cd /etc && mkdir collectd-config")
27                 if status:
28                     raise Exception("Command failed with non-zero status.")
29                     logger.info(stdout.splitlines())
30                 with open("/home/opnfv/bottlenecks/monitor/install-collectd-client.sh") as stdin_file:
31                     ssh_d.run("cat > /etc/collectd-config/install.sh", stdin=stdin_file)
32                 with open("/home/opnfv/bottlenecks/monitor/config/collectd-client.conf") as stdin_file:
33                     ssh_d.run("cat > /etc/collectd-config/collectd.conf", stdin=stdin_file)
34                 status, stdout, stderr = ssh_d.execute("sudo apt-get install docker.io")
35                 if status:
36                     raise Exception("Command for installing docker failed.")
37                     logger.info(stdout.splitlines())
38                 ssh_d.run("cd /etc/collectd-config/ && bash ./install.sh")