def discoverEsxByBaseServerProfile(context, framework, baseServerProfile):
    '''
    ConnectionContext, Framework, Profile -> UnitaryComputerSystem
    @raise Exception
    @raise ValueError in case UnitaryComputerSystem cannot be found
    '''
    cimv2Client = None
    try:
        cimv2Client = cim_discover.createClient(framework, context.ipAddress,
                                                cim.CimNamespace.CIMV2,
                                                context.credentialId)

        unitaryComputerSystem = vmware_cim_discover.getUnitaryComputerSystemByBaseServerProfile(
            cimv2Client, baseServerProfile)
        if unitaryComputerSystem is None:
            raise ValueError("UnitaryComputerSystem cannot be found")

        unitaryComputerSystem._chassis = vmware_cim_discover.getChassisByUnitaryComputerSystem(
            cimv2Client, unitaryComputerSystem)

        unitaryComputerSystem._hypervisorSoftwareIdentity = vmware_cim_discover.getHypervisorSoftwareIdentityByUnitaryComputerSystem(
            cimv2Client, unitaryComputerSystem)

        unitaryComputerSystem._ethernetPorts = vmware_cim_discover.getVmwareEthernetPortsByUnitaryComputerSystem(
            cimv2Client, unitaryComputerSystem)

        return unitaryComputerSystem

    finally:
        try:
            cimv2Client and cimv2Client.close()
        except:
            pass
Пример #2
0
def discoverEsxVirtualTopology(ipAddress, credentialsId, esxBiosUuid, framework):
    client = None
    try:
        client = cim_discover.createClient(framework, ipAddress, vmware_cim_discover.CimNamespace.ESXV2, credentialsId)
        
        esxList = vmware_cim_discover.getVmwareEsxComputerSystems(client)

        isValidEsxFn = fptools.partiallyApply(_esxMatchesBiosUuid, fptools._, esxBiosUuid.lower())
        esxInstance = fptools.findFirst(isValidEsxFn, esxList)
        
        if not esxInstance:
            raise ValueError("Cannot find ESX Server instance in '%s' namespace" % vmware_cim_discover.CimNamespace.ESXV2)
        
        
        virtualMachines = vmware_cim_discover.getVirtualMachinesByEsx(client, esxInstance)
        totalVms = len(virtualMachines)
        
        virtualMachines = filter(_vmIsReportable, virtualMachines)
        reportableVms = len(virtualMachines)
        
        logger.debug("Virtual machines found: %s, filtered out: %s" % (totalVms, totalVms - reportableVms))
        
        return virtualMachines        
    
    finally:
        if client is not None:
            client.close()
def discoverBaseServerProfile(context, framework):
    '''
    ConnectionContext, Framework -> Profile
    @raise Exception
    @raise ValueError in case no BaseServerprofile can be found
    '''
    baseServerProfile = None
    interopClient = None
    try:
        interopClient = cim_discover.createClient(framework, context.ipAddress,
                                                  cim.CimNamespace.INTEROP,
                                                  context.credentialId)

        profiles = vmware_cim_discover.getProfiles(interopClient)
        baseServerProfile = fptools.findFirst(
            vmware_cim_discover.isBaseServerProfile, profiles)
        if baseServerProfile is None:
            raise ValueError("Base server profile cannot be found")
        else:
            return baseServerProfile
    finally:
        try:
            interopClient and interopClient.close()
        except:
            pass
Пример #4
0
def discoverEsxInventory(ipAddress, credentialsId, esxBiosUuid, framework):
    client = None
    try:
        client = cim_discover.createClient(framework, ipAddress, cim.CimNamespace.CIMV2, credentialsId)
        
        unitaryComputerSystem = None
        try:
            unitaryComputerSystem = vmware_cim_discover.getUnitaryComputerSystemByUuid(client, esxBiosUuid)
            if unitaryComputerSystem is None:
                raise ValueError()
        except:
            logger.error("Failed to get UnitaryComputerSystem by UUID")
            raise ValueError("Failed to get UnitaryComputerSystem by ESX BIOS UUID the job triggered to")
        
        processors = vmware_cim_discover.getProcessorsByUnitaryComputerSystem(client, unitaryComputerSystem)
        vmware_cim_discover.computeProcessorIndexes(processors)
        unitaryComputerSystem._processors = processors
        
        unitaryComputerSystem._memory = vmware_cim_discover.getMemoryByUnitaryComputerSystem(client, unitaryComputerSystem)
        
        return unitaryComputerSystem
    
    finally:
        if client is not None:
            client.close()
def discoverEsxByBaseServerProfile(context, framework, baseServerProfile):
    '''
    ConnectionContext, Framework, Profile -> UnitaryComputerSystem
    @raise Exception
    @raise ValueError in case UnitaryComputerSystem cannot be found
    '''
    cimv2Client = None
    try:
        cimv2Client = cim_discover.createClient(framework, context.ipAddress, cim.CimNamespace.CIMV2, context.credentialId)
        
        unitaryComputerSystem = vmware_cim_discover.getUnitaryComputerSystemByBaseServerProfile(cimv2Client, baseServerProfile)
        if unitaryComputerSystem is None:
            raise ValueError("UnitaryComputerSystem cannot be found")
        
        unitaryComputerSystem._chassis = vmware_cim_discover.getChassisByUnitaryComputerSystem(cimv2Client, unitaryComputerSystem)
        
        unitaryComputerSystem._hypervisorSoftwareIdentity = vmware_cim_discover.getHypervisorSoftwareIdentityByUnitaryComputerSystem(cimv2Client, unitaryComputerSystem)
        
        unitaryComputerSystem._ethernetPorts = vmware_cim_discover.getVmwareEthernetPortsByUnitaryComputerSystem(cimv2Client, unitaryComputerSystem)
        
        return unitaryComputerSystem
    
    finally:
        try:
            cimv2Client and cimv2Client.close()
        except:
            pass
def discoverBaseServerProfile(context, framework):
    '''
    ConnectionContext, Framework -> Profile
    @raise Exception
    @raise ValueError in case no BaseServerprofile can be found
    '''
    baseServerProfile = None
    interopClient = None
    try:
        interopClient = cim_discover.createClient(framework, context.ipAddress, cim.CimNamespace.INTEROP, context.credentialId)
    
        profiles = vmware_cim_discover.getProfiles(interopClient)
        baseServerProfile = fptools.findFirst(vmware_cim_discover.isBaseServerProfile, profiles)
        if baseServerProfile is None:
            raise ValueError("Base server profile cannot be found")
        else:
            return baseServerProfile
    finally:
        try:
            interopClient and interopClient.close()
        except:
            pass
Пример #7
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:
Пример #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: