Implementing a configuration script

This Python script creates the links in a network that includes a router, three workstations, a bridge, and a tunnel.

Note

Note

Because vSLX configuration is persistent, this script is not needed for a single vSLX virtual lab. But it might be useful for setting up multiple networks to run multiple tests.
  1. Open a Python editor or integrated development environment (IDE) and create a new *.py file.
  2. Type the required from vsh import statement.
    from vsh import m, cmdparser
    # The function "m" defines a command executable in vShell.
  3. Create the target function.
    def demo():
    
        m("create link RT3 1/1 host6 1")
        m("create link RT3 1/2 -b BR1")
        m("create link RT3 1/5 T2 1")
        m("create link RT3 1/6 T2 2")
        m("create link -b BR1 host7 1")
        m("create link -b BR1 host30 1")
  4. Create the cmdparser(<target-function>, <syntax>, <msg>) command that calls the target function.
    cmdparser(demo, "demo_01", "Configures network of router, three workstations, bridge, and tunnel.")
    # The demo target function does not require any parameters.
  5. Save the file and copy it to the ~/.vsh directory.
    bash$ cp net_demo_01.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
     demo_01                 Configures network of router, three workstations, bridge, and tunnel.
     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 that you created.
    (vsh) demo_01
    Note

    Note

    The command you created will load every time you log in to this instance of vShell.
  9. Enter the show link command to verify that your configuration was successful.
    (vsh) show link
     Name           Port        Name           Port           State
     .....................................................................
     RT3            1/1    <--> host6          0/1            Up
     RT3            1/2    <--> BR1          [bridge]         Up
     RT3            1/5    <--> T2             0/1            Up
     RT3            1/6    <--> T2             0/2            Up
     host30         0/1    <--> BR1          [bridge]         Up
     host7          0/1    <--> BR1          [bridge]         Up