Exemple #1
0
def DiscoveryMain(Framework):
    resultVector = ObjectStateHolderVector()

    ipAddress = Framework.getDestinationAttribute(DestinationProperty.IP_ADDRESS)
    credentialsId = Framework.getDestinationAttribute(DestinationProperty.CREDENTIALS_ID)
    hypervisorCmdbId = Framework.getDestinationAttribute(DestinationProperty.HYPERVISOR_CMDB_ID)
    esxCmdbId = Framework.getDestinationAttribute(DestinationProperty.ESX_CMDB_ID)
    esxBiosUuid = Framework.getDestinationAttribute(DestinationProperty.ESX_BIOS_UUID)
    
    if not esxBiosUuid:
        msg = "ESX BIOS UUID from trigger data is empty"
        errorObject = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [cim.Protocol.DISPLAY, msg], msg)
        logger.reportErrorObject(errorObject)
        logger.error(msg)
        return resultVector
    
    try:
        unitaryComputerSystem = discoverEsxInventory(ipAddress, credentialsId, esxBiosUuid, Framework)
        
        inventoryResultVector = reportEsxInventory(unitaryComputerSystem, esxCmdbId)
        resultVector.addAll(inventoryResultVector)
        
        virtualMachines = discoverEsxVirtualTopology(ipAddress, credentialsId, esxBiosUuid, Framework)
        if virtualMachines:
            virtualResultVector = reportVirtualTopology(virtualMachines, hypervisorCmdbId)
            resultVector.addAll(virtualResultVector)
        
    except JException, ex:
        msg = ex.getMessage()
        msg = cim_discover.translateErrorMessage(msg)
        logger.debug(msg)
        errormessages.resolveAndReport(msg, cim.Protocol.DISPLAY, Framework)
    def onConnection(self, context):
        '''
        Method handles successful connection described by context
        '''
        
        self.connected = True
        
        try:

            vector = self.discoveryFunction(context, self.framework)

            if vector is not None:
                
                logger.debug(" -- Sending vector of %s objects" % vector.size())
                if self._logVector:
                    logger.debug(vector.toXmlString())
                
                self.framework.sendObjects(vector)
                self.framework.flushObjects()
            
            else:
                logger.warn("Discovery function returned result vector that is None")
        
        except JException, ex:
            msg = ex.getMessage()
            msg = cim_discover.translateErrorMessage(msg)
            logger.debug(msg)
            errormessages.resolveAndReport(msg, cim.Protocol.DISPLAY, self.framework)
    def onConnection(self, context):
        '''
        Method handles successful connection described by context
        '''

        self.connected = True

        try:

            vector = self.discoveryFunction(context, self.framework)

            if vector is not None:

                logger.debug(" -- Sending vector of %s objects" %
                             vector.size())
                if self._logVector:
                    logger.debug(vector.toXmlString())

                self.framework.sendObjects(vector)
                self.framework.flushObjects()

            else:
                logger.warn(
                    "Discovery function returned result vector that is None")

        except JException, ex:
            msg = ex.getMessage()
            msg = cim_discover.translateErrorMessage(msg)
            logger.debug(msg)
            errormessages.resolveAndReport(msg, cim.Protocol.DISPLAY,
                                           self.framework)
    def discover(self, firstSuccessful=True):
        '''
        bool -> None
        @raise ValueError in case no connection configurations were initialized
        Perform discovery of connections
        '''

        if not self.contextsMap:
            raise NoConnectionConfigurationsException(
                "No connection configurations were found")

        vmwareNamespaces = [ns for ns in self.vmwareCategory.getNamespaces()]
        vmwareNamespacesCount = len(vmwareNamespaces)

        for contextsByCredentialsMap in self.contextsMap.itervalues():

            for contextList in contextsByCredentialsMap.itervalues():

                for context in contextList:

                    successfulNamespaces = []
                    for namespace in vmwareNamespaces:

                        try:
                            cim_discover.testConnectionWithNamespace(
                                self.framework, context.ipAddress,
                                context.credentialId, namespace)
                            # no exception, connection successful
                            successfulNamespaces.append(namespace)

                        except JException, ex:
                            msg = ex.getMessage()
                            msg = cim_discover.translateErrorMessage(msg)
                            logger.debug(msg)
                            errormessages.resolveAndAddToCollections(
                                msg, cim.Protocol.DISPLAY, context.warnings,
                                context.errors)
                            self.connectionHandler.onFailure(context)
                            break

                        except:
                            msg = logger.prepareJythonStackTrace('')
                            logger.debug(msg)
                            errormessages.resolveAndAddToCollections(
                                msg, cim.Protocol.DISPLAY, context.warnings,
                                context.errors)
                            self.connectionHandler.onFailure(context)
                            break
