OPS Configuration Commands
assistant scheduler suspend
Function
The assistant scheduler suspend command disables the OPS maintenance assistant function.
The undo assistant scheduler suspend command enables the OPS maintenance assistant function.
By default, the OPS maintenance assistant function is enabled.
Usage Guidelines
If the OPS maintenance assistant function is no longer needed, the assistant scheduler suspend command applies to the following scenarios:
Before deleting configured Python script assistants one by one, you can run this command to disable the OPS maintenance assistant function to prevent the assistants from running.
During system maintenance, you can run this command to disable the OPS maintenance assistant function temporarily.
After you run the assistant scheduler suspend command to disable the OPS maintenance assistant function, none of Python script assistants will run again.
display ops assistant
Parameters
Parameter |
Description |
Value |
---|---|---|
current |
Displays brief information about the current status of Python script assistants. |
- |
verbose |
Displays detailed information about the current status of Python script assistants. |
- |
history |
Displays historical operation records of Python script assistants. |
- |
name assistant-name |
Specifies the name of a Python script assistant, namely, a Python script name for a script assistant. |
The value must be the name of a script file for which the script assistant has been configured. |
Usage Guidelines
You can use this command to check the current status and historical operation record of a Python script assistant, including the Python script assistant name, running status, and execution result. The command can display a maximum of 100 latest Python script assistant records.
Example
# Display brief information about the current status of Python script assistants.
<HUAWEI> display ops assistant current
------------------------------------------------------
Assistant State Condition
------------------------------------------------------
subscribe_cli_sync_1.py ready cli
user-correlat-10.py ready multi
------------------------------------------------------
# Display detailed information about the current status of Python script assistants.
<HUAWEI> display ops assistant current verbose
Assistant information
Name :user-correlat-10.py
State :ready
Running statistics
Running times :0
Queue size/(free) :5/(5)
Skip for queue full :0
Skip for delay :0
Skip for suppression :0
Condition information
Condition tag :cli1
Condition type :multi
Threshold :1
Period (s) :0
Hits in period :0
Condition tag :cli2
Condition type :multi
Threshold :1
Period (s) :0
Hits in period :0
Condition tag :cli3
Condition type :multi
Threshold :1
Period (s) :0
Hits in period :0
Condition tag :cli4
Condition type :multi
Threshold :1
Period (s) :0
Hits in period :0
Correlate expression :((cli1 andnot cli2) and (cli3 andnot cli4))
Trigger control
Threshold :1
Period (s) :30
Delay (s) :0
Suppress max :0
Hits in period :0
Item |
Description |
---|---|
Assistant information |
Information about a Python script assistant. |
Name |
Name of a Python script assistant. |
State |
Current status of a Python script assistant.
|
Running statistics |
Detailed running information about a Python script assistant. |
Running times |
Number of running times. |
Queue size/(free) |
Number of buffered Python script assistants. If the number of buffered Python script assistants reaches the maximum value, excessive assistants will be discarded. |
Skip for queue full |
Number of tasks discarded because the queue is full. |
Skip for delay |
Number of tasks discarded within the delay. |
Skip for suppression |
Number of times the triggering of the assistant is suppressed. |
Condition information |
Condition information about a Python script assistant. The Condition information field is displayed only for a complex event script. |
Condition tag |
Condition name. |
Condition type |
Type of triggering condition. The value is multi. |
Threshold |
Maximum number of times that tasks are executed. The default value is 1. |
Period (s) |
Detection period, in seconds. The default value is 30. |
Hits in period |
Number of times the triggering condition is met in the detection period. |
Correlate expression |
Condition combination mode. |
Trigger control |
Trigger control. |
Delay (s) |
Delay in triggering a working task. The default value is 0 seconds. |
Suppress max |
Maximum number of times working tasks are triggered within the delay. The default value is 0, indicating that working tasks will not be suppressed. |
# Display historical operation records of Python script assistants.
<HUAWEI> display ops assistant history
Assistant history information
Name :subscribe_cli_sync_1.py
Running information
Trigger condition :cli
Trigger event name :cli1
Trigger time :2017-03-25 19:48:51
Execute start time :2017-03-25 19:48:51
Execute end time :2017-03-25 19:48:53
Execute result :normal
Item |
Description |
---|---|
Assistant history information |
Historical information about a Python script assistant. |
Name |
Name of a Python script assistant. |
Running information |
Running information about a Python script assistant. |
Trigger condition |
Triggering condition for a Python script assistant.
|
Trigger event name |
Trigger event name for a Python script assistant. |
Trigger time |
Triggering time of a Python script assistant. |
Execute start time |
Execution time of a Python script assistant. |
Execute end time |
End time of a Python script assistant. |
Execute result |
Execution result of a Python script assistant.
|
display ops environment
Function
The display ops environment command displays information about user-defined environment variables.
Usage Guidelines
You can run the display ops environment command to check information about user-defined environment variables after user-defined environment variables are configured using the environment command.
Example
# Display user-defined environment variables.
<HUAWEI> display ops environment
No. Name Value
1 user admin
Item |
Description |
---|---|
No. |
User-defined environment variable number. The value ranges from 1 to 100. |
Name |
Name of a user-defined environment variable. To configure this parameter, run the environment command. |
Value |
Value of a user-defined environment variable. To configure this parameter, run the environment command. |
display ops error
Usage Guidelines
You can run this command to view execution errors of all scripts or a specified script. According to the errors in the command output, you can modify the script.
Example
# Display execution errors of all scripts.
<HUAWEI> display ops error
--------------------------------------------------------------------------------
test12.py:
Traceback (most recent call last):
File ".lib/frame.py", line 114, in <module>
ret = m.ops_execute(ops)
File "flash:$_user/test12.py", line 7, in ops_execute
status, err_context = ops.context.save(varName, value)
NameError: global name 'varName' is not defined
--------------------------------------------------------------------------------
test13.py:
Traceback (most recent call last):
File ".lib/frame.py", line 114, in <module>
ret = m.ops_execute(ops)
File "flash:$_user/test13.py", line 6, in ops_execute
status, err_log = ops.syslog("Syslog: Hello, World..", ops.CRITICAL, "syslog
")
AttributeError: 'module' object has no attribute 'syslog'
--------------------------------------------------------------------------------
Item |
Description |
---|---|
test12.py |
Python script file name. |
Traceback (most recent call last) |
Last call error. |
File ".lib/frame.py", line 114, in <module> |
Stack where an error occurs. |
File "flash:$_user/test12.py", line 7, in ops_execute |
Information about location where an error occurs, including the Python script name, number of line, and phase when the error occurs. |
status, err_context = ops.context.save(varName, value) |
Invalid contents. |
NameError |
A variable error. The system is attempting to access a variable that is not declared. |
AttributeError |
An attribute error. The system is attempting to access an unknown object attribute. |
display ops system-script
Usage Guidelines
When associating OIDS with OPS, you need to use OPS scripts to subscribe to OIDS events. The device provides built-in OPS scripts, which removing the need to make scripts or download scripts from websites and import the scripts to the device. To view system built-in OPS scripts, run the display ops system-script command.
PrecautionsThe system built-in OPS scripts are not installed by default.
Example
# Display system built-in OPS scripts.
<HUAWEI> display ops system-script
ScriptName Description
--------------------------------------------------------------------------------
huawei_oids.py The OIDS sample script describes the subscriptio
n process. The execution result of the script ha
s been recorded to OIDS. You can refer to this s
cript to implement the OIDS script process.
environment
Function
The environment command configures a user-defined environment variable.
The undo environment command deletes a user-defined environment variable.
By default, no user-defined environment variable is configured.
Parameters
Parameter |
Description |
Value |
---|---|---|
variable-name |
Specifies the name of a user-defined environment variable. |
The value is a string of 1 to 31 case-sensitive characters without spaces. It starts with a letter and contains only letters, digits, and underscores (_). |
variable-value |
Specifies the value of a user-defined environment variable. |
The value is a string of 1 to 64 case-sensitive characters without spaces. If the string is enclosed in double quotation marks (""), the string can contain spaces. |
Usage Guidelines
Usage Scenario
An environment variable consists of a name and a value. In a Python script, you can input an environment variable name in the location where a parameter needs to be input to indicate that an environment variable value needs to be referenced. When the system is running a Python script, it replaces an environment variable name with an environment variable value. To change the value, you can directly change it on the device without having to change and install the Python script. You can define and use user-defined environment variables to simplify the configuration and improve flexibility and feasibility of the Python script.
Precautions
If variable-name is specified multiple times, the system will prompt that the configured user-defined environment variable already exists. You can choose whether to overwrite the existing variable value. After overwriting the existing variable value, you need to run the undo script-assistant python command to delete the Python script assistant that uses the environment variable and then run the script-assistant python command to re-configure the Python script assistant.
A maximum of 100 environment variables can be configured on the device.
To check configured user-defined environment variables, run the display ops environment command.
ops abort
Usage Guidelines
Usage Scenario
If commands cannot be entered on the switch due to OPS Python script exceptions, run the ops abort command to stop all OPS Python scripts to make the switch work properly.
Prerequisites
Running the ops abort command on the active MPU will not be captured by the CLI event subscription API (ops.cli.subscribe), but running this command on the standby MPU will be captured by this API.
ops install file
Parameters
Usage Guidelines
Usage Scenario
OPS allows you to run the scripts you make. A script can be executed after the script assistant is configured. Before configuring a script assistant, install the script.
To check information about the scripts installed in $_user, run the dir (user view) command.
Precautions
- Before installing a script, upload the script to the root directory of flash: on the device.
- Ensure that the device has sufficient storage space when the script is installed. Otherwise, the script fails to be installed.
- If the specified installation directory does not exist, a directory will be created. A maximum of seven levels of subdirectories can be created in $_user.
- The name of the script to be installed cannot be the same as an existing directory name on the device. After scripts are installed successfully, you cannot create a directory whose name is the same as that of an installed script.
- To install scripts in $_user, you can only run the ops install file command. The scripts installed in this directory will be automatically backed up to the standby card.
- To modify a script that has been installed, run the ops uninstall file command to uninstall the script and the delete (user view) command to delete the script file. After modifying the script, upload and reinstalling the script file.
- It is recommended that the total size of files installed in $_user be smaller than 100 MB. If the total size of files exceeds 100 MB, performance of data synchronization between the active and standby cards may deteriorate.
Example
# Install the script file config.py in the flash: root directory to the default flash:/$_user.
<HUAWEI> ops install file config.py
# Install the script file config.py in the flash: root directory to the specified flash:/$_user/user.
<HUAWEI> ops install file config.py destination user
# Install the script file config.py in the flash:/admin directory to the default flash:/$_user.
<HUAWEI> ops install file admin/config.py
ops uninstall file
Parameters
Parameter |
Description |
Value |
---|---|---|
file-name |
Specifies the name of the script file to be uninstalled. |
The value must be the name of a script file that has been installed. If a script in a specified installation directory directory/file-name needs to be deleted, directory specifies the installation directory of the script. NOTE:
The total length of file-name and the installation directory of the script cannot exceed 118. The total length refers to the storage path + $_user + directory name + file name. |
Usage Guidelines
Usage Scenario
You can uninstall unnecessary scripts to release storage space on a device. If an installed script needs to be updated, uninstall it first, and reinstall it after the update.
Precautions
This command cannot uninstall a script for which a script assistant has been configured. To uninstall the script, delete the script assistant first.
If the script for which a script assistant has configured invokes another script, the called script can be uninstalled using this command. Therefore, it is recommended that you use one script to implement required functions.
script-assistant python
Function
The script-assistant python command configures a Python script assistant.
The undo script-assistant python command deletes a Python script assistant.
By default, no Python script assistant is configured.
Parameters
Parameter |
Description |
Value |
---|---|---|
script-name |
Specifies the name of a Python script assistant, namely, a Python script name for a script assistant. |
The value must be the name of a script file that has been installed. NOTE:
script-name cannot be set to the file name of a built-in Python script, including ConfigParser.py, copy_reg.py, locale.py, sre.py, Queue.py, decimal.py, macurl2path.py, sre_compile.py, StringIO.py, dis.py, modulefinder.py, sre_constants.py, UserDict.py, dummy_thread.py, ntpath.py, sre_parse.py, UserList.py, dummy_threading.py, nturl2path.py, stat.py, UserString.py, filecmp.py, numbers.py, string.py, __future__.py, fileinput.py, opcode.py, stringold.py, _abcoll.py, fnmatch.py, os.py, struct.py, _pyio.py, formatter.py, os2emxpath.py, subprocess.py, _strptime.py, fractions.py, pickle.py, sysconfig.py, _threading_local.py, functools.py, pkgutil.py, textwrap.py, _weakrefset.py, genericpath.py, platform.py, threading.py, abc.py, getopt.py, posixpath.py, token.py, argparse.py, getpass.py, pprint.py, tokenize.py, atexit.py, gettext.py, re.py, trace.py, base64.py, glob.py, repr.py, traceback.py, bisect.py, heapq.py, runpy.py, types.py, calendar.py, imputil.py, sched.py, user.py, codecs.py, inspect.py, sets.py, warnings.py, collections.py, io.py, shutil.py, weakref.py, contextlib.py, keyword.py, site.py, xmllib.py, copy.py, linecache.py, socket.py, _cli.py, _device.py, _frame.py, _route.py, _timer.py, _common.py, _environment.py, _iclog.py, _snmp.py, _trap.py, _context.py, _farg.py, _lldp.py, _terminal.py, and ops.py. |
Usage Guidelines
Usage Scenario
As networks are developing rapidly, existing network devices provide only limited functions and predefined services, failing to meet the requirements for diversified services. You can run the script using OPS to implement customized functions.
The device supports a built-in Python script interpreter. You can run the script-assistant python command to run a Python script and register the events defined in the script.
Prerequisites
The script has been uploaded to the device and installed using the ops install file command in the user view.
Precautions
Only one assistant can be configured for a Python script. A maximum of 100 Python script assistants can be configured on the device.
The system does not check correctness of the Python script.
If you run the undo script-assistant python command to uninstall the script assistant, the corresponding Python script will be terminated.
shutdown script-assistant
Function
The shutdown script-assistant command stops a Python script assistant.
The undo shutdown script-assistant command starts a Python script assistant.
By default, the Python script assistant is started.