ce_static_route: fix some bugs. (#58251)
* 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.
This commit is contained in:
parent
442d275ae3
commit
bb33c922f7
1 changed files with 21 additions and 5 deletions
|
@ -274,10 +274,24 @@ def is_valid_v6addr(addr):
|
||||||
"""check if ipv6 addr is valid"""
|
"""check if ipv6 addr is valid"""
|
||||||
if addr.find(':') != -1:
|
if addr.find(':') != -1:
|
||||||
addr_list = addr.split(':')
|
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
|
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
|
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 True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -407,7 +421,7 @@ class StaticRoute(object):
|
||||||
if int(each_num) > 255:
|
if int(each_num) > 255:
|
||||||
return False
|
return False
|
||||||
byte_len = 8
|
byte_len = 8
|
||||||
ip_len = int(self.mask) / byte_len
|
ip_len = int(self.mask) // byte_len
|
||||||
ip_bit = int(self.mask) % byte_len
|
ip_bit = int(self.mask) % byte_len
|
||||||
else:
|
else:
|
||||||
if self.prefix.find(':') == -1:
|
if self.prefix.find(':') == -1:
|
||||||
|
@ -422,7 +436,7 @@ class StaticRoute(object):
|
||||||
if length > 6:
|
if length > 6:
|
||||||
return False
|
return False
|
||||||
byte_len = 16
|
byte_len = 16
|
||||||
ip_len = int(self.mask) / byte_len
|
ip_len = int(self.mask) // byte_len
|
||||||
ip_bit = int(self.mask) % byte_len
|
ip_bit = int(self.mask) % byte_len
|
||||||
|
|
||||||
if self.aftype == "v4":
|
if self.aftype == "v4":
|
||||||
|
@ -571,7 +585,7 @@ class StaticRoute(object):
|
||||||
replace('xmlns="http://www.huawei.com/netconf/vrp"', "")
|
replace('xmlns="http://www.huawei.com/netconf/vrp"', "")
|
||||||
root = ElementTree.fromstring(xml_str)
|
root = ElementTree.fromstring(xml_str)
|
||||||
static_routes = root.findall(
|
static_routes = root.findall(
|
||||||
"data/staticrt/staticrtbase/srRoutes/srRoute")
|
"staticrt/staticrtbase/srRoutes/srRoute")
|
||||||
|
|
||||||
if static_routes:
|
if static_routes:
|
||||||
for static_route in static_routes:
|
for static_route in static_routes:
|
||||||
|
@ -763,6 +777,8 @@ class StaticRoute(object):
|
||||||
|
|
||||||
self.get_static_route(self.state)
|
self.get_static_route(self.state)
|
||||||
self.end_state['sroute'] = self.static_routes_info["sroute"]
|
self.end_state['sroute'] = self.static_routes_info["sroute"]
|
||||||
|
if self.end_state == self.existing:
|
||||||
|
self.changed = False
|
||||||
|
|
||||||
def work(self):
|
def work(self):
|
||||||
"""worker"""
|
"""worker"""
|
||||||
|
|
Loading…
Reference in a new issue