bug-fix: node-exporter on centos7 isolated with host net
[bottlenecks.git] / monitor / uninstall.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 yaml
12 import os
13 import utils.infra_setup.passwordless_SSH.ssh as ssh
14
15 LOG = logging.getLogger(__name__)
16 DEL_DOCKER_SCRIPT = "/home/opnfv/bottlenecks/docker/docker_cleanup.sh"
17
18
19 def ssh_del_docker(docker_name):
20     with open('/tmp/pod.yaml') as f:
21         dataMap = yaml.safe_load(f)
22         for x in dataMap:
23             for y in dataMap[x]:
24                 if (y['role'] == 'Controller') or (y['role'] == 'Compute'):
25                     ip = str(y['ip'])
26                     user = str(y['user'])
27                     pwd = str(y['password'])
28                     ssh_d = ssh.SSH(user, host=ip, password=pwd)
29
30                     status, stdout, stderr = ssh_d.execute(
31                         "cd /etc"
32                     )
33                     with open(DEL_DOCKER_SCRIPT) as stdin_file:
34                         ssh_d.run("cat > /etc/docker_cleanup.sh",
35                                   stdin=stdin_file)
36
37                     ssh_d.run("cd /etc/ && bash ./docker_cleanup.sh -d " +
38                               docker_name)
39
40
41 def local_del_docker(docker_name):
42         os.system('bash ' + DEL_DOCKER_SCRIPT + ' -d ' + docker_name)
43
44
45 ssh_del_docker('cadvisor')
46 ssh_del_docker('barometer')
47
48 local_del_docker('prometheus')
49 local_del_docker('cadvisor')
50 local_del_docker('barometer')
51 local_del_docker('grafana')
52 local_del_docker('collectd')