Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read content of Multivalue #66

Open
alexandreseitz opened this issue May 12, 2022 · 7 comments
Open

Read content of Multivalue #66

alexandreseitz opened this issue May 12, 2022 · 7 comments

Comments

@alexandreseitz
Copy link

Hello
I need to read content of Multivalue.
Typically in my program when I connect to Ixnetwork controler with some configuration already
deployed (or a config uploaded via ixncfg file) and I discover the config by parsing the complete topology.

For the Multivalue object I need to detect which type of mutlivalue it is:

  • singlevalue
  • counter
  • valueList
  • ....etc

There are some @Property defined in Multivalue like Pattern, but there is a complex mecanism to hide the real type of Multivalue
I would expect to get the real pattern value (MV._properties['pattern']), but instead it returns a string:

  • Alt: ...
  • Inc: ...
  • Dec: ...
  • Randr: ..

So I try to access data in the private property mv._properties[] but sometime data is not there..so it raise a KeyError

So for now, I have no other solution than doing some kind of reverse engineering from the string returned by the @Property Pattern

@Vibaswan
Copy link
Collaborator

Hi @alexandreseitz ,
Thanks for pointing this to us.

So we would be exposing another property in Multivalue class named PatternType
function signature would be something of this sort.

@property    
def PatternType(self):
  # type: () -> str
  """
  Returns
  -------
  - str: a string containing information about the type for this Multivalue
         possible returns (Alternate, Custom, Decrement, Distributed, Increment, Random, RandomRange, RandomMask,
         Single, String, ValueList)
  """

To see a simple test scenario

from ixnetwork_restpy import SessionAssistant

session_assistant = SessionAssistant(
    IpAddress="127.0.0.1",
    UserName="admin",
    Password="admin",
    LogLevel=SessionAssistant.LOGLEVEL_INFO,
    ClearConfig=True,
)

# adding ipv4 stack
ipv4 = (
    session_assistant.Ixnetwork.Topology.add()
    .DeviceGroup.add()
    .Ethernet.add()
    .Ipv4.add()
)

# fetching ipv4 address multivalue object
address = ipv4.Address

# modifying multivalue base on pattern type
if address.PatternType == "Increment":
    address.Increment(start_value="1.1.1.1", step_value="1.0.0.0")

elif address.PatternType == "Decrement":
    address.Decrement(start_value="100.1.1.1", step_value="1.0.0.0")

Please let us know if this will help you in achieving your use-case

@alexandreseitz
Copy link
Author

Hello

Yes it could be a solution to expose a property like @PatternType.
Then based on value of PatternType property, I will be able to inspect Multivalue subclasses like: alternate, counter, nest...
to discover configuration of each Multivalue instance.
Thanks
best regards

@Vibaswan
Copy link
Collaborator

Hi @alexandreseitz ,
Thanks for your valuable feedback

Just so that we are in the same page .
The @PatternType property would be returning any of the following strings from this (Alternate, Custom, Decrement, Distributed, Increment, Random, RandomRange, RandomMask, Single, String, ValueList) as mentioned in the above function signature
It would not return counters, the reason is that the return string should be inline with the name of the functions we provide to change a multivalue instance as it would be easy for a user to know which function they should call in order to modify the existing multivalue pattern.

Note: as you have mentioned nest in your previous comment we use @steps property to get and modify nest patterns from a multivalue instance

@alexandreseitz
Copy link
Author

Hello @Vibaswan

Yes we are on the same page. @PatternType should return a string. And based on its value, I will be able to discover the configuration of the Multivalue instance by accessing subclasses with code similar to:

getattr(mv, mv.PatternType)

@alexandreseitz
Copy link
Author

Hi

I am testing the lastest release 1.1.6 with mutlivalue PatternType. It seems to work well, but now I am facing an issue
when I discover a Subset multivalue:
For example, a subset on a Loopbackipv4 address. Accessing the mv.PatternType raise an error:
Exception('Could not retrieve Pattern type for the multivalue Instance').

@Vibaswan
Copy link
Collaborator

Hi,
Would you please elaborate on what you mean by subset Multivalue. Probably a scenario of the config and snippet of the code were you are facing the issue
Also which multivalue pattern are you expecting ?

@alexandreseitz
Copy link
Author

Hello
sorry for the late reply.
Here a sceenshot of a "Subset Multivalue"

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants