cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
222
Views
5
Helpful
5
Replies
Highlighted
Beginner

pyats connection to n9k in aci mode

Hi, we think of monitoring state of ACI leaf interfaces, routes  during upgrade using pyats. Unfortunately I'm not able to connect to it using pyats.  When connecting pyats tries commands which are not supported by n9k aci mode. How do I specify os; type, series for n9k in aci mode?

my inventory looks like this:

devices:

  ACIxxxx:

    connections:

      cli:

        ip:  1.1.1.1.

        protocol: ssh

    credentials:

      default:

        password: xxx

        username: xxx

    os: 'nxos'

    series: 'aci'

    type: 'aci'

 

 

 

(venv) [username@dev-hostgenie-demo]$             cat interface_nxos_ACIXXXX_exception.txt

Issue while building the feature

 

Traceback (most recent call last):

  File "src/genie/cli/commands/learn.py", line 343, in genie.cli.commands.learn.LearnCommand._retrieve_ops

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/genie/libs/ops/interface/nxos/interface.py", line 337, in learn

    self.make(final_call=True)

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/genie/ops/base/base.py", line 101, in make

    self.maker.make(*args, **kwargs)

  File "src/genie/ops/base/maker.py", line 312, in genie.ops.base.maker.Maker.make

  File "src/genie/ops/base/maker.py", line 418, in genie.ops.base.maker.Maker._call_parser

  File "src/genie/metaparser/_metaparser.py", line 271, in genie.metaparser._metaparser.MetaParser.parse

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/genie/libs/parser/nxos/show_interface.py", line 1283, in cli

    intf_lst = [interface]

UnboundLocalError: local variable 'interface' referenced before assignment

(venv) [username@dev-hostgenie-demo]$

 

this is what happens when i try genie shell

 

venv) [username@dev-host genie-demo]$ genie shell --testbed-file demo-testbed.yml

Welcome to pyATS Interactive Shell

==================================

Python 3.6.8 (default, Jun 11 2019, 15:15:01)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

 

>>> from genie.testbed import load

>>> testbed = load('demo-testbed.yml')

-------------------------------------------------------------------------------           

>>> testbed.devices

TopologyDict({'ACIxxxx': <Device ACIxxxx at 0x7fa5de7c85f8>})

>>> testbed.devices['ACIxxxx'].connect()

[2020-05-25 17:25:50,090] +++ ACIXXXX logfile /tmp/ACIXXXX-cli-20200525T172550089.log +++

[2020-05-25 17:25:50,091] +++ Unicon plugin nxos +++

 

 

[2020-05-25 17:25:50,425] +++ connection to spawn: ssh 1.1.1.1., id: 140350372206968 +++

[2020-05-25 17:25:50,425] connection to ACIXXXX

Password:

Last login: Mon May 25 17:20:37 2020 from 2.2.2.2.

Cisco Nexus Operating System (NX-OS) Software

TAC support: http://www.cisco.com/tac

Copyright (c) 2002-2018, Cisco Systems, Inc. All rights reserved.   

The copyrights to certain works contained in this software are

owned by other third parties and used and distributed under

license. Certain components of this software are licensed under

the GNU General Public License (GPL) version 2.0 or the GNU

Lesser General Public License (LGPL) Version 2.1. A copy of each

such license is available at

http://www.opensource.org/licenses/gpl-2.0.php and

http://www.opensource.org/licenses/lgpl-2.1.php

ACIXXXX#

[2020-05-25 17:25:53,678] +++ initializing handle +++

[2020-05-25 17:25:53,679] +++ ACIXXXX: executing command 'term length 0' +++

term length 0

bash: term: command not found

ACIXXXX#

[2020-05-25 17:25:53,757] +++ ACIXXXX: executing command 'term width 511' +++

term width 511

bash: term: command not found

ACIXXXX#

[2020-05-25 17:25:53,833] +++ ACIXXXX: executing command 'terminal session-timeout 0' +++

terminal session-timeout 0

bash: terminal: command not found

ACIXXXX#

[2020-05-25 17:25:53,908] +++ ACIXXXX: config +++

config term

bash: config: command not found

ACIXXXX#

 

 

Traceback (most recent call last):

  File "src/unicon/statemachine/statemachine.py", line 719, in unicon.statemachine.statemachine.StateMachine.go_to

  File "src/unicon/statemachine/statetransition.py", line 222, in unicon.statemachine.statetransition.StateTransition.do_transitions

  File "src/unicon/eal/dialogs.py", line 457, in unicon.eal.dialogs.Dialog.process

  File "src/unicon/eal/dialog_processor.py", line 306, in unicon.eal.dialog_processor.SimpleDialogProcessor.process

  File "src/unicon/eal/dialog_processor.py", line 265, in unicon.eal.dialog_processor.SimpleDialogProcessor.timeout_handler

unicon.core.errors.TimeoutError: timeout occurred:

              timeout value: 10

              last_command: 'config term\r'

             pattern: ['^(.*)(\\(maint-mode\\))?\\(.*(con|cfg|ipsec-profile)\\S*\\)#\\s?$', '^.*--\\s?[Mm]ore\\s?--.*$']

             buffer:'config term\r\nbash: config: command not found\r\nACIXXXX# '

 

The above exception was the direct cause of the following exception:

 

Traceback (most recent call last):

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/unicon/plugins/generic/utils.py", line 60, in retry_state_machine_go_to

    prompt_recovery=prompt_recovery)

  File "src/unicon/statemachine/statemachine.py", line 722, in unicon.statemachine.statemachine.StateMachine.go_to

unicon.core.errors.StateMachineError: Failed while bringing device to "config" state

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "src/unicon/bases/connection.py", line 627, in unicon.bases.connection.Connection.connect

  File "src/unicon/bases/routers/connection_provider.py", line 149, in unicon.bases.routers.connection_provider.BaseSingleRpConnectionProvider.connect

  File "src/unicon/bases/routers/connection_provider.py", line 199, in unicon.bases.routers.connection_provider.BaseSingleRpConnectionProvider.init_handle

  File "src/unicon/bases/routers/connection_provider.py", line 121, in unicon.bases.routers.connection_provider.BaseCommonRpConnectionProvider.execute_init_commands

  File "src/unicon/bases/routers/services.py", line 192, in unicon.bases.routers.services.BaseService.__call__

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/unicon/plugins/generic/service_implementation.py", line 868, in call_service

    prompt_recovery=self.prompt_recovery

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/unicon/plugins/generic/utils.py", line 86, in retry_handle_state_machine_go_to

    prompt_recovery=prompt_recovery)

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/unicon/plugins/generic/utils.py", line 64, in retry_state_machine_go_to

    raise SubCommandFailure(err, spawn.buffer)

unicon.core.errors.SubCommandFailure: (StateMachineError('Failed while bringing device to "config" state',), 'config term\r\nbash: config: command not found\r\nACIXXXX# ')

 

The above exception was the direct cause of the following exception:

 

Traceback (most recent call last):

  File "<console>", line 1, in <module>

  File "src/genie/conf/base/device.py", line 636, in genie.conf.base.device.Device.connect

  File "src/pyats/connections/manager.py", line 334, in pyats.connections.manager.ConnectionManager.connect

  File "src/unicon/bases/connection.py", line 633, in unicon.bases.connection.Connection.connect

unicon.core.errors.ConnectionError: failed to connect to ACIXXXX

(StateMachineError('Failed while bringing device to "config" state',), 'config term\r\nbash: config: command not found\r\nACIXXXX# ')

>>> 

 

5 REPLIES 5
Highlighted
Enthusiast

Re: pyats connection to n9k in aci mode

Hi @MykolasB74835 

 

ACI is supported to the extent NXOS is the same on ACI, if that makes sense.

 

Using the CLI you are correct in using OS as NXOS.   There is a customization you need to implement but first:

 

For ACI I always recommend using REST.    That's going right to the source and you get structured data back, rather than using the CLI which, lets face it, is a command overlay to make us CLI geeks more comfortable using ACI. :D which we then have to parse when we could have just gotten the data via REST already parsed.   Gets you away from parsing (data that was structured to begin with) and saves you a step.

 

https://pubhub.devnetcloud.com/media/rest-connector/docs/user_guide/services/apic.html#

 

But I digress..sorry about that.

 

Try this:

 

devices:
  nxos_aci_mode:
    os: nxos 
    series: aci
    (snip)
    custom: 
      abstraction:
        order:
          - os
          - series

The problem with this is that you will invariable run into issues when ACI "NX-OS" has slightly different output than NX-OS "Classic".  

 

 

Highlighted
Beginner

Re: pyats connection to n9k in aci mode

I agree, will ditch pyats for ACI and do through the REST

 

adding custom and abstraction didn't work until i added model, type. it still doesn't parse interfaces.

 

(venv) [username@dev-hostgenie-demo]$                                        vim demo-testbed.yml

devices:

  ACIxxxx:

    connections:

      cli:

        ip: 1.1.1.1

        protocol: ssh

    credentials:

      default:

        password: X7xxxxxxxx

        username: username

    os: nxos

    series: aci

    custom:

      abstraction:

        order:

         - os

         - series

~

~

~

~

~

~

~

~

~

~

~

"demo-testbed.yml" 17L, 295C written

(venv) [username@dev-hostgenie-demo]$ genie learn interface --testbed-file demo-testbed.yml

 

Argument should be a path to a pyATS testbed file, or a pyATS Testbed object not demo-testbed.yml

 

(venv) [username@dev-hostgenie-demo]$                                        vim demo-testbed.yml

devices:

  ACIxxxx:

    connections:

      cli:

        ip: 1.1.1.1

        protocol: ssh

    credentials:

      default:

        password: xxxx

        username: username

    os: nxos

    series: aci

    model: aci

    type: aci

    custom:

      abstraction:

        order:

         - os

         - series

~

~

~

~

~

~

~

~

~

"demo-testbed.yml" 19L, 324C written                                                                                                                                            

(venv) [username@dev-hostgenie-demo]$ genie learn interface --testbed-file demo-testbed.yml

 

Learning '['interface']' on devices '['ACIxxxx']'

100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [01:54<00:00, 114.21s/it]

+==============================================================================+

| Genie Learn Summary for device ACIxxxx                                       |

+==============================================================================+

|  Connected to ACIxxxx                                                        |

|  -   Log: ./connection_ACIxxxx.txt                                           |

|------------------------------------------------------------------------------|

|  Could not learn feature 'interface'                                         |

|  -  Exception:      ./interface_nxos_ACIxxxx_exception.txt                   |

|  -  Ops structure:  ./interface_nxos_ACIxxxx_ops.txt                         |

|  -  Device Console: ./interface_nxos_ACIxxxx_console.txt                     |

|==============================================================================|

 

 

 

(venv) [username@dev-hostgenie-demo]$ cat interface_nxos_ACIxxxx_exception.txt 

Issue while building the feature

 

Traceback (most recent call last):

  File "src/genie/cli/commands/learn.py", line 343, in genie.cli.commands.learn.LearnCommand._retrieve_ops

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/genie/libs/ops/interface/nxos/interface.py", line 337, in learn

    self.make(final_call=True)

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/genie/ops/base/base.py", line 101, in make

    self.maker.make(*args, **kwargs)

  File "src/genie/ops/base/maker.py", line 312, in genie.ops.base.maker.Maker.make

  File "src/genie/ops/base/maker.py", line 418, in genie.ops.base.maker.Maker._call_parser

  File "src/genie/metaparser/_metaparser.py", line 271, in genie.metaparser._metaparser.MetaParser.parse

  File "/home/username/genie-demo/venv/lib64/python3.6/site-packages/genie/libs/parser/nxos/show_interface.py", line 1283, in cli

    intf_lst = [interface]

UnboundLocalError: local variable 'interface' referenced before assignment

(venv) [username@dev-hostgenie-demo]$ cat interface_nxos_ACIxxxx_ops.txt 

{

  "_exclude": [

    "in_discards",

    "in_octets",

    "in_pkts",

    "last_clear",

    "out_octets",

    "out_pkts",

    "in_rate",

    "out_rate",

    "in_errors",

    "in_crc_errors",

    "in_rate_pkts",

    "out_rate_pkts",

    "in_broadcast_pkts",

    "out_broadcast_pkts",

    "in_multicast_pkts",

    "out_multicast_pkts",

    "in_unicast_pkts",

    "out_unicast_pkts",

    "last_change",

    "mac_address",

    "phys_address",

    "((t|T)unnel.*)",

    "(Null.*)",

    "chars_out",

    "chars_in",

    "pkts_out",

    "pkts_in",

    "mgmt0"

  ],

  "attributes": null,

  "commands": null,

  "connections": null,

  "context_manager": {},

  "info": {

    "Mgmt0": {

      "vrf": "management"

    }

  }

}(venv) [username@dev-hostgenie-demo]$

Highlighted
Enthusiast

Re: pyats connection to n9k in aci mode

Hi,

 

You can still use pyats...just use the REST connector.   Particularly for testing, you may want all the testing extras you will get with pyATS.

 

Good luck!

Highlighted
Beginner

Re: pyats connection to n9k in aci mode

Thanks, want to give a try. I'm so new pyats, struggling to get it structured understanding. I can do the basics with IOS and cli connectors by copy/paste from tutorials, but unable to understand documentation for more advanced things 

- Does it work directly to NXOS in ACI mode?

- How would I specify rest.connector in testbed file?

- In general my use case is to take interface status and full routing table and monitor changes, is pyats the right tool for it? Or better I should just build my own rest query based script...

Highlighted
Beginner

Re: pyats connection to n9k in aci mode

seems managed to get it working by looking at https://github.com/CiscoTestAutomation/rest/blob/master/connector/src/rest/connector/tests/testbed.yaml

 

(venv) [usernam@dev-hostname genie-demo]$ vim demo-testbed3.yml
devices:
  ACIxxxx:
    os: apic
    type: apic
    custom:
      abstraction:
        order: [os]
    connections:
      rest:
        class: rest.connector.Rest
        ip: 1.1.1.1
        username: xxx
        password: xxx
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"demo-testbed3.yml" 13L, 249C written                                                                                                                                          
(venv) [username@dev-hostname genie-demo]$ pyats shell --testbed-file demo-testbed3.yml
Welcome to pyATS Interactive Shell
==================================
Python 3.6.8 (default, Jun 11 2019, 15:15:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
>>> from genie.testbed import load
>>> testbed = load('demo-testbed3.yml')
-------------------------------------------------------------------------------           
>>> testbed.devices['ACIxxx'].connect(alias='rest', via='rest')
Connecting to 'ACIxxx' with alias 'rest'
<Response [200]>
Connected successfully to 'ACIxxx'
>>>  
This widget could not be displayed.