Cisco Active Network Abstraction Customization User Guide, 3.6.4
Running Command Scripts

Table Of Contents

Running Command Scripts

Syntax

Output

Examples

ChangePortStatus

Add_VRF

RunScript

Script Results

IScriptResult

IScriptEvent

Successful Example

Unsuccessful Example


Running Command Scripts


This chapter describes running command scripts. It contains the following topics:\

Syntax

Output

Examples

Script Results


Note Read Chapter 19, "Getting Started with BQL" for an understanding of BQL, and as a prerequisite to understanding this chapter.


For more information about Cisco ANA Macro Language scripts, see Defining Cisco ANA Macro Language Script Lines, page 14-12.

Syntax

Table 16-1 Command Syntax 

Item
Code and Explanation

General Syntax

<command name="Command Script Name ">

<param name="oid">
<value> OID </value>
</param>
<param name="Parameter name 1">
<value>

Parameter Value

</value>

</param>
<param name="Parameter name 2">
<value>

Parameter Value

</value>

</param>

</command>

Command Script Name

Each command script is considered to be a BQL command. Thus, the name of the script is used as the command name.

OID

OID format as explained in the Cisco Active Network Abstraction BQL Guide.

The OID specifies the IMO object with which the command is associated.

Parameter name 1
(2) (3) ...

The value of the input parameters. A script can have none or many input parameters.



Note A command is always associated with an IMO object that enables it to use the properties of the object inside the script lines. For example, by selecting a Port object, the port's properties such as portAlias, and status are automatically made available to the script, but the command can access any other entity in the device.


Output

The output of a script is the IMO object "IScriptResult". See IScriptResult for a description of this object.

Examples

ChangePortStatus

The following example runs the script ChangePortStatus. This script changes the status of specified port. The parameter "portstatus" specifies the desired status of the port.

<command name="ChangePortStatus">

<param name="oid">

<value>{[ManagedElement(Key=PE_South)][PhysicalRoot][Chassis][Slot(SlotNum=1)][Module][ Port(PortNumber=FastEthernet1/0)]}</value>

</param>

<param name="portstatus">

<value>no shutdown</value>

</param>

</command>


Add_VRF

The following example runs the script Add_VRF. This script adds a new VRF to specified router. It receives the parameters vfrName, rt, and rd.

<command name="Add_VRF">

<param name="oid">

<value>{[ManagedElement(Key=P-North)]}</value>

</param>

<param name="rt">

<value>333:333</value>

</param>

<param name="vrfName">

<value>sharona2</value>

</param>

<param name="rd">

<value>445:445</value>

</param>

</command>


The script code in Cisco ANA Macro Language is:

show ip vrf $vrfName$ [success= No VRF named $vrfName$]

[rollback]

[activity=Creating The VRF]

config terminal [prompt=(config)]

ip vrf $vrfName$ [prompt=(config-vrf)]

[activity=Setting the route destinguisher]

