Executing CLI command
Execution phase
result1_string, result2_next, result3_description = ops.cli.execute(fd, command, choice=None)
Parameter |
Description |
Value |
---|---|---|
fd |
Indicates a CLI channel handle. |
The value is generated through Opening CLI Channel API. |
command |
Indicates a command to be executed. |
The value is in CLI format, for example, display device. Only one command can be executed each time. |
choice |
Indicates the automatic response of an interactive command. This parameter does not need to be specified for a non-interactive command. |
The value contains a maximum of eight options, for example, {"Continue?": "n", "save": "n"}, which contains two options. The default value is None, which indicates that no option is included. |
The result1_string, result2_next, and result3_description in the API prototype indicate return values.
The first return value None indicates that a command is not sent to the CLI or execution of the command times out. Other values indicate output information, and at most 32 KB data can be displayed each time.
The second return value Next:0 indicates that there will be no output later, while Next:1 indicates that there will be output later. If the next batch of data needs to be obtained, this API will be invoked again, and the command and choice parameters must be set to None.
The third return value is the failure cause when the first return value is None.
Using the executing CLI command API, you can enable a script to automatically execute commands. Only one command can be executed at a time. If the choice parameter is specified, interactive information will be displayed after a command is executed, implementing interaction between users and devices.
After the ftp 10.137.217.201 command is executed, the device automatically responds to the user name and password for logging in to the FTP server.
result, n1, n2 = ops.cli.execute(handle, "ftp 10.137.217.201", {"User":"admin","password":"huawei"})
The device automatically runs the display device command to check the component information and status of the device.
result, n1, n2 = ops.cli.execute(handle, "display device")