Implementation flow for vShell extensions

This topic presents a top-level view of how to add a command to your vShell instance.

  1. Open a Python editor or integrated development environment (IDE) and create a new *.py file.
  2. Type the required from vsh import statement.
    # Import Python functions from the vsh module
    from vsh import output, cmdparser
  3. Create the target function.
    # Define the function that the command will call.
    def hello(username):
    
        output("Hello %s, how are you doing?", username)
  4. Create the command that calls the target function.
    # cmdparser(<target-function>, <syntax>, <msg>)
    cmdparser(hello, "hello:%s", "Say hello to someone")
  5. Save the file and copy it to the ~/.vsh directory.
    bash$ cp demo.py ~/.vsh
  6. Start vShell.
    $ vsh
    For help anytime, type '?'
    When you're done, type '^D'
    (vsh)
  7. Verify that the command you created is available.
    (vsh) ?
     clear                   Clear
     connect                 Connect console
     create                  Provisioning
     hello                   Say hello to someone
     delete                  Destroy
     exit                    Exit shell
     help                    Get help
     list                    Show running devices
     poweroff                Power off device
     poweron                 Power on device
     show                    Show info
     start                   Power on and connect 
     system                  Bridge daemon control
  8. Enter the command—with required parameters—and verify that it performs as expected.
    (vsh) hello Mark
     Hello Mark, how are you doing?
    Note

    Note

    The command you created will load every time you log in to this instance of vShell.