fooelisa / pyiosxr

Python library to interact with Cisco devices running IOS-XR
Apache License 2.0
68 stars 32 forks source link

pyIOSXR #40

Open annejg opened 7 years ago

annejg commented 7 years ago

Hi!

I'm been working on a program where I want to push configuration to Cisco IOS XR devices and I run into problems when trying to use the code below.

This is my current code snippets:

device = IOSXR(hostname=router["ip"], username=router["username"], password=["password", port=router["port"], timeout=120)

device.open() device.load_candidate_config(filename=router["path"])` device.compare_replace_config() device.commit_replace_config(label='test') device.close()

I've made sure that the device xml agent is configured with 'iteration off' and I've tried different combinations of locking and unlocking the configuration, and wrapping it in 'try' statements to figure out where the problem lies.

The device just wont accept the load_candidate, compare_replace and commit_replace command.

Have I missed something obvious with the pyIOSXR library?

Best regards, Anne Golinski

fooelisa commented 7 years ago

Hi Anne, this is the right approach. Does the code or device return any errors? What's the error you are seeing?

annejg commented 7 years ago

Hi Elisa,

Sorry, rookie mistake! The error was in my json file where I had replaced a " with a ' by mistake.. The code above now replaces the running configuration without errors!

However, it does not always commit the configuration into the commit database. I'm then left with an error that target buffer is empty, as a response to the commit request, i.e.:

DEBUG:netmiko:read_channel: <?xml version="1.0" encoding="UTF-8"?> 
<Response MajorVersion="1" MinorVersion="0"><Commit ErrorCode="0x41864e00" 
ErrorMsg="&apos;CfgMgr&apos; detected the &apos;warning&apos; condition &apos;The target 
configuration buffer is empty.&apos;"/> ResultSummary ErrorCount="1"/></Response> 

This problem seam to appear sporadically regardless of content of the configuration text file I try to push to the device.

annejg commented 7 years ago

Hi @fooelisa!

I really can't figure this out and would like to ask for your help.

The code runs without errors, but it still wont commit the changes into the devices database. I've hardcoded the device information into the script to avoid errors caused by the json file

I'm using

netmiko 1.3.0 lxml 3.7.3 IOS-XR 5.3.3

and this is the code:

def configure_router(router):
    try:
        print('\nConfiguring: ' + router["name"])
        device = IOSXR(hostname='', username='', password='', port=22, timeout=120)
        device.open()
        try: 
            device.load_candidate_config(filename='/home/...')
            device.compare_replace_config()     
            device.commit_replace_config(label='test')
        except: 
            print('Configuration: Did not commit into database\n')

        device.close()
        print('Configuration: OK\n')
    except: 
        print('Configuration: Unable to communicate with device\n')

Do you have any idea of what could be wrong?

Is there way to integrate some form of delay in the commands to exclude that the error is not due to slow connections?

Thank you in advance!

Best Regards, Anne Golinski

Update: I've tried to look at the return values from each function. While load_candidate_config() and commit_replace_config() returns 'None', the compare_replace_config() doesn't return anything at all. Is that as it should?

thorko commented 7 years ago

Hi Anne, I'm not sure if it the same problem. But I also run into this problem and I could figure out the issue. When my configuration file contains a "commit" at the end I also get this error message which is quite obvious. Because the router already committed the changes the second commit will tell you that there are no changes, so the buffer is empty. Hope this helps Cheers thorko

annejg commented 7 years ago

Hi @thorko! Yes, You are absolutely right, that was the problem all along Thank you!

Best Regards, Anne