Example #1
0
	def __init__(self, argv):
		self._config = None
		try:
			optlist, extraopts, args = nmsgetopt.getopt(argv[1:], "hdvc:f:n:N")
		except nmsgetopt.GetoptError, err:
			print >>sys.stderr, err
			sys.exit(2)
Example #2
0
 def __call__(self, argv):
     """
     this function is called whenever an instance object is called.
     ex. tr = TestRunner(cf); 
     """
     cf = self._config
     try:
         optlist, extraopts, args = nmsgetopt.getopt(argv[1:], "hdeRIvc:f:n:s:N")
     except nmsgetopt.GetoptError, err:
         print >>sys.stderr, err
Example #3
0
def testbed(argv):
    """testbed [-s <script>] <testbed>

    Interact with testbed and its devices.

    Options:
        -s <script> Run a CLI script from the given file instead of entering
           interactive mode.

    """
    import sys, os
    import slstorage
    import nmsgetopt

    script = None

    try:
        optlist, longopts, args = nmsgetopt.getopt(argv[1:], "s:?g")
    except GetoptError:
            print testbed.__doc__
            return
    for opt, val in optlist:
        if opt == "-?":
            print testbed.__doc__
            return
        elif opt == "-s":
            script = val

    if len(args) >= 1:
        tbname = args[0]
    else:
        print testbed.__doc__
        return


    cf = slstorage.get_config(initdict=longopts)
    # fake test module attributes
    cf.reportfile = "testbed_cli"
    cf.logbasename = "testbed_cli.log"
    cf.arguments = argv

    tb = cf.testbeds.get(tbname)
    if tb is None:
        print "Testbed not found."
        return

    tbr = strataobjects.TestBedRuntime(tb, cf.devices, cf.logfile)

    io = CLI.ConsoleIO()
    theme = TestBedTheme()
    ui = CLI.UserInterface(io, cf, theme)
    cmd = TestBedRuntimeEditor(ui)
	cmd._setup(tbr, "TestBed:%s" % (tbname,))
Example #4
0
def storagecli(argv):
    """storagecli [-?rg] [<scriptfile>...]

Provides an interactive session to the configuration server. This allows you to
interactively view and change the persistent database.

Options:
   -?        = This help text.
   -g        = used paged output (like 'more').

"""
    import nmsgetopt

    paged = False

    try:
        optlist, longopts, args = nmsgetopt.getopt(argv[1:], "?g")
    except GetoptError:
            print storagecli.__doc__
            return
    for opt, val in optlist:
        if opt == "-?":
            print storagecli.__doc__
            return
        elif opt == "-g":
            paged = True

    if paged:
        import termtools
        io = termtools.PagedIO()
    else:
        io = CLI.ConsoleIO()

    ui = CLI.UserInterface(io)

    cf = slstorage.get_config(initdict=longopts)

    cf.reportfile = __name__.replace(".", "_")
    cf.logbasename = "%s.log" % (__name__.replace(".", "_"),)
    cf.arguments = argv
    cmd = RootContainerEditor(ui)
    cmd._setup(cf, "root")

    parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_storagecli"))
    if args:
        for arg in args:
            try:
                parser.parse(arg)
            except KeyboardInterrupt:
                break
    else:
        parser.interact()
Example #5
0
def remotecli(argv):
    """remotecli [-h|-?] [-g] [-s <script>]

Provides an interactive session to a remote Client server object. Most of the
methods in the module remote.Server may be called this way.

"""
    #import testrunner
    import nmsgetopt
    import storage.Storage

    paged = False
    script = None
    try:
        optlist, longopts, args = nmsgetopt.getopt(argv[1:], "s:?hg")
    except GetoptError:
            print remotecli.__doc__
            return
    for opt, val in optlist:
        if opt == "-?" or opt == "-h":
            print remotecli.__doc__
            return
        elif opt == "-g":
            paged = True
        elif opt == "-s":
            script = val

    # do runtime setup
    cf = storage.Storage.get_config(initdict=longopts)
    #testrunner.connect_user(cf)
    #testrunner.runtime_config(cf)
    # fake test module attributes
    cf.reportfile = "remotecli"
    cf.logbasename = "remotecli.log"
    cf.arguments = argv

    theme = CLI.DefaultTheme(PROMPT)
    history=os.path.expandvars("$HOME/.hist_clientcli")
    parser = CLI.get_cli(TopLevelCLI, env=cf, paged=paged, theme=theme, historyfile=history)

    if script:
        try:
            parser.parse(script)
        except KeyboardInterrupt:
            pass
    else:
        parser.interact()
Example #6
0
def configurator_cli(argv):
    """configurator_cli [-s <script>] [-g] [<device>]

    Interact with a device configurator.

    Options:
        -g Use paged output (like 'more')
        -s <script> Run a CLI script from the given file instead of entering
           interactive mode.

    """
    import os
    import configurator
    import stratatestrunner
    import slstorage as Storage
    import nmsgetopt

    paged = False 
    script = None

    try:
        optlist, longopts, args = nmsgetopt.getopt(argv[1:], "s:?g")
    except GetoptError:
            print configurator_cli.__doc__
            return
    for opt, val in optlist:
        if opt == "-?":
            print configurator_cli.__doc__
            return
        elif opt == "-g":
            paged = True
        elif opt == "-s":
            script = val

    if len(args) >= 1:
        devname = args[0]
    else:
        print configurator_cli.__doc__
        return

    if paged:
        import termtools
        io = termtools.PagedIO()
    else:
        io = CLI.ConsoleIO()

    cf = Storage.get_config(initdict=longopts)
    stratatestrunner.runtime_config(cf)
    # fake test module attributes
    cf.reportfile = "configurator_cli"
    cf.logbasename = "configurator_cli.log"
    cf.arguments = argv

    dev = cf.devices.getpath(devname)
    if dev is None:
        print "Could not find that device."
        return
    ctor = dev.get_configurator(cf.logfile)

    # construct the CLI
    theme = ConfiguratorTheme("Configurator> ")
    ui = CLI.UserInterface(io, cf, theme)
    cmd = CLI.get_generic_cmd(ctor, ui, ConfiguratorCLI)
    parser = CLI.CommandParser(cmd, historyfile=os.path.expandvars("$HOME/.hist_configurator"))

    try:
        if script:
            try:
                parser.parse(script)
            except KeyboardInterrupt:
                pass
        else:
            parser.interact()
    finally:
        ctor.close()
        del cf.logfile