7 Definition of Standard Methods
This chapter describes the standard methods that scripts can use. Many of these methods are dependent on the context in which they are called.
Summary of Methods
Table 7-1 list the methods that scripts use.
Table 7-1 Standard Methods for Scripts
Method | Context | Purpose |
---|---|---|
setCode |
General |
Sets the return status of a script run. |
setDetails |
General |
Sets a result string to be passed back to the user, typically explaining an error. |
sendScriptObjectiveFailure |
General |
Creates a notification message indicating script failure to be passed back to the policy server. |
openSession |
Device |
Connects to the device, authenticates and gets to the enable prompt. This method must be called before any call to deliverCommand. |
deliverCommand |
Device |
Sends a command to the device followed by a new line. openSession must have been called before this method. |
closeSession |
Device |
Closes the connection to the device. This method should be called after all commands have been delivered. |
getIpAddress |
Device |
Gets the primary IP address of the device, that is, the IP address that the driver uses to contact the device. |
getIos |
Device |
Gets the Cisco IOS version. This method is relevant to the Cisco IOS device driver only. |
getOs |
Device |
Gets the operating system version. |
getDeviceType |
Device |
Gets the device type. This method is relevant to the Cisco IOS device driver only. |
getFeatureSet |
Device |
Gets the feature set. This method is relevant to the Cisco IOS device driver only. |
getNumberOfInterfaces |
Device |
Gets the number of interfaces on the device. This is the number of managed interfaces, not the total number of interfaces. |
getInterfaces |
Device |
Gets the interface object at index position in the total set of interfaces. The total number of interfaces is given by the call. Valid index values are from 0 to |
log |
Device |
Logs a message string to the driver log. |
getThisCommitSharedData |
Device |
Gets the information stored in the shared data area for the current transaction only. Information is stored as a dictionary or class, depending on whether the -SharedDataModule driver command-line option is used. |
getLifetimeSharedData |
Device |
Gets the information that is stored in the shared data area for the lifetime of the device (since the device was last managed or the device driver restarted). Information is stored as a dictionary or class, depending on whether the -SharedDataModule driver commadn-line option is used. |
getInterfaceName |
Interface |
Gets the name fo the interface. |
getIpAddress |
Interface |
Gets the IP address of the interface. |
getVipType |
Interface |
Gets type of the VIP the interface is on, if known. This method is relevant to the Cisco IOS device driver only. |
getAdapterType |
Interface |
Gets the type of physical card the interface is on. This method is relevant to the Cisco IOS device driver only. |
getNumberOfFramePvcs |
Interface |
Gets the number of Frame Relay PVCs on the interface. This is the number of managed PVCs, not the total number of PVCs. |
getNumberOfAtmPvcs |
Interface |
Gets the number of ATM PVCs on the interface. This is the number of managed PVCs, not the total number of PVCs. |
getFramePvc |
Interface |
Gets a Frame Relay PVC object. |
getAtmPvc |
Interface |
Gets an ATM PVC object. |
getVpi |
ATM PVC |
Gets the PVC VPI. |
getVci |
ATM PVC |
Gets the PVC VCI. |
getDlci |
FR PVC |
Gets the PVC DCLI. |
General Context
The General context is available to all scripts. This context provides the _result object.
The _result Object
The _result object passes a result out of a script. The type of this object is ScriptResultPtr.
Table 7-2 lists the variables of the _result object.
Table 7-2 The _result Object Variables
Variable | Purpose |
---|---|
_id |
Indicates the unique ID of the concrete script. |
_failure_code |
Indicates the code a particular script should use if the script does not run successfully. The value of the variable differes depending on the script's scheduling properties and whether it is set to run on remove. |
Note:
You cannot assign values to these variables. If these values need to be changed, you must call the sendScriptObjectFailure method on the _result object.
The following methods can be called on the _result object:
The setCode Method
The setCode method sets the status of a script run.
Table 7-3 shows the arguments for the setCode method.
Table 7-3 setCode Method Arguments
Argument | Description | Default |
---|---|---|
code |
OK or FAILED |
|
Syntax
The syntax for the setCode method is:
setCode ({OK | FAILED})
Exceptions
N/A
Return
N/A
The setDetails Method
The setDetails method sets a result string to be passed back to the user.
Table 7-4 shows the arguments for the setDetails method.
Table 7-4 setDetails Method Arguments
Argument | Description | Default |
---|---|---|
details |
A string that can be used to pass a reason for failure or the result of a successful script. |
|
Syntax
The syntax for the setDetails method is:
setDetails (details)
Exceptions
N/A
Return
N/A
The sendScriptObjectFailure Method
The sendScriptObjectFailure method creates a notification message indicating script failure to be passed back to the policy server.
Table 7-5 shows the arguments for the sendScriptObjectFailure method.
Table 7-5 sendScriptObjectFailure Method Arguments
Argument | Description |
---|---|
id |
A variable that indicates the script's ID number held by the IP Service Activator _id variable. |
failure_code |
A variable that indicates the script's failure code held by the IP Service Activator _failure_code variable. |
message |
A string that indicates the cause of the failure. The message is passed back to the policy server and displayed in the Current Faults pane of the IP Service Activator client. |
Syntax
The syntax for the sendScriptObjectFailure method is:
sendScriptObjectFailure (id,failure_code,'message'
Exceptions
N/A
Return
N/A
Device Context
The Device context is available to Device, Interface, Sub-interface, ATM PVC and Frame PVC scripts. This context provides the _device object.
The _device Object
The _device object provides access to the device functions. The type of this object is PythonCiscoProxyDevicePtr.
The following methods can be called on the _device object:
The openSession Method
The openSession method connects to the device, authenticates and gets to the Enable prompt. This method must be called before any call to deliverCommand.
The openSession method has no arguments.
Syntax
The syntax for the openSession method is:
openSession( )
Exceptions
RuntimeError will be raised if a session cannot be established.
Return
N/A
The deliverCommand Method
The deliverCommand method sends a command to the device followed by a CRLF. The openSession method must have been run before this method.
Table 7-6 shows the arguments for the deliverCommand method.
Table 7-6 deliverCommand Method Arguments
Argument | Description |
---|---|
command |
String command to send to the device. |
Syntax
The syntax for the deliverCommand method is:
[result=]deliverCommand(‘command')
Exceptions
RuntimeError will be raised if the command cannot be delivered.
Return
The deliverCommand method returns a string that is the result of executing the command, for example, the output of a “show version".
The closeSession Method
The closeSession method closes the connection to the device. This method should be called after all commands have been delivered. If it is not called, the connection will be automatically closed.
The closeSession method has no arguments.
Syntax
The syntax for the closeSession method is:
closeSession( )
Exceptions
RuntimeError will be raised if a session cannot be closed or was never opened.
Return
N/A
The getIpAddress Method
The getIpAddress method gets the primary IP address of teh device, that is, the IP address the driver uses to contact the device.
The getIpAddress method has no arguments.
Syntax
The syntax for the getIpAddress method is:
getIpAddress( )
Exceptions
N/A
Return
The getIpAddress method returns an integer that represents the IP Address in host byte order.
The getIos Method
The getIos method gets the IOS version of the device. This method is relevant to the Cisco IOS driver only.
The getIos method has no arguments.
Syntax
The syntax for the getIos method is:
getIos( )
Exceptions
N/A
Return
The getIos method returns a string that represents the IOS version, for example, 11.1(12XP1) or 12.1(1)E.
The getOs Method
The getOs method gets the operating system of the device. This method is relevant to all devices.
The getOs method has no arguments.
Syntax
The syntax for the getOs method is:
getOs( )
Exceptions
N/A
Return
The getIos method returns a string that represents the OS version.
The getDeviceType Method
The getDeviceType method gets the device type. This method is relevant to the Cisco IOS driver only.
The information is obtained by querying the driver by a show version command.
The getDeviceType method has no arguments.
Syntax
The syntax for the getDeviceType method is:
getDeviceType( )
Exceptions
N/A
Return
The getDeviceType method returns a string that represents the device type, for example, RSP or C7200.
The getFeatureSet Method
The getIos method gets the character(s) representing the IOS feature set available on the device. This method is relevant to the Cisco IOS driver only.
The getFeatureSet method has no arguments.
Syntax
The syntax for the getFeatureSet method is:
getFeatureSet( )
Exceptions
N/A
Return
The getFeatureSet method returns a string of alphanumeric characters that represents the IOS feature set, for example, p
for Service Provider feature set, i
for IP subset. Check Cisco documentation for the complete list.
The getNumberOfInterfaces Method
The getNumberOfInterfaces method gets the number of interfaces on the device. This is the number of managed interfaces, not the total number of interfaces.
The getNumberOfInterfaces method has no arguments.
Syntax
The syntax for the getNumberOfInterfaces method is:
getNumberOfInterfaces( )
Exceptions
N/A
Return
The getIos method returns an integer that represents the number of interfaces on the device.
The getThisCommitSharedData Method
The getThisCommitSharedData method gets the information stored in the shared data area for the current transaction only.
The getThisCommitSharedData method has no arguments.
Syntax
The syntax for the getThisCommitSharedData method is:
[result=]getThisCommitSharedData( )
Exceptions
Not applicable.
Return
The getThisCommitSharedData method returns a string that represents the information stored in the data area for the current transaction.
The getLifetimeSharedData Method
The getLifetimeSharedData method gets the information stored in the shared data area for the lifetime of the device; that is, since the device was last managed or the device driver was restarted.
The getLifetimeSharedData method has no arguments.
Syntax
The syntax for the getLifetimeSharedData method is:
[result=]getLifetimeSharedData( )
Exceptions
N/A
Return
The getLifetimeSharedData method returns a string that represents the information stored in the shared data of the area since the device was last managed or teh device driver was restarted.
The getInterface Method
The getInterface method gets the interface object at index position in the total set of interfaces. The total number of interfaces is given by the getNumberOfInterfaces method. Valid index values are from 0 to the number given by getNumberOfInterfaces minus 1.
Table 7-7 lists the arguments for the getInterface method.
Table 7-7 getInterface Method Arguments
Argument | Decription |
---|---|
index |
Interface to fetch. |
Syntax
The syntax for the getInterface method is:
getInterface(index)
Exceptions
RuntimeError will be raised if index is not valid.
Return
The getInterface method returns the PythonCiscoProxyInterfacePtr object if index is valid, None if index is not valid.
The log Method
The log method logs a specified string to the driver log.
Table 7-8 lists the arguments for the log method.
Table 7-8 log Method Arguments
Argument | Decription |
---|---|
string |
Message to write to log. |
Syntax
The syntax for the log method is:
log(string)
Exceptions
N/A
Return
N/A
The auditLog Method
The auditLog method logs a message to the device driver's audit trail log.
Table 7-9 lists the arguments for the log method.
Table 7-9 auditLog Method Arguments
Argument | Decription |
---|---|
message |
Message to write to log. |
Syntax
The syntax for the auditLog method is:
auditLog(‘message')
Exceptions
N/A
Return
N/A
Interface Context
The Interface context is available to Interface, Sub-interface, ATM PVC and Frame PVC scripts. This context provides the _interface object.
The _interface Object
The _interface object provides access to interface function. The type of this object is PythonCiscoProxyInterfacePtr.
The following methods can be called on the _interface object:
The getInterfaceName Method
The getInterfaceName method gets the name of the interface.
The getInterfaceName method has no arguments.
Syntax
The syntax for the getInterfaceName method is:
getInterfaceName( )
Exceptions
RuntimeError will be raised if index is not valid.
Return
The getInterfaceName method returns a string that represents the interface name, for example, Serial1/0 or Ethernet1.
The getIpAddress Method
The getIpAddress method gets the IP address of the interface.
The getIpAddress method has no arguments.
Syntax
The syntax for the getIpAddress method is:
getIpAddress( )
Exceptions
N/A
Return
The getIpAddress method returns an integer that represents the IP address in host byte order.
The getVipType Method
The getVipType method gets the VIP adapter (if any). This method is relevant to the Cisco IOS driver only.
The getVipType method has no arguments.
Syntax
The syntax for the getVipType method is:
getVipType( )
Exceptions
N/A
Return
The getVipType method returns a string that represents the VIP. Conversion is as follows:
-
VIP = ‘VIP'
-
VIP2-10 = ‘VIP2_10'
-
VIP2-15 = ‘VIP2_15'
-
VIP2-20 = ‘VIP2_20'
-
VIP2-40 = ‘VIP2_40'
-
VIP2-50 = ‘VIP2_50'
-
VIP4-80 = ‘VIP4_80'
If the interface is not on a VIP or the type is unknown, an emtpy string is returned.
The getAdapterType Method
The getAdapterType method gets the type of physical card that the interface is on. This method is relevant to the Cisco IOS driver only.
The getAdapterType method has no arguments.
Syntax
The syntax for the getAdapterType method is:
getAdapterType( )
Exceptions
N/A
Return
The getIpAddress method returns a string that represents the card type.
The getNumberOfFramePvcs Method
The getNumberOfFramePvs method gets the number of Frame Relay PVCs on the interface. This is the number of managed PVCs, not the total number of PVCs.
The getNumberOfFramePvcs method has no arguments.
Syntax
The syntax for the getNumberOfFramePvcs method is:
getNumberOfFramePvcs( )
Exceptions
N/A
Return
The getNumberOfFramePvcs method returns an integer that represents the number of Frame Relay PVCs.
The getNumberOfAtmPvcs Method
The getNumberOfAtmPvcs method gets the number of ATM PVCs on the interface. This is the number of managed PVCs, not the total number of PVCs.
The getNumberOfAtmPvcs method has no arguments.
Syntax
The syntax for the getNumberOfAtmPvcs method is:
getNumberOfAtmPvcs( )
Exceptions
N/A
Return
The getNumberOfAtmPvcs method returns an integer that represents the number of ATM PVCs.
The getFramePvc Method
The getFramePvc method gets the Frame Relay PVC object at index position in the total set of Frame PVCs. The total number of Frame PVCs is given by the getNumberOfFramePvcs method. Valid index values are from 0 to the return of getNumberOfFramePvcs minus 1.
Table 7-10 shows the arguments for the getFramePvc method.
Table 7-10 getFramePvc Method Arguments
Argument | Description |
---|---|
index |
Frame Relay PVC to fetch. |
Syntax
The syntax for the getFramePvc method is:
getFramePvc(index)
Exceptions
RuntimeError will be raised if index is not valid.
Return
The getFramePvc method returns the PythonCiscoProxyFramePtr object if index is valid, None if index is not valid.
The getAtmPvc Method
The getAtmPvc method gets the ATM PVC object at index position in the total set of ATM PVCs. The total number of ATM PVCs is given by the getNumberOfAtmPvcs method. Valid index values are from 0 to the return of getNumberOfAtmPvcs minus 1.
Table 7-11 shows the arguments for the getAtmPvc method.
Table 7-11 getAtmPvc Method Arguments
Argument | Description |
---|---|
index |
ATM PVC to fetch. |
Syntax
The syntax for the getAtmPvc method is:
getAtmPvc(index)
Exceptions
RuntimeError will be raised if index is not valid.
Return
The getAtmPvc method returns the PythonCiscoProxyFramePtr object if index is valid, None if index is not valid.
ATM PVC Context
The ATM PVC context is available to all ATM PVC scripts. This context provides the _atm_pvc object.
The _atm_pvc Object
The _atm_pvc object provides access to ATM PVC scripts. The type of this object is PythonCiscoProxyAtmPvcPtr.
The following methods can be called on the _atm_pvc object:
The getVpi Method
The getVpi method gets the PVC VPI.
The getVpi method has no arguments.
Syntax
The syntax for the getVpi method is:
getVpi( )
Exceptions
N/A
Return
The getVPI method returns an integer that represents the VPI of the PVC.
Frame PVC Context
The Frame PVC context is available to all Frame Relay PVC scripts. This context provides the _frame_pvc object.