diff options
author | hu xinhui <xinhui_hu@foxmail.com> | 2017-08-30 15:36:13 +0800 |
---|---|---|
committer | hu xinhui <xinhui_hu@foxmail.com> | 2017-09-08 22:22:58 +0800 |
commit | 0d057d8e10fd5e29156516196ffec60ecb115087 (patch) | |
tree | cf0c2ca0caef922a1fd9e57f8c29173ba0f47aa3 /deploy/adapters/ansible/kubernetes/roles/setup-k8s-network/files/setup_networks/check_network.py | |
parent | acab17c36763b7679a6d761f438412e591347902 (diff) |
Add k8s support
JIRA: -
Add a new k8s scenario for compass
Change-Id: Ic5f58a6152315333684e4f2752aaa0d5d870d9ee
Signed-off-by: hu xinhui <xinhui_hu@foxmail.com>
Diffstat (limited to 'deploy/adapters/ansible/kubernetes/roles/setup-k8s-network/files/setup_networks/check_network.py')
-rw-r--r-- | deploy/adapters/ansible/kubernetes/roles/setup-k8s-network/files/setup_networks/check_network.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/deploy/adapters/ansible/kubernetes/roles/setup-k8s-network/files/setup_networks/check_network.py b/deploy/adapters/ansible/kubernetes/roles/setup-k8s-network/files/setup_networks/check_network.py new file mode 100644 index 00000000..ffdafcd3 --- /dev/null +++ b/deploy/adapters/ansible/kubernetes/roles/setup-k8s-network/files/setup_networks/check_network.py @@ -0,0 +1,70 @@ +############################################################################## +# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD 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 yaml +import sys +import subprocess + +import log as logging + +LOG = logging.getLogger("net-check") + + +def is_ip_reachable(ip): + cmd = "ping -c 2 %s" % ip + process = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + stderr=None, + shell=True) + + output = process.communicate()[0] + if " 0% packet loss" in output: + LOG.info("%s is reachable", ip) + elif "100% packet loss" in output: + LOG.error("%s is unreachable" % (ip)) + return False + else: + LOG.warn("%r", output) + + return True + + +def is_host_ips_reachable(settings): + external = settings["external"]["ip"] + external_gw = settings["external"]["gw"] + # storage = settings["storage"]["ip"] + mgmt = settings["mgmt"]["ip"] + + return is_ip_reachable(external) \ + and is_ip_reachable(external_gw) \ + and is_ip_reachable(mgmt) + + +def main(hostname, config): + LOG.info("host is %s", hostname) + + result = True + + for host, settings in config.iteritems(): + LOG.info("check %s network connectivity start", host) + result = result and is_host_ips_reachable(settings) + + if result: + LOG.info("All hosts ips are reachable") + else: + LOG.error("Some hosts ips are unreachable !!!") + sys.exit(-1) + +if __name__ == "__main__": + hostname = yaml.load(sys.argv[1]) + config = yaml.load(sys.argv[2]) + config.pop(hostname, None) + + main(hostname, config) |