Exemplo n.º 1
0
Arquivo: arp.py Projeto: rajat007/vfm
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
Exemplo n.º 2
0
def _vfabric_spec(output, id, value):
    """ Display for the show vfabric """
    output.beginAssembling("VfabricListAll")

    output.setVirtualNameValue("ID", id)
    output.setVirtualNameValue("NAME", value['name'])
    output.setVirtualNameValue("CTX_TABLE_ID", value['ctx_table_id'])
    output.setVirtualNameValue("PRIMARY_GW_ID", value['primary_gateway'])
    output.setVirtualNameValue("PROTOCOL", value['protocol'])
    output.setVirtualNameValue("TYPE", value.get('type', 'HOST_INITIATED'))
    output.setVirtualNameValue("NUM_VADAPTER", value['num_vadapter_id'])
    output.setVirtualNameValue("VADAPTER_IDs", value['vadapter_id'])
    output.setVirtualNameValue("DESC", value['desc'])
    output.setVirtualNameValue("BACKUP_GW_ID", value['backup_gateway'])
    output.setVirtualNameValue("AUTO_FAILOVER", value['auto_failover'])
    output.setVirtualNameValue("AUTO_FAILBACK", value['auto_failback'])
    #Running mode:default set to OFFLINE
    output.setVirtualNameValue("RUNNING_MODE",
                               value.get('running_mode', 'OFFLINE'))
    output.setVirtualNameValue("HA_STATE", value.get('ha_state', 'NORMAL'))

    if value['protocol'] == 1:
        output.setVirtualNameValue("MAC", value['en_attr']['mac'])
        output.setVirtualNameValue("VLAN", value['en_attr']['vlan'])

    if value['protocol'] == 3:
        output.setVirtualNameValue("WWNN", value['fc_attr']['wwnn'])
        output.setVirtualNameValue("WWPN", value['fc_attr']['wwpn'])
        output.setVirtualNameValue("FCID", value['fc_attr']['fcid'])

    output.endAssembling("VfabricListAll")
Exemplo n.º 3
0
def _vfabric_spec(output, id, value):
    """ Display for the show vfabric """
    output.beginAssembling("VfabricListAll")

    output.setVirtualNameValue("ID", id)
    output.setVirtualNameValue("NAME", value['name'])
    output.setVirtualNameValue("CTX_TABLE_ID", value['ctx_table_id'])
    output.setVirtualNameValue("PRIMARY_GW_ID", value['primary_gateway'])
    output.setVirtualNameValue("PROTOCOL", value['protocol'])
    output.setVirtualNameValue("TYPE", value.get('type','HOST_INITIATED'))
    output.setVirtualNameValue("NUM_VADAPTER", value['num_vadapter_id'])
    output.setVirtualNameValue("VADAPTER_IDs", value['vadapter_id'])
    output.setVirtualNameValue("DESC", value['desc'])
    output.setVirtualNameValue("BACKUP_GW_ID",value['backup_gateway'])
    output.setVirtualNameValue("AUTO_FAILOVER",value['auto_failover'])
    output.setVirtualNameValue("AUTO_FAILBACK",value['auto_failback'])
    #Running mode:default set to OFFLINE
    output.setVirtualNameValue("RUNNING_MODE", value.get('running_mode', 'OFFLINE'))
    output.setVirtualNameValue("HA_STATE", value.get('ha_state', 'NORMAL'))

    if value['protocol'] == 1:
        output.setVirtualNameValue("MAC", value['en_attr']['mac'])
        output.setVirtualNameValue("VLAN", value['en_attr']['vlan'])

    if value['protocol'] == 3:
        output.setVirtualNameValue("WWNN", value['fc_attr']['wwnn'])
        output.setVirtualNameValue("WWPN", value['fc_attr']['wwpn'])
        output.setVirtualNameValue("FCID", value['fc_attr']['fcid'])
        
    output.endAssembling("VfabricListAll")
