Style-check for monitoring scripts
[bottlenecks.git] / monitor / automate_cadvisor_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 yaml
12 import utils.infra_setup.passwordless_SSH.ssh as ssh
13
14 logger = logging.getLogger(__name__)
15 cadvisor_install_sh = "/home/opnfv/bottlenecks/monitor/cadvisor_install.sh"
16
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(
27                     "cd /etc && mkdir cadvisor_config"
28                 )
29                 if status:
30                     raise Exception("Command failed with non-zero status.")
31                     logger.info(stdout.splitlines())
32                 with open(cadvisor_install_sh) as stdin_file:
33                     ssh_d.run("cat > /etc/cadvisor_config/install.sh",
34                               stdin=stdin_file)
35                 status, stdout, stderr = ssh_d.execute(
36                     "sudo apt-get install docker.io"
37                 )
38                 if status:
39                     raise Exception("Command for installing docker failed.")
40                     logger.info(stdout.splitlines())
41                 ssh_d.run("cd /etc/cadvisor_config/ && bash ./install.sh")