7bbfa70195a74b895e1c14d6f73486517f4d9248
[bottlenecks.git] / monitor / barometer_automated_client_install.py
1 ##############################################################################
2 # Copyright (c) 2018 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 barometer-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/barometer_client.conf") as stdin_file:
31                     ssh_d.run("cat > /etc/barometer-config/barometer_client_collectd.conf", stdin=stdin_file)
32
33                 with open("/home/opnfv/bottlenecks/monitor/barometer_install_client.sh") as stdin_file:
34                     ssh_d.run("cat > /etc/barometer-config/install.sh", stdin=stdin_file)
35
36                 ssh_d.run("cd /etc/barometer-config/ && bash ./install.sh")