Exemplo n.º 4
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
Exemplo n.º 5
0
def _vadapter_spec(output, id, value):    

    output.beginAssembling("VadapterListAll")

    output.setVirtualNameValue("ID", id)
    output.setVirtualNameValue("NAME", value['name'])
    output.setVirtualNameValue("IO_MODULE_ID", value['io_module_id'])
    output.setVirtualNameValue("VFABRIC", value['vfabric_id'])
    output.setVirtualNameValue("PROTOCOL", value['protocol'])
    output.setVirtualNameValue("INIT_TYPE", value['init_type'])
    output.setVirtualNameValue("DESC", value['desc'])

    # When we get transient states, the state will automatically get udpated.
    # By default, it is RUNNING
    output.setVirtualNameValue("STATUS", value.get('status', 'RUNNING'))
    output.setVirtualNameValue("RUNNING_MODE", value.get('running_mode', 'OFFLINE'))


    if value['protocol'] == 1:
        output.setVirtualNameValue("MAC", value['en_attr']['mac'])
        output.setVirtualNameValue("PROMISCUOUS", value['en_attr']['promiscuous_mode'])
        output.setVirtualNameValue("SILENT", value['en_attr']['silent_listener'])
        output.setVirtualNameValue("VLAN", value['en_attr']['vlan'])
    
    elif value['protocol'] == 3:
        output.setVirtualNameValue("WWNN", value['fc_attr']['wwnn'])
        output.setVirtualNameValue("WWPN", value['fc_attr']['wwpn'])
        output.setVirtualNameValue("FC_ID",value['fc_attr']['fcid'])
        output.setVirtualNameValue("SPMA", value['fc_attr']['spma'])
        output.setVirtualNameValue("FPMA", value['fc_attr']['fpma'])

    output.endAssembling("VadapterListAll") 
Exemplo n.º 6
0
Arquivo: ip.py Projeto: rajat007/vfm
def _ip_address_spec(output, ipaddress, netmask, interface, scope, active):
    """Output an IPaddressSpec in XML form"""
    output.beginAssembling("IPaddressSpec")
    output.setVirtualNameValue("IPaddress", ipaddress)
    output.setVirtualNameValue("IPnetmask", netmask)
    output.setVirtualNameValue("InterfaceName", interface)
    output.setVirtualNameValue("Active", scope)
    output.setVirtualNameValue("Scope", active)
    output.endAssembling("IPaddressSpec")
Exemplo n.º 7
0
Arquivo: ip.py Projeto: gautamrege/vfm
def _ip_address_spec(output, ipaddress, netmask, interface, scope, active ):
    """Output an IPaddressSpec in XML form"""
    output.beginAssembling("IPaddressSpec")
    output.setVirtualNameValue("IPaddress", ipaddress)
    output.setVirtualNameValue("IPnetmask", netmask)
    output.setVirtualNameValue("InterfaceName", interface)
    output.setVirtualNameValue("Active", scope)
    output.setVirtualNameValue("Scope", active)
    output.endAssembling("IPaddressSpec")
Exemplo n.º 8
0
def _bridge_spec(output, guid, name, desc, num_gateway_module, firmware_version, bxm_guid):
    """Outout the bridge spec """
    output.beginAssembling("Bridge_Device")
    output.setVirtualNameValue("GUID", guid)
    output.setVirtualNameValue("NAME", name)
    output.setVirtualNameValue("DESCRIPTION", desc)
    output.setVirtualNameValue("NUM_GW_MODULE", num_gateway_module)
    output.setVirtualNameValue("FIRMWARE_VERSION", firmware_version)
    output.setVirtualNameValue("BXM_GUID", bxm_guid)
    output.endAssembling("Bridge_Device")
Exemplo n.º 9
0
def _bridge_spec(output, guid, name, desc, num_gateway_module,
                 firmware_version, bxm_guid):
    """Outout the bridge spec """
    output.beginAssembling("Bridge_Device")
    output.setVirtualNameValue("GUID", guid)
    output.setVirtualNameValue("NAME", name)
    output.setVirtualNameValue("DESCRIPTION", desc)
    output.setVirtualNameValue("NUM_GW_MODULE", num_gateway_module)
    output.setVirtualNameValue("FIRMWARE_VERSION", firmware_version)
    output.setVirtualNameValue("BXM_GUID", bxm_guid)
    output.endAssembling("Bridge_Device")
Exemplo n.º 10
0
def iomodule_spec(output, id , name , type, mac, guid, num_vhba, num_vnic, slot, port,support_speed):
    output.beginAssembling("IomoduleListAll")
    output.setVirtualNameValue("ID", id)
    output.setVirtualNameValue("NAME", name)
    output.setVirtualNameValue("TYPE", type)
    output.setVirtualNameValue("MAC", mac)
    output.setVirtualNameValue("GUID", guid)
    output.setVirtualNameValue("NUM_VHBA", num_vhba)
    output.setVirtualNameValue("NUM_VNIC", num_vnic)
    output.setVirtualNameValue("SLOT", slot)
    output.setVirtualNameValue("PORT", port)
    output.setVirtualNameValue("SUPPORT_SPEED", support_speed)
    output.endAssembling("IomoduleListAll")  
Exemplo n.º 11
0
def _bridge_select(output, desc, state, running_mode, firmware_module,
                   vfm_guid, no_gw_module, gw_module_index, last_keep_alive):
    """Output of the show bridge """
    output.beginAssembling("Bridge_Device")
    output.setVirtualNameValue("desc", desc)
    output.setVirtualNameValue("state", state)
    output.setVirtualNameValue("running-mode", running_mode)
    output.setVirtualNameValue("firmware-version", firmware_module)
    output.setVirtualNameValue("vfm-guid", vfm_guid)
    output.setVirtualNameValue("number-gw-module", no_gw_module)
    output.setVirtualNameValue("gw-Module-Index", gw_module_index)
    output.setVirtualNameValue("last-keep-alive", last_keep_alive)
    output.endAssembling("Bridge_Device")
Exemplo n.º 12
0
def _bridge_select(output, desc, state, running_mode , 
		  firmware_module , vfm_guid, no_gw_module, 
		  gw_module_index, last_keep_alive):
    """Output of the show bridge """
    output.beginAssembling("Bridge_Device")
    output.setVirtualNameValue("desc", desc)
    output.setVirtualNameValue("state",state)
    output.setVirtualNameValue("running-mode", running_mode)
    output.setVirtualNameValue("firmware-version",firmware_module)
    output.setVirtualNameValue("vfm-guid",vfm_guid)
    output.setVirtualNameValue("number-gw-module",no_gw_module)
    output.setVirtualNameValue("gw-Module-Index",gw_module_index)
    output.setVirtualNameValue("last-keep-alive",last_keep_alive)
    output.endAssembling("Bridge_Device")
Exemplo n.º 13
0
def _gateway_spec(output, gw_id, gw_module, bxm_guid, name, desc, int_port,
                  ext_port, ingress_learning, ingress_secure, egress_secure,
                  flood, checksum_offload):
    """Output the gateway spec"""
    output.beginAssembling("GatewayList")
    output.setVirtualNameValue("GW_ID", gw_id)
    output.setVirtualNameValue("GW_MODULE", gw_module)
    output.setVirtualNameValue("BXM_GUID", bxm_guid)
    output.setVirtualNameValue("NAME", name)
    output.setVirtualNameValue("DESC", desc)
    output.setVirtualNameValue("INT_PORT", int_port)
    output.setVirtualNameValue("EXT_PORT", ext_port)
    output.setVirtualNameValue("INGRESS_LEARNING", ingress_learning)
    output.setVirtualNameValue("INGRESS_SECURE", ingress_secure)
    output.setVirtualNameValue("EGRESS_SECURE", egress_secure)
    output.setVirtualNameValue("FLOOD", flood)
    output.setVirtualNameValue("CHECKSUM_OFFLOAD", checksum_offload)
    output.endAssembling("GatewayList")
Exemplo n.º 14
0
def _gateway_spec(output, gw_id, gw_module, bxm_guid, name, 
                    desc, int_port, ext_port,ingress_learning,
                    ingress_secure, egress_secure, flood, checksum_offload):
    """Output the gateway spec"""
    output.beginAssembling("GatewayList")
    output.setVirtualNameValue("GW_ID", gw_id)
    output.setVirtualNameValue("GW_MODULE", gw_module)
    output.setVirtualNameValue("BXM_GUID", bxm_guid)
    output.setVirtualNameValue("NAME", name)
    output.setVirtualNameValue("DESC", desc)
    output.setVirtualNameValue("INT_PORT",int_port)
    output.setVirtualNameValue("EXT_PORT", ext_port)
    output.setVirtualNameValue("INGRESS_LEARNING", ingress_learning)
    output.setVirtualNameValue("INGRESS_SECURE", ingress_secure)
    output.setVirtualNameValue("EGRESS_SECURE",egress_secure)
    output.setVirtualNameValue("FLOOD", flood)
    output.setVirtualNameValue("CHECKSUM_OFFLOAD", checksum_offload)
    output.endAssembling("GatewayList")
Exemplo n.º 15
0
def _bridge_detail(output, name , desc, running_mode,
		  firmware_module , vfm_guid, no_gw_modules,
		  gw_module_index, gw_module_id,
		  int_protocol, ext_protocol, no_int_protocol,
		  no_ext_protocol, int_ports, ext_ports, gw_ids,
		  port_id, phy_index, type, protocol, state, mac,
		  wwnn, wwpn, fcid, ib_guid, lid, qpn, sl, support_speed,
		  actual_speed, rx_stat, tx_stat, last_keep_alive):
    output.beginAssembling("Bridge_Device")
    output.setVirtualNameValue("name", name)
    output.setVirtualNameValue("desc", desc)
    output.setVirtualNameValue("state",state)
    output.setVirtualNameValue("running-mode", running_mode)
    output.setVirtualNameValue("firmware-module",firmware_module)
    output.setVirtualNameValue("vfm-guid",vfm_guid)
    output.setVirtualNameValue("number-gw-module",no_gw_module)
    output.setVirtualNameValue("gw-module-index",gw_module_index)
    output.setVirtualNameValue("gw-module-id",gw_module_id)
    output.setVirtualNameValue("int_protocol", int_protocol)
    output.setVirtualNameValue("ext_protocol",ext_protocol)
    output.setVirtualNameValue("no_int_protocols",no_int_protocol)
    output.setVirtualNameValue("no_ext_protocols",no_ext_protocol)
    output.setVirtualNameValue("int-ports",int_ports)
    output.setVirtualNameValue("ext-ports",ext_ports)
    output.setVirtualNameValue("gw-ids",gw_ids)
    output.setVirtualNameValue("port-id",port_id)
    output.setVirtualNameValue("phy-index",phy_index)
    output.setVirtualNameValue("type",type)
    output.setVirtualNameValue("protocol",protocol)
    output.setVirtualNameValue("state",state)
    output.setVirtualNameValue("mac",mac)
    output.setVirtualNameValue("wwnn",wwnn)
    output.setVirtualNameValue("wwpn",wwpn)
    output.setVirtualNameValue("fcid",fcid)
    output.setVirtualNameValue("ib_guid",ib_guid)
    output.setVirtualNameValue("lid",lid)
    output.setVirtualNameValue("qpn",qpn)
    output.setVirtualNameValue("sl",sl)
    output.setVirtualNameValue("support-speed",support_speed)
    output.setVirtualNameValue("actual-speed",actual_speed)
    output.setVirtualNameValue("rx-stat",rx_stat)
    output.setVirtualNameValue("tx-stat",tx_stat)
    output.setVirtualNameValue("last-keep-alive",last_keep_alive)
    output.endAssembling("Bridge_Device")
Exemplo n.º 16
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
Exemplo n.º 17
0
Arquivo: ip.py Projeto: gautamrege/vfm
def _show_ip_routes(output, argv):
    """Show network routes
        syntax: show ip route
    """
    cmd = [_ROUTE, '-n']
    (exitval, output_result, err, fullstatus) = lib.process.execute_command(cmd)
    
    output.beginList("IProuteList")
    for ln in output_result[2:]:        
        fields = ln.split()
        if fields[-1] == "lo":
            continue
        output.beginAssembling("IProute")
        output.setVirtualNameValue("Destination", fields[0])
        output.setVirtualNameValue("IPnetmask", fields[2])
        output.setVirtualNameValue("Gateway", fields[1])
        output.setVirtualNameValue("InterfaceName", fields[-1])
        output.endAssembling("IProute")
    output.endList("IProuteList")
Exemplo n.º 18
0
def _bridge_detail(output, name, desc, running_mode, firmware_module, vfm_guid,
                   no_gw_modules, gw_module_index, gw_module_id, int_protocol,
                   ext_protocol, no_int_protocol, no_ext_protocol, int_ports,
                   ext_ports, gw_ids, port_id, phy_index, type, protocol,
                   state, mac, wwnn, wwpn, fcid, ib_guid, lid, qpn, sl,
                   support_speed, actual_speed, rx_stat, tx_stat,
                   last_keep_alive):
    output.beginAssembling("Bridge_Device")
    output.setVirtualNameValue("name", name)
    output.setVirtualNameValue("desc", desc)
    output.setVirtualNameValue("state", state)
    output.setVirtualNameValue("running-mode", running_mode)
    output.setVirtualNameValue("firmware-module", firmware_module)
    output.setVirtualNameValue("vfm-guid", vfm_guid)
    output.setVirtualNameValue("number-gw-module", no_gw_module)
    output.setVirtualNameValue("gw-module-index", gw_module_index)
    output.setVirtualNameValue("gw-module-id", gw_module_id)
    output.setVirtualNameValue("int_protocol", int_protocol)
    output.setVirtualNameValue("ext_protocol", ext_protocol)
    output.setVirtualNameValue("no_int_protocols", no_int_protocol)
    output.setVirtualNameValue("no_ext_protocols", no_ext_protocol)
    output.setVirtualNameValue("int-ports", int_ports)
    output.setVirtualNameValue("ext-ports", ext_ports)
    output.setVirtualNameValue("gw-ids", gw_ids)
    output.setVirtualNameValue("port-id", port_id)
    output.setVirtualNameValue("phy-index", phy_index)
    output.setVirtualNameValue("type", type)
    output.setVirtualNameValue("protocol", protocol)
    output.setVirtualNameValue("state", state)
    output.setVirtualNameValue("mac", mac)
    output.setVirtualNameValue("wwnn", wwnn)
    output.setVirtualNameValue("wwpn", wwpn)
    output.setVirtualNameValue("fcid", fcid)
    output.setVirtualNameValue("ib_guid", ib_guid)
    output.setVirtualNameValue("lid", lid)
    output.setVirtualNameValue("qpn", qpn)
    output.setVirtualNameValue("sl", sl)
    output.setVirtualNameValue("support-speed", support_speed)
    output.setVirtualNameValue("actual-speed", actual_speed)
    output.setVirtualNameValue("rx-stat", rx_stat)
    output.setVirtualNameValue("tx-stat", tx_stat)
    output.setVirtualNameValue("last-keep-alive", last_keep_alive)
    output.endAssembling("Bridge_Device")
Exemplo n.º 19
0
Arquivo: ip.py Projeto: rajat007/vfm
def _show_ip_routes(output, argv):
    """Show network routes
        syntax: show ip route
    """
    cmd = [_ROUTE, '-n']
    (exitval, output_result, err,
     fullstatus) = lib.process.execute_command(cmd)

    output.beginList("IProuteList")
    for ln in output_result[2:]:
        fields = ln.split()
        if fields[-1] == "lo":
            continue
        output.beginAssembling("IProute")
        output.setVirtualNameValue("Destination", fields[0])
        output.setVirtualNameValue("IPnetmask", fields[2])
        output.setVirtualNameValue("Gateway", fields[1])
        output.setVirtualNameValue("InterfaceName", fields[-1])
        output.endAssembling("IProute")
    output.endList("IProuteList")
Exemplo n.º 20
0
            output.completeOutputError(
                "count should be a number greater than 0")
            return output
        if (cnt > 1024):
            output.completeOutputError("count should not exceed 1024")
            return output
    except ValueError:
        output.completeOutputError("count should be a number greater than 0")
        return output

    try:
        ipaddr = socket.gethostbyname(name)
    except socket.error, e:
        output.completeOutputError("cannot resolve '%s': %s" % (name, e))
        return output

    try:
        pipe = popen2.Popen4("/bin/ping -nb -c %d -w %d %s" % \
                                                (cnt, cnt+10, name),
                                                0)
        #output.beginList("PingSpecList")
        output.beginAssembling("Ping")
        output.setVirtualNameValue("PingOutput", pipe)
        output.endAssembling("Ping")
        #output.endList("PingSpecList")
        output.completeOutputSuccess()
    except OSError, e:
        output.completeOutputError("Internal error: ping failed: %s" % (e, ))

    return output
Exemplo n.º 21
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
Exemplo n.º 22
0
	    output.completeOutputError("count should be a number greater than 0")
	    return output
	if (cnt > 1024):
	    output.completeOutputError("count should not exceed 1024")
	    return output
    except ValueError:
        output.completeOutputError("count should be a number greater than 0")
        return output

    try:
        ipaddr = socket.gethostbyname(name)
    except socket.error, e:
        output.completeOutputError("cannot resolve '%s': %s" % (name, e))
        return output

    try:
        pipe = popen2.Popen4("/bin/ping -nb -c %d -w %d %s" % \
                                                (cnt, cnt+10, name),
                                                0)
	#output.beginList("PingSpecList")
        output.beginAssembling("Ping")
        output.setVirtualNameValue("PingOutput", pipe)
        output.endAssembling("Ping")
	#output.endList("PingSpecList")
        output.completeOutputSuccess()
    except OSError, e:
        output.completeOutputError("Internal error: ping failed: %s" % (e,))
       
    return output

Exemplo n.º 23
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