from trigger import tacacsrcfrom trigger.netdevices import NetDevicesfrom twisted.python import loglog.startLogging(open('trig.log', 'w'), 'setStdout=False')tcrc = tacacsrc.Tacacsrc()nd = NetDevices()print ('nd: ', nd)dev = nd.find('10.252.17.122')print ('dev: ', dev)dev.connect()
2012-08-06 14:04:42-0400 [-] Log opened.2012-08-06 14:04:42-0400 [-] Using GPG method: False2012-08-06 14:04:42-0400 [-] Got username: 'tpurcell'2012-08-06 14:04:42-0400 [-] skipping '# Saved by trigger.tacacsrc at 2012-08-06 14:04:11 EDT'2012-08-06 14:04:42-0400 [-] skipping ''2012-08-06 14:04:42-0400 [-] using set_wakeup_fd2012-08-06 14:04:42-0400 [-] ('nd: ', {'10.252.17.122': <NetDevice: 10.252.17.122>})2012-08-06 14:04:42-0400 [-] ('dev: ', <NetDevice: 10.252.17.122>)2012-08-06 14:04:42-0400 [-] Connecting to 10.252.17.122. Use ^X to exit.2012-08-06 14:04:42-0400 [-] File not found: '/home/tpurcell/.gorc'2012-08-06 14:04:42-0400 [-] No config data, not sending init commands2012-08-06 14:04:42-0400 [-] SSH connection test PASSED2012-08-06 14:04:42-0400 [-] Could not connect to 10.252.17.122.
('nd: ', {'10.252.17.122': <NetDevice: 10.252.17.122>})('dev: ', <NetDevice: 10.252.17.122>)Connecting to 10.252.17.122. Use ^X to exit.Fetching credentials from /home/tpurcell/.tacacsrcConnection failed for the following reason:ssh_exchange_identification: Connection closed by remote hostBYE
Hi Tom-Welcome to the world of Trigger! I'm glad you found it! Thanks for posting your issue. First things first, I have not officially tested the Cisco ASR, but since it falls under an IOS-like device, it should work fine but there are a few things I'd like to check.A few questions:+ How are you populating your NetDevices?
From the following netdevices.xml file (Note: Its copied from the sample and I've change only a few of the values):
<?xml version="1.0" encoding="UTF-8"?><!-- Dummy version of netdevices.xml, with just one real entry copiedfrom the real file (version of 2006-06-19 20:01 UTC). --><NetDevices><device nodeName="ur03"><adminStatus>PRODUCTION</adminStatus><assetID>90000041207</assetID><authMethod>tacacs</authMethod><barcode>001020020</barcode><budgetCode>100124.06</budgetCode><budgetName>DCNETS - IW</budgetName><coordinate>16AH</coordinate><deviceType>ROUTER</deviceType><enablePW>mkL0v3!w4r</enablePW><lastUpdate>2006-07-19 19:56:32.0</lastUpdate><layer2>1</layer2><layer3>1</layer3><lifecycleStatus>INSTALLED</lifecycleStatus><loginPW><an-actual-password-here></loginPW><make>ASR9000 ROUTER</make><manufacturer>Cisco</manufacturer><model>ASR9006</model><nodeName>10.252.17.122</nodeName><onCallEmail>dcn...@aol.net</onCallEmail><onCallID>17</onCallID><onCallName>NETOPS DCNETS</onCallName><OOBTerminalServerConnector>C</OOBTerminalServerConnector><OOBTerminalServerFQDN>ts-cr3-w7-srv5.oob.aol.com</OOBTerminalServerFQDN><OOBTerminalServerNodeName>ts-cr3-w7-srv5</OOBTerminalServerNodeName><OOBTerminalServerPort>18</OOBTerminalServerPort><OOBTerminalServerTCPPort>5018</OOBTerminalServerTCPPort><operationStatus>MONITORED</operationStatus><owner>NETWORK ENGINEERING</owner><room>LAB</room><serialNumber>12345</serialNumber><site>UCS</site></device></NetDevices>
+ I'm curious about the contents of your device object for 10.252.17.122. Can you please show me the output of `dev.dump()` for that device?
Here's my code. I made two small changes: the startLogging statement and added dev.dump() on the last line:
From trigger import tacacsrc
from trigger.netdevices import NetDevicesfrom twisted.python import log
import syslog.startLogging(sys.stdout)
tcrc = tacacsrc.Tacacsrc()nd = NetDevices()print ('nd: ', nd)dev = nd.find('10.252.17.122')print ('dev: ', dev)dev.connect()
dev.dump()
Here's the output:
(vtrigger)tpurcell@tpurcell-Latitude-E6500 ~/data/comcast-code/mytrigger $ python mytrigger.py2012-08-07 10:23:57-0400 [-] Log opened.2012-08-07 10:23:57-0400 [-] Using GPG method: False2012-08-07 10:23:57-0400 [-] Got username: 'tpurcell'2012-08-07 10:23:57-0400 [-] skipping '# Saved by trigger.tacacsrc at 2012-08-06 14:04:11 EDT'2012-08-07 10:23:57-0400 [-] skipping ''2012-08-07 10:23:57-0400 [-] ('nd: ', {'10.252.17.122': <NetDevice: 10.252.17.122>})2012-08-07 10:23:57-0400 [-] ('dev: ', <NetDevice: 10.252.17.122>)2012-08-07 10:23:57-0400 [-] Connecting to 10.252.17.122. Use ^X to exit.2012-08-07 10:23:57-0400 [-] File not found: '/home/tpurcell/.gorc'2012-08-07 10:23:57-0400 [-] No config data, not sending init commands2012-08-07 10:23:57-0400 [-] SSH connection test PASSED2012-08-07 10:23:57-0400 [-] Could not connect to 10.252.17.122.2012-08-07 10:23:57-0400 [-]2012-08-07 10:23:57-0400 [-] Hostname: 10.252.17.1222012-08-07 10:23:57-0400 [-] Owning Org.: NETWORK ENGINEERING2012-08-07 10:23:57-0400 [-] Owning Team: None2012-08-07 10:23:57-0400 [-] OnCall Team: NETOPS DCNETS2012-08-07 10:23:57-0400 [-]2012-08-07 10:23:57-0400 [-] Vendor: Cisco (Cisco)2012-08-07 10:23:57-0400 [-] Make: ASR9000 ROUTER2012-08-07 10:23:57-0400 [-] Model: ASR90062012-08-07 10:23:57-0400 [-] Type: ROUTER2012-08-07 10:23:57-0400 [-] Location: UCS LAB 16AH2012-08-07 10:23:57-0400 [-]2012-08-07 10:23:57-0400 [-] Project: None2012-08-07 10:23:57-0400 [-] Serial: 123452012-08-07 10:23:57-0400 [-] Asset Tag: 900000412072012-08-07 10:23:57-0400 [-] Budget Code: 100124.06 (DCNETS - IW)2012-08-07 10:23:57-0400 [-]2012-08-07 10:23:57-0400 [-] Admin Status: PRODUCTION2012-08-07 10:23:57-0400 [-] Lifecycle Status: INSTALLED2012-08-07 10:23:57-0400 [-] Operation Status: MONITORED2012-08-07 10:23:57-0400 [-] Last Updated: 2006-07-19 19:56:32.02012-08-07 10:23:57-0400 [-]
+ Can you also provide a simple copy/paste of the output you get back from the device when connecting manually from the command-line?
tpurcell@tpurcell-Latitude-E6500 ~ $ ssh aut...@10.252.17.122This system is solely for the use of authorized Comcast employees and contractors.aut...@10.252.17.122's password:RP/0/RSP0/CPU0:ur03.hsi.cc38.ula#show clockTue Aug 7 21:31:33.671 UTC21:31:33.697 UTC Tue Aug 07 2012RP/0/RSP0/CPU0:ur03.hsi.cc38.ula#
JathanThanks for the response. I really appreciate your help. Answers to your question are inline below.
def __init__(self, deferred, creds=None, init_commands=None):self.d = deferredself.tcrc = tacacsrc.Tacacsrc()if creds is None:log.msg('creds not defined, fetching...', debug=True)realm = settings.DEFAULT_REALMcreds = self.tcrc.creds.get(realm, tacacsrc.get_device_password(realm))self.creds = credsprint('TriggerClientFactory.__init__ self.creds: ', self.creds)
...
(vtrigger)tpurcell@tpurcell-Latitude-E6500 ~/data/comcast-code/mytrigger $ python mytrigger.py
('nd: ', {'10.252.17.122': <NetDevice: 10.252.17.122>})('dev: ', <NetDevice: 10.252.17.122>)Connecting to 10.252.17.122. Use ^X to exit.
('TriggerClientFactory.__init__ self.creds: ', Credentials(username='autoacl', password='<actual-password-here>', realm=''))
Fetching credentials from /home/tpurcell/.tacacsrcConnection failed for the following reason:ssh_exchange_identification: Connection closed by remote hostBYE
Hostname: 10.252.17.122Owning Org.: NETWORK ENGINEERINGOwning Team: NoneOnCall Team: NETOPS DCNETSVendor: Cisco (Cisco)Make: ASR9000 ROUTERModel: ASR9006Type: ROUTERLocation: UCS LAB 16AHProject: NoneSerial: 12345Asset Tag: 90000041207
Budget Code: 100124.06 (DCNETS - IW)
Admin Status: PRODUCTIONLifecycle Status: INSTALLEDOperation Status: MONITORED
Last Updated: 2006-07-19 19:56:32.0
def startedConnecting(self, connector):"""Called when a connection has been started.You can call connector.stopConnecting() to stop the connection attempt.@param connector: a Connector object."""import pdbpdb.set_trace()
(vtrigger)tpurcell@tpurcell-Latitude-E6500 ~/data/comcast-code/mytrigger $ python mytrigger.py('nd: ', {'10.252.17.122': <NetDevice: 10.252.17.122>})('dev: ', <NetDevice: 10.252.17.122>)Connecting to 10.252.17.122. Use ^X to exit.
('TriggerClientFactory.__init__ self.creds: ', Credentials(username='autoacl', password='c0mcast!', realm=''))--Return--> /home/tpurcell/data/comcast-code/mytrigger/vtrigger/local/lib/python2.7/site-packages/twisted/internet/protocol.py(124)startedConnecting()->None-> pdb.set_trace()(Pdb) w/home/tpurcell/data/comcast-code/mytrigger/mytrigger.py(24)<module>()-> dev.connect(init_commands=['show clock', 'exit'])/home/tpurcell/data/comcast-code/mytrigger/vtrigger/local/lib/python2.7/site-packages/trigger/twister.py(231)connect()-> init_commands=init_commands)/home/tpurcell/data/comcast-code/mytrigger/vtrigger/local/lib/python2.7/site-packages/trigger/twister.py(172)pty_connect()-> reactor.connectTCP(device.nodeName, port, factory)/home/tpurcell/data/comcast-code/mytrigger/vtrigger/local/lib/python2.7/site-packages/twisted/internet/posixbase.py(471)connectTCP()-> c.connect()/home/tpurcell/data/comcast-code/mytrigger/vtrigger/local/lib/python2.7/site-packages/twisted/internet/base.py(1027)connect()-> self.factory.startedConnecting(self)> /home/tpurcell/data/comcast-code/mytrigger/vtrigger/local/lib/python2.7/site-packages/twisted/internet/protocol.py(124)startedConnecting()->None-> pdb.set_trace()
Just to make sure I'm clear, on the successful login, did you execute the command "show configuration commit list" manually? What is the estimated amount of time the device is taking to present a "#" prompt after logging in manually? Is it significant?
This is what I'm currently executing:
from trigger import tacacsrcfrom trigger.netdevices import NetDevices
tcrc = tacacsrc.Tacacsrc()nd = NetDevices()dev = nd.find('10.252.17.122')dev.connect(init_commands=['show configuration commit list', 'exit'])As you can see I'm not attempting an interactive session. I'm passing in the commands on the call to connect. If I manually perform an old fashioned ssh logon(ssh aut...@10.252.17.122) from a linux terminal there is no significant delay in connecting. After entering a password there is no significant delay in getting # prompt.
I'm just wondering if this is somehow a factor, and Twisted's default connection timeout is abnormally low, however, as far as I can tell it defaults to 30 seconds. There must be something wonky with the SSH channel negotiation that your device is not happy about.I've never run into this before for SSH. For telnet we have a configuration directive TELNET_TIMEOUT which defaults to 60 seconds. There is an ability to specify a command_interval for when you're executing commands asynchronously (using the .execute() method) that was the result of a similar issue when connecting to and executing commands on some older Foundry hardware. But since I've never run into this exact issue you're experiencing for SSH on Cisco devices there is not a configuration setting to toggle a login pause.The other thing that stands out to me is you're using the .connect() method which is intended for interactive logins and there is the "gong" script bundled with Trigger that does all of that for you by instantiating NetDevices for you and doing a lookup based on IP/hostname and then connecting you.
It is entirely possible I'm going about this the wrong way. Right now I'm just trying to connect and execute a command but eventually I need to maintain ACLs.
What will need to happen is a call will be made by another system to a component I'm responsible for developing. The other system will send the ACL. My component will be responsible for pushing the ACL to the network device and maintaining a change log. Initially the devices will be of the ASR9000 variety but it is not a homogeneous environment. Eventually we will need to communicate with other vendors products as well.
So I'm hoping to use trigger as a library that will handle the transformation, connection and execution parts of what needs to happen but right now I'm just trying to understand what it has to offer.
Jathan
Response inline. Thanks for the help.On Wednesday, August 8, 2012 6:09:51 PM UTC-4, Jathan McCollum wrote:Just to make sure I'm clear, on the successful login, did you execute the command "show configuration commit list" manually? What is the estimated amount of time the device is taking to present a "#" prompt after logging in manually? Is it significant?This is what I'm currently executing:from trigger import tacacsrcfrom trigger.netdevices import NetDevicestcrc = tacacsrc.Tacacsrc()nd = NetDevices()dev = nd.find('10.252.17.122')dev.connect(init_commands=['show configuration commit list', 'exit'])As you can see I'm not attempting an interactive session. I'm passing in the commands on the call to connect. If I manually perform an old fashioned ssh logon(ssh aut...@10.252.17.122) from a linux terminal there is no significant delay in connecting. After entering a password there is no significant delay in getting # prompt.
I'm just wondering if this is somehow a factor, and Twisted's default connection timeout is abnormally low, however, as far as I can tell it defaults to 30 seconds. There must be something wonky with the SSH channel negotiation that your device is not happy about.I've never run into this before for SSH. For telnet we have a configuration directive TELNET_TIMEOUT which defaults to 60 seconds. There is an ability to specify a command_interval for when you're executing commands asynchronously (using the .execute() method) that was the result of a similar issue when connecting to and executing commands on some older Foundry hardware. But since I've never run into this exact issue you're experiencing for SSH on Cisco devices there is not a configuration setting to toggle a login pause.The other thing that stands out to me is you're using the .connect() method which is intended for interactive logins and there is the "gong" script bundled with Trigger that does all of that for you by instantiating NetDevices for you and doing a lookup based on IP/hostname and then connecting you.It is entirely possible I'm going about this the wrong way. Right now I'm just trying to connect and execute a command but eventually I need to maintain ACLs.What will need to happen is a call will be made by another system to a component I'm responsible for developing. The other system will send the ACL. My component will be responsible for pushing the ACL to the network device and maintaining a change log. Initially the devices will be of the ASR9000 variety but it is not a homogeneous environment. Eventually we will need to communicate with other vendors products as well.So I'm hoping to use trigger as a library that will handle the transformation, connection and execution parts of what needs to happen but right now I'm just trying to understand what it has to offer.
from trigger.cmds import Commandofrom twisted.python import loglog.startLogging(open('trig.log', 'w'), setStdout=False)class ShowCommitList(Commando):vendors = ['cisco']commands = ['terminal length 0', 'show configuration commit list']devnames= ['10.252.17.122']scl = ShowCommitList(devices=devnames, verbose=True)scl.run()
['show configuration commit list', 'terminal length 0']