@ -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
@ -407,7 +421,7 @@ class StaticRoute(object):
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 :
@ -422,7 +436,7 @@ class StaticRoute(object):
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 " :
@ -571,7 +585,7 @@ class StaticRoute(object):
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 :
@ -763,6 +777,8 @@ class StaticRoute(object):
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 """