cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
594
Views
0
Helpful
7
Replies

Multiple credentials in PyATS yaml file not working

assadniang
Level 1
Level 1

Hello,

I have the following configuration

I have read somewhere (google AI), that you can have multiple credentials in your yaml file

Google PyATS 

But PyATS always uses the default credentials, even when I specify the 'ro_credentials' to use

    u350-s2-17-vcsr:
        type: router
        os: iosxe
        platform: c8kv
        #alias: 'uut'
        credentials:
            default:
                username: ******
                password: ******
            ro_credentials:
                username: cisco_ro
                password: ******
            
        connections:
            cli:
                protocol: ssh
                ip: FD:192:168:53:0:9:17:4
                ssh_options: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
    try:
        LOGGER.info(f">>> Connecting to {device_name}...1")
        device.connect(log_stdout=False, init_config_commands=[], credentials='ro_credentials')
        LOGGER.info(f"Successfully connected to {device_name}\n")
        return device
    
    except (TimeoutError, StateMachineError, ConnectionError) as e:
        LOGGER.error(f"Failed to connect to {device_name}: {e}\n")
        return None

Sometimes, I also get the error message:

TypeError: function() got multiple values for keyword argument 'credentials'
7 Replies 7

@assadniang looking at the error you see/posted here, looks like how pyats deals with the creds parameter in the connect() method. Try using the via  parameter instead of credentials. This i think is the simple fix, try this and see how this works, if this does not work If the issue might be in the YAML structure or how the testbed is being loaded.

 

try:
    LOGGER.info(f">>> Connecting to {device_name}...1")
    device.connect(log_stdout=False, init_config_commands=[], via='ro_credentials')
    LOGGER.info(f"Successfully connected to {device_name}\n")
    return device

except (TimeoutError, StateMachineError, ConnectionError) as e:
    LOGGER.error(f"Failed to connect to {device_name}: {e}\n")
    return None

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

assadniang
Level 1
Level 1

@bigevilbeard 
I am getting this error message:

ValueError: via='ro_credentials' does not exist for device 'u350-s2-17-vcsr'

BTW, I can connect with the default credential without any issues 

@assadniang under the connection in yaml file add 

credentials: ro_credentials

Then the python stuff from before. I think this happnes due to the expectation of cli, console..

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

assadniang
Level 1
Level 1
    u350-s2-17-vcsr:
        type: router
        os: iosxe
        platform: c8kv
        #alias: 'uut'
        credentials:
            default:
                username: ******
                password: ******
            ro_credentials:
                username: cisco_ro
                password: *****
            
        connections:
            credentials: ro_credentials
            cli:
                protocol: ssh
                ip: FD:192:168:53:0:9:17:4
                ssh_options: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null

This is the error message

pyats.utils.exceptions.SchemaTypeError: devices.u350-s2-17-vcsr.connections.credentials:

Sorry this is my bad.  ro_credentials at the wrong indentation level, try

u350-s2-17-vcsr:
    type: router
    os: iosxe
    platform: c8kv
    #alias: 'uut'
    credentials:
        default:
            username: ******
            password: ******
        ro_credentials:
            username: cisco_ro
            password: *****

    connections:
        cli:
            protocol: ssh
            ip: FD:192:168:53:0:9:17:4
            ssh_options: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
            credentials: ro_credentials

 Your credentials parameter should be specified within the individual connection definition (cli in this case)

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

assadniang
Level 1
Level 1

Still not working...

    u350-s2-17-vcsr:
        type: router
        os: iosxe
        platform: c8kv
        #alias: 'uut'
        credentials:
            default:
                username: *****
                password: *****
            ro_credentials:
                username: cisco_ro
                password: ********           
        connections:
            cli:
                protocol: ssh
                ip: FD:192:168:53:0:9:17:4
                ssh_options: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
                credentials: ro_credentials
pyats.utils.exceptions.SchemaTypeError: devices.u350-s2-17-vcsr.connections.cli.credentials:

Hmmmm ... out on a limb here now .. so try

u350-s2-17-vcsr:
    type: router
    os: iosxe
    platform: c8kv
    credentials:
        default:
            username: *****
            password: *****
        ro_credentials:
            username: cisco_ro
            password: ********
    connections:
        cli:
            protocol: ssh
            ip: FD:192:168:53:0:9:17:4
            ssh_options: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
        ro_cli:
            protocol: ssh
            ip: FD:192:168:53:0:9:17:4
            ssh_options: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
            via: ro_credentials

In python use 

device.connect(alias='ro_cli', log_stdout=False, init_config_commands=[])
Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io