Comments (9)
"""Demonstrates how to get an object given an href
The TestPlatform.Sessions class has a helper method that assists in returning an object given a valid href
"""
from ixnetwork_restpy.testplatform.testplatform import TestPlatform
test_platform = TestPlatform('127.0.0.1', rest_port=11009)
test_platform.Trace = 'request_response'
sessions = test_platform.Sessions.add()
ixnetwork = sessions.Ixnetwork
ixnetwork.NewConfig()
vport = ixnetwork.Vport.add()
""" the following code is an attempt to get the object that the vport is connected to
in this case the href that is returned from the .ConnectedTo property is null so the object returned is None
if the vport was connected to an actual hardware port a valid /availableHardware/chassis/card/port object reference
would be returned from the Vport.ConnectedTo property
this reference is then used to get an actual object
"""
hardware_port = sessions.GetObjectFromHref(vport.ConnectedTo)
assert(hardware_port is None)
from ixnetwork.
But what if the use case is to get the actual session handle itself? Here you have an object under sessions. But I want to get the session object itself.
from ixnetwork.
There is a property called .href on every object that is the 'handle' of the object.
This is a valid href for the object - if you have the object why do you need to get the href to get the object - you have the object. Please post some code that outlines what you are trying to solve.
from ixnetwork.
There could me multiple reasons for a lookup by href One of them is below.
Say I have multiple sessions open on the linux api server. I have the href (string) to the session that has certain configuration. I can get back into a session by just retrieving the object using the href.
Note that this is not all done within one script, so I would not have the initial session object created in the first run where the session was added.
This and many more use cases are there where you would need a lookup by href.
from ixnetwork.
There is no need to find a session by 'href', the actual way to do it is to use the 'id' which is part of the .find method. The entire library is based around the find method. Sessions.find(Id=x) is what you should be using.
from ixnetwork.
Thanks. This helps for the session use case. Will use this from now
from ixnetwork.
For sessions Id is a good way to find what you want. for other types of objects, other properties might be better to find, for example Topology.find(Name="Topo1") is also a good way to use the find method.
The documentation will show you all the properties that can be used to find, and i believe they can be used in combination to be more and more specific.
Topology.find(DescriptiveName=None, Errors=None, Name=None, Note=None, PortCount=None, Ports=None, PortsStateCount=None, Status=None, Vports=None)
from ixnetwork.
Not to extend this thread, but I think it would be good to add code for an href lookup across all Objects. This really helps because it seems like the href is the only fully resolved named property that accurately describes and object. i.e. an href is always unique across all objects across all classes.
from ixnetwork.
There is no need to find a session by 'href', the actual way to do it is to use the 'id' which is part of the .find method. The entire library is based around the find method. Sessions.find(Id=x) is what you should be using.
Has anyone tried this? I can't seem to get the ixnetwork object or any other object instance using this
session = testPlatform.Sessions.find(Id='17')
2019-03-05 00:04:34 [ixnetwork_restpy.connection] [DEBUG] GET https://10.23.239.233:443/api/v1/sessions None
2019-03-05 00:04:34 [ixnetwork_restpy.connection] [DEBUG] 200 OK
ixNetwork = session.GetObjectFromHref('/api/v1/sessions/17/ixnetwork')
ixNetwork
ixNetwork = session.GetObjectFromHref(href = '/api/v1/sessions/17/ixnetwork')
ixNetwork
r = session.GetObjectFromHref(href = '/api/v1/sessions/17/ixnetwork/topology')
r
from ixnetwork.
Related Issues (20)
- How to read vport object HOT 3
- Any timeout for one session HOT 3
- RestPy: CsvSnapshot.update doesn't work HOT 3
- What's sdmPort used for? HOT 1
- method startQuickTest in IxNetRestApiQuickTest.py not work HOT 1
- Bug in function getTrafficItemPktHeaderStackObj HOT 1
- Loadconfig.py not able to find the rfcquicktest object/href HOT 6
- TakeSnapshotPy method used by concurrent sessions can overwrite results
- Cannot start single traffic item HOT 1
- StatViewAssistant - Statistics view does not exist
- ixnetwork-restpy 1.1.5 with IxNetwork 9.20 error with InstanceId is not a string for field stack operation HOT 3
- loadQuickTest.py doesn't download all CSV files properly
- Packet capture does not capture IGMP related data HOT 1
- Incorrect snapshot file at debugging session HOT 1
- Ethernet destination field cannot be updated HOT 2
- prefixAddrStep not available to configNetworkGroup() in IxNetRestApiProtocol.py
- Create a QuickTest without configuration file (ixncfg or json)
- Route range endpoint not selected in traffic destinations HOT 4
- Using IxNetwork RestPy
- VLAN HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ixnetwork.