def DiscoveryMain(Framework):
	OSHVResult = ObjectStateHolderVector()

	connection_url = _getOptionalTriggerParameter(TriggerParameters.CONNECTION_URL, Framework)
	credentialsId = _getOptionalTriggerParameter(TriggerParameters.CREDENTIALS_ID, Framework)
	vcenterCmdbId = _getOptionalTriggerParameter(TriggerParameters.VCENTER_CMDB_ID, Framework)
	runningSoftwareCmdbId = _getOptionalTriggerParameter(TriggerParameters.RUNNING_SOFTWARE_CMDB_ID, Framework)
	ips = Framework.getTriggerCIDataAsList(TriggerParameters.IPS)
	
	if not runningSoftwareCmdbId and not vcenterCmdbId:
		logger.error("Invalid trigger data, neither RunningSoftware nor VirtualCenter Server CMDB IDs are present")
		msg = "%s: Invalid trigger data" % _vmware_vim_base.VimProtocol.DISPLAY
		Framework.reportError(msg)
		return OSHVResult
	
	cmdbId = vcenterCmdbId or runningSoftwareCmdbId 
	
	ipAddress = None
	if connection_url:
		ipAddress = vmware_vim.getIpFromUrlString(connection_url)
	
	connected = 0
	if connection_url and credentialsId and ipAddress:
		#verify existing credentials
		logger.debug("Connecting with previously discovered credentials")
	
		connectionDiscoverer = _configureConnectionDiscoverer(Framework, [ipAddress], vmware_vim.ConstantUrlGenerator(connection_url))
		
		connectionHandler = _configureConnectionHandler(Framework, cmdbId)
		
		connectionDiscoverer.setConnectionHandler(connectionHandler)
		connectionDiscoverer.initConnectionConfigurations()
		connectionDiscoverer.discover()
		
		connected = connectionHandler.connected
		if not connectionHandler.connected:
			logger.debug("Failed to connect with previously discovered credentials")
	
	if not connected:
		#try all credentials, since previous either do not exist or stale
		
		connectionDiscoverer = _configureConnectionDiscoverer(Framework, ips, vmware_vim.UrlByProtocolGenerator(Framework))
		
		connectionHandler = _configureConnectionHandler(Framework, cmdbId)
		
		connectionDiscoverer.setConnectionHandler(connectionHandler)
		connectionDiscoverer.initConnectionConfigurations()
		connectionDiscoverer.discover()
		
		if not connectionHandler.connected:
			connectionHandler.reportConnectionErrors()
			
	return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    connectionUrl = Framework.getDestinationAttribute(
        TriggerParameters.CONNECTION_URL)
    credentialsId = Framework.getDestinationAttribute(
        TriggerParameters.CREDENTIALS_ID)

    if not connectionUrl or not credentialsId:
        logger.error("Invalid trigger data")
        msg = "%s: Invalid trigger data" % _vmware_vim_base.VimProtocol.DISPLAY
        Framework.reportError(msg)
        return OSHVResult

    ipAddress = vmware_vim.getIpFromUrlString(connectionUrl)
    if not ipAddress:
        logger.error("Cannot resolve IP address of server")
        msg = "%s: Cannot resolve IP address of server" % _vmware_vim_base.VimProtocol.DISPLAY
        Framework.reportError(msg)
        return OSHVResult

    connectionDiscoverer = vmware_vim.ConnectionDiscoverer(Framework)
    connectionDiscoverer.setUrlGenerator(
        vmware_vim.ConstantUrlGenerator(connectionUrl))
    connectionDiscoverer.addIp(ipAddress)
    connectionDiscoverer.setCredentialId(credentialsId)

    connectionHandler = vmware_vim.BaseDiscoveryConnectionHandler(Framework)
    connectionHandler.setDiscoveryFunction(discoverVcenterTopology)

    connectionDiscoverer.setConnectionHandler(connectionHandler)

    connectionDiscoverer.initConnectionConfigurations()
    connectionDiscoverer.discover()

    if not connectionHandler.connected:
        connectionHandler.reportConnectionErrors()

    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    connectionUrl = Framework.getDestinationAttribute(TriggerParameters.CONNECTION_URL)
    credentialsId = Framework.getDestinationAttribute(TriggerParameters.CREDENTIALS_ID)

    if not connectionUrl or not credentialsId:
        logger.error("Invalid trigger data")
        msg = "%s: Invalid trigger data" % _vmware_vim_base.VimProtocol.DISPLAY
        Framework.reportError(msg)
        return OSHVResult

    ipAddress = vmware_vim.getIpFromUrlString(connectionUrl)
    if not ipAddress:
        logger.error("Cannot resolve IP address of server")
        msg = "%s: Cannot resolve IP address of server" % _vmware_vim_base.VimProtocol.DISPLAY
        Framework.reportError(msg)
        return OSHVResult

    connectionDiscoverer = vmware_vim.ConnectionDiscoverer(Framework)
    connectionDiscoverer.setUrlGenerator(vmware_vim.ConstantUrlGenerator(connectionUrl))
    connectionDiscoverer.addIp(ipAddress)
    connectionDiscoverer.setCredentialId(credentialsId)

    connectionHandler = vmware_vim.BaseDiscoveryConnectionHandler(Framework)
    connectionHandler.setDiscoveryFunction(discoverVcenterTopology)

    connectionDiscoverer.setConnectionHandler(connectionHandler)

    connectionDiscoverer.initConnectionConfigurations()
    connectionDiscoverer.discover()

    if not connectionHandler.connected:
        connectionHandler.reportConnectionErrors()

    return OSHVResult
