当前位置: 首页>>代码示例>>Python>>正文


Python netutils.isValidIp函数代码示例

本文整理汇总了Python中netutils.isValidIp函数的典型用法代码示例。如果您正苦于以下问题:Python isValidIp函数的具体用法?Python isValidIp怎么用?Python isValidIp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isValidIp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parseNetworkingInformation

 def parseNetworkingInformation(self, buffer):
     """
     This function performs parsing of the 'lshmc -n' command output
     @param buffer: string buffer of the command output 
     @return: host and ip information
     @rtype: instance of HostDo object
     """
     host = ibm_hmc_lib.Host()
     if buffer:
         propertiesDict = self.buildPropertiesDict(buffer)
         host.hostname = propertiesDict.get('hostname')
         host.domainName = propertiesDict.get('domain')
         for (key, value) in propertiesDict.items():
             if key.startswith('ipv4addr_eth'):
                 if value and netutils.isValidIp(value) and not netutils.isLocalIp(value):
                     ip = ibm_hmc_lib.Ip(value, propertiesDict.get(key.replace('addr', 'netmask')))
                     host.ipList.append(ip)
         
         if not host.ipList: #another version of HMC outputs, for the minor HMC version change
             ipStr = propertiesDict.get('ipaddr')
             netMaskStr = propertiesDict.get('networkmask')
             if ipStr and netMaskStr:
                 ipList = ipStr.split(',')
                 netMaskList = netMaskStr.split(',')
                 for i in range(len(ipList)):
                     ipAddr = ipList[i].strip()
                     netMask = netMaskList[i].strip()
                     if ipAddr and netutils.isValidIp(ipAddr) and not netutils.isLocalIp(ipAddr):
                         ip = ibm_hmc_lib.Ip(ipAddr, netMask)
                         host.ipList.append(ip)
                         
         if not host.ipList:
             raise ValueError("Failed parsing HMC host IP addresses from  %s " % buffer)
     return host
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:34,代码来源:ibm_hmc_discoverer.py

示例2: createScpOSHV

def createScpOSHV(container, type, host, port, context, shell, localIP=None, dnsServers=None):
    OSHVResult = ObjectStateHolderVector()
    if not host:
        return OSHVResult
    ipAddresses = []
    if (host in LOCALHOST) and localIP:
        logger.debug("found local ip: %s , use %s instead" % (host, localIP))
        host = localIP
    if netutils.isValidIp(host):
        ipAddresses.append(host)
    else:
        # try to resolve ip address from hostname
        logger.debug('Trying to resolve ip address from hostname:', host)
        ipAddresses = resolveIPByNsLookup(dnsServers, shell, host)
        if len(ipAddresses) == 0:
            ipAddresses = resolveIPByINet(host, port)
        if len(ipAddresses) == 0:
            ipAddresses = resolveIPBySocket(host)

    for ipAddress in ipAddresses:
        if not netutils.isValidIp(ipAddress):
            logger.debug("ignore invalid ip address: ", ipAddress)
            continue
        scpOsh = createScpOsh(container, type, ipAddress, port, context, host)
        OSHVResult.add(scpOsh)
        # Add additional ip CIs for all next hops to make sure new jobs could be triggered.
        ip = ip_addr.IPAddress(ipAddress)
        OSHVResult.add(modeling.createIpOSH(ip))

    return OSHVResult
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:30,代码来源:scp.py

示例3: __init__

    def __init__(self, id, ip = None, name = None, systemObjId = None, descr = None, localHba = None, \
                 localPorts = None, model = None, serial = None, version = None, vendor = None, status = None):
        '''
        @param id: string
        @param ip: string
        @param name: string
        @param systemObjId: id of the object in Storage System
        @param description: string
        @param localHba: list of host base adapters
        @param localPorts: list of fcPorts
        @raise ValueError: in case ip is invalid and no name, or no name and ip
        '''
        self.ip = None
        try:
            if netutils.isValidIp(ip):
                self.ip = ip
        except:
            logger.warn('IP "%s" for node name "%s" is invalid' % (ip, name))

        if not id and not (name or self.ip):
            raise ValueError("Name or ip attribute must be set along with id attribute")
        self.name = name
        self.id = id
        self.localHba = localHba or []
        self.localPorts = localPorts or []
        self.systemObjId = systemObjId
        self.description = descr
        self.model = model
        self.serial = serial
        self.version = version
        self.vendor = vendor
        self.status = status
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:32,代码来源:smis.py

