summaryrefslogtreecommitdiffstats
path: root/monitor/uninstall.py
blob: 263517220d0cc56687eecd7b0b53d6300988d536 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
##############################################################################
# Copyright (c) 2018 Huawei Tech and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

import logging
import yaml
import os
import utils.infra_setup.passwordless_SSH.ssh as ssh

LOG = logging.getLogger(__name__)
DEL_DOCKER_SCRIPT = "/home/opnfv/bottlenecks/docker/docker_cleanup.sh"


def ssh_del_docker(docker_name):
    with open('/tmp/pod.yaml') as f:
        dataMap = yaml.safe_load(f)
        for x in dataMap:
            for y in dataMap[x]:
                if (y['role'] == 'Controller') or (y['role'] == 'Compute'):
                    ip = str(y['ip'])
                    user = str(y['user'])
                    pwd = str(y['password'])
                    ssh_d = ssh.SSH(user, host=ip, password=pwd)

                    status, stdout, stderr = ssh_d.execute(
                        "cd /etc"
                    )
                    with open(DEL_DOCKER_SCRIPT) as stdin_file:
                        ssh_d.run("cat > /etc/docker_cleanup.sh",
                                  stdin=stdin_file)

                    ssh_d.run("cd /etc/ && bash ./docker_cleanup.sh -d " +
                              docker_name)


def local_del_docker(docker_name):
        os.system('bash ' + DEL_DOCKER_SCRIPT + ' -d ' + docker_name)


ssh_del_docker('cadvisor')
ssh_del_docker('barometer')

local_del_docker('prometheus')
local_del_docker('cadvisor')
local_del_docker('barometer')
local_del_docker('grafana')
local_del_docker('collectd')
local_del_docker('openstack-exporter')