ActionCLI, CLI action

Syntax

Inside a callback action:

ActionCLI("<command>"[, title=<title>])

Outside of a callback action:

self.r.action("CLI","<command>"[, title=<title>])

Description

The CLI action executes the specified command from the switch CLI.

Parameters

<command>

A text string of the CLI command as it would be entered at a switch prompt. Examples:

  • show vlan 100

  • show running-config

  • top memory

The string can be either a single line or a multiline string with line breaks using any Python line break technique.

<title>

Specifies the title to be displayed for this action. The definition of <title> must use the Title function.

For example: title=Title("interface 1/1/1 no shutdown")

Usage

  • All CLI commands are supported as input to CLI actions.

  • Command strings are passed without validation.

  • The first CLI action executed in a script starts from the manager (#) command context. To execute commands in another context, you must include the commands to enter that context.

    For example, to execute a configuration command, you must enter the correct configuration context, as in the following action:

    ActionCLI("config\ninterface 1/1/1\nno shutdown")

    Similar to a single CLI session, subsequent CLI actions in the script execute from the command context that is in place after the previous command is executed. In the previous example, the command context is the config context, and the next CLI action starts in the config context. Commands that cannot be executed in the config context fail.

    As a best practice, include commands in each CLI command to return to a standard command context appropriate for the script—such as the manager (#) context. For example:

    ActionCLI("config\ninterface 1/1/1\nno shutdown\nexit\nexit")
    
  • You can create a custom title for this action. The title you create can help the user of the Web UI to determine what action was executed. The title is displayed in the Action Results section of the Alert Details dialog box.

Examples

Examples of a multiline CLI actions:

ActionCLI("config\ninterface 1/1/1\nno shutdown\nexit\nexit")

Example of a CLI action that uses a parameter:

ActionCLI("show interface {}",[ self.params["iface_id"]])

Example of a CLI action that uses a parameter and a custom title:

title = Title("Print interface {} details",[self.params["iface_id"]])
self.ActionCLI("show interface {}", [self.params["iface_id"]], title=title)