Restructure monitoring scripts
[bottlenecks.git] / monitor / dispatch / 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_client_install_sh =\
16     "/home/opnfv/bottlenecks/monitor/dispatch/install_cadvisor_client.sh"
17
18 with open('/tmp/pod.yaml') as f:
19     dataMap = yaml.safe_load(f)
20     for x in dataMap:
21         for y in dataMap[x]:
22             if (y['role'] == 'Controller') or (y['role'] == 'Compute'):
23                 ip = str(y['ip'])
24                 user = str(y['user'])
25                 pwd = str(y['password'])
26                 ssh_d = ssh.SSH(user, host=ip, password=pwd)
27                 status, stdout, stderr = ssh_d.execute(
28                     "cd /etc && mkdir cadvisor_config"
29                 )
30                 if status:
31                     print Exception(
32                         "Command: \"mkdir cadvisor_config\" failed.")
33                     logger.info(stdout.splitlines())
34                 with open(cadvisor_client_install_sh) as stdin_file:
35                     ssh_d.run("cat > /etc/cadvisor_config/install.sh",
36                               stdin=stdin_file)
37                 status, stdout, stderr = ssh_d.execute(
38                     "sudo apt-get install -y docker.io"
39                 )
40                 if status:
41                     raise Exception("Command for installing docker failed.")
42                     logger.info(stdout.splitlines())
43                 ssh_d.run("cd /etc/cadvisor_config/ && bash ./install.sh")