Skip to content

Commit

Permalink
ce_static_route: fix some bugs. (ansible#58251)
Browse files Browse the repository at this point in the history
* add a util function to ce.

* add a util function to ce.

* update to fix bugs for ce_static_route

* update to fix bugs for ce_static_route

* update to fix bugs for ce_static_route

* update

* update for shippable.
  • Loading branch information
YuandongXu authored and agowa committed Jun 30, 2019
1 parent 2f46c73 commit 0bbc262
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions lib/ansible/modules/network/cloudengine/ce_static_route.py
Expand Up @@ -274,10 +274,24 @@ def is_valid_v6addr(addr):
"""check if ipv6 addr is valid"""
if addr.find(':') != -1:
addr_list = addr.split(':')
if len(addr_list) > 6:
# The IPv6 binary system has a length of 128 bits and is grouped by 16 bits.
# Each group is separated by a colon ":" and can be divided into 8 groups, each group being represented by 4 hexadecimal
if len(addr_list) > 8:
return False
if addr_list[1] != "":
# You can use a double colon "::" to represent a group of 0 or more consecutive 0s, but only once.
if addr.count('::') > 1:
return False
# if do not use '::', the length of address should not be less than 8.
if addr.count('::') == 0 and len(addr_list) < 8:
return False
for group in addr_list:
if group.strip() == '':
continue
try:
# Each group is represented in 4-digit hexadecimal
int(group, base=16)
except ValueError:
return False
return True
return False

Expand Down Expand Up @@ -407,7 +421,7 @@ def convert_ip_prefix(self):
if int(each_num) > 255:
return False
byte_len = 8
ip_len = int(self.mask) / byte_len
ip_len = int(self.mask) // byte_len
ip_bit = int(self.mask) % byte_len
else:
if self.prefix.find(':') == -1:
Expand All @@ -422,7 +436,7 @@ def convert_ip_prefix(self):
if length > 6:
return False
byte_len = 16
ip_len = int(self.mask) / byte_len
ip_len = int(self.mask) // byte_len
ip_bit = int(self.mask) % byte_len

if self.aftype == "v4":
Expand Down Expand Up @@ -571,7 +585,7 @@ def get_static_route(self, state):
replace('xmlns="http://www.huawei.com/netconf/vrp"', "")
root = ElementTree.fromstring(xml_str)
static_routes = root.findall(
"data/staticrt/staticrtbase/srRoutes/srRoute")
"staticrt/staticrtbase/srRoutes/srRoute")

if static_routes:
for static_route in static_routes:
Expand Down Expand Up @@ -763,6 +777,8 @@ def get_end_state(self):

self.get_static_route(self.state)
self.end_state['sroute'] = self.static_routes_info["sroute"]
if self.end_state == self.existing:
self.changed = False

def work(self):
"""worker"""
Expand Down

0 comments on commit 0bbc262

Please sign in to comment.