This feature is supported only by the "Advanced Script Execution" mode configlets. In order to provide this feature, we have introduced some additional attributes for the <command> tag defined in the Advanced Script Execution mode configlets. The additional attributes are described below.
Sequence: Sequence is used as an identifier for commands, which can be referred from any other command defined in the same configlet. Sequence id is used to direct the command execution flow based on the response received for a particular command. We have a set of constraints for this attribute: Sequence id should be unique within the configlet. the command which has the sequence id 1 will be taken as a starting point of configlet execution work flow. If no command has the sequence id 1, then the first command would be taken as the starting point of the configlet execution work flow.
Note: Every command should have sequence attribute, as it is the identifier for the command. The sequence numbers need not to be in the sorted order, it can be defined in any order.
Condition: This attribute specifies the condition which should be satisfied in response for that particular command. It can take the values contains, notcontains, equals and onlyonce which will be applied on the response with the value attribute defined in the same command. This attribute is an optional field and it must be implemented only with value attribute. If Condition attribute is specified without value attribute, it will be validated while saving the configlet.
Value: This attribute takes the value as regular expression / String which can be used as an operand while checking for the Condition. This should not exist without a Condition attribute. If it exists without Condition attribute, it would be validated while saving the configlet. Based on these attributes, the flow will be directed to any one of the paths which are defined as Success or Failure attributes.
Success: This attribute takes Sequence number defined in any one of the commands in the configlet. It must be specified along with Condition and Value attributes. If not, it would be validated while saving the configlet. If the specified Condition is matched with Value in the current command response, then the next command to be executed should be executed with the sequence id defined in Success. If this attribute is not provided and the condition is success, then the next command in the order will be executed.
Failure: This attribute takes Sequence number defined in any one of the commands in the configlet. This has the similar characteristics as the Success attribute. The difference is, this attribute is an optional one. If the user specified Condition does not match with Value, then the next command to be executed with the sequence id defined in Failure. If it is not specified, then it would be considered as end and the execution would be halted in the failure case.
ErrorString: Error string is a different attribute which can be used to determine the configlet execution failure state based on the string provided. This failure is different from the one which is defined as failure. If the command response contains the errorString, then the over all execution state for that particular device would be marked as FAILURE.
Execution:
Command execution starts with the command with the Sequence number 1 and proceeds with the flow. If no condition values are specified, then it works as the same way as it does in the existing implementation. If the condition attributes are specified in the command, then the command response is taken from result and based on the condition and value attributes the success or failure is decided. If it is success then, the next command to be executed is taken from Success attribute. If the condition fails, then the next command is taken from Failure attribute. If failure is not specified, the execution will be halted. The flow can be diverted in any direction, both forward and backward directions.
Notes:
At any case, if the condition is not specified for the last command, then it is treated as final command and execution comes to an end.
For those commands which do not have condition values, the flow will be taken as they defined in the order, not based on the sequence number. Sequence number is used only as the identifier and not for flow sequence.
The user can stop the execution and mark it as a SUCCESS by specifying the value as "end" or "END" for any success or failure condition. Similarly, specifying the value as "ERROR-HALT" will stop the execution and mark it as a FAILURE.
Auto Loop Detection: if the command flow tends to an infinite loop, it would not be detected automatically by NCM. User should take care of avoiding such infinite loop cases. In case, if user is facing the looping issue in some specific scenario and he / she wants NCM to take care of Auto Loop Detection, there is an option to enable this feature. In Client / Server settings page, enable Enable auto loop detection in Advanced Script Execution mode configlets checkbox to handle Auto Loop Detection. If this is enabled, configlet execution work flow will be terminated, when the same command line is executed more than thrice.
User Input example and Timeout
<command prompt=']?'>copy tftp: flash:</command>
<command prompt=']?'>$TFTP_SERVER_IP</command>
<command prompt=']?'>$SOURCE_FILE_NAME</command>
<command prompt='confirm'>$DESTINATION_FILE_NAME</command>
<command timeout='120' suffix='$NO_ENTER'>y</command>
Above is an example configlet for uploading an os image file from TFTP server to cisco ios device.
Let us take the first command, <command prompt=']?'>copy tftp: flash:</command>. This describes, when you exeucte a command copy tftp: flash:, it will prompt for a tftp host name ending with [hostname]?. This also determines that the next command (TFTP_SERVER_IP) can be sent after seeing the prompt.
Let us take the fourth command, <command prompt='confirm'> $DESTINATION_FILE_NAME </command>. This indicates, once you sent a destination file name, it will prompt you for confirmation.
In the last command, we used suffix='$NO_ENTER' which means there is no suffix for the corresponding command. By default we append a line feed at the end of each command. In case of confirmation commands like this, we no need to send a line feed, once we enter 'y', it will proceed to next. So we can ignore the line feed using suffix='$NO_ENTER' tag.
The same format we can use it for prompt changes such as configure mode. All the configure mode commands will have a different prompt than usual.
Determine the execution status
To determine the execution status based on the response for a command, we need to add "ErrorString" attribute for that command as shown below. Consider the below configlet script to export sflow from the brocade switch to any Flow analysing tool.
<command>sflow enable</command>
<command>sflow destination $NETFLOW_IP 9996</command>
<command>sflow polling-interval 60</command>
<command>sflow agent-ip $LOOPBACK_IFNAME</command>
<command>sflow sample $SAMPLING_NUMBER</command>
<command>interface $IF_NAME</command>
<command>sflow-forwarding</command>
In case the above command is not supported in a particular series, it will not be executed properly. As mentioned initially, we were unable to determine the error based on the response and the execution result is decided as Success, even though it originally failed in the device. Refer the below screenshot for the same.
User can provide the ErrorString tag to decide the complete execution as failure and stop the execution. In this case the ErrorString will be unknown command. Refer the below configlet with error handling.
<command ErrorString="unknown command">sflow enable</command>
<command>sflow destination $NETFLOW_IP 9996</command>
<command>sflow polling-interval 60</command>
<command>sflow agent-ip $LOOPBACK_IFNAME</command>
<command>sflow sample $SAMPLING_NUMBER</command>
<command>interface $IF_NAME</command>
<command>sflow-forwarding</command>
The corresponding execution result screenshot is below. Here the execution result is decided as Failure.
Determine the execution flow.
Consider the same export sflow example. We can determine which command should be executed next based on the current response. For example, if the response contains "unknown command" string then we can execute the last command and halt the execution. If there is no error string we can proceed with the next command in sequence. Refer the below configlet.
<command Sequence="1" Condition="contains" Value="unknown command" Success="8" Failure="2">sflow enable</command>
<command Sequence="2" >sflow destination $NETFLOW_IP 9996</command>
<command Sequence="3" >sflow polling-interval 60</command>
<command Sequence="4" >sflow agent-ip $LOOPBACK_IFNAME</command>
<command Sequence="5" >sflow sample $SAMPLING_NUMBER</command>
<command Sequence="6" >interface $IF_NAME</command>
<command Sequence="7" >sflow-forwarding</command>
<command Sequence="8" >exit</command>
We can use this configlets workflow for other cases such as checking interface up/down status before configuring, checking number of ips configured for flow export before enabline new etc. Also we can check whether the configuration is properly updated or not after executing a command. If it is not reflected in the configuration we can execute the same loop again to make sure we don't miss the configuration update. Here the sequence number can be in any order. At any point you can stop the execution flow, by giving "end" in the success or failure value. If the success or failure is not defined, then the next command in the order will be executed.