diff options
author | KingPoo <haojingbo@huawei.com> | 2016-11-09 22:39:01 -0500 |
---|---|---|
committer | KingPoo <haojingbo@huawei.com> | 2016-11-09 22:39:01 -0500 |
commit | 404fcf8f737f405da7fd2e61441dd20a57d63935 (patch) | |
tree | be6f2214774edb1c803303eede8e810028a7584d /util | |
parent | 5f7e61eb5419681359af3ff3e37fac2b771a5c08 (diff) |
autopep8 make py files more standard
Change-Id: Ibaa74a1f508b28548668e764d1860393caa356d4
Signed-off-by: KingPoo <haojingbo@huawei.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/check_valid.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/util/check_valid.py b/util/check_valid.py index 713a292f..ad5437f1 100644 --- a/util/check_valid.py +++ b/util/check_valid.py @@ -4,32 +4,40 @@ import yaml import sys import traceback + def init(file): - with open (file) as fd: + with open(file) as fd: try: return yaml.load(fd) except: traceback.print_exc() return None + def err_print(info): - print '\033[0;31m%s\033[0m' %info + print '\033[0;31m%s\033[0m' % info + def check_ip(ip): if not ip: return False - res=re.search("^(0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}(\/(\d|[1-2]\d|3[0-2]))?$",ip)!=None + res = re.search( + "^(0?\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}(\/(\d|[1-2]\d|3[0-2]))?$", + ip) is not None return res + def check_mac(mac): if not mac: return False - res=re.search("^([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}$",mac)!=None + res = re.search("^([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}$", mac) is not None return res + def check_network(network): for i in network.get('ip_settings'): - if not (check_ip(i['cidr']) and check_ip(i['ip_ranges'][0][0]) and check_ip(i['ip_ranges'][0][1])): + if not (check_ip(i['cidr']) and check_ip( + i['ip_ranges'][0][0]) and check_ip(i['ip_ranges'][0][1])): return False if i['name'] == 'external' and not check_ip(i['gw']): return False @@ -54,10 +62,12 @@ def check_network(network): return True + def check_dha(dha): if dha['TYPE'] == 'baremetal': for i in dha['hosts']: - if not (check_mac(i['mac']) and check_mac(i['interfaces'][0]['eth1']) and check_ip(i['ipmiIp'])): + if not (check_mac(i['mac']) and check_mac( + i['interfaces'][0]['eth1']) and check_ip(i['ipmiIp'])): return False return True |