Login and basic command-line interaction support using the Twisted asynchronous I/O framework. The Trigger Twister is just like the Mersenne Twister, except not at all.
Version of XMLTreeBuilder that runs a callback on each tag.
We need this because JunoScript treats the entire session as one XML document. IETF NETCONF fixes that.
Creates an interactive shell.
Intended for use as an action with pty_connect(). See gong for an example.
Fire up stdin/stdout once we connect.
And write data to the terminal.
Action for use with TriggerTelnet as a state machine.
Take a list of commands, and send them to the device until we run out or one errors. Wait for a prompt after each.
Do this when we connect.
Do this when we get data.
Do this when we timeout.
Factory for all clients. Subclass me.
Do this when the connection fails.
Do this when the connection is lost.
An SSH channel that requests a non-interactive pty intended for async usage.
Some devices won’t allow a shell without a pty, so we have to do a ‘pty-req’.
This is distinctly different from ~trigger.twister.TriggerSSHPtyChannel` which is intended for interactive end-user sessions.
Base class for SSH channels.
The method self._setup_channelOpen() should be called by channelOpen() in the subclasses. Before you subclass, however, see if you can’t just use TriggerSSHGenericChannel as-is!
Do this when the channel opens.
Do this when we receive data.
Terminate the connection. Link this to the transport method of the same name.
Check if a device requires enable.
Parameters: | data – Prompt data to check. |
---|
Send ‘enable’ and enable password to device.
Do this when the connection times out.
Intended to be used as a parent of automated SSH channels (e.g. Junoscript, NetScreen, NetScaler) to eliminate boiler plate in those subclasses.
Run SSH commands on a system using ‘exec’
This will multiplex channels over a single connection. Because of the nature of the multiplexing setup, the master list of commands is stored on the SSH connection, and the state of each command is stored within each individual channel which feeds its result back to the factory.
Do this when the channel opens.
Default loseConnection
Send the next command in the stack stored on the connection
Used to manage, you know, an SSH connection.
Optionally takes a list of commands that may be passed on.
Forcefully close the transport connection when a channel closes connection. This is assuming only one channel is open.
Open the channel once we start.
An SSH channel using all of the Trigger defaults to interact with network devices that implement SSH without any tricks.
Currently A10, Cisco, Brocade, NetScreen can simply use this. Nice!
Before you create your own subclass, see if you can’t use me as-is!
An SSH channel to execute Junoscript commands on a Juniper device running Junos.
This completely assumes that we are the only channel in the factory (a TriggerJunoscriptFactory) and walks all the way back up to the factory for its arguments.
Do this when channel opens.
Do this when we receive data.
Used for multiplexing SSH ‘exec’ channels on a single connection.
Opens a new channel for each command in the stack once the previous channel has closed. In this pattern the Connection and the Channel are intertwined.
Close the channel when we’re done. But not the transport connection
Send the next command in the stack once the previous channel has closed.
An SSH channel to interact with Citrix NetScaler hardware.
It’s almost a generic SSH channel except that we must check for errors first, because a prompt is not returned when an error is received. This had to be accounted for in the dataReceived() method.
Do this when we receive data.
Used by pty_connect() to turn up an interactive SSH pty channel.
Setup the terminal when the channel opens.
Factory for an interactive SSH connection.
‘action’ is a Protocol that will be connected to the session after login. Use it to interact with the user and pass along commands.
SSH transport with Trigger’s defaults.
Call with magic factory attributes creds, a tuple of login credentials, and connection_class, the class of channel to open, and commands, the list of commands to pass to the connection.
Detect when the transport connection is lost, such as when the remote end closes the connection prematurely (hosts.allow, etc.)
Once we’re secure, authenticate.
Do this when we receive an error.
Trigger disconnect of the transport.
Verify host key, but don’t actually verify. Awesome.
Perform user authentication over SSH.
Send along the password when authentication mechanism is not ‘password’. This is most commonly the case with ‘keyboard-interactive’, which even when configured within self.preferredOrder, does not work using default getPassword() method.
Send along the password.
Display SSH banner.
An almost exact duplicate of SSHUserAuthClient.ssh_USERAUTH_FAILURE modified to forcefully disconnect. If we receive authentication failures, instead of looping until the server boots us and performing a sendDisconnect(), we raise a LoginFailure and call loseConnection().
See the base docstring for the method signature.
Telnet-based session login state machine. Primarily used by IOS-like type devices.
Allow telnet clients to enable options if for some reason they aren’t enabled already (e.g. ECHO). (Ref: http://bit.ly/wkFZFg) For some reason Arista Networks hardware is the only vendor that needs this method right now.
Track user login state.
Special Foundry breakage because they don’t do auto-enable from TACACS by default. Use ‘aaa authentication login privilege-mode’. Also, why no space after the Password: prompt here?
Pass the enable password from the factory or NetDevices
Once we’re logged in, exit state machine and pass control to the action.
Pass the login password from the factory or NetDevices
After we got password prompt, check for enabled prompt.
Found a % error message. Don’t return immediately because we don’t have the error text yet.
Do this when we get a login failure.
After we’ve gotten username, check for password prompt.
Do this when we timeout logging in.
Factory for a telnet connection.
Connect to a network device via pty for an interactive shell.
Parameters: |
|
---|
Connect to a device and sequentially execute all the commands in the iterable commands.
Returns a Twisted Deferred object, whose callback will get a sequence of all the results after the connection is finished.
commands is usually just a list, however, you can have also make it a generator, and have it and incremental share a closure to some state variables. This allows you to determine what commands to execute dynamically based on the results of previous commands. This implementation is experimental and it might be a better idea to have the incremental callback determine what command to execute next; it could then be a method of an object that keeps state.
BEWARE: Your generator cannot block; you must immediately decide what next command to execute, if any.
Any None in the command sequence will result in a None being placed in the output sequence, with no command issued to the device.
If any command returns an error, the connection is dropped immediately and the errback will fire with the failed command. You may set with_errors to get the exception objects in the list instead.
Connection failures will still fire the errback.
LoginTimeout errors are always possible if the login process takes longer than expected and cannot be disabled.
Parameters: |
|
---|---|
Returns: | A Twisted Deferred object |
Execute via SSH for a device that requires shell + pty-req.
Please see execute for a full description of the arguments and how this works.
Use multiplexed SSH ‘exec’ command channels to execute commands.
This will maintain a single SSH connection and run each new command in a separate channel after the previous command completes.
Please see execute for a full description of the arguments and how this works.
Use default SSH channel to execute commands on a device. Should work with anything not wonky.
Please see execute for a full description of the arguments and how this works.
Execute commands on a Cisco/IOS-like device. It will automatically try to connect using SSH if it is available and not disabled in settings.py. If SSH is unavailable, it will fallback to telnet unless that is also disabled in the settings. Otherwise it will fail, so you should probably make sure one or the other is enabled!
Please see execute for a full description of the arguments and how this works.
Execute via SSH for IOS-like devices with some exceptions.
Please see execute for a full description of the arguments and how this works.
Execute commands via telnet on a Cisco/IOS-like device.
Please see execute for a full description of the arguments and how this works.
Connect to a Juniper device and enable Junoscript XML mode. All commands are expected to be XML commands (ElementTree.Element objects suitable for wrapping in <rpc> elements). Errors are expected to be of type xnm:error. Note that prompt detection is not used here.
Please see execute for a full description of the arguments and how this works.
Execute commands on a NetScaler device.
Please see execute for a full description of the arguments and how this works.
Execute commands on a NetScreen device running ScreenOS. For NetScreen devices running Junos, use execute_junoscript.
Please see execute for a full description of the arguments and how this works.
An errback to try detect a login failure
Parameters: | failure – A Twisted Failure instance |
---|
Test whether a string seems to contain an IOS-like error.
Test whether a string seems to contain an Juniper error.
Test whether an Element contains a Junoscript xnm:error.
Test whether a string seems to contain a NetScaler error.
Checks if a prompt is asking for us for confirmation and returns a Boolean.
Parameters: | prompt – The prompt string to check |
---|
Connect to a device and log in. Use SSHv2 or telnet as appropriate.
Parameters: |
|
---|---|
Returns: | A Twisted Deferred object |
Stop the reactor if it’s already running.