- Table of Contents
-
- 02-Fundamentals Configuration Guide
- 00-Preface
- 01-CLI configuration
- 02-RBAC configuration
- 03-Login management configuration
- 04-FTP and TFTP configuration
- 05-File system management configuration
- 06-Configuration file management configuration
- 07-Software upgrade configuration
- 08-Python configuration
- 09-Tcl configuration
- Related Documents
-
Title | Size | Download |
---|---|---|
09-Tcl configuration | 97.91 KB |
Restrictions and guidelines: Tcl
Using Tcl commands to configure the device
Executing Comware commands in Tcl configuration view
About executing Comware commands in Tcl configuration view
Using Tcl
About Tcl
Comware 9 provides a built-in tool command language (Tcl) interpreter. From user view, you can use the tclsh command to enter Tcl configuration view to execute the following commands:
· Tcl 8.5 commands.
· Comware commands.
The Tcl configuration view is equivalent to the user view. You can use Comware commands in Tcl configuration view in the same way they are used in user view.
Restrictions and guidelines: Tcl
To return from a subview under Tcl configuration view to the upper-level view, use the quit command.
To return from a subview under Tcl configuration view to the Tcl configuration view, press Ctrl+Z.
Using Tcl commands to configure the device
Restrictions and guidelines
When you use Tcl to configure the device, follow these restrictions and guidelines:
· You can apply Tcl environment variables to Comware commands.
· No online help information is provided for Tcl commands.
· You cannot press Tab to complete an abbreviated Tcl command.
· Make sure the Tcl commands can be executed correctly.
· As a best practice, log in through Telnet or SSH. You cannot stop Tcl commands by using a shortcut key or a CLI command. If a problem occurs when the Tcl commands are being executed, you can terminate the process by closing the connection if you logged in through Telnet or SSH. If you logged in from the console port, you must perform one of the following tasks:
¡ Restart the device.
¡ Log in to the device by using a different method, and use the free line command to release the AUX line. For more information about the command, see Fundamentals Command Reference.
· You can press Ctrl+D to abort Tcl command read stdin.
Procedure
1. Enter Tcl configuration view from user view.
tclsh
2. Execute a Tcl command.
Tcl command
3. Return from Tcl configuration view to user view.
¡ tclquit
¡ quit
Executing Comware commands in Tcl configuration view
About executing Comware commands in Tcl configuration view
To execute a Comware command in Tcl configuration view, use one of the following methods:
· Enter the Comware command directly. If a Tcl command uses the same command string as the Comware command, the Tcl command is executed.
· Prefix the Comware command with the cli keyword. If a Tcl command uses the same command string as the Comware command, the Comware command is executed.
Restrictions and guidelines
Follow these restrictions and guidelines when you execute Comware commands in Tcl configuration view:
· To specify a string enclosed in quotation marks (") or braces ({ and }), you must use the escape character (\) before the quotation marks or braces. For example, to specify "a" as the description for an interface, you must enter description \"a\". If you enter description "a", the description is a.
· For Comware commands, you can enter ? to obtain online help or press Tab to complete an abbreviated command. For more information, see "Using the CLI."
· The cli command is a Tcl command, so you cannot enter ? to obtain online help or press Tab to complete an abbreviated command.
· Successfully executed Comware commands are saved to command history buffers. You can use the upper arrow or lower arrow key to obtain executed commands.
· To execute multiple Comware commands in one operation:
¡ Enter multiple Comware commands separated by semi-colons to execute the commands in the order they are entered. For example, vlan 2;description Tech.
¡ Specify multiple Comware commands for the cli command, quote them, and separate them by a space and a semicolon. For example, cli "vlan 2 ;description Tech".
¡ Specify one Comware command for each cli command and separate them by a space and a semicolon. For example, cli vlan 2 ;cli description Tech.
Procedure
1. Enter Tcl configuration view
tclsh
2. Execute Comware commands.
¡ Execute Comware commands directly.
Command
¡ Execute Comware commands by using the cli command.
cli command
3. Return from Tcl configuration view to user view.
¡ tclquit
¡ quit
Comware 9 extended Tcl API
The Comware 9 extended Tcl API is compatible with the Tcl syntax.
create-cli
Use create-cli to create CLI channels.
Syntax
::comware::create-cli
Usage guidelines
CLI channels are used to execute commands. For more information, see "write-cli."
You can create multiple CLI channels by executing this command multiple times. The created CLI channels are named cli0, cli1, and so on.
CLI channels are independent of each other and can be regarded as separate command line terminals.
Examples
# Create a CLI channel.
<Sysname> tclsh
<Sysname-tcl> ::comware::create-cli
Sample output
cli0
destroy-cli
Use destroy-cli to delete a CLI channel.
Syntax
::comware::destroy-cli cli-channel-name
Parameters
cli-channel-name: Specifies an existing CLI channel by its name.
Examples
# Delete CLI channel cli0.
<Sysname> tclsh
<Sysname-tcl> ::comware::destroy-cli cli0
write-cli
Use write-cli to execute a Comware command by using a CLI channel.
Syntax
::comware::write-cli cli-channel-name command
Parameters
cli-channel-name: Specifies an existing CLI channel by its name.
command: Specifies the command to be executed. Quotation marks (") are required before and after the command. Only one command can be executed at a time.
Usage guidelines
CLI channels do not support interactive commands. A CLI channel executes a command at the background and does not display any command output information.
By default, a CLI channel executes a command in user view. To execute a command in a different view, you must execute the commands required to enter the view first.
Examples
# Use CLI channel cli0 to enter system view and change the device name to abc.
<Sysname> tclsh
<Sysname-tcl> ::comware::write-cli cli0 "system-view"
<Sysname-tcl> ::comware::write-cli cli0 "sysname abc"
<Sysname-tcl>
Sample output
<abc-tcl>
execute-shell-cmd
Use execute-shell-cmd to execute Comware commands.
Syntax
::comware::execute-shell-cmd command
Parameters
command: Specifies the commands to be executed. To enter multiple commands, use a space and a semicolon (;) as the delimiter, for example, "system-view ;sysname test."
Usage guidelines
By default, the commands are executed in user view. To execute a command in a different view, enter the commands required to enter the view first.
Examples
# Enter system view, change the device name to test, and then ping a remote device.
<Sysname> tclsh
<Sysname-tcl> ::comware::execute-shell-cmd "system-view ;sysname test ;ping 192.168.56.1"
Sample output
<Sysname> system-view
System View: return to User View with Ctrl+Z.
[Sysname] sysname test
[test] ping 192.168.56.1
Ping 192.168.56.1 (192.168.56.1): 56 data bytes, press the char(ASCII 0) to break
56 bytes from 192.168.56.1: icmp_seq=0 ttl=128 time=1.000 ms
...
getmaxslotnumber
Use getmaxslotnumber to get the maximum slot number in the system.
Syntax
::comware::getmaxslotnumber
Returns
The output of this command is a global slot number.
Examples
# Get the maximum slot number in the system.
<Sysname> tclsh
<Sysname-tcl> ::comware::getmaxslotnumbers
Sample output
1
getminslotnumber
Use getminslotnumber to get the minimum slot number in the system.
Syntax
::comware::getminslotnumber
Examples
# Get the minimum slot number in the system.
<Sysname> tclsh
<Sysname-tcl> ::comware::getminslotnumber
Sample output
1
get_self_slot
(Centralized cloud cluster devices.) Use get_self_slot to get the member ID of the master device.
Syntax
::comware::get_self_slot
Returns
A list object in the format of (-1,slot-number). The slot-number indicates the member ID of the master device.
Examples
# Get the member ID of the master device.
<Sysname> tclsh
<Sysname-tcl> ::comware::get_self_slot
Sample output
(-1,-1)
get_slot_info
Use get_slot_info to get information about the device.
Use get_slot_info to get information about a member device.
Use get_slot_info to get information about a card.
Syntax
::comware::get_slot_info global-slot-number
Parameters
global-slot-number: Specifies a global slot number.
Returns
A dictionary object in the format of Chassis chassis-number Slot slot-number Cpu CPU-number Role role Status status.
Field |
Description |
chassis-number |
Fixed at 0. |
slot-number |
Member ID of the member device. |
CPU-number |
Fixed at 0. |
role |
Role of the member device. |
status |
Status of the member device. |
Examples
# Get information about the device, a card, or a member device.
<Sysname> tclsh
<Sysname-tcl> ::comware::get_slot_info 1
Sample output
Chassis Slot 1 Cpu 0 Role Master Status Normal
get_standby_slot
Use get_standby_slot to get the member IDs of the subordinate devices.
Syntax
::comware::get_standby_slot
Returns
A list object in one of the following formats:
· (-1,slot-number)—The cloud cluster fabric has only one subordinate device.
· (-1,slot-number1),(-1,slot-number2),...—The cloud cluster fabric has multiple subordinate devices.
If the cloud cluster fabric does not have a subordinate device, the return is fixed at null.
Examples
# Get the member IDs of the subordinate devices.
<Sysname> tclsh
<Sysname-tcl> ::comware::get_standby_slot
Sample output
(-1,1),(-1,2)
transfer
Use transfer to download a file from a server.
Syntax
::comware::transfer protocol server-ip source-file dest-file vpn-instance-name session-timeout user-name password
Parameters
protocol: Specifies the protocol used to download a file:
· ftp—Uses FTP.
· tftp—Uses TFTP.
· http—Uses HTTP.
server-ip: Specifies the IP address of the remote server.
source-file: Specifies the name of the file to be downloaded.
dest-file: Specifies a name for the downloaded file.
vpn-instance-name: Specifies the VPN instance to which the remote server belongs. This argument represents the VPN instance name, a case-sensitive string of 1 to 31 characters.
session-timeout: Specifies the timeout for the operation, in seconds. The session timeout must be a non-negative integer. If the value for this argument is 0, the timeout will be 300 seconds.
user-name: Specifies the username for logging in to the server.
password: Specifies the login password.
Examples
# Download file testfile from an FTP server and save it as flash:/localfile.cfg.
<Sysname> tclsh
<Sysname-tcl> ::comware::transfer ftp 192.168.3.76 testfile flash:/localfile.cfg vpn1 0 admin admin