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

Rest.Py config in Json format #48

Closed
alakendu opened this issue Apr 12, 2021 · 2 comments
Closed

Rest.Py config in Json format #48

alakendu opened this issue Apr 12, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@alakendu
Copy link

Using new Rest.Py Config assistance (#47) , user will be able to save configuration in json format.

This allow in future to extend various other format like yml or oprenapi format.

@Vibaswan
Copy link
Collaborator

Using new Rest.Py Config assistance (#47), user can write something like the snippet shown below to save configuration

import json
# import ConfigAssistant
from ixnetwork_restpy import SessionAssistant

# connect to IxNetwork using SessionAssistant
session_assistant = SessionAssistant(IpAddress='127.0.0.1', UserName='admin', Password='admin',
                                     LogLevel=SessionAssistant.LOGLEVEL_INFO, ClearConfig=False)

conf_assist = session_assistant.ConfigAssistant()
config = conf_assist.config

# build the whole configuration over the config object
...

# when done with the configuration save it in a json file
print('saving json')
with open('sample.json', 'w') as outfile:
    json.dump(conf_assist.config_json, outfile)
    

The json file for the configuration will be saved in your local system.

The json file can later be used to load and get configuration as well.

from ixnetwork_restpy import SessionAssistant

# connect to IxNetwork using SessionAssistant
session_assistant = SessionAssistant(IpAddress='127.0.0.1', UserName='admin', Password='admin',
                                     LogLevel=SessionAssistant.LOGLEVEL_INFO, ClearConfig=False)

ixnetwork = session_assistant.Ixnetwork

# read the json file
with open('sample.json') as json_file:
    config_json = json.load(json_file)

# use ixnetwork's ResourceManager to import the json config 
ixnetwork.ResourceManager.ImportConfig(json.dumps(config_json), True)

@ajbalogh
Copy link
Collaborator

ajbalogh commented Sep 3, 2021

This is now supported in v1.1.0

@ajbalogh ajbalogh closed this as completed Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants