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


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


Configuration Guide - Device Management

CloudEngine 12800 and 12800E V200R003C00

This document describes the configurations of Device Management, including device status query, hardware management, Information Center Configuration, NTP, Synchronous Ethernet Configuration, Fault Management Configuration, Energy-Saving Management Configuration, Performance Management Configuration, Maintenance Assistant Configuration, and OPS Configuration.

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).
OPS Scripting and Sample Template

OPS Scripting and Sample Template

Currently, the OPS integrates the Python running environment and can run Python scripts. In a Python script, methods of sending HTTP requests to the system need to be defined based on open RESTful APIs. When the Python script runs, HTTP requests are sent to the system to implement system management.

The following example describes how to make Python scripts to obtain device startup information.
  • When using the OPS function, you need to be familiar with the Python language and write Python scripts correctly.

  • The following Python script is for your reference. You can modify the script according to service requirements.

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import traceback
import httplib
import string

# Define the class that invokes RESTful APIs. This class defines some methods to perform the operations of setting up an HTTP connection. You can invoke this part of script without modifying it.
# You can invoke this part of script without modifying it.
class OPSConnection(object):
    """Make an OPS connection instance."""

    # Initialization class that creates an HTTP connection
    def __init__(self, host, port = 80): = host
        self.port = port
        self.headers = {
            "Content-type": "text/xml",
            "Accept":       "text/xml"
        self.conn = None

    # Close an HTTP connection.
    def close(self):
        """Close the connection"""

    # Create device resources.
    def create(self, uri, req_data):
        """Create operation"""
        ret = self.rest_call("POST", uri, req_data)
        return ret

    # Delete device resources.
    def delete(self, uri, req_data):
        """Delete operation"""
        ret = self.rest_call("DELETE", uri, req_data)
        return ret

    # Query device resources.
    def get(self, uri, req_data = None):
        """Get operation"""
        ret = self.rest_call("GET", uri, req_data)
        return ret

    # Modify device resources.
    def set(self, uri, req_data):
        """Set operation"""
        ret = self.rest_call("PUT", uri, req_data)
        return ret

    # Invoke classes internally.
    def rest_call(self, method, uri, req_data):
        """REST call"""
        print('|---------------------------------- request: ----------------------------------|')
        print('%s %s HTTP/1.1\n' % (method, uri))
        if req_data == None:
            body = ""
            body = req_data
        if self.conn:
        self.conn = httplib.HTTPConnection(, self.port)

        self.conn.request(method, uri, body, self.headers)
        response = self.conn.getresponse()
        response.status = httplib.OK    # stub code
        ret = (response.status, response.reason,
        print('|---------------------------------- response: ---------------------------------|')
        print('HTTP/1.1 %s %s\n\n%s' % ret)
        return ret

# Define the function for querying device startup information.
def get_startup_info(ops_conn):

    # Specify the uniform resource identifier (URI) of system startup information. The URI is the managed object defined in Resetful APIs. Different managed objects have different URIs.
    # You can modify the URI according to service requirements. For the supported URIs, see RESTful API.
    uri = "/cfg/startupInfos/startupInfo"

    # Specify the request to be sent. Different URIs correspond to different requests. 
    # You can modify the request based on the actual URI. For details about the request format, see RESTful API.
    req_data = \
'''<?xml version="1.0" encoding="UTF-8"?>
    # Perform a get operation request. uri and req_data indicate the request URI and request data. ret indicates whether a request is successful, and rsp_data indicates the data sent in response to the request. For details about the response data, see RESTful API.
    # The following provides the response data of device startup information. You can parse the response data to obtain device startup information.
    <?xml version="1.0" encoding="UTF-8"?>
        <cfg xmlns="" format-version="1.0" content-version="1.0">
    # You can change the request type get() according to service requirements. For example, change get() to set() or create().
    ret, _, rsp_data = ops_conn.get(uri, req_data)
    if ret != httplib.OK:
        return None

    return rsp_data

    # main() function defines the operations to be performed by this script. You can modify the function according to service requirements.
def main():
    """The main function."""

    # host indicates a loop address. Currently, RESTful API can only be invoked within the device. That is, the value is localhost.
    host = "localhost"
        # Set up an HTTP connection.
        ops_conn = OPSConnection(host)
        # Invoke the function for obtaining device startup information.
        rsp_data = get_startup_info(ops_conn)
        # Close an HTTP connection.

        errinfo = traceback.format_exc()

if __name__ == "__main__":

Updated: 2019-05-05

Document ID: EDOC1100004193

Views: 71357

Downloads: 26

Average rating:
This Document Applies to these Products

Related Version

Related Documents

Previous Next