Parse Device region field in Minigraph (#4486)
This commit is contained in:
parent
bd370fd2b6
commit
3c92bc02cd
@ -419,6 +419,7 @@ def parse_meta(meta, hname):
|
||||
mgmt_routes = []
|
||||
erspan_dst = []
|
||||
deployment_id = None
|
||||
region = None
|
||||
device_metas = meta.find(str(QName(ns, "Devices")))
|
||||
for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))):
|
||||
if device.find(str(QName(ns1, "Name"))).text.lower() == hname.lower():
|
||||
@ -441,7 +442,9 @@ def parse_meta(meta, hname):
|
||||
erspan_dst = value_group
|
||||
elif name == "DeploymentId":
|
||||
deployment_id = value
|
||||
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id
|
||||
elif name == "Region":
|
||||
region = value
|
||||
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region
|
||||
|
||||
def parse_deviceinfo(meta, hwsku):
|
||||
port_speeds = {}
|
||||
@ -599,6 +602,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
|
||||
erspan_dst = []
|
||||
bgp_peers_with_range = None
|
||||
deployment_id = None
|
||||
region = None
|
||||
|
||||
hwsku_qn = QName(ns, "HwSku")
|
||||
hostname_qn = QName(ns, "Hostname")
|
||||
@ -623,7 +627,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
|
||||
elif child.tag == str(QName(ns, "UngDec")):
|
||||
(u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname)
|
||||
elif child.tag == str(QName(ns, "MetadataDeclaration")):
|
||||
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname)
|
||||
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region) = parse_meta(child, hostname)
|
||||
elif child.tag == str(QName(ns, "DeviceInfos")):
|
||||
(port_speeds_default, port_descriptions) = parse_deviceinfo(child, hwsku)
|
||||
|
||||
@ -632,6 +636,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
|
||||
results['DEVICE_METADATA'] = {'localhost': {
|
||||
'bgp_asn': bgp_asn,
|
||||
'deployment_id': deployment_id,
|
||||
'region': region,
|
||||
'docker_routing_config_mode': docker_routing_config_mode,
|
||||
'hostname': hostname,
|
||||
'hwsku': hwsku,
|
||||
|
@ -215,6 +215,11 @@
|
||||
<a:Reference i:nil="true"/>
|
||||
<a:Value>1</a:Value>
|
||||
</a:DeviceProperty>
|
||||
<a:DeviceProperty>
|
||||
<a:Name>Region</a:Name>
|
||||
<a:Reference i:nil="true"/>
|
||||
<a:Value>usfoo</a:Value>
|
||||
</a:DeviceProperty>
|
||||
<a:DeviceProperty>
|
||||
<a:Name>ErspanDestinationIpv4</a:Name>
|
||||
<a:Reference i:nil="true"/>
|
||||
|
@ -53,6 +53,11 @@ class TestCfgGen(TestCase):
|
||||
output = self.run_script(argument)
|
||||
self.assertEqual(output.strip(), 'Force10-Z9100')
|
||||
|
||||
def test_minigraph_region(self):
|
||||
argument = '-v "DEVICE_METADATA[\'localhost\'][\'region\']" -m "' + self.sample_graph_metadata + '"'
|
||||
output = self.run_script(argument)
|
||||
self.assertEqual(output.strip(), 'usfoo')
|
||||
|
||||
def test_print_data(self):
|
||||
argument = '-m "' + self.sample_graph + '" --print-data'
|
||||
output = self.run_script(argument)
|
||||
|
Loading…
Reference in New Issue
Block a user