Exemple #5
0
def DiscoveryMain(Framework):
    warningsList = []
    errorsList = []
    vector = ObjectStateHolderVector()
    ip_address = Framework.getDestinationAttribute('ip_address')
    ip_domain = Framework.getDestinationAttribute('ip_domain')
    protocolName = cim.Protocol.DISPLAY

    credentials = netutils.getAvailableProtocols(Framework, cim.Protocol.FULL,
                                                 ip_address, ip_domain)
    credentials = smis_discoverer.getSmisCredentials(credentials, Framework)
    if len(credentials) == 0:
        msg = errormessages.makeErrorMessage(
            protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(
            errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        warningsList.append(errobj)
        logger.debug(msg)

    smisNamespaces = smis_discoverer.getSmisNamespaces(Framework)
    if not smisNamespaces:
        msg = errormessages.makeErrorMessage(protocolName,
                                             "No SMI-S namespaces found")
        errobj = errorobject.createError(
            errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS,
            [cim.Protocol.DISPLAY, msg], msg)
        errorsList.append(errobj)
        logger.reportErrorObject(errobj)
        return vector

    for credential in credentials:
        testedNamespace = None
        for namespaceObject in smisNamespaces:
            try:

                testedNamespace = cim_discover.testConnectionWithNamespace(
                    Framework, ip_address, credential, namespaceObject)
                break
            except JException, ex:
                msg = ex.getMessage()
                msg = cim_discover.translateErrorMessage(msg)
                errormessages.resolveAndAddToObjectsCollections(
                    msg, protocolName, warningsList, errorsList)
            except:
    def discover(self, firstSuccessful=True):
        '''
        bool -> None
        @raise ValueError in case no connection configurations were initialized
        Perform discovery of connections
        '''
        
        if not self.contextsMap:
            raise NoConnectionConfigurationsException("No connection configurations were found")
        
        vmwareNamespaces = [ns for ns in self.vmwareCategory.getNamespaces()]
        vmwareNamespacesCount = len(vmwareNamespaces)
        
        for contextsByCredentialsMap in self.contextsMap.itervalues():
            
            for contextList in contextsByCredentialsMap.itervalues():
                
                for context in contextList:

                    successfulNamespaces = []
                    for namespace in vmwareNamespaces:
                    
                        try:
                            cim_discover.testConnectionWithNamespace(self.framework, context.ipAddress, context.credentialId, namespace)
                            # no exception, connection successful
                            successfulNamespaces.append(namespace)
                            
                        except JException, ex:
                            msg = ex.getMessage()
                            msg = cim_discover.translateErrorMessage(msg)
                            logger.debug(msg)
                            errormessages.resolveAndAddToCollections(msg, cim.Protocol.DISPLAY, context.warnings, context.errors)
                            self.connectionHandler.onFailure(context)
                            break
                        
                        except:
                            msg = logger.prepareJythonStackTrace('')
                            logger.debug(msg)
                            errormessages.resolveAndAddToCollections(msg, cim.Protocol.DISPLAY, context.warnings, context.errors)
                            self.connectionHandler.onFailure(context)
                            break
def DiscoveryMain(Framework):
    warningsList = []
    errorsList = []
    vector = ObjectStateHolderVector()
    ip_address = Framework.getDestinationAttribute('ip_address')
    ip_domain = Framework.getDestinationAttribute('ip_domain')
    protocolName = cim.Protocol.DISPLAY
    
    credentials = netutils.getAvailableProtocols(Framework, cim.Protocol.FULL, ip_address, ip_domain)
    credentials = smis_discoverer.getSmisCredentials(credentials, Framework)
    if len(credentials) == 0:
        msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        warningsList.append(errobj)
        logger.debug(msg)
    
    smisNamespaces = smis_discoverer.getSmisNamespaces(Framework)
    if not smisNamespaces:
        msg = errormessages.makeErrorMessage(protocolName, "No SMI-S namespaces found")
        errobj = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [cim.Protocol.DISPLAY, msg], msg)
        errorsList.append(errobj)
        logger.reportErrorObject(errobj)
        return vector
    
    for credential in credentials:
        testedNamespace = None
        for namespaceObject in smisNamespaces:
            try:
    
                testedNamespace = cim_discover.testConnectionWithNamespace(Framework, ip_address, credential, namespaceObject)
                break
            except JException, ex:
                msg = ex.getMessage()
                msg = cim_discover.translateErrorMessage(msg)
                errormessages.resolveAndAddToObjectsCollections(msg, protocolName, warningsList, errorsList)
            except:
Exemple #8
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    protocol = cim.Protocol.DISPLAY
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    ipAddress = Framework.getDestinationAttribute('ip_address')

    smisNamespaces = smis_discoverer.getSmisNamespaces(Framework)
    if not smisNamespaces:
        msg = errormessages.makeErrorMessage(cim.Protocol.DISPLAY,
                                             "No SMI-S namespaces found")
        errobj = errorobject.createError(
            errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS,
            [cim.Protocol.DISPLAY, msg], msg)
        logger.reportErrorObject(errobj)
        return OSHVResult
    errorMessges = []
    for namespaceObject in smisNamespaces:
        client = None
        namespace = namespaceObject.getName()
        try:
            try:
                client = cim_discover.createClient(Framework, ipAddress,
                                                   namespace, credentialsId)

                logger.debug('Connected to namespace "%s"' % namespace)
                storageFabricDiscoverer = smis_discoverer.getStorageFabricDiscoverer(
                    namespace)
                if storageFabricDiscoverer:
                    storageFabrics = storageFabricDiscoverer.discover(client)
                    switch2FabricLinksDiscover = smis_discoverer.getSwitch2FabricLinksDiscoverDiscoverer(
                        namespace)
                    switch2FabricMap = {}
                    if switch2FabricLinksDiscover:
                        switch2FabricMap = switch2FabricLinksDiscover.discover(
                            client)

                    fcSwitchs = []
                    hosts = []
                    switchDiscoverer = smis_discoverer.getSwitchComputerSystemDiscoverer(
                        namespace)
                    if switchDiscoverer:
                        (fcSwitchs, hosts) = switchDiscoverer.discover(client)

                    fcPorts = []
                    fcPortsDiscover = smis_discoverer.getFcPortDiscoverer(
                        namespace)
                    if fcPortsDiscover:
                        fcPorts = fcPortsDiscover.discover(client)

                    connections = {}
                    portConnectionDiscover = smis_discoverer.getFCPortConnectionsDiscover(
                        namespace)
                    if portConnectionDiscover:
                        connections = portConnectionDiscover.discover(client)
                    topoBuilder = smis.TopologyBuilder()
                    OSHVResult.addAll(
                        topoBuilder.reportFcSwitchTopolopy(
                            storageFabrics, fcSwitchs, hosts, fcPorts,
                            switch2FabricMap, connections))
                    return OSHVResult

                systemDiscoverer = smis_discoverer.getStorageSystemDiscoverer(
                    namespace)
                storageSystems = systemDiscoverer.discover(client)
                storageProcessorDiscoverer = smis_discoverer.getStorageProcessorDiscoverer(
                    namespace)
                storageProcessors = storageProcessorDiscoverer.discover(client)
                physicalDrives = []
                localFchPorts = []
                pools = []
                lvs = []
                endPoints = []
                portDiscoverer = smis_discoverer.getFcPortDiscoverer(namespace)
                localFchPorts = portDiscoverer.discover(client)
                poolDiscoverer = smis_discoverer.getStoragePoolDiscoverer(
                    namespace)
                pools = poolDiscoverer.discover(client)
                lvDiscoverer = smis_discoverer.getLogicalVolumeDiscoverer(
                    namespace)
                lvs = lvDiscoverer.discover(client)
                pvDiscoverer = smis_discoverer.getPhysicalVolumeDiscoverer(
                    namespace)
                pvs = pvDiscoverer.discover(client)
                logger.debug(localFchPorts)
                endPointDiscoverer = smis_discoverer.getRemoteEndpointDiscoverer(
                    namespace)
                endPoints = endPointDiscoverer.discover(client)

                endPointToVolumeDiscoverer = smis_discoverer.getEndPointToVolumeDiscoverer(
                    namespace)
                endpointLinks = endPointToVolumeDiscoverer.discover(client)

                lunMappings = []
                lunMaksingMappingViewDiscover = smis_discoverer.getLunMaskingMappingViewDiscover(
                    namespace)
                if lunMaksingMappingViewDiscover:
                    lunMappings = lunMaksingMappingViewDiscover.discover(
                        client)

                pv2poolLinks = {}
                pv2poolLinksDiscover = smis_discoverer.getPhysicalVolume2StoragePoolLinksDiscover(
                    namespace)
                if pv2poolLinksDiscover:
                    pv2poolLinks = pv2poolLinksDiscover.discover(client)

    ##          #building topology
                topoBuilder = smis.TopologyBuilder()
                OSHVResult.addAll(
                    topoBuilder.reportTopology(
                        storageSystems=storageSystems,
                        ports=localFchPorts,
                        pools=pools,
                        lvs=lvs,
                        endPoints=endPoints,
                        storageProcessors=storageProcessors,
                        pvs=pvs,
                        endpointLinks=endpointLinks,
                        lunMappings=lunMappings,
                        pv2poolLinks=pv2poolLinks))
                errorMessges = []
                break

            finally:
                try:
                    client and client.close()
                except:
                    logger.error("Unable to close client")
        except JavaException, ex:
            logger.debugException('')
            msg = ex.getMessage()
            msg = cim_discover.translateErrorMessage(msg)
            errorMessges.append(msg)
            #errormessages.resolveAndReport(msg, protocol, Framework)
        except:
Exemple #9
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    protocol = cim.Protocol.DISPLAY
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    ipAddress = Framework.getDestinationAttribute('ip_address')
    
    smisNamespaces = smis_discoverer.getSmisNamespaces(Framework)
    if not smisNamespaces:
        msg = errormessages.makeErrorMessage(cim.Protocol.DISPLAY, "No SMI-S namespaces found")
        errobj = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [cim.Protocol.DISPLAY, msg], msg)
        logger.reportErrorObject(errobj)
        return OSHVResult
    errorMessges = []
    for namespaceObject in smisNamespaces:
        client = None
        namespace = namespaceObject.getName()
        try:
            try:
                client = cim_discover.createClient(Framework, ipAddress, namespace, credentialsId)
                
                logger.debug('Connected to namespace "%s"' % namespace)
                storageFabricDiscoverer = smis_discoverer.getStorageFabricDiscoverer(namespace)
                if storageFabricDiscoverer:
                    storageFabrics = storageFabricDiscoverer.discover(client)
                    switch2FabricLinksDiscover = smis_discoverer.getSwitch2FabricLinksDiscoverDiscoverer(namespace)
                    switch2FabricMap = {}
                    if switch2FabricLinksDiscover:
                        switch2FabricMap = switch2FabricLinksDiscover.discover(client)

                    fcSwitchs = []
                    hosts = []
                    switchDiscoverer = smis_discoverer.getSwitchComputerSystemDiscoverer(namespace)
                    if switchDiscoverer:
                        (fcSwitchs, hosts) = switchDiscoverer.discover(client)

                    fcPorts = []
                    fcPortsDiscover = smis_discoverer.getFcPortDiscoverer(namespace)
                    if fcPortsDiscover:
                        fcPorts = fcPortsDiscover.discover(client)

                    connections = {}
                    portConnectionDiscover = smis_discoverer.getFCPortConnectionsDiscover(namespace)
                    if portConnectionDiscover:
                        connections = portConnectionDiscover.discover(client)
                    topoBuilder = smis.TopologyBuilder()
                    OSHVResult.addAll(topoBuilder.reportFcSwitchTopolopy(storageFabrics,fcSwitchs,hosts,fcPorts,switch2FabricMap,connections))
                    return OSHVResult

                systemDiscoverer = smis_discoverer.getStorageSystemDiscoverer(namespace)
                storageSystems = systemDiscoverer.discover(client)
                storageProcessorDiscoverer = smis_discoverer.getStorageProcessorDiscoverer(namespace)
                storageProcessors = storageProcessorDiscoverer.discover(client)
                physicalDrives = []
                localFchPorts = []
                pools = []
                lvs = []
                endPoints = []
                portDiscoverer = smis_discoverer.getFcPortDiscoverer(namespace)
                localFchPorts = portDiscoverer.discover(client)
                poolDiscoverer = smis_discoverer.getStoragePoolDiscoverer(namespace)
                pools = poolDiscoverer.discover(client)
                lvDiscoverer = smis_discoverer.getLogicalVolumeDiscoverer(namespace)
                lvs = lvDiscoverer.discover(client)
                pvDiscoverer = smis_discoverer.getPhysicalVolumeDiscoverer(namespace)
                pvs = pvDiscoverer.discover(client)
                logger.debug(localFchPorts)
                endPointDiscoverer = smis_discoverer.getRemoteEndpointDiscoverer(namespace)
                endPoints = endPointDiscoverer.discover(client)
                
                endPointToVolumeDiscoverer = smis_discoverer.getEndPointToVolumeDiscoverer(namespace)
                endpointLinks = endPointToVolumeDiscoverer.discover(client)

                lunMappings = []
                lunMaksingMappingViewDiscover = smis_discoverer.getLunMaskingMappingViewDiscover(namespace)
                if lunMaksingMappingViewDiscover:
                    lunMappings = lunMaksingMappingViewDiscover.discover(client)

                pv2poolLinks = {}
                pv2poolLinksDiscover = smis_discoverer.getPhysicalVolume2StoragePoolLinksDiscover(namespace)
                if pv2poolLinksDiscover:
                    pv2poolLinks = pv2poolLinksDiscover.discover(client)

    ##          #building topology
                topoBuilder = smis.TopologyBuilder()
                OSHVResult.addAll(topoBuilder.reportTopology(storageSystems=storageSystems, ports=localFchPorts, pools=pools, lvs=lvs,
                                            endPoints=endPoints, storageProcessors = storageProcessors, pvs = pvs,
                                             endpointLinks = endpointLinks, lunMappings = lunMappings, pv2poolLinks = pv2poolLinks))
                errorMessges = []
                break
                
            finally:
                try:
                    client and client.close()
                except:
                    logger.error("Unable to close client")
        except JavaException, ex:
            logger.debugException('')
            msg = ex.getMessage()
            msg = cim_discover.translateErrorMessage(msg)
            errorMessges.append(msg)
            #errormessages.resolveAndReport(msg, protocol, Framework)
        except: