Пример #1
0
def no(argv):
    """Invalidate an ARP entry or all ARP entries
        syntax: no arp [<ip-address>]
    """
    if argv[0] == 'clear_arp':
        msg = clear.__doc__
    else:
        msg = no.__doc__

    output = lib.output.CLIoutput("arp")
    if len(argv) > 2:
        output.completeOutputError(InvalidArgumentCount(syntax=msg))
        return output

    if len(argv) == 1:
        arp_entries = open("/proc/net/arp", 'r').readlines()
        for line in arp_entries[1:]:  # skip header
            cmd = (_ARP, "-d", line.split()[0])
            lib.process.execute_command(cmd)
        output.completeOutputSuccess()
        return output

    ipaddr = argv[1]
    try:
        lib.essentials.checkIp(ipaddr)
    except InvalidIpException, ex:
        output.completeOutputError(ex)
        return output
Пример #2
0
def edit(argv):
    """Halt the system. 
        syntax: halt [now]
    """

    output = lib.output.CLIoutput("halt")

    xml_out = 0

    if len(argv) == 2 and argv[1] == "now":
	xml_out = 1

    if (len(argv) == 2 and argv[1] != "now") or len(argv) > 2:
        output.completeOutputError(InvalidArgumentCount ())
	return output

    if (len(argv) == 1):
        try:
            doit = lib.essentials.confirm(
                "Are you sure that you want to halt the system")
        except lib.errorhandler.InteractiveCliRequired, ex:
            output.completeOutputError(ex)
            return output
            
        if not doit:
	    print "\nHalt aborted."
            output.completeOutputSuccess()
	    return output
Пример #3
0
def show(argv):
    """Show the contents of the ARP cache
        syntax: show arp
    """
    output = lib.output.CLIoutput("arp", _output_handlers)
    if len(argv) != 1:
        output.completeOutputError(InvalidArgumentCount (syntax = show.__doc__))
        return output

    arp_entries = open("/proc/net/arp", 'r').readlines()
    output.beginList("ARPentryList")
    for line in arp_entries[1:]:           # skip header
        fields = line.split()
        output.beginAssembling("ARPentry")
        output.setVirtualNameValue("IPaddress", fields[0])
        if int(fields[2], 16) == 0:
            output.setVirtualNameValue("HWaddress", "(unresolved)")
        else:
            output.setVirtualNameValue("HWaddress", fields[3])
        output.setVirtualNameValue("InterfaceName", fields[5])
        output.endAssembling("ARPentry")

    output.endList("ARPentryList")
    output.completeOutputSuccess()
    #print output
    return output
Пример #4
0
def no(argv):
    """Invalidate an ARP entry or all ARP entries
        syntax: no arp [<ip-address>]
    """
    if argv[0] == 'clear_arp':
        msg = clear.__doc__
    else:
        msg = no.__doc__

    output = lib.output.CLIoutput("arp")
    if len(argv) > 2:
        output.completeOutputError(InvalidArgumentCount (syntax = msg))
        return output

    if len(argv) == 1:
        arp_entries = open("/proc/net/arp", 'r').readlines()
        for line in arp_entries[1:]:           # skip header
            cmd = (_ARP, "-d", line.split()[0])
            lib.process.execute_command(cmd)
        output.completeOutputSuccess()
        return output

    ipaddr = argv[1]
    try:
        lib.essentials.checkIp(ipaddr)
    except InvalidIpException, ex:
        output.completeOutputError(ex)
        return output
Пример #5
0
def show(argv):
    """Show the contents of the ARP cache
        syntax: show arp
    """
    output = lib.output.CLIoutput("arp", _output_handlers)
    if len(argv) != 1:
        output.completeOutputError(InvalidArgumentCount(syntax=show.__doc__))
        return output

    arp_entries = open("/proc/net/arp", 'r').readlines()
    output.beginList("ARPentryList")
    for line in arp_entries[1:]:  # skip header
        fields = line.split()
        output.beginAssembling("ARPentry")
        output.setVirtualNameValue("IPaddress", fields[0])
        if int(fields[2], 16) == 0:
            output.setVirtualNameValue("HWaddress", "(unresolved)")
        else:
            output.setVirtualNameValue("HWaddress", fields[3])
        output.setVirtualNameValue("InterfaceName", fields[5])
        output.endAssembling("ARPentry")

    output.endList("ARPentryList")
    output.completeOutputSuccess()
    #print output
    return output
Пример #6
0
def edit(argv):
    """Halt the system. 
        syntax: halt [now]
    """

    output = lib.output.CLIoutput("halt")

    xml_out = 0

    if len(argv) == 2 and argv[1] == "now":
        xml_out = 1

    if (len(argv) == 2 and argv[1] != "now") or len(argv) > 2:
        output.completeOutputError(InvalidArgumentCount())
        return output

    if (len(argv) == 1):
        try:
            doit = lib.essentials.confirm(
                "Are you sure that you want to halt the system")
        except lib.errorhandler.InteractiveCliRequired, ex:
            output.completeOutputError(ex)
            return output

        if not doit:
            print "\nHalt aborted."
            output.completeOutputSuccess()
            return output
Пример #7
0
def _gen_timezones(output, timezones):
    output.beginList(_XMLTAG_TimeZoneList)
    for x in timezones:
        output.setVirtualNameValue(_XMLTAG_TimeZone, x)
    output.endList(_XMLTAG_TimeZoneList)
    
    output.completeOutputSuccess()
    return output
Пример #8
0
def add(argv):
    """Print all help messages for commands that take the "add" modifier
        syntax: add help
    """
    output = lib.output.CLIoutput("help")
    output.setVirtualNameValue("Help", _ADD_HELP_TEXT)
    output.completeOutputSuccess()
    return output
Пример #9
0
def _gen_timezones(output, timezones):
    output.beginList(_XMLTAG_TimeZoneList)
    for x in timezones:
        output.setVirtualNameValue(_XMLTAG_TimeZone, x)
    output.endList(_XMLTAG_TimeZoneList)

    output.completeOutputSuccess()
    return output
Пример #10
0
def clear(argv):
    """Print all help messages for commands that take the "clear" modifier
        syntax: clear help
    """
    output = lib.output.CLIoutput("help")
    output.setVirtualNameValue("Help", _CLEAR_HELP_TEXT)
    output.completeOutputSuccess()
    return output
Пример #11
0
def _show_bridge(output, argv, bridge_id):
    """
       Show bridge
           syntax : show bridge
    """
    output.beginList("BridgeSpecList")
    _get_bridge_from_db(output, "bridge", bridge_id)
    output.endList("BridgeSpecList")
    output.completeOutputSuccess()
Пример #12
0
def _show_iomodule(output, argv):
    """
       Show iomodule
           syntax : show iomodule
    """
    output.beginList("IomoduleSpecList")
    _get_iomodule_values(output, "iomodule")
    output.endList("IomoduleSpecList")
    output.completeOutputSuccess()
Пример #13
0
def _show_bridge(output, argv, bridge_id):
    """
       Show bridge
           syntax : show bridge
    """
    output.beginList("BridgeSpecList")
    _get_bridge_from_db(output, "bridge", bridge_id)
    output.endList("BridgeSpecList")
    output.completeOutputSuccess()
Пример #14
0
def _show_vadapter_module(output, argv, vadapter_id):
    """
       Show vadapter <vadapter-id>
           syntax : show vadapter <vadapter-id>
    """
    param1 = 0
    output.beginList("VadapterSpecList")
    param1 =  _get_vadapter_values(output, "vadapter", vadapter_id)    
    output.endList("VadapterSpecList")
    if param1 != -1 :
        output.completeOutputSuccess()
    return output
Пример #15
0
def _show_vfabric(output, argv):
    """
       Show vfabric
           syntax : show vfabric
    """
    param1 = 0
    output.beginList("VfabricSpecList")
    param1 = _get_vfabric_values(output, "vfabric", "All")
    output.endList("VfabricSpecList")
    if param1 != -1:
        output.completeOutputSuccess()
    return output
Пример #16
0
def _show_vfabric_module(output, argv, vfabric_id):
    """
       Show vfabric <vfabric_id>
           syntax : show vfabric <vfabric_id>
    """
    param1 = 0
    output.beginList("VfabricSpecList")
    _get_vfabric_values(output, "vfabric", vfabric_id)
    output.endList("VfabricSpecList")
    if param1 != -1:
        output.completeOutputSuccess()
    return output
Пример #17
0
def _show_vadapter(output, argv):
    """
       Show vadapter
           syntax : show vadapter
    """
    param1 = 0
    output.beginList("VadapterSpecList")
    param1 =_get_vadapter_values(output, "vadapter", "ALL")
    output.endList("VadapterSpecList")
    if param1 != -1 :
         output.completeOutputSuccess()
    return output
Пример #18
0
def _show_vfabric(output, argv):
    """
       Show vfabric
           syntax : show vfabric
    """
    param1 = 0
    output.beginList("VfabricSpecList")
    param1 = _get_vfabric_values(output, "vfabric", "All")
    output.endList("VfabricSpecList")
    if param1 != -1 :
        output.completeOutputSuccess()
    return output
Пример #19
0
def _show_vfabric_module(output, argv, vfabric_id):
    """
       Show vfabric <vfabric_id>
           syntax : show vfabric <vfabric_id>
    """
    param1 = 0
    output.beginList("VfabricSpecList")
    _get_vfabric_values(output, "vfabric", vfabric_id)
    output.endList("VfabricSpecList")
    if param1 != -1:
        output.completeOutputSuccess()
    return output 
Пример #20
0
def _show_gateway(output, argv):
    """
       Show gateway
           syntax : show gateway
		    show gateway < gateway-id >
		    show gateway < help | ?  >
    """

    if len(argv) > 1 or argv[0] == "?" or argv[0] == "help" or argv[0] == "":
        output.completeOutputError(InvalidArgumentCount(syntax=show.__doc__))
        return output

    elif len(argv) == 1:
        print argv[0]

    output.beginList("GatewaySpecList")
    _get_gateway_from_db(output, "gateway")
    output.endList("GatewaySpecList")
    output.completeOutputSuccess()
Пример #21
0
def show(argv):
    """Get the hostname
        syntax: show hostname
   """ 
    output = lib.output.CLIoutput("hostname")
    if len(argv) > 1:
        output.completeOutputError(InvalidArgumentCount (syntax=show.__doc__))
        return output
    # Get hostname from the system.
    hostname = getSystemHostname()
    #print hostname
    if hostname is None:
        output.completeOutputError("unable to determine current hostname")
        return output
    output.beginAssembling("hostname")
    output.setVirtualNameValue("hostname",hostname)
    output.endAssembling("hostname")
    output.completeOutputSuccess()
    return output
Пример #22
0
def _show_gateway(output, argv):
    """
       Show gateway
           syntax : show gateway
		    show gateway < gateway-id >
		    show gateway < help | ?  >
    """
   
    if len(argv) > 1 or argv[0] == "?" or argv[0] == "help" or argv[0] == "":
	output.completeOutputError(InvalidArgumentCount(syntax =show.__doc__))
	return output

    elif len(argv) == 1:
	print argv[0]

    output.beginList("GatewaySpecList")
    _get_gateway_from_db(output,"gateway")
    output.endList("GatewaySpecList")
    output.completeOutputSuccess()
Пример #23
0
def _set_timezone(entered_time_zone):
    output = lib.output.CLIoutput("clock")

    new_time_zone = entered_time_zone
    tz_link_target = _TZ_TARGET_DIR + new_time_zone

    if not os.path.isfile(tz_link_target):
        new_time_zone = _find_case_insensitive_timezone(entered_time_zone)
        if not new_time_zone:
            print NameError('Invalid timezone specified.'
                            ' Try "show clock timezones [all]".')
            return output
        tz_link_target = _TZ_TARGET_DIR + new_time_zone
        if not os.path.isfile(tz_link_target):
            print NameError("Unable to find timezone file.")
            return output

    # Create the symlink at a temporary location, and move it onto the
    # old file (the rename is atomic).
    tz_link_source_tmp = _TZLOCATION_LINK + ".tmp"
    try:
        # Try to remove the temporary file. If it doesn't exist, just proceed.
        try:
            os.unlink(tz_link_source_tmp)
        except OSError:
            pass
        # Make the link value a relative path from /etc to /usr (..)
        os.symlink(".." + tz_link_target, tz_link_source_tmp)
        os.rename(tz_link_source_tmp, _TZLOCATION_LINK)
    except OSError:
        print NameError("Could not set timezone link.")
        return output

    # Set the TZ environment variable to the new timezone datafile
    os.environ['TZ'] = new_time_zone

    output.completeOutputSuccess()
    return output
Пример #24
0
def _set_timezone(entered_time_zone):
    output = lib.output.CLIoutput("clock")

    new_time_zone = entered_time_zone
    tz_link_target = _TZ_TARGET_DIR + new_time_zone

    if not os.path.isfile(tz_link_target):
        new_time_zone = _find_case_insensitive_timezone(entered_time_zone)
        if not new_time_zone:
            print NameError('Invalid timezone specified.'
                                   ' Try "show clock timezones [all]".');
            return output
        tz_link_target = _TZ_TARGET_DIR + new_time_zone
        if not os.path.isfile(tz_link_target):
            print NameError("Unable to find timezone file.")
            return output
        
    # Create the symlink at a temporary location, and move it onto the
    # old file (the rename is atomic). 
    tz_link_source_tmp = _TZLOCATION_LINK + ".tmp"
    try :
        # Try to remove the temporary file. If it doesn't exist, just proceed.
        try :
            os.unlink(tz_link_source_tmp)
        except OSError:
            pass
        # Make the link value a relative path from /etc to /usr (..)
        os.symlink(".." + tz_link_target, tz_link_source_tmp)
        os.rename(tz_link_source_tmp, _TZLOCATION_LINK)
    except OSError:
        print NameError("Could not set timezone link.")
        return output
    
    # Set the TZ environment variable to the new timezone datafile
    os.environ['TZ'] = new_time_zone
   
    output.completeOutputSuccess()
    return output
Пример #25
0
def show(argv):
    """Get the current time and date. 
        syntax: show clock
                show clock timezones [all]
        The default is to show timezones in the USA.
    """

    output = lib.output.CLIoutput("clock", _output_handlers)

    if len(argv) > 3:
        lib.errorhandler.InvalidArgumentCount(syntax=show.__doc__)
        return output

    if len(argv) >= 2 and (argv[1] == '' or \
           not "timezones".startswith(argv[1].lower())):
        lib.errorhandler.InvalidArgumentCount(2, argv[1], show.__doc__)
        return output
        
    if len(argv) == 3 and (argv[2] == '' or \
           not "all".startswith(argv[2].lower())):
        lib.errorhandler.InvalidArgumentCount(3, argv[2], show.__doc__)
        return output
        
    if len(argv) == 3:
        return _show_timezones(output)
    elif len(argv) == 2:
        return _show_usa_timezones(output)

    now_time = time.strftime(_TIME_FORMAT)
    dateInfo = now_time.split(' ')

    output.beginAssembling(_XMLTAG_TIMESPEC)

    output.setVirtualNameValue(_XMLTAG_Year,       dateInfo[0])
    output.setVirtualNameValue(_XMLTAG_Month,      dateInfo[1])
    output.setVirtualNameValue(_XMLTAG_MonthName,  dateInfo[2])
    output.setVirtualNameValue(_XMLTAG_Date,       dateInfo[3])
    output.setVirtualNameValue(_XMLTAG_DayName,    dateInfo[4])
    output.setVirtualNameValue(_XMLTAG_Hour,       dateInfo[5])
    output.setVirtualNameValue(_XMLTAG_Minute,     dateInfo[6])
    output.setVirtualNameValue(_XMLTAG_Second,     dateInfo[7])

    TZoffsetString=dateInfo[8]

    output.beginAssembling(_XMLTAG_TZD)

    output.setVirtualNameValue(_XMLTAG_TZDoffset,  TZoffsetString[0])
    output.setVirtualNameValue(_XMLTAG_TZDhours,   TZoffsetString[1:3])
    output.setVirtualNameValue(_XMLTAG_TZDminutes, TZoffsetString[3:5])
    output.setVirtualNameValue(_XMLTAG_TZDlabel,   dateInfo[9])

    TZlocation = _TZLOCATION_UNAVAILABLE
    try: 
        # factor out most of the relative path in the symbolic link value
        TZlocation = os.readlink(_TZLOCATION_LINK)
        TZlocation = TZlocation.replace(".." + _TZ_TARGET_DIR, "")
    except:
        pass

    output.setVirtualNameValue(_XMLTAG_TZDlocation,   TZlocation)

    output.endAssembling(_XMLTAG_TZD)

    output.endAssembling(_XMLTAG_TIMESPEC)
    output.completeOutputSuccess()
    return output
Пример #26
0
            doit = lib.essentials.confirm(
                "Are you sure that you want to halt the system")
        except lib.errorhandler.InteractiveCliRequired, ex:
            output.completeOutputError(ex)
            return output

        if not doit:
            print "\nHalt aborted."
            output.completeOutputSuccess()
            return output

    try:
        #
        # Instruct init to allows 45secs for processes to terminate (before
        # SIGKILLing them) and switch to runlevel 0.
        #
        status = os.system('/sbin/telinit -t 45 0')
        if status == 0:
            if not xml_out:
                print "Halting Virtual Fabric Manager..."
            output.completeOutputSuccess()
            return output
        else:
            output.completeOutputError("System halt failed.")
            return output
    except:
        pass

    output.completeOutputError("Exception calling system halt.")
    return output
Пример #27
0
    new_name = argv[1]
    try:
        checkHostname(new_name)
    except InvalidHostnameException, ex:
        output.completeOutputError(ex)
        return output

    #if '.' in new_name:
    #    output.completeOutputError("cannot specify a domain")
    #    return output
   
    if _set_hostname(new_name) != 1:
        output.completeOutputError("could not set the hostname")
        return output
   
    output.completeOutputSuccess()
    return output

def _init():
    """Hostname initialization.
       Reads the hostname from the configuration, and sets the hostname.
    """
    try:
        hostname = lib.essentials.getHostname()
        cmd = (_SET_HOSTNAME_CMD, hostname)
        lib.process.execute_command(cmd)
    except:
	pass


def _main():
Пример #28
0
def edit(argv):
    """Print help messages
        syntax: help
                help commands
                help <command-category>
                help <modifier>
                help [<modifier>] <command-name>
        modifier: add | clear | edit | no | show
    """
    output = lib.output.CLIoutput("help")
    if len(argv) == 1:
        # No argument - print out the general help
        output.setVirtualNameValue("Help", _GENERAL_HELP)
        output.completeOutputSuccess()
        return output

    # Now the arguments can be a category or a modifier or a command
    # Try treat it as a category first
    if len(argv) == 2:
        category = argv[1]
        try:
            output.setVirtualNameValue("Help", _display_help_category(category))
            output.completeOutputSuccess()
            return output
        except KeyError:
            # Not a category. Fine.
            pass

    # Maybe it's a modifier or a plugin... Get the plugin.
    try:
        try:
            modifier, cmd, plugin_name = \
                      lib.command_ref.cmdToPlugin(argv[1:])
        except lib.command_ref.UnknownPluginException, ex:
            modifier = ex.getModifier()
            # No plugin because the user wants help on a modifier ("help no")?
            # If the exception doesn't have any command, that means the user
            # only entered a modifier.
            if not ex.getCommand():
                output.setVirtualNameValue('Help', _display_modifier_help(modifier))
                output.completeOutputSuccess()
                return output
            raise ex

        if not sys.modules.has_key(plugin_name):
            try:
                __import__(plugin_name)
            except ImportError:
                raise NameError("INTERNAL ERROR: no such plugin: " + \
                                plugin_name)

        module = sys.modules[plugin_name]
        doc_str = None
        if hasattr(module, modifier):
            function = getattr(module, modifier)
            doc_str = getattr(function, '__doc__', None)

        if doc_str is None and modifier == lib.command_ref.EDIT_MODIFIER:
            doc_str = module.__doc__
        if doc_str is not None:
            output.setVirtualNameValue('Help', doc_str)
            output.completeOutputSuccess()
            return output
Пример #29
0
def show(argv):
    """Get the current time and date. 
        syntax: show clock
                show clock timezones [all]
        The default is to show timezones in the USA.
    """

    output = lib.output.CLIoutput("clock", _output_handlers)

    if len(argv) > 3:
        lib.errorhandler.InvalidArgumentCount(syntax=show.__doc__)
        return output

    if len(argv) >= 2 and (argv[1] == '' or \
           not "timezones".startswith(argv[1].lower())):
        lib.errorhandler.InvalidArgumentCount(2, argv[1], show.__doc__)
        return output

    if len(argv) == 3 and (argv[2] == '' or \
           not "all".startswith(argv[2].lower())):
        lib.errorhandler.InvalidArgumentCount(3, argv[2], show.__doc__)
        return output

    if len(argv) == 3:
        return _show_timezones(output)
    elif len(argv) == 2:
        return _show_usa_timezones(output)

    now_time = time.strftime(_TIME_FORMAT)
    dateInfo = now_time.split(' ')

    output.beginAssembling(_XMLTAG_TIMESPEC)

    output.setVirtualNameValue(_XMLTAG_Year, dateInfo[0])
    output.setVirtualNameValue(_XMLTAG_Month, dateInfo[1])
    output.setVirtualNameValue(_XMLTAG_MonthName, dateInfo[2])
    output.setVirtualNameValue(_XMLTAG_Date, dateInfo[3])
    output.setVirtualNameValue(_XMLTAG_DayName, dateInfo[4])
    output.setVirtualNameValue(_XMLTAG_Hour, dateInfo[5])
    output.setVirtualNameValue(_XMLTAG_Minute, dateInfo[6])
    output.setVirtualNameValue(_XMLTAG_Second, dateInfo[7])

    TZoffsetString = dateInfo[8]

    output.beginAssembling(_XMLTAG_TZD)

    output.setVirtualNameValue(_XMLTAG_TZDoffset, TZoffsetString[0])
    output.setVirtualNameValue(_XMLTAG_TZDhours, TZoffsetString[1:3])
    output.setVirtualNameValue(_XMLTAG_TZDminutes, TZoffsetString[3:5])
    output.setVirtualNameValue(_XMLTAG_TZDlabel, dateInfo[9])

    TZlocation = _TZLOCATION_UNAVAILABLE
    try:
        # factor out most of the relative path in the symbolic link value
        TZlocation = os.readlink(_TZLOCATION_LINK)
        TZlocation = TZlocation.replace(".." + _TZ_TARGET_DIR, "")
    except:
        pass

    output.setVirtualNameValue(_XMLTAG_TZDlocation, TZlocation)

    output.endAssembling(_XMLTAG_TZD)

    output.endAssembling(_XMLTAG_TIMESPEC)
    output.completeOutputSuccess()
    return output
Пример #30
0
def _show_imodule_module(output, argv, io_module):
    output.beginList("IomoduleSpecList")
    _get_iomodule_values(output, "iomodule", io_module)
    output.endList("IomoduleSpecList")
    output.completeOutputSuccess()