cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
245
Views
2
Helpful
4
Replies
khgrant
Cisco Employee

Issue with maapi.load_config

 

Hello Team,

I managed to have the python maapi.load_config with the help of Fredrik. All is fine, I am able to connect from a client machine to the nso server but there is a problem when fetching the xml file.

When I was running the script I was having this error:

 

root@goserver01 load-merge]# python2.7 load-merge.py /root/nso-41/load-merge/ns.xml  

Will merge data from /root/nso-41/load-merge/ns.xml

ok

Traceback (most recent call last):

  File "load-merge.py", line 20, in <module>

    main()

  File "load-merge.py", line 15, in main

    maapi.load_config(s.sock, th.th, maapi.CONFIG_XML, xmlFile)

_ncs.error.Error: system call failed (24): No such file or directory

 

So I thought I would place the file on the server at that path and it all worked.

So apparently this call:

maapi.load_config(s.sock, th.th, maapi.CONFIG_XML, xmlFile)

 

is looking for the xmkFile on the server and not on the client from where I am running the script.
Is this a bug or is there a way around it? Maybe I need to configure more parameters?

Thanks for your help,

Cheers,
Francesco.

 

4 REPLIES 4
khgrant
Cisco Employee

 

Francesco,

 

 

I managed to have the python maapi.load_config with the help of Fredrik. All is fine, I am able to connect from a client machine to the nso server but there is a problem when fetching the xml file.

 

 

...

 

So I thought I would place the file on the server at that path and it all worked.

So apparently this call:

 

 

maapi.load_config(s.sock, th.th, maapi.CONFIG_XML, xmlFile)

 

 

is looking for the xmkFile on the server and not on the client from where I am running the script.

Is this a bug or is there a way around it? Maybe I need to configure more parameters?

 

 

That's right, and that's how it's supposed to work. A more convenient function for you might be the related

 

maapi.load_config_cmds()

 

which accepts a string instead of a file. If the file you have is local, just load the contents and feed it in.

 

 

Best Regards,

 

/jan

 

khgrant
Cisco Employee

Hi Jan,

thanks for your reply.

I have looked at that function, it is defined like this:

load_config_cmds(...)

        load_config_cmds(sock, thandle, flags, cmds, path) -> None

        Loads configuration from the string 'cmds'

        Keyword arguments:

        sock -- a python socket instance

        thandle -- a transaction handle

        cmds -- a string of cmds

        flags -- as above

Do you know what the path parameter is? How am I supposed to load the content of the full xml file? If I normally read a file by line in python, it then creates a list of strings.
Is there any example of the usage of this command that could clarify a bit?

Thanks for your help!

Cheers,
Francesco.

khgrant
Cisco Employee

 

Francesco,

 

 

I have looked at that function, it is defined like this:

     load_config_cmds(...)
         load_config_cmds(sock, thandle, flags, cmds,
path
) -> None
        
         Loads configuration from the string 'cmds'
        
         Keyword arguments:
         sock -- a python socket instance
         thandle -- a transaction handle
         cmds -- a string of cmds
         flags -- as above
    
Do you know what the path parameter is? How am I supposed to load the content of the full xml file? If I normally read a file by line in python, it then creates a list of strings.

 

 

In python you can read the entire file using the file read() method.

 

 

with open('file.xml', 'r') as xml_file:

 

    xml_text = xml_file.read()

 

 

The path parameter allows you to lock-in (chroot) the commands to only be able to touch a certain part of the data model. You can use "/".

 

 

Makes sense?

 

 

Best Regards,

 

/jan

 

khgrant
Cisco Employee

Hi Jan,

thanks for replying back!

I had actually tried it this morning, the only difference is that I had set the path to an empty string but it worked anyway.

So finally all seems to be working Now I can provision a new network element to nso, push a config file (from a script residing on a different server than the NSO)  and I can thus accomplish a kind of zero config config  to a newly spun up virtual network element.

Thanks for all your help!

Cheers,
Francesco.

Content for Community-Ad