No relevant resource is found in the selected language.

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Read our privacy policy>Search

Reminder

To have a better experience, please upgrade your IE browser.

upgrade

Configuration Guide - Device Management

S7700 and S9700 V200R013C00

This document describes the configurations of Device Management, including device status query, hardware management, CSS, SVF, PoE, OPS, OIDS, energy-saving management, information center, fault management, NTP, synchronous ethernet, PTP.
Rate and give feedback:
Huawei uses machine translation combined with human proofreading to translate this document to different languages in order to help you better understand the content of this document. Note: Even the most advanced machine translation cannot match the quality of professional translators. Huawei shall not bear any responsibility for translation accuracy and it is recommended that you refer to the English document (a link for which has been provided).
Example for Using a User-defined Command to Monitor Changes of Important Routes

Example for Using a User-defined Command to Monitor Changes of Important Routes

Networking Requirements

In Figure 6-3, the user remotely manages a switch through a network and wants to use a user-defined command to monitor changes of important routes and generate logs to detect changes of important routes as soon as they occur.

Figure 6-3  Networking for important route change monitoring using a user-defined command

Configuration Roadmap

  1. Make Python scripts climuti.py and route_track.py to customize the command for monitoring changes of important routes and generate logs when important routes change.

  2. Log in to the switch remotely, upload the Python script to the switch, and install the script climuti.py.

  3. Configure a Python script assistant.

Procedure

  1. Make Python scripts.

    # Make Python scripts climuti.py and route_track.py to implement the following functions:
    • The script climuti.py defines the routetrack command to enable the function of monitoring changes of important routes and install the script route_track.py.

      NOTE:

      To prevent failures to copy or delete Python script files, ensure that the command lines subscribed using ops.cli.subscribe are different from the names of Python script files.

    • The script route_track.py monitors the changes of routes and generates logs when routes change.

  2. Upload and install the Python script.

    # Log in to the switch remotely and upload the Python scripts from the PC to the switch. For details about how to upload a file, see File Management in S7700 and S9700 V200R013C00 Configuration Guide - Basic Configuration.

    # Install the Python script on the switch.

    <Switch> ops install file climuti.py

  3. Configure a Python script assistant.

    # Configure a Python script assistant and register the CLI event in the script climuti.py. Wait for the event to be triggered.

    <Switch> system-view
    [Switch] ops
    [Switch-ops] script-assistant python climuti.py
    [Switch-ops] quit
    [Switch] quit

  4. Verify the configuration.

    # After the preceding configurations are complete, run the routetrack command to enable the function of monitoring the changes of important routes and then check whether the script route_track.py has been installed successfully in the flash:/$_user/ directory of the switch.

    <Switch> routetrack
    <Switch> cd $_user
    <Switch> dir
    Directory of flash:/$_user/                                                       
                                                                                    
      Idx  Attr     Size(Byte)  Date        Time       FileName                     
        0  -rw-          1,672  Mar 22 2018 14:29:33   climuti.py              
        1  -rw-          2,000  Mar 22 2018 14:29:57   climuti.pyc             
        2  -rw-            441  Mar 22 2018 14:31:00   route_track.py              
        3  -rw-            891  Mar 22 2018 14:31:03   route_track.pyc             
                                                                                    
    1,927,468 KB total available (387,044 KB free)
    NOTE:

    A .pyc file is generated after a Python script file is compiled. Whether the .pyc file is generated is irrelevant to the installation result of the corresponding Python script. Therefore, you do not need to focus on the .pyc file.

    A .pyc file cannot be deleted separately. It is automatically deleted when the ops uninstall file command is executed to uninstall the corresponding Python script.

    # Enable the log function. When changes of important routes are monitored, the switch automatically generates logs.

    <Switch> system-view
    [Switch] info-center enable
    [Switch] quit
    <Switch> terminal monitor
    <Switch> terminal logging
    <Switch>
    Mar 28 2018 14:29:17+08:00 Switch %%01OPSA/2/SCRIPT_LOG: OPS: Syslog: The important route changed. (user="route_track.py", session=964036020).

