OpenIxia / IxNetwork

A central location for IxNetwork sample scripts and utilities. Please also visit http://openixia.com
MIT License
50 stars 59 forks source link

Modification for getTopologyObjAndDeviceGroupObjByPortName #75

Closed NickKeating closed 5 years ago

NickKeating commented 5 years ago

I have made the following changes to getTopologyObjAndDeviceGroupObjByPortName function in IxNetRestApiProtocol.py within my local environment.

I need my NextGen topologies most of the time to resemble something similar to the picture below. The current implementation does not account for Daisy chained device groups (i.e. where connected to Bundle interfaces on the network elements) or where there are multiple device groups within a single topology.

I am not sure if this is a usual implementation for most users but sharing for informative purposes.

diff --git a/RestApi/Python/Modules/IxNetRestApiProtocol.py b/RestApi/Python/Modules/IxNetRestApiProtocol.py
index ff2157d..f88fa40 100644
--- a/RestApi/Python/Modules/IxNetRestApiProtocol.py
+++ b/RestApi/Python/Modules/IxNetRestApiProtocol.py
@@ -3012,10 +3012,15 @@ class Protocol(object):
             topologyObj = eachTopology['links'][0]['href']
             vportList = eachTopology['ports']
             response = self.ixnObj.get(self.ixnObj.httpHeader + topologyObj + '/deviceGroup')
+            response2 = self.ixnObj.get(self.ixnObj.httpHeader + topologyObj + '/deviceGroup/1/deviceGroup')

             deviceGroupList = []
-            for eachDeviceGroup in response.json()[0]['links']:
-                deviceGroupObj = eachDeviceGroup['href']
+            for eachDeviceGroup in response.json():
+                deviceGroupObj = eachDeviceGroup['links'][0]['href']
+                deviceGroupList.append(deviceGroupObj)
+
+            for eachDeviceGroup in response2.json():
+                deviceGroupObj = eachDeviceGroup['links'][0]['href']
                 deviceGroupList.append(deviceGroupObj)

             for eachVport in vportList:

NegGen Topology

Thanks, /Nick

hubertgee commented 5 years ago

Hi Nick,

Please get the updated module IxNetRestApiProtocol.py. I enhanced it to dynamically get inner device group also.

Hubert

NickKeating commented 5 years ago

Hi Nick,

Please get the updated module IxNetRestApiProtocol.py. I enhanced it to dynamically get inner device group also.

Hubert

Hi Hubert,

Thanks for that.

I hit the same issue yesterday in the getEndpointObjByDeviceGroupName function. I have put the messy little workaround below in my environment to workaround.

@@ -3829,7 +3834,9 @@ class Protocol(object):
             topologyObj = response.json()['links'][0]['href']
             print('topoObj:', topologyObj)
             response = self.ixnObj.get(topology+'/deviceGroup', silentMode=False)
+            response2 = self.ixnObj.get(topology+'/deviceGroup/1/deviceGroup', silentMode=False)
             deviceGroupList = ['%s/%s/%s' % (topology, 'deviceGroup', str(i["id"])) for i in response.json()]
+            deviceGroupList.extend('%s/%s/%s' % (topology, 'deviceGroup/1/deviceGroup', str(i["id"])) for i in response2.json())

             for deviceGroup in deviceGroupList:
                 deviceGroupObj = '/api' + deviceGroup.split('/api')[1]

/Nick

hubertgee commented 5 years ago

Hi Nick,

I enhanced getEndpointObjByDeviceGroupName() also. Get the updated module.

We no longer put any more energy into the library that you’re using. Do you know about our RestPy library? If you don’t, I highly recommend you use this library. This is a superior library to use for automating IxNetwork over the library that you’re using. The one you’re using is our original rest api library. After a while, it doesn’t scale. Somebody has to create new api python classes, parameters, etc. RestPy has all the APIs and all of each API’s attributes. You could query for any object by names. It’s a complete automation library. Just about all of our customers moved on to use RestPy.

Overview: https://www.openixia.com/tutorials?subject=ixNetwork/restApi&page=restPy.html

RestPy sample scripts: https://github.com/OpenIxia/IxNetwork/tree/master/RestPy/SampleScripts

BGP sample script: https://github.com/OpenIxia/IxNetwork/blob/master/RestPy/SampleScripts/bgpNgpf.py

Hubert Gee