示例4: reportDatasourceWithDeployer

 def reportDatasourceWithDeployer(self, domainOsh, deploymentScopeOsh, datasource):
     r'''@types: ObjectStateHolder, ObjectStateHolder, jms.Datasource -> ObjectStateHolderVector
     @param deploymentScope: Used as a container for the resources
     '''
     # for instance resources for cell has the same deployment scope as domain\
     # no need to create link
     containerOsh = domainOsh
     vector = self._createVector()
     # first of all report datasource
     datasourceOsh = self.reportDatasource(datasource, containerOsh)
     vector.add(datasourceOsh)
     # report all destinations where datasource is a container
     for destination in datasource.getDestinations():
         destinationOsh = self.reportDestination(destination, datasourceOsh)
         vector.add(destinationOsh)
         # report mq server if present
         if destination.server and netutils.isValidIp(destination.server.address):
             vector.addAll(self.reportMqServerWithEndpoint(destination.server))
             # also there must be a link between datasource and server
             #vector.add(self.linkDatasourceAndMqServer(
             #                  datasourceOsh,
             #                  destination.server.getOsh())
             #)
     if deploymentScopeOsh:
         vector.add(self.linkDeploymentScopeAndDatasource(deploymentScopeOsh, datasourceOsh))
     return vector
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:26,代码来源:jms.py

示例5: getUrl

def getUrl(WSDLUrl, containerOSH):

    res = ObjectStateHolderVector()
    urlIP = None
    try:
        url = URL(WSDLUrl)
        hostName = url.getHost()
        urlIP = netutils.getHostAddress(hostName, None)

        if (not netutils.isValidIp(urlIP)) or netutils.isLocalIp(urlIP):
            urlIP = None
    except:
        urlIP = None
    
    urlOSH = modeling.createUrlOsh(containerOSH, WSDLUrl, 'wsdl')

    urlIpOSH = None
    if urlIP != None:
        try:
            urlIpOSH = modeling.createIpOSH(urlIP)
        except:
            urlIpOSH = None

    res.add(urlOSH)

    if urlIpOSH:
        res.add(urlIpOSH)
        urlToIpOSH = modeling.createLinkOSH('depend', urlOSH, urlIpOSH)
        res.add(urlToIpOSH)

    return res
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:31,代码来源:OracleAplicationServer.py

示例6: reportProcessToPort

def reportProcessToPort(hostId, processes, endpoints):
    if not (processes and endpoints):
        return 
    vector = ObjectStateHolderVector()
    hostOsh = modeling.createOshByCmdbId('node', hostId)
    vector.add(hostOsh)
    proc_builder = ProcessBuilder()
    key_to_endpoints_map = {}
    [ key_to_endpoints_map.update({x.getKey(): x.getEndpoints()}) for x in endpoints ]
    for process in processes:
        processOsh = proc_builder.buildProcessOsh(process)
        processOsh.setContainer(hostOsh)
        vector.add(processOsh)
        remotes = key_to_endpoints_map.get(process.getPid())
        if remotes:
            for remote in remotes:
                if not netutils.isValidIp(remote.getAddress()):
                    logger.debug(remote, ' is not a valid ip')
                    continue
                builder = netutils.ServiceEndpointBuilder()
                reporter = netutils.EndpointReporter(builder)
                nodeOsh = reporter.reportHostFromEndpoint(remote)
                endpointOsh = reporter.reportEndpoint(remote, nodeOsh)
                linkOsh = modeling.createLinkOSH('client_server', processOsh, endpointOsh)
                linkOsh.setStringAttribute('clientserver_protocol', 'tcp')
                vector.add(nodeOsh)
                vector.add(endpointOsh)
                vector.add(linkOsh)
    return vector
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:29,代码来源:tcp_discovery_server_asm.py

示例7: DiscoveryMain

def DiscoveryMain(Framework):
	OSHVResult = ObjectStateHolderVector()
	
	urlString = Framework.getParameter(PARAM_URL)
	
	reportPoweredOffVms = 0
	reportPoweredOffVmsValue = Framework.getParameter(PARAM_REPORT_POWERED_OFF_VMS)
	if reportPoweredOffVmsValue and reportPoweredOffVmsValue.lower() =='true':
		reportPoweredOffVms = 1

	
	ipAddress = None
	try:
		urlObject = URL(urlString)
		hostname = urlObject.getHost()
		
		if not hostname:
			logger.debug("Hostname is not defined in URL '%s'" % urlString)
			raise MalformedURLException()
		
		ipAddress = vcloud_discover.getIpFromUrlObject(urlObject)
		if not ipAddress or not netutils.isValidIp(ipAddress) or netutils.isLocalIp(ipAddress):
			msg = "Failed to resolve the IP address of server from specified URL"
			errormessages.resolveAndReport(msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework)
			return OSHVResult
		
	except MalformedURLException:
		msg = "Specified URL '%s' is malformed" % urlString
		errormessages.resolveAndReport(msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework)
	except:
		msg = logger.prepareJythonStackTrace("")
		errormessages.resolveAndReport(msg, vcloud_discover.VcloudProtocol.DISPLAY, Framework)
	else:
		
		#configure how connections should be discovered/established
		connectionDiscoverer = vcloud_discover.ConnectionDiscoverer(Framework)
		urlGenerator = vcloud_discover.ConstantUrlGenerator(urlString)
		connectionDiscoverer.setUrlGenerator(urlGenerator)
		connectionDiscoverer.addIp(ipAddress)
		
		#configure how established/failed connection should be used
		connectionHandler = vcloud_discover.BaseDiscoveryConnectionHandler(Framework)
		topologyDiscoverer = vcloud_discover.createVcloudDiscoverer(Framework)
		topologyReporter = vcloud_report.createVcloudReporter(Framework, None, reportPoweredOffVms)
		connectionHandler.setDiscoverer(topologyDiscoverer)
		connectionHandler.setReporter(topologyReporter)
		
		connectionDiscoverer.setConnectionHandler(connectionHandler)
		
		connectionDiscoverer.initConnectionConfigurations()
		
		connectionDiscoverer.discover(firstSuccessful=0)
		
		if not connectionHandler.connected:
			for errorMsg in connectionHandler.connectionErrors:
				Framework.reportError(errorMsg)
			for warningMsg in connectionHandler.connectionWarnings:
				Framework.reportWarning(warningMsg)

	return OSHVResult
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:60,代码来源:vcloud_director_url_by_vcloud_api.py

示例8: discoverOAMEndpoint

def discoverOAMEndpoint(shell, configFile):
    """
    Discover OAM endpoint in ObAccessClient.xml
    @types: str -> Endpoint
    """
    logger.debug('find OAM server')
    root = _buildDocumentForXpath(configFile, 0)
    xpath = _getXpath()
    servers = xpath.evaluate('//CompoundList/ValNameList[@ListName="primaryServer1"]', root, XPathConstants.NODESET)
    for i in range(0, servers.getLength()):
        server = servers.item(i)
        host = xpath.evaluate('//NameValPair[@ParamName="host"]/@Value', server, XPathConstants.STRING)
        port = xpath.evaluate('//NameValPair[@ParamName="port"]/@Value', server, XPathConstants.STRING)
        if host and port:
            logger.debug('got OAM server: %s:%s' % (host, port))
            if netutils.isValidIp(host):
                ip = host
            else:
                ip = _resolveHostName(shell, host)
            if ip:
                return netutils.createTcpEndpoint(ip, port)
            else:
                logger.error('Cannot resolve ip from host name "%s"' % host)
        else:
            logger.error('failed to get OAM server')
    return None
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:26,代码来源:tcp_discovery_oam.py

示例9: createCimOsh

def createCimOsh(ipAddress, containerOsh, credentialId, category=None):
    '''
    Builds a CIM OSH representing successful connection.
    @param ipAddress: string
    @param containerOsh: corresponding container OSH
    @param credentialId: protocol entry
    @raise ValueError: no credential or no IP.  
    @return: OSH
    '''
    if not credentialId:
        raise ValueError('CredentialsId must be set')
    if not netutils.isValidIp(ipAddress):
        raise ValueError('IP Address must be set')
    
    cimOsh = ObjectStateHolder('cim')
    cimOsh.setAttribute('data_name', Protocol.FULL)
    cimOsh.setAttribute('credentials_id', credentialId)
    cimOsh.setAttribute('application_ip', ipAddress)
    cimOsh.setContainer(containerOsh)
    
    if category:
        list_ = StringVector((category,))
        categoryAttribute = AttributeStateHolder('cim_category', list_)
        cimOsh.addAttributeToList(categoryAttribute)
    
    return cimOsh
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:26,代码来源:cim.py

示例10: discoverReplication

    def discoverReplication(self, mysqlOsh):
        """
        Tries to find config variables related to mysql replication 
        @param ObjectStateHolder mysqlOsh mysql osh
        @return list list of OSHs
        """
        masterHostIp = self.getProperty('master-host')
        if not masterHostIp:
            return 
        if not netutils.isValidIp(masterHostIp):
            try:
                resolver = netutils.DnsResolverByShell(self.shell)
                masterHostIp = resolver.resolveIpsByHostname(masterHostIp)[0]
            except netutils.ResolveException:
                logger.warn('Failed to resolve Master Host into IP')
                return
        masterPort = self.getProperty('master-port')
        mysqlReplicationOsh = ObjectStateHolder('mysql_replication')
        mysqlReplicationOsh.setAttribute('data_name', 'MySQL Replication')
        mysqlReplicationOsh.setContainer(mysqlOsh)
        self.setAttribute(mysqlReplicationOsh, 'master_user', self.REPL_ARGS_MAPPING)
        self.setAttribute(mysqlReplicationOsh, 'master_connect_retry', self.REPL_ARGS_MAPPING)
        masterHostOsh = modeling.createHostOSH(masterHostIp)
        serviceAddressOsh = modeling.createServiceAddressOsh(masterHostOsh, masterHostIp, masterPort, modeling.SERVICEADDRESS_TYPE_TCP)
        clientServerLink = modeling.createLinkOSH('client_server', mysqlReplicationOsh, serviceAddressOsh)
        clientServerLink.setStringAttribute('clientserver_protocol', 'TCP')
        clientServerLink.setLongAttribute('clientserver_destport', int(masterPort))
#        masterMysqlOsh = modeling.createDatabaseOSH('mysql', 'MySQL. Port ' + masterPort, masterPort, masterHostIp, masterHostOsh)
#        useLink = modeling.createLinkOSH('use', masterHostOsh, serviceAddressOsh)
        return [masterHostOsh, serviceAddressOsh, clientServerLink, mysqlReplicationOsh]
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:30,代码来源:MySqlDiscoverer.py

示例11: _resolve

def _resolve(hostname):
    '@types: str -> str?'
    if netutils.isValidIp(hostname):
        return hostname
    ip = netutils.getHostAddress(hostname)
    if ip and not netutils.isLocalIp(ip):
        return ip
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:7,代码来源:sap_site_by_jco.py

示例12: reportMqServerWithEndpoint

    def reportMqServerWithEndpoint(self, server):
        r''' Make reporting of MQ server based on its IP where contains
        is incomplete host built using IP address and if port specified
        linked with corresponding service endpoint

        @types: jms.MqServer -> ObjectStateHolderVector
        @raise ValueError: JMS Server is not specified
        @raise ValueError: MQ Server IP address is empty or not resolved
        '''
        if not server:
            raise ValueError("JMS Server is not specified")
        ip = server.address
        if not (ip and netutils.isValidIp(ip)):
            raise ValueError("MQ Server IP address is empty or not resolved")
        vector = ObjectStateHolderVector()
        hostOsh = modeling.createIpOSH(ip)
        vector.add(hostOsh)
        serverOsh = self.reportMqServer(server, hostOsh)
        vector.add(serverOsh)
        if server.getPort() is not None:
            vector.add(modeling.createServiceAddressOsh(hostOsh, ip,
                                                        server.getPort(),
                                                        modeling.SERVICEADDRESS_TYPE_TCP
                       )
            )
        return vector
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:26,代码来源:jms.py

示例13: set

 def set(self, ip):
     '''@types: str
     @raise ValueError: IP is not valid
     '''
     if not netutils.isValidIp(ip):
         raise ValueError( "IP is not valid %s" % ip )
     self.__ip = ip
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:7,代码来源:j2ee_entity.py

示例14: __discoverClimInterface

    def __discoverClimInterface(self, climName):
        """
        @types: string -> None
        @raise ValueError: when command "gtacl -cv "climcmd %s /sbin/ifconfig -a % <clim_name>" gives no output or fails
        """
        cmd = "climcmd %s /sbin/ifconfig -a" % climName
        cmdOutput = self.__shell.execCmd('gtacl -cv "%s"' % cmd)
        if not cmdOutput or self.__shell.getLastCmdReturnCode() != 0:
            raise ValueError('Failed to get CLIM')

        (header, interfaceData) = cmdOutput.split(cmd)
        if header and interfaceData:
            interfacesByName = {}
            matches = ShellDiscoverer.__INTERFACE_REGEXP.findall(interfaceData)
            for match in matches:
                name = match[0]
                uniqueName = "%s.%s" % (climName, match[0])
                mac= match[1]

                if netutils.isValidMac(mac):
                    interface = Interface(netutils.parseMac(mac), uniqueName)

                    parentInterfaceName = self.__getParentInterfaceName(name)
                    if parentInterfaceName and interfacesByName.has_key(parentInterfaceName):
                        parentInterface = interfacesByName[parentInterfaceName]
                        aliasRole = AliasRole()
                        aliasRole.parentInterface = parentInterface
                        interface._addRole(aliasRole)

                    self.__networking.addInterface(interface)
                    interfacesByName[name] = interface

            matches = ShellDiscoverer.__INTERFACE_AND_IP_REGEXP.findall(interfaceData)
            for match in matches:
                name = match[0]
                ip = match[2]
                netmask = match[4]

                if netutils.isValidIp(ip) and netutils.isValidIp(netmask):
                    if interfacesByName.has_key(name):
                        interface = interfacesByName[name]
                        self.__networking.addIpAndNetwork(ip, netmask, interface.name)
                    else:
                        self.__networking.addIpAndNetwork(ip, netmask)
        else:
            logger.warn('Unrecognized output')
            logger.reportWarning("Failed to discover CLIM network interfaces")
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:47,代码来源:hpnonstop_networking.py

示例15: _resolveEndpoint

def _resolveEndpoint(resolver, endpoint):
    r'@types: dns_resolver.DnsResolver, Endpoint -> list[Endpoint]'
    address = endpoint.getAddress()
    if netutils.isValidIp(address):
        return [endpoint]
    resolveAddressFn = Sfn(resolver.resolveIpsByHostname, fallbackFn = constantly([]))
    return filter(None, (netutils.updateEndpointAddress(endpoint, ip)
            for ip in resolveAddressFn(address)))
开发者ID:ddonnelly19,项目名称:dd-git,代码行数:8,代码来源:plugins_sap_trex.py


注:本文中的netutils.isValidIp函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。