Giter Site home page Giter Site logo

Comments (9)

ajbalogh avatar ajbalogh commented on September 26, 2024

"""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.

muthvar1 avatar muthvar1 commented on September 26, 2024

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.

ajbalogh avatar ajbalogh commented on September 26, 2024

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.

muthvar1 avatar muthvar1 commented on September 26, 2024

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.

ajbalogh avatar ajbalogh commented on September 26, 2024

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.

muthvar1 avatar muthvar1 commented on September 26, 2024

Thanks. This helps for the session use case. Will use this from now

from ixnetwork.

whandjr avatar whandjr commented on September 26, 2024

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.

muthvar1 avatar muthvar1 commented on September 26, 2024

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.

muthvar1 avatar muthvar1 commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.