Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return False
reqs = R(
['process_id',
'(?P.*)',
'sids',
'(?P.*)',
'index',
'(?P.*)',
'prefix',
'(.*)']
)
found = find([out], reqs, filter_=False, all_keys=True)
if found:
key_list = GroupKeys.group_keys(
reqs=reqs.args, ret_num={}, source=found, all_keys=True
)
unexpected_prefix = False
for v in key_list:
# Get current dictionary from filtered values
# Current process id
c_process_id = v.get('process_id')
# Current SID
c_sid = v.get('sid')
# Current index
c_index = v.get('index')
# sid_dict:
# {
"(?P.*)",
"address_family",
"(?P.*)",
"prefix",
"(?P.*)",
"nexthop",
"(?P.*)",
"outgoing_interface",
"(?P.*)",
"(?:.*)",
]
)
found = find([out], reqs, filter_=False, all_keys=True)
if found:
keys = GroupKeys.group_keys(
reqs=reqs.args, ret_num={}, source=found, all_keys=True
)
else:
log.error("No interface was found")
return None
interface = keys[0]["intf"]
return interface
except SchemaEmptyParserError:
return None
reqs = R(
[
"slot",
str(slot),
"(?P.*)",
"(?P.*)",
"state",
"(?P.*)",
]
)
found = find([out], reqs, filter_=False, all_keys=True)
if found:
keys = GroupKeys.group_keys(
reqs=reqs.args, ret_num={}, source=found, all_keys=True
)
return keys[0]["state"]
else:
return None
except (SchemaEmptyParserError, SubCommandFailure) as e:
return fans
reqs = R(
[
"slot",
"(?P.*)",
"sensor",
"(?P.*)",
"state",
"(?P.*)",
]
)
found = find([out], reqs, filter_=False, all_keys=True)
if found:
fans = GroupKeys.group_keys(
reqs=reqs.args, ret_num={}, source=found, all_keys=True
)
for fan in fans:
fan["speed"] = int(p.search(fan["state"]).groupdict()["speed"])
log.info(
"Found fan on {fan[slot]} with Speed {fan[speed]}%".format(fan=fan)
)
return fans
def _verify_finds_root_interface(ops, requirements, **kwargs):
'''Triggers in this file specified verify method. This is to check only 1 interface
change to root after change the priority to highest
'''
log.info(banner("check only One interface change to root for each vlan"))
ret = find([ops], R(requirements), filter_=False)
if not ret:
raise Exception('There is no Root interfaces after changing the priority')
group_keys = GroupKeys.group_keys(reqs=[requirements], ret_num={}, source=ret)
vlan_dict = {}
for item in group_keys:
vlan_dict.setdefault(item['vlan'], {}).setdefault(item['interface'], {})
for vlan in vlan_dict:
if len(vlan_dict[vlan].keys()) != 1:
raise Exception('Expect ONE Root interface for vlan {v} but got {i}'
.format(v=vlan, i=list(vlan_dict[vlan].keys())))
else:
log.info('Find ONE ROOT interface {i} for vlan {v}'
.format(i=list(vlan_dict[vlan].keys())[0], v=vlan))
try:
out = device.parse(cmd)
except Exception as e:
log.error("Failed to parse '{}':\n{}".format(cmd, e))
timeout.sleep()
continue
reqs = R(['vrf', '(.*)', 'address_family', '(.*)',
'instance', '(.*)', 'areas', '(.*)',
'database', 'lsa_types', '(.*)',
'lsas', '(.*)', 'ospfv2', 'body',
'opaque', 'extended_prefix_tlvs', '(.*)',
'sub_tlvs', '(.*)', 'flags', '(?P.*)'])
found = find([out], reqs, filter_=False, all_keys=True)
if found:
keys = GroupKeys.group_keys(reqs=reqs.args, ret_num={},
source=found, all_keys=True)
else:
log.error("Failed to get flags from ospf database with Link State ID: '{}'"
.format(lsa_id))
timeout.sleep()
continue
if len(keys) == 1:
flags = keys[0]['flags']
else:
log.error("Found multiple items {}, expected to have only one item"
.format(keys))
timeout.sleep()
continue
if has_flag:
'local_label', '(?P.*)',
'outgoing_label_or_vc', '(?P.*)',
'prefix_or_tunnel_id', '(?P.*)',
'outgoing_interface', '(?P.*)',
'next_hop', '(?P.*)'])
found3 = find([out3], reqs3, filter_=False, all_keys=True)
route_dict3 = {}
# eg: {'GigabitEthernet4': {
# "local_label": 16,
# "outgoing_label": "Pop Label",
# "prefix": "10.0.0.13-A",
# "interface": "GigabitEthernet4",
# "next_hop": "10.0.0.13"}}
if found3:
keys = GroupKeys.group_keys(reqs=reqs3.args, ret_num={},
source=found3, all_keys=True)
for item in keys:
route_dict3.update({item['interface']: item})
else:
log.error("Failed to get outgoing interface from '{}'".format(cmd3))
result = False
timeout.sleep()
continue
if len(route_dict1) != len(route_dict2) != len(route_dict3):
log.error("The number of routes are different in the 3 output")
result = False
timeout.sleep()
continue
for interface in route_dict1.keys():
cmd = 'show ip ospf interface {intf}'.format(intf=interface)
try:
out = device.parse(cmd)
except Exception as e:
log.error("Failed to parse '{cmd}': {e}".format(cmd=cmd, e=e))
return None
reqs = R(['vrf','(.*)',
'address_family','(.*)',
'instance','(.*)','areas','(.*)',
'interfaces','(.*)','teapp','(.*)',
'affinity','bits','(?P.*)'])
found = find([out], reqs, filter_=False, all_keys=True)
if found:
keys = GroupKeys.group_keys(reqs=reqs.args, ret_num={},
source=found, all_keys=True)
bits = keys[0]['bits']
log.info("Get affinity bits '{bits}' on {intf}".format(bits=bits, intf=interface))
return bits
else:
log.error("Failed to get affinity bits on {intf}".format(intf=interface))
return None
protocol_codes = '(.*)'
try:
out = device.parse(cmd)
except Exception as e:
log.error("Failed to parse '{}':\n{}".format(cmd, e))
return routes
reqs = R(['vrf', '(.*)',
'address_family', '(.*)',
'routes', '(?P.*)',
'source_protocol_codes', protocol_codes])
found = find([out], reqs, filter_=False, all_keys=True)
if found:
keys = GroupKeys.group_keys(reqs=reqs.args, ret_num={},
source=found, all_keys=True)
for route in keys:
routes.append(route['route'])
else:
log.error("Could not find any route with protocol_codes '{}'".\
format(protocol_codes))
return routes