From: Nick Keating notifications@github.com Sent: Thursday, October 17, 2019 3:08 PM To: OpenIxia/IxNetwork IxNetwork@noreply.github.com Cc: Hubert Gee hubert.gee@keysight.com; State change state_change@noreply.github.com Subject: Re: [OpenIxia/IxNetwork] Modification for getTopologyObjAndDeviceGroupObjByPortName (#75)

[EXTERNAL]

Hi Nick,

Please get the updated module IxNetRestApiProtocol.py. I enhanced it to dynamically get inner device group also.

Hubert

Hi Hubert,

Thanks for that.

I hit the same issue yesterday in the getEndpointObjByDeviceGroupName function. I have put the messy little workaround below in my environment to workaround.

@@ -3829,7 +3834,9 @@ class Protocol(object):

         topologyObj = response.json()['links'][0]['href']

         print('topoObj:', topologyObj)

         response = self.ixnObj.get(topology+'/deviceGroup', silentMode=False)

/Nick

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/OpenIxia/IxNetwork/issues/75?email_source=notifications&email_token=AINVQX7C4IYGCSTNJYDE7ULQPDO4PA5CNFSM4JBSGYMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBRVUCQ*issuecomment-543382026__;Iw!49nWKsucTI8wPg!x6bcaSbnAyqD0vVFYG7GepHSgr-BNMW2--tmgH_4ohOLaz7fhZMiXC5ugWb_OfVYUqg$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AINVQX4P3WTUZKRBW55YYZLQPDO4PANCNFSM4JBSGYMA__;!49nWKsucTI8wPg!x6bcaSbnAyqD0vVFYG7GepHSgr-BNMW2--tmgH_4ohOLaz7fhZMiXC5ugWb_zsUvs8w$.

NickKeating commented 5 years ago

Hi Hubert,

Thanks again for your help. I am aware of the RestPy module but from my understanding running version 8.5 is a requirement to use it? Is this the case or have I misunderstood?

The lab I work in has 16 IXIA Chassis which makes the software upgrade process a massive job for the environment team. Unfortunately it looks like the 8.5 upgrade across all the infrastructure is still a while off so I am stuck using version 8.40 until it is completed.

Thanks again for the quick turn around, RestPy info and for letting me know this library isn't maintained much anymore, I will keep the modifications I need local.

/Nick

hubertgee commented 5 years ago

Hi Nick,

Thanks for explaining. Correct. RestPy requires 8.50 minimum. And on our latest 9.0 release, the Linux API server includes a web UI that reflects the Windows IxNetwork GUI. When your team is ready to upgrade, upgrade to 9.0 and start thinking about migrating your scripts to using RestPy. You will enjoy automating with RestPy a lot more.

Hubert Gee

From: Nick Keating notifications@github.com Sent: Thursday, October 17, 2019 7:19 PM To: OpenIxia/IxNetwork IxNetwork@noreply.github.com Cc: Hubert Gee hubert.gee@keysight.com; State change state_change@noreply.github.com Subject: Re: [OpenIxia/IxNetwork] Modification for getTopologyObjAndDeviceGroupObjByPortName (#75)

[EXTERNAL]

Hi Hubert,

Thanks again for your help. I am aware of the RestPy module but from my understanding running version 8.5 is a requirement to use it? Is this the case or have I misunderstood?

The lab I work in has 16 IXIA Chassis which makes the software upgrade process a massive job for the environment team. Unfortunately it looks like the 8.5 upgrade across all the infrastructure is still a while off so I am stuck using version 8.40 until it is completed.

Thanks again for the quick turn around and thanks for letting me know this library isn't maintained much anymore, I will keep my modifications local.

/Nick

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/OpenIxia/IxNetwork/issues/75?email_source=notifications&email_token=AINVQX2BTUCYU7SJH25MYW3QPEMKPA5CNFSM4JBSGYMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBSHKHI*issuecomment-543454493__;Iw!49nWKsucTI8wPg!wVth0DYAd8R3XwOr44Aoi4PHk_vuPr6TFSu0hbE1AHWhhUlXXzLQE2Y5PLkPemj5fa0$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AINVQX3BNBU7K5Y6K4G6CJLQPEMKPANCNFSM4JBSGYMA__;!49nWKsucTI8wPg!wVth0DYAd8R3XwOr44Aoi4PHk_vuPr6TFSu0hbE1AHWhhUlXXzLQE2Y5PLkPq27n7KA$.