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

RESTful API Reference

CloudEngine 12800 and 12800E V200R005C10

This document describes the OPS APIs supported by the device, including OPS-supported operations, request examples, elements in the requests, response examples, elements in the responses, and response status codes.
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).
Execute Commands

Execute Commands

  • Function Description

    The OPS allows the system to use the Python script to open a CLI channel and execute commands.

  • Command Prototype

    ops.cli.execute(fd, command, choice=None)

  • Parameter Description
    Table 31-8 Parameters supported by APIs for executing commands

    Method

    Description

    opsObj

    Specifies an OPS object. It is obtained using ops.ops() in instance mode.

    fd

    Specifies a command handle. It is generated by ops.cli.open().

    command

    Specifies a command to be executed, for example, system-view im. You do not need to press Enter; the CLI automatically adds the Enter function. The value can only be one command.

    choice

    Specifies a lexical type, used for auto reply for interactive commands.choice = {"Continue?": "n", "save": "n"}. A maximum of eight options are supported. Multiple lines are entered for multi-line commands, such as header login information, for example, choice={"": "a\r\nb\r\n\a"}.

  • Description of Return Values

    First return value: If None is returned, the command fails to be issued to the CLI or command execution times out. Otherwise, the command output is returned. Each data package is 32 KB in size, separated at a carriage return.

    Second return value: If Next is 0, no more output will be displayed. If Next is 1, more output will be displayed, and this function is still called for obtaining the next batch of data, except that you must set command=None and choice=None.

    Third return value: result description expressed in character strings

  • Example
    test.py
    
    import ops
    import igpcomm
    
    def ops_condition(_ops):
        _ops.cli.subscribe("con11","logbuffer1",True,True,False,10)
        _ops.correlate("con11")
        return ret
    
    def ops_execute(_ops):
        handle, err_desp= _ops.cli.open()
        choice = {"Continue": "y", "save": "n"}
        _ops.cli.execute(handle,"sys")
        _ops.cli.execute(handle,"pm",None)
        _ops.cli.execute(handle,"undo statistics-task a",choice)
        _ops.cli.execute(handle,"commit",None)
        ret = _ops.cli.close(handle)
        print 'test2 =',ret
        return 0
    1. When the front end executes the script, the CLI channel is opened, and the CLI terminal displays the user view.
    2. Run the system-view command to enter the system view.
    3. Run the pm command to enter the PM view.
    4. Run the undo statistics-task a command so the system operates based on the choice variable value. This command is an interactive command.
    5. Run the commit command to commit the configuration.
    6. Close the CLI channel.
Translation
Download
Updated: 2019-04-03

Document ID: EDOC1100075372

Views: 10702

Downloads: 16

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