Configuration Files and Scripts

  • Configuration file of the switch

    #
    ops
     script-assistant python climuti.py
     script-assistant python route_track.py
    #
    return
    NOTE:

    The script-assistant python route_track.py command is displayed in the configuration file only when the event subscribed in the climuti.py script is triggered by the routetrack command.

  • Example of the script climuti.py

    # -*- coding: utf-8 -*-
    import ops         # Import the OPS module.
    import sys         # Import the sys module.
    import os          # Import the os module.
    # Subscription processing function
    def ops_condition (ops):
    	# User-defined command routetrack
    	value1, err_str1 = ops.cli.subscribe("cli1", "routetrack", enter=True)
    	# User-defined command no routetrack
    	value2, err_str2 = ops.cli.subscribe("cli2", "no routetrack", enter=True)
    	# Combined event, input the routetrack or no routetrack command.
    	value10, err_str10 = ops.correlate("cli1 or cli2")
    	return 0
    # Work processing function
    def ops_execute (ops):
    	# Obtain the system environment variable _cli_input, indicating the user input command.
    	key, value = ops.environment.get("_cli_input")
    	# When finding that the routetrack command is input, perform the following operations:
    	if key == "routetrack":
    		# Open the CLI channel.
    		handle, err_desp = ops.cli.open()
    		# Run the ops install file route_track.py command to install the script route_track.py.
    		result, n11, n21 = ops.cli.execute(handle,"ops install file route_track.py")
    		# Run the system-view command to enter the system view.
    		result, n11, n21 = ops.cli.execute(handle,"system-view")
    		# Run the ops command to enter the OPS view.
    		result, n11, n21 = ops.cli.execute(handle,"ops")
    		# Run the script-assistant python route_track.py command to configure an assistant for the script route_track.py.
    		result, n11, n21 = ops.cli.execute(handle,"script-assistant python route_track.py")
    		# Close the CLI channel.
    		result = ops.cli.close(handle)
    	# When finding that the no routetrack command is input, perform the following operations:
    	elif key == "no routetrack":
    		# Open the CLI channel.
    		handle, err_desp = ops.cli.open()
    		# Run the system-view command to enter the system view.
    		result, n11, n21 = ops.cli.execute(handle,"system-view")
    		# Run the ops command to enter the OPS view.
    		result, n11, n21 = ops.cli.execute(handle,"ops")
    		# Run the undo script-assistant python route_track.py command to delete the assistant for the script route_track.py.
    		result, n11, n21 = ops.cli.execute(handle,"undo script-assistant python route_track.py")
    		# Run the quit command to return to the system view.
    		result, n11, n21 = ops.cli.execute(handle,"quit")
    		# Run the quit command to return to the user view.
    		result, n11, n21 = ops.cli.execute(handle,"quit")
    		# Run the ops uninstall file route_track.py command to uninstall the script route_track.py.
    		result, n11, n21 = ops.cli.execute(handle,"ops uninstall file route_track.py")   
    		# Close the CLI channel.
    		result = ops.cli.close(handle)
    	else:
    		return 1
    	return 0
    
  • Example of the script route_track.py

    # -*- coding: utf-8 -*-
    import ops         # Import the OPS module.
    import sys         # Import the sys module.
    import os          # Import the OS module.
    # Subscription processing function
    def ops_condition (ops):
    	# Monitor changes of OSPF routes to network segment 10.20.1.0/24.
    	value, err_str = ops.route.subscribe("route1", "10.20.1.0", maskLen=24, optype="modify", protocol="ospf")
    	return 0
    # Work processing function
    def ops_execute (ops):
    	# Record user-defined critical user logs to notify route changes.
    	status, err_log = ops.syslog("Syslog: The important route changed.", "critical", "syslog")
    	return 0
    
Translation
Download
Updated: 2019-04-20

Document ID: EDOC1100065738

Views: 44919

Downloads: 37

Average rating:
This Document Applies to these Products
Related Version
Related Documents
Share
Previous Next