Package onep :: Package vty :: Module VtyService :: Class VtyService
[frames] | no frames]

Class VtyService


The VtyService class represents a vty on a network element i.e. a cisco device.

VTY Service Set hides the commands executed through it. To view the commands executed through VTY, enable CLI logs as follows.

On NXOS, use vty.write("debug cli parser-detail") in your application, future onep_vty_write() will have the CLI logs in the response. Use vty.write("no debug cli parser-detail") to turn off CLI log or simply reopen vty session.

On IOS, use the following command to view CLI logs on the Router. "show history all"

On XR, use the following command to view CLI logs on the Router. "show cli history detail"

Nested Classes
  Listener
For internal use
  CmdResults
cmdResults is the collection of command results associated with the VTY and last command run
  ParserState
ParserState is used to determine what went wrong with a command block.
Instance Methods
 
__init__(self, element)
Constructor
 
open(self)
Open a vty on the network element with the default cmd interpreter - no control messages
 
set_output_format(self, format)
Set the output format for vty This API can only be used before the vty is opened.
 
write(self, s)
Write a String to a vty on the network element
 
write_0(self, s, typeahead)
Write a String to a vty on the network element with a typeahead list
 
close(self)
Close a vty.
 
cancel(self)
Cancel command execution.
 
get_parser_state(self)
Returns the state of the parser after the last command interpretation.
 
is_open(self)
Returns true if a connected vty exists between the network element and application.
 
destroy(self)
Done with VtyService instance so destroy it

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  OnepVtyState = enum('ONEP_VTY_STATE_DISCONNECTED', 'ONEP_VTY_S...
  OnepVtyCmdInterp = enum('ONEP_VTY_CMD_IOS_SH', 'ONEP_VTY_CMD_T...
  OnepVtyOutputFormat = enum('ONEP_VTY_OUTPUT_FORMAT_TLV', 'ONEP...
  log = None
Instance Variables
  element
The Network Element associated with this VTY service
Properties
  max_response
The maximum response byte length.
  timeout
The maximum length to wait for a Network Element response in seconds

Inherited from object: __class__

Method Details

__init__(self, element)
(Constructor)

 

Constructor

@raise OnepIllegalArgumentException
            The exception is thrown when the input argument is invalid
@raise OnepConnectionException:
            The exception is thrown when the connection to a network element
            has failed.
@raise OnepRemoteProcedureException:
            The exception is thrown when an error has occurred in the
            remote procedure call made to a network element.
@raise OnepException:
            The exception is thrown when the server returns an invalid CPU
            sampling interval value.

@param  element: The Network Element on which to open the vty

Overrides: object.__init__

open(self)

 

Open a vty on the network element with the default cmd interpreter - no control messages

Raises:
  • OnepConnectionException - The exception is thrown when the connection to a network element has failed.
  • OnepRemoteProcedureException - The exception is thrown when an error has occurred in the remote procedure call made to a network element.
  • OnepException - The exception is thrown when the server returns an invalid CPU sampling interval value.

Note: On XR, "aaa authorization eventmanager default local" must be configured in config mode, otherwise open() will fail to get a valid handle. Also, the device should have "hostname <whatever-hostname>" config. aaa authorization commands default <group | none>" is recommended to config prior to use.

set_output_format(self, format)

 

Set the output format for vty This API can only be used before the vty is opened. It will raise an exception if vty is already open.

Parameters:
  • format (OnepVtyOutputFormat) - The vty output format to be set on the network element
Raises:
  • OnepConnectionException - The exception is thrown when the connection to a network element has failed.
  • OnepRemoteProcedureException - The exception is thrown when an error has occurred in the remote procedure call made to a network element.
  • OnepException - The exception is thrown when the vty is already open and this API is called.

write(self, s)

 

Write a String to a vty on the network element

Parameters:
  • s - The String to write to the vty
Returns:
The interpreted result from the Network Element
Raises:
  • OnepConnectionException - The exception is thrown when the connection to a network element has failed.
  • OnepRemoteProcedureException - The exception is thrown when an error has occurred in the remote procedure call made to a network element.
  • OnepException - The exception is thrown when the server returns an invalid CPU sampling interval value.

write_0(self, s, typeahead)

 

Write a String to a vty on the network element with a typeahead list

Parameters:
  • s - The String to write to the vty
  • typeAhead - The list of strings to type ahead of running the command
Returns:
The interpreted result from the Network Element
Raises:
  • OnepConnectionException - The exception is thrown when the connection to a network element has failed.
  • OnepRemoteProcedureException - The exception is thrown when an error has occurred in the remote procedure call made to a network element.
  • OnepException - The exception is thrown when the server returns an invalid CPU sampling interval value.

close(self)

 

Close a vty.

Raises:
  • OnepConnectionException - The exception is thrown when the connection to a network element has failed.
  • OnepRemoteProcedureException - The exception is thrown when an error has occurred in the remote procedure call made to a network element.
  • OnepException - The exception is thrown when the server returns an invalid CPU sampling interval value.

cancel(self)

 

Cancel command execution.

Raises:
  • OnepConnectionException - The exception is thrown when the connection to a network element has failed.
  • OnepRemoteProcedureException - The exception is thrown when an error has occurred in the remote procedure call made to a network element.
  • OnepException - The exception is thrown when the server returns an invalid CPU sampling interval value.

get_parser_state(self)

 

Returns the state of the parser after the last command interpretation.

Returns:
The parser state
Raises:
  • OnepConnectionException - The exception is thrown when the connection to a network element has failed.
  • OnepRemoteProcedureException - The exception is thrown when an error has occurred in the remote procedure call made to a network element.
  • OnepException - The exception is thrown when the server returns an invalid CPU sampling interval value.

destroy(self)

 

Done with VtyService instance so destroy it

Throws OnepVtyNotClosed if VTY service is still open


Class Variable Details

OnepVtyState

Value:
enum('ONEP_VTY_STATE_DISCONNECTED', 'ONEP_VTY_STATE_CONNECTING', 'ONEP\
_VTY_STATE_CONNECTED', 'ONEP_VTY_STATE_IDLE_TIMEOUT', 'ONEP_VTY_STATE_\
INVALID')

OnepVtyCmdInterp

Value:
enum('ONEP_VTY_CMD_IOS_SH', 'ONEP_VTY_CMD_TCL')

OnepVtyOutputFormat

Value:
enum('ONEP_VTY_OUTPUT_FORMAT_TLV', 'ONEP_VTY_OUTPUT_FORMAT_TEXT', 'ONE\
P_VTY_OUTPUT_FORMAT_XML')

Property Details

max_response

The maximum response byte length. Responses truncated to this length. Zero is unlimited

Get Method:
unreachable.max_response(self) - The maximum response byte length.
Set Method:
unreachable.max_response(self, max)

timeout

The maximum length to wait for a Network Element response in seconds

Get Method:
unreachable.timeout(self) - The maximum length to wait for a Network Element response in seconds
Set Method:
unreachable.timeout(self, time_out)