rd $rd$ [fail=% Cannot set RD, check if it's unique]

route-target both $rt$

end


RunScript

The following example runs the script RunScript. This script enables the system to log into a Cisco device using the specified user and then execute the script. It takes the parameters cid, userName, and password.

<?xml version="1.0" encoding="UTF-8"?>

<command name="RunScript">

<param name="cid">

            <value>

<command name="ChangePortStatus">

    <param name="oid">

        <value>{[ManagedElement(Key=CISCO-80.80.80.60)][PhysicalRoot][Chassis][Slot(SlotNum=0)] [Module][Port(PortNumber=Ethernet0/1)]}</value>

    </param>

    <param name="portstatus">

        <value>no shutdown</value>

    </param>

</command>

</value>

</param>

<param name="userName">

            <value>tomer</value>

</param>

<param name="password">

            <value>tom1</value>

</param>

</command>


Script Results

IScriptResult

IScriptResult is the IMO object that holds the result of a script execution.

The object properties are:

ExecutionTime—In milliseconds, the time it took to run the script.

StatusEnum—The status of the result represented by a numeric value:

0 = Unknown

1 = Success

2 = Failure

3 = Failure: device user switch unsupported

4 = Failure: invalid credentials for device user switch

FailedActivity—If the script failed, this property holds one of the script labels defined in the script describing the part of the activity that failed.

ExecutionSequence—This property holds an array of IScriptEvent that holds the execution sequence that occurred in the script.

IScriptEvent

IScriptEven is the IMO object that describes a single event script that was run.

The object properties are:

EventType—The type of event represented by a numeric value:

0 = Telnet Prompt

1 = Telnet Command

2 = Telnet Reply

3 = SNMP Get Command

4 = SNMP Set Command

5 = SNMP Result

6 = Exception

7 = User Remark

Message—The message content of the event.

Successful Example

The following example shows the returned result of successful execution of the Add_VRF script (see Add_VRF):

<IScriptResult>

<ID type="Oid">{[ScriptResult(ScriptName=Add_VRF)(Sequence=1125562053773)]}</ID>

<ExecutionSequence type="IMObjects_Array">

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=1)]}</ID>

<EventTypeEnum type="Integer">1</EventTypeEnum>

<Message type="String">P-North#show ip vrf sharona2</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=2)]}</ID>

<EventTypeEnum type="Integer">2</EventTypeEnum>

<Message type="String">% No VRF named sharona2

</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=3)]}</ID>

<EventTypeEnum type="Integer">1</EventTypeEnum>

<Message type="String">P-North#config terminal</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=4)]}</ID>

<EventTypeEnum type="Integer">2</EventTypeEnum>

<Message type="String">Enter configuration commands, one per line. End with CNTL/Z.</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=5)]}</ID>

<EventTypeEnum type="Integer">1</EventTypeEnum>

<Message type="String">P-North(config)#ip vrf sharona2</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=6)]}</ID>

<EventTypeEnum type="Integer">1</EventTypeEnum>

<Message type="String">P-North(config-vrf)#rd 445:445</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=7)]}</ID>

<EventTypeEnum type="Integer">1</EventTypeEnum>

<Message type="String">P-North(config-vrf)#route-target both 333:333</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=8)]}</ID>

<EventTypeEnum type="Integer">1</EventTypeEnum>

<Message type="String">P-North(config-vrf)#end</Message>

</IScriptEvent>

</ExecutionSequence>

<ExecutionTime type="Long">852</ExecutionTime>

<FailedActivity type="">Null</FailedActivity>

<StatusEnum type="Integer">1</StatusEnum>

</IScriptResult>


Unsuccessful Example

Here is an example of the same script that failed to execute:

<IScriptResult>

<ID type="Oid">{[ScriptResult(ScriptName=Add_VRF)(Sequence=1125562233194)]}</ID>

<ExecutionSequence type="IMObjects_Array">

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=1)]}</ID>

<EventTypeEnum type="Integer">1</EventTypeEnum>

<Message type="String">P-North#show ip vrf sharona2</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=2)]}</ID>

<EventTypeEnum type="Integer">2</EventTypeEnum>

<Message type="String"> Name Default RD Interfaces

sharona2 445:445

</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=3)]}</ID>

<EventTypeEnum type="Integer">2</EventTypeEnum>

<Message type="String">P-North#</Message>

</IScriptEvent>

<IScriptEvent>

<ID type="Oid">{[ScriptEvent(Index=4)]}</ID>

<EventTypeEnum type="Integer">6</EventTypeEnum>

<Message type="String"> ^ Failed to find the text ' No VRF named sharona2' in the device reply!, script terminated.</Message>

</IScriptEvent>

</ExecutionSequence>

<ExecutionTime type="Long">162</ExecutionTime>

<FailedActivity type="String" />

<StatusEnum type="Integer">2</StatusEnum>

</IScriptResult>