示例#4
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    connection_url = _getOptionalTriggerParameter(
        TriggerParameters.CONNECTION_URL, Framework)
    credentialsId = _getOptionalTriggerParameter(
        TriggerParameters.CREDENTIALS_ID, Framework)
    vcenterCmdbId = _getOptionalTriggerParameter(
        TriggerParameters.VCENTER_CMDB_ID, Framework)
    runningSoftwareCmdbId = _getOptionalTriggerParameter(
        TriggerParameters.RUNNING_SOFTWARE_CMDB_ID, Framework)
    ips = Framework.getTriggerCIDataAsList(TriggerParameters.IPS)

    if not runningSoftwareCmdbId and not vcenterCmdbId:
        logger.error(
            "Invalid trigger data, neither RunningSoftware nor VirtualCenter Server CMDB IDs are present"
        )
        msg = "%s: Invalid trigger data" % _vmware_vim_base.VimProtocol.DISPLAY
        Framework.reportError(msg)
        return OSHVResult

    cmdbId = vcenterCmdbId or runningSoftwareCmdbId

    ipAddress = None
    if connection_url:
        ipAddress = vmware_vim.getIpFromUrlString(connection_url)

    connected = 0
    if connection_url and credentialsId and ipAddress:
        #verify existing credentials
        logger.debug("Connecting with previously discovered credentials")

        connectionDiscoverer = _configureConnectionDiscoverer(
            Framework, [ipAddress],
            vmware_vim.ConstantUrlGenerator(connection_url))

        connectionHandler = _configureConnectionHandler(Framework, cmdbId)

        connectionDiscoverer.setConnectionHandler(connectionHandler)
        connectionDiscoverer.initConnectionConfigurations()
        connectionDiscoverer.discover()

        connected = connectionHandler.connected
        if not connectionHandler.connected:
            logger.debug(
                "Failed to connect with previously discovered credentials")

    if not connected:
        #try all credentials, since previous either do not exist or stale

        connectionDiscoverer = _configureConnectionDiscoverer(
            Framework, ips, vmware_vim.UrlByProtocolGenerator(Framework))

        connectionHandler = _configureConnectionHandler(Framework, cmdbId)

        connectionDiscoverer.setConnectionHandler(connectionHandler)
        connectionDiscoverer.initConnectionConfigurations()
        connectionDiscoverer.discover()

        if not connectionHandler.connected:
            connectionHandler.reportConnectionErrors()

    return OSHVResult