question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can we use Attributes between cisco statements?

See original GitHub issue

Hi Ktbyers,

Am trying something out here and doesnt seem to work. Maybe am doing something wrong or its simply not possible. What am trying to do is when a user select a vlan from the “vlans” list. That vlan name will be put in the cisco statements:

con = net_connect.send_command_expect(‘show interfaces status | count’, vlan, ‘* connected’)

vlan Will be the vlan selected by the user from the list.

`from netmiko import ConnectHandler
from getpass import getpass
from netmiko.ssh_exception import NetMikoTimeoutException
from netmiko.ssh_exception import NetMikoAuthenticationException
from netmiko.ssh_exception import SSHException

vlans = ['CHEESE', 'HAM', 'COOKIE', 'CANDY', 'WATER', 'COLA']
print(vlans)
number = input('Select VLAN [0-6]: ')

if number =='0':
    vlan = print(vlans[0])
elif vlan =='1':
    vlan = print(vlans[1])
elif vlan =='2':
    vlan = print(vlans[2])
elif vlan =='3':
    vlan = print(vlans[3])
elif vlan =='4':
    vlan = print(vlans[4])
elif vlan =='5':
    vlan = print(vlans[5])
else:
    print('That option is not available!')

def vlan_stats():
    con = net_connect.send_command_expect('show interfaces status | count', vlan, '* connected')
    notcon = net_connect.send_command_expect('show interfaces status | count', vlan, '* notconnect')
    ports = net_connect.send_command_expect('show interfaces status | count ', vlan)

    print('CON / NOTCON / SIZE:', con.strip(',Number of lines which match regexp =  '), 
    notcon.strip(',Number of lines which match regexp = '), 
    ports.strip(',Number of lines which match regexp = '))`

Hope to hear from you!

Best regards Arpanet86

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
daanvdsandencommented, Jun 18, 2020
con = net_connect.send_command_expect('show interfaces status | count', vlan ,'* connected')

a comma is not used for concatenating strings. you are now doing this:

con = net_connect.send_command_expect(command_string='show interfaces status | count', expect_string=vlan, delay_factor='* connected')

replace it with:

con = net_connect.send_command_expect('show interfaces status | count '+ vlan +'* connected')
# or
con = net_connect.send_command_expect(f"show interfaces status | count {vlan}* connected")
0reactions
Arpanet86commented, Jun 23, 2020

Yeah got that figured out. I really like the F string method.

Thanks for the help guys! Am closing this ticket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RADIUS Attributes Configuration Guide - Cisco
A dictionary file provides a list of attributes that are dependent on which attributes your NAS supports. However, you can add your own...
Read more >
Managing Resources [Cisco Identity Services Engine]
Cisco ISE allows you to create, edit, and delete user-defined dictionaries and dictionary attributes that you can use in policy conditions.
Read more >
Configuring Authorization Policies [Cisco Identity Services ...
Profiles consist of attributes chosen from a set of resources, which are stored in a dictionary and these are returned when the compound...
Read more >
Cisco IOS XR Routing Configuration Guide for the Cisco CRS ...
A routing policy instructs the router to inspect routes, filter them, and potentially modify their attributes as they are accepted from a peer, ......
Read more >
Understanding BGP MED Attribute - Cisco
When a BGP speaker learns a route from a peer, the route's MED is passed to ... For easy convention, IP addresses in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found