コード例 #1
0
ファイル: TTY_HR_Disk_Lib.py プロジェクト: ddonnelly19/dd-git
    def handleDiskRow(self, fileSystem, mountedOn, size, usedSize=None):
        """
        @param usedSize: disk used size in 1K-blocks
        @param size: disk size in 1K-blocks
        """
        if mountedOn in self.mountPointToDisk:
            logger.reportWarning("File system object already reported for the mount point; skipping new one")
            logger.warn(
                "File system object already reported for the mount point '%s'; skipping new one (mount point: '%s'; file system: '%s')"
                % (mountedOn, mountedOn, fileSystem)
            )
            return
        if str(size).isdigit():
            sizeInMb = _kbToMb(size)
        else:
            sizeInMb = None
        if str(usedSize).isdigit():
            usedSizeInMb = _kbToMb(usedSize)
        else:
            usedSizeInMb = None
        type_ = modeling.UNKNOWN_STORAGE_TYPE
        diskOsh = modeling.createDiskOSH(
            self.containerOsh, mountedOn, type_, size=sizeInMb, name=fileSystem, usedSize=usedSizeInMb
        )
        if diskOsh:
            self.mountPointToDisk[mountedOn] = diskOsh
            self.resultVector.add(diskOsh)

            host_reporter = host_topology.Reporter()
            resolver = dns_resolver.create(shell=self.shell)
            try:
                (remoteHost, remoteMountPoint) = getRemoteHostAndMountPoint(fileSystem)
                if remoteHost and remoteMountPoint:
                    if remoteHost.startswith("[") and remoteHost.endswith("]"):
                        remoteHost = remoteHost[1:-1]
                    host_osh = self.remoteHosts.get(remoteHost)
                    if not host_osh:
                        host = host_base_parser.parse_from_address(remoteHost, resolver.resolve_ips)
                        # do not report hostname as it may be alias
                        host_osh, _, oshs = host_reporter.report_host_with_ips(host.ips)
                        self.remoteHosts[remoteHost] = host_osh
                        self.resultVector.addAll(oshs)

                    remoteShareOsh = ObjectStateHolder("networkshare")
                    remoteShareOsh.setContainer(host_osh)
                    remoteShareOsh.setStringAttribute("data_name", remoteMountPoint)
                    remoteShareOsh.setStringAttribute("share_path", remoteMountPoint)
                    self.resultVector.add(remoteShareOsh)

                    self.resultVector.add(modeling.createLinkOSH("realization", remoteShareOsh, diskOsh))
            except:
                stackTrace = logger.prepareFullStackTrace("Failed to link disk to the remote share.")
                logger.warn(stackTrace)
コード例 #2
0
def discoverDiskByWmic(shell, OSHVec, hostOSH):
    wmiProvider = wmiutils.getWmiProvider(shell)
    queryBuilder = wmiProvider.getBuilder("Win32_LogicalDisk")
    queryBuilder.usePathCommand(1)
    queryBuilder.addWmiObjectProperties("DeviceID", "DriveType", "FreeSpace", "ProviderName", "Size", "FileSystem")
    queryBuilder.addWhereClause("DriveType=3")
    wmicAgent = wmiProvider.getAgent()

    diskItems = []
    try:
        diskItems = wmicAgent.getWmiData(queryBuilder)
    except:
        logger.debugException("Failed getting disks information via wmic")
        return 0

    for diskItem in diskItems:

        # size in MB
        diskSize = diskItem.Size and diskItem.Size.strip() or None
        if diskSize:
            diskSize = _bytesToMB(diskSize)
        diskFreeSize = diskItem.FreeSpace and diskItem.FreeSpace.strip() or None
        if diskFreeSize:
            diskFreeSize = _bytesToMB(diskFreeSize)
        diskUsedSize = None
        if diskFreeSize is not None and diskFreeSize is not None:
            diskUsedSize = diskSize - diskFreeSize

        diskName = diskItem.DeviceID and diskItem.DeviceID.strip() or None
        if diskName:
            diskName = re.sub(":$", "", diskName)

        # if provderName is set - this is a remote disk
        diskProviderName = diskItem.ProviderName and diskItem.ProviderName.strip() or diskName

        diskType = diskItem.DriveType and int(diskItem.DriveType.strip()) or None

        logger.debug(
            "found disk: %s, sizeInMB=%s, freespace=%s, type=%s" % (diskName, diskSize, diskFreeSize, diskType)
        )

        diskType = diskType and modeling.STORAGE_ID_TO_STORAGE_TYPE.get(diskType) or modeling.OTHER_STORAGE_TYPE

        diskOsh = modeling.createDiskOSH(
            hostOSH, diskName, diskType, size=diskSize, name=diskProviderName, usedSize=diskUsedSize
        )
        OSHVec.add(diskOsh)

    return 1
コード例 #3
0
def createZoneFileSystemObjects(zone, globalZoneOsh, resultsVector):
    for fileSystem in zone.fileSystems:

        localZoneDiskOsh = modeling.createDiskOSH(zone.hostOsh, fileSystem.dir, type = modeling.UNKNOWN_STORAGE_TYPE)
        localZoneDiskOsh.setBoolAttribute('isvirtual', 1)
        resultsVector.add(localZoneDiskOsh)

        globalDiskOsh = ObjectStateHolder('networkshare')
        globalDiskOsh.setAttribute('data_name', fileSystem.special)
        globalDiskOsh.setAttribute('share_path', fileSystem.special)
        globalDiskOsh.setContainer(globalZoneOsh)
        resultsVector.add(globalDiskOsh)

        realizationLink = modeling.createLinkOSH('realization', globalDiskOsh, localZoneDiskOsh)
        resultsVector.add(realizationLink)
コード例 #4
0
def discoverDisk(client, myVec, hostOSH):
    cmdDiskInfo = 'diskinfo.exe'

    localFile = CollectorsParameters.BASE_PROBE_MGR_DIR + CollectorsParameters.getDiscoveryResourceFolder(
    ) + CollectorsParameters.FILE_SEPARATOR + 'diskinfo.exe'
    remoteFile = client.copyFileIfNeeded(localFile)
    if not remoteFile:
        logger.debug('Failed copying %s' % cmdDiskInfo)
        return

    ntcmdErrStr = 'Remote command returned 1(0x1)'
    buffer = client.execCmd(
        remoteFile,
        DISKINFO_TIMEOUT)  # V@@CMD_PERMISION ntcmd protocol execution
    logger.debug('Output of ', remoteFile, ': ', buffer)

    if buffer.find(ntcmdErrStr) != -1:
        logger.warn('Failed getting disk info')
    else:
        logger.debug('Got disk info - parsing...')

        disks = buffer.split('\n')
        for disk in disks:
            disk = disk.strip()
            name = ''
            size = 0
            usedSize = None
            diskType = ''
            try:
                # Get disk size
                matchSize = re.search('Size: (\d+) MB', disk)
                if matchSize:
                    size = int(matchSize.group(1))
                    matchFreeSize = re.search('Free: (\d+) MB', disk)
                    if matchFreeSize:
                        freeSize = int(matchFreeSize.group(1))
                        usedSize = size - freeSize
                # Get disk type
                matchType = re.search('Type: (.*)', disk)
                if matchType:
                    diskType = matchType.group(1)
                    diskType = diskType.strip()
                    if (diskType == 'FLOPPY' and size > 5):
                        diskType = 'FLASH'

                # Get disk name
                matchName = re.search(r'Name: (\w):\\,', disk)
                if matchName:
                    name = matchName.group(1)
                    name = name.strip()
                # Create DISK OSH
                if name != '':
                    if diskType in STORAGE_NAME_TO_STORAGE_TYPE:
                        storageType = STORAGE_NAME_TO_STORAGE_TYPE[diskType]
                    else:
                        storageType = modeling.OTHER_STORAGE_TYPE
                    diskOsh = modeling.createDiskOSH(hostOSH,
                                                     name,
                                                     storageType,
                                                     size,
                                                     name=name,
                                                     usedSize=usedSize)
                    myVec.add(diskOsh)
            except:
                logger.errorException('Error in discoverDisk()')
コード例 #5
0
def discoverDiskByWmic(shell, OSHVec, hostOSH):
    wmiProvider = wmiutils.getWmiProvider(shell)
    queryBuilder = wmiProvider.getBuilder('Win32_LogicalDisk')
    queryBuilder.usePathCommand(1)
    queryBuilder.addWmiObjectProperties(
        'DeviceID',
        'DriveType',
        'FreeSpace',
        'ProviderName',
        'Size',
        'FileSystem',
    )
    queryBuilder.addWhereClause('DriveType=3')
    wmicAgent = wmiProvider.getAgent()

    diskItems = []
    try:
        diskItems = wmicAgent.getWmiData(queryBuilder)
    except:
        logger.debugException('Failed getting disks information via wmic')
        return 0

    for diskItem in diskItems:

        #size in MB
        diskSize = diskItem.Size and diskItem.Size.strip() or None
        if diskSize:
            diskSize = _bytesToMB(diskSize)
        diskFreeSize = diskItem.FreeSpace and diskItem.FreeSpace.strip(
        ) or None
        if diskFreeSize:
            diskFreeSize = _bytesToMB(diskFreeSize)
        diskUsedSize = None
        if diskFreeSize is not None and diskFreeSize is not None:
            diskUsedSize = diskSize - diskFreeSize

        diskName = diskItem.DeviceID and diskItem.DeviceID.strip() or None
        if diskName:
            diskName = re.sub(':$', '', diskName)

        # if provderName is set - this is a remote disk
        diskProviderName = diskItem.ProviderName and diskItem.ProviderName.strip(
        ) or diskName

        diskType = diskItem.DriveType and int(
            diskItem.DriveType.strip()) or None

        logger.debug('found disk: %s, sizeInMB=%s, freespace=%s, type=%s' %
                     (diskName, diskSize, diskFreeSize, diskType))

        diskType = diskType and modeling.STORAGE_ID_TO_STORAGE_TYPE.get(
            diskType) or modeling.OTHER_STORAGE_TYPE

        diskOsh = modeling.createDiskOSH(hostOSH,
                                         diskName,
                                         diskType,
                                         size=diskSize,
                                         name=diskProviderName,
                                         usedSize=diskUsedSize)
        OSHVec.add(diskOsh)

    return 1
コード例 #6
0
def discoverDisk(client, myVec, hostOSH):
    cmdDiskInfo = "diskinfo.exe"

    localFile = (
        CollectorsParameters.BASE_PROBE_MGR_DIR
        + CollectorsParameters.getDiscoveryResourceFolder()
        + CollectorsParameters.FILE_SEPARATOR
        + "diskinfo.exe"
    )
    remoteFile = client.copyFileIfNeeded(localFile)
    if not remoteFile:
        logger.debug("Failed copying %s" % cmdDiskInfo)
        return

    ntcmdErrStr = "Remote command returned 1(0x1)"
    buffer = client.execCmd(remoteFile, DISKINFO_TIMEOUT)  # V@@CMD_PERMISION ntcmd protocol execution
    logger.debug("Output of ", remoteFile, ": ", buffer)

    if buffer.find(ntcmdErrStr) != -1:
        logger.warn("Failed getting disk info")
    else:
        logger.debug("Got disk info - parsing...")

        disks = buffer.split("\n")
        for disk in disks:
            disk = disk.strip()
            name = ""
            size = 0
            usedSize = None
            diskType = ""
            try:
                # Get disk size
                matchSize = re.search("Size: (\d+) MB", disk)
                if matchSize:
                    size = int(matchSize.group(1))
                    matchFreeSize = re.search("Free: (\d+) MB", disk)
                    if matchFreeSize:
                        freeSize = int(matchFreeSize.group(1))
                        usedSize = size - freeSize
                # Get disk type
                matchType = re.search("Type: (.*)", disk)
                if matchType:
                    diskType = matchType.group(1)
                    diskType = diskType.strip()
                    if diskType == "FLOPPY" and size > 5:
                        diskType = "FLASH"

                # Get disk name
                matchName = re.search(r"Name: (\w):\\,", disk)
                if matchName:
                    name = matchName.group(1)
                    name = name.strip()
                # Create DISK OSH
                if name != "":
                    if diskType in STORAGE_NAME_TO_STORAGE_TYPE:
                        storageType = STORAGE_NAME_TO_STORAGE_TYPE[diskType]
                    else:
                        storageType = modeling.OTHER_STORAGE_TYPE
                    diskOsh = modeling.createDiskOSH(hostOSH, name, storageType, size, name=name, usedSize=usedSize)
                    myVec.add(diskOsh)
            except:
                logger.errorException("Error in discoverDisk()")
コード例 #7
0
ファイル: xen_by_tty.py プロジェクト: ddonnelly19/dd-git
def doDicovery(shell, framework, rootServerOsh):
    resultVector = ObjectStateHolderVector()
    try:
        domainsList = discoverDomainsList(shell)
    except ValueError:
        raise ValueError, 'No libvirt Found. Failed to discover neither Xen nor KVM'
    domainsConfigDict = discoverDomainConfiguration(shell, domainsList)
    
    bridgeDict = discoverBridges(shell)
    ifaceNameToIfaceMacMap = discoverInterfacesByIfconfig(shell)
    #building topology
    ucmdbVersion = logger.Version().getVersion(framework)
    
    resultVector.add(rootServerOsh)
    bridgeToPortOshMap = {}
    for bridge in bridgeDict.values():
        bridgeOsh = createBridgeOsh(bridge.mac, bridge.name, rootServerOsh)
        if bridgeOsh:
            portNumber = 0
            for ifaceName in bridge.ifaceNameList:
                ifaceMac = ifaceNameToIfaceMacMap.get(ifaceName)
                interfaceOsh = modeling.createInterfaceOSH(ifaceMac, rootServerOsh)
                resultVector.add(bridgeOsh)
                if interfaceOsh:
                    linkOsh = modeling.createLinkOSH('containment', bridgeOsh, interfaceOsh)
                    resultVector.add(linkOsh)
                    resultVector.add(interfaceOsh)
                    portOsh = createBridgePhysicalPort(str(portNumber), bridgeOsh)
                    portNumber += 1
                    linkOsh = modeling.createLinkOSH('realization', portOsh, interfaceOsh)
                    bridgeToPortOshMap[bridge.name] = portOsh
                    resultVector.add(portOsh)
                    resultVector.add(linkOsh)
    
    (hypervisorVersion, hypervisorVersionDescription) = getHypervisorData(shell)
    if hypervisorVersion and not domainsConfigDict and checkKvmIrqProcess(shell):
        hypervisorOsh = KvmHypervisor(hypervisorVersion, hypervisorVersionDescription).build(rootServerOsh)
        resultVector.add(hypervisorOsh)
        
    for (domainName, config) in domainsConfigDict.items():
        hypervisorOsh = config.name == XEN_DOMAIN and XenHypervisor(hypervisorVersion, hypervisorVersionDescription).build(rootServerOsh) or KvmHypervisor(hypervisorVersion, hypervisorVersionDescription).build(rootServerOsh)
        resultVector.add(hypervisorOsh)

        if config.domainId == 0 and config.name == XEN_DOMAIN:
            domainConfigOsh = createXenDomainConfigOsh(config, rootServerOsh)
            resultVector.add(domainConfigOsh)
        else:
            vHostOsh = createVirtHostOsh(config)
            if vHostOsh: 
                domainConfigOsh = config.name == XEN_DOMAIN and createXenDomainConfigOsh(config, vHostOsh) or createKvmDomainConfigOsh(config, vHostOsh) 
                linkOsh = modeling.createLinkOSH('run', hypervisorOsh, vHostOsh)
                resultVector.add(vHostOsh)
                resultVector.add(domainConfigOsh)
                resultVector.add(linkOsh)
                for networkInterface in config.interfaceList:  
                    interfaceOsh = modeling.createInterfaceOSH(networkInterface.macAddress, vHostOsh)
                    if interfaceOsh: 
                        interfaceOsh.setBoolAttribute('isvirtual', 1)
                        resultVector.add(interfaceOsh)
                for i in range(len(config.bridgeNameList)):
                    bridgeName = config.bridgeNameList[i]
                    ifaceMac = config.interfaceList[i]
                    bridge = bridgeDict.get(bridgeName)
                    if bridge:
                        interfaceOsh = modeling.createInterfaceOSH(networkInterface.macAddress, vHostOsh)
                        portOsh = bridgeToPortOshMap.get(bridgeName)
                        if ucmdbVersion < 9:
                            linkOsh = modeling.createLinkOSH('layertwo', interfaceOsh, portOsh)
                            resultVector.add(linkOsh)
                shareOsh = createNetworkShare(config.disk, rootServerOsh, ucmdbVersion)
                if shareOsh:
                    diskOsh = modeling.createDiskOSH(vHostOsh, config.mountPoint, modeling.UNKNOWN_STORAGE_TYPE)
                    if diskOsh:
                        linkOsh = modeling.createLinkOSH('realization', shareOsh, diskOsh)
                        resultVector.add(shareOsh)
                        resultVector.add(diskOsh)
                        resultVector.add(linkOsh)
    return resultVector
コード例 #8
0
def doQueryDisks(client, OSHVResult):
    ip_address = client.getIpAddress()
    _hostObj = modeling.createHostOSH(ip_address)
    ################     Query and data    ################################
    data_name_mib = '1.3.6.1.2.1.25.2.3.1.3,1.3.6.1.2.1.25.2.3.1.4,string,1.3.6.1.2.1.25.2.3.1.5,double,1.3.6.1.2.1.25.2.3.1.6,string,1.3.6.1.2.1.25.2.3.1.7,string,1.3.6.1.2.1.25.2.3.1.2,string,1.3.6.1.2.1.25.2.3.1.4,string'
    resultSet = client.executeQuery(data_name_mib)#@@CMD_PERMISION snmp protocol execution
    count = 0
    while resultSet.next():
        count = count + 1
        try:

            diskNametmp = resultSet.getString(2)
            diskSizeStr = resultSet.getString(3)
            diskSizetmp = 0
            if (diskSizeStr != None and diskSizeStr != ''):
                diskSizetmp = int(diskSizeStr)

            diskFailuresStr = resultSet.getString(5)
            if (diskFailuresStr != None and diskFailuresStr != ''):
                diskFailures = int(diskFailuresStr)
            else:
                diskFailures = None
                logger.debug('Failed parsing DiskFailures value')

            diskTypeOid = resultSet.getString(6)

            diskSizeUnitStr = resultSet.getString(7)
            diskSizeUnit = 0
            if (diskSizeUnitStr != None and diskSizeUnitStr != ''):
                diskSizeUnit = int(diskSizeUnitStr)

            # calculate disk size in Bytes
            # to get disk size we multiply cluster size (allocation units) by number of clusters on disk
            #diskSize =(float(diskSizetmp)*float(diskSizeUnit))#/(1024)

            # calculate disk size in Bytes and translate to Megabytes
            # to get disk size we multiply cluster size (allocation units) by number of clusters on disk
            diskSize = round((float(diskSizetmp) * float(diskSizeUnit)) / 1048576, 2)
        except:
            logger.warnException('Failed creating disk #%d OSH target ip: %s' % (count , ip_address))
            continue
        ########################## Change the Lable   #########################
        # handle win drive letters representation
        m = re.search('(\w):\\\\',diskNametmp)
        if (m != None):
            #found win drive letter (such as 'c:\')- keep only the drive letter (i.e. 'c')
            diskNametmp = m.group(1)
        if (diskNametmp != None):
            diskName = diskNametmp
        else:
            diskName = 'None'
            
        #################    Found matching Disk type   #########################
        if OID_TO_STORAGE_TYPE.has_key(diskTypeOid):
            diskType = OID_TO_STORAGE_TYPE[diskTypeOid]
        else:
            logger.warn('Unknown Storage type found: %s' % diskTypeOid)
            diskType = modeling.OTHER_STORAGE_TYPE
            
        #################  prints parameters for debug   ######################
        logger.debug('Found Disk. Name=%s, Type=%s' % (diskName, diskType))

        #######################   send object #################################
        disk_details = modeling.createDiskOSH(_hostObj, diskName, diskType, diskSize, diskFailures, name = diskName)
        if disk_details:
            OSHVResult.add(disk_details)
コード例 #9
0
def getDisk(path,hostId):
    diskName = path.split(':\\')[0].upper()
    type = modeling.UNKNOWN_STORAGE_TYPE
    return modeling.createDiskOSH(hostId, diskName, type, name = diskName)
コード例 #10
0
ファイル: snmp_dis_disk_lib.py プロジェクト: deezeesms/dd-git
def doQueryDisks(client, OSHVResult):
    ip_address = client.getIpAddress()
    _hostObj = modeling.createHostOSH(ip_address)
    ################     Query and data    ################################
    data_name_mib = '1.3.6.1.2.1.25.2.3.1.3,1.3.6.1.2.1.25.2.3.1.4,string,1.3.6.1.2.1.25.2.3.1.5,double,1.3.6.1.2.1.25.2.3.1.6,string,1.3.6.1.2.1.25.2.3.1.7,string,1.3.6.1.2.1.25.2.3.1.2,string,1.3.6.1.2.1.25.2.3.1.4,string'
    resultSet = client.executeQuery(
        data_name_mib)  #@@CMD_PERMISION snmp protocol execution
    count = 0
    while resultSet.next():
        count = count + 1
        try:

            diskNametmp = resultSet.getString(2)
            diskSizeStr = resultSet.getString(3)
            diskSizetmp = 0
            if (diskSizeStr != None and diskSizeStr != ''):
                diskSizetmp = int(diskSizeStr)

            diskFailuresStr = resultSet.getString(5)
            if (diskFailuresStr != None and diskFailuresStr != ''):
                diskFailures = int(diskFailuresStr)
            else:
                diskFailures = None
                logger.debug('Failed parsing DiskFailures value')

            diskTypeOid = resultSet.getString(6)

            diskSizeUnitStr = resultSet.getString(7)
            diskSizeUnit = 0
            if (diskSizeUnitStr != None and diskSizeUnitStr != ''):
                diskSizeUnit = int(diskSizeUnitStr)

            # calculate disk size in Bytes
            # to get disk size we multiply cluster size (allocation units) by number of clusters on disk
            #diskSize =(float(diskSizetmp)*float(diskSizeUnit))#/(1024)

            # calculate disk size in Bytes and translate to Megabytes
            # to get disk size we multiply cluster size (allocation units) by number of clusters on disk
            diskSize = round(
                (float(diskSizetmp) * float(diskSizeUnit)) / 1048576, 2)
        except:
            logger.warnException('Failed creating disk #%d OSH target ip: %s' %
                                 (count, ip_address))
            continue
        ########################## Change the Lable   #########################
        # handle win drive letters representation
        m = re.search('(\w):\\\\', diskNametmp)
        if (m != None):
            #found win drive letter (such as 'c:\')- keep only the drive letter (i.e. 'c')
            diskNametmp = m.group(1)
        if (diskNametmp != None):
            diskName = diskNametmp
        else:
            diskName = 'None'

        #################    Found matching Disk type   #########################
        if OID_TO_STORAGE_TYPE.has_key(diskTypeOid):
            diskType = OID_TO_STORAGE_TYPE[diskTypeOid]
        else:
            logger.warn('Unknown Storage type found: %s' % diskTypeOid)
            diskType = modeling.OTHER_STORAGE_TYPE

        #################  prints parameters for debug   ######################
        logger.debug('Found Disk. Name=%s, Type=%s' % (diskName, diskType))

        #######################   send object #################################
        disk_details = modeling.createDiskOSH(_hostObj,
                                              diskName,
                                              diskType,
                                              diskSize,
                                              diskFailures,
                                              name=diskName)
        if disk_details:
            OSHVResult.add(disk_details)
コード例 #11
0
def doDicovery(shell, framework, rootServerOsh):
    resultVector = ObjectStateHolderVector()
    try:
        domainsList = discoverDomainsList(shell)
    except ValueError:
        raise ValueError, 'No libvirt Found. Failed to discover neither Xen nor KVM'
    domainsConfigDict = discoverDomainConfiguration(shell, domainsList)

    bridgeDict = discoverBridges(shell)
    ifaceNameToIfaceMacMap = discoverInterfacesByIfconfig(shell)
    #building topology
    ucmdbVersion = logger.Version().getVersion(framework)

    resultVector.add(rootServerOsh)
    bridgeToPortOshMap = {}
    for bridge in bridgeDict.values():
        bridgeOsh = createBridgeOsh(bridge.mac, bridge.name, rootServerOsh)
        if bridgeOsh:
            portNumber = 0
            for ifaceName in bridge.ifaceNameList:
                ifaceMac = ifaceNameToIfaceMacMap.get(ifaceName)
                interfaceOsh = modeling.createInterfaceOSH(
                    ifaceMac, rootServerOsh)
                resultVector.add(bridgeOsh)
                if interfaceOsh:
                    linkOsh = modeling.createLinkOSH('containment', bridgeOsh,
                                                     interfaceOsh)
                    resultVector.add(linkOsh)
                    resultVector.add(interfaceOsh)
                    portOsh = createBridgePhysicalPort(str(portNumber),
                                                       bridgeOsh)
                    portNumber += 1
                    linkOsh = modeling.createLinkOSH('realization', portOsh,
                                                     interfaceOsh)
                    bridgeToPortOshMap[bridge.name] = portOsh
                    resultVector.add(portOsh)
                    resultVector.add(linkOsh)

    (hypervisorVersion,
     hypervisorVersionDescription) = getHypervisorData(shell)
    if hypervisorVersion and not domainsConfigDict and checkKvmIrqProcess(
            shell):
        hypervisorOsh = KvmHypervisor(
            hypervisorVersion,
            hypervisorVersionDescription).build(rootServerOsh)
        resultVector.add(hypervisorOsh)

    for (domainName, config) in domainsConfigDict.items():
        hypervisorOsh = config.name == XEN_DOMAIN and XenHypervisor(
            hypervisorVersion, hypervisorVersionDescription).build(
                rootServerOsh) or KvmHypervisor(
                    hypervisorVersion,
                    hypervisorVersionDescription).build(rootServerOsh)
        resultVector.add(hypervisorOsh)

        if config.domainId == 0 and config.name == XEN_DOMAIN:
            domainConfigOsh = createXenDomainConfigOsh(config, rootServerOsh)
            resultVector.add(domainConfigOsh)
        else:
            vHostOsh = createVirtHostOsh(config)
            if vHostOsh:
                domainConfigOsh = config.name == XEN_DOMAIN and createXenDomainConfigOsh(
                    config, vHostOsh) or createKvmDomainConfigOsh(
                        config, vHostOsh)
                linkOsh = modeling.createLinkOSH('run', hypervisorOsh,
                                                 vHostOsh)
                resultVector.add(vHostOsh)
                resultVector.add(domainConfigOsh)
                resultVector.add(linkOsh)
                for networkInterface in config.interfaceList:
                    interfaceOsh = modeling.createInterfaceOSH(
                        networkInterface.macAddress, vHostOsh)
                    if interfaceOsh:
                        interfaceOsh.setBoolAttribute('isvirtual', 1)
                        resultVector.add(interfaceOsh)
                for i in range(len(config.bridgeNameList)):
                    bridgeName = config.bridgeNameList[i]
                    ifaceMac = config.interfaceList[i]
                    bridge = bridgeDict.get(bridgeName)
                    if bridge:
                        interfaceOsh = modeling.createInterfaceOSH(
                            networkInterface.macAddress, vHostOsh)
                        portOsh = bridgeToPortOshMap.get(bridgeName)
                        if ucmdbVersion < 9:
                            linkOsh = modeling.createLinkOSH(
                                'layertwo', interfaceOsh, portOsh)
                            resultVector.add(linkOsh)
                shareOsh = createNetworkShare(config.disk, rootServerOsh,
                                              ucmdbVersion)
                if shareOsh:
                    diskOsh = modeling.createDiskOSH(
                        vHostOsh, config.mountPoint,
                        modeling.UNKNOWN_STORAGE_TYPE)
                    if diskOsh:
                        linkOsh = modeling.createLinkOSH(
                            'realization', shareOsh, diskOsh)
                        resultVector.add(shareOsh)
                        resultVector.add(diskOsh)
                        resultVector.add(linkOsh)
    return resultVector
コード例 #12
0
ファイル: TTY_HR_Disk_Lib.py プロジェクト: deezeesms/dd-git
    def handleDiskRow(self, fileSystem, mountedOn, size, usedSize=None):
        '''
        @param usedSize: disk used size in 1K-blocks
        @param size: disk size in 1K-blocks
        '''
        if mountedOn in self.mountPointToDisk:
            logger.reportWarning(
                'File system object already reported for the mount point; skipping new one'
            )
            logger.warn(
                "File system object already reported for the mount point '%s'; skipping new one (mount point: '%s'; file system: '%s')"
                % (mountedOn, mountedOn, fileSystem))
            return
        if str(size).isdigit():
            sizeInMb = _kbToMb(size)
        else:
            sizeInMb = None
        if str(usedSize).isdigit():
            usedSizeInMb = _kbToMb(usedSize)
        else:
            usedSizeInMb = None
        type_ = modeling.UNKNOWN_STORAGE_TYPE
        diskOsh = modeling.createDiskOSH(self.containerOsh,
                                         mountedOn,
                                         type_,
                                         size=sizeInMb,
                                         name=fileSystem,
                                         usedSize=usedSizeInMb)
        if diskOsh:
            self.mountPointToDisk[mountedOn] = diskOsh
            self.resultVector.add(diskOsh)

            host_reporter = host_topology.Reporter()
            resolver = dns_resolver.create(shell=self.shell)
            try:
                (remoteHost,
                 remoteMountPoint) = getRemoteHostAndMountPoint(fileSystem)
                if remoteHost and remoteMountPoint:
                    if remoteHost.startswith('[') and remoteHost.endswith(']'):
                        remoteHost = remoteHost[1:-1]
                    host_osh = self.remoteHosts.get(remoteHost)
                    if not host_osh:
                        host = host_base_parser.parse_from_address(
                            remoteHost, resolver.resolve_ips)
                        #do not report hostname as it may be alias
                        host_osh, _, oshs = host_reporter.report_host_with_ips(
                            host.ips)
                        self.remoteHosts[remoteHost] = host_osh
                        self.resultVector.addAll(oshs)

                    remoteShareOsh = ObjectStateHolder('networkshare')
                    remoteShareOsh.setContainer(host_osh)
                    remoteShareOsh.setStringAttribute('data_name',
                                                      remoteMountPoint)
                    remoteShareOsh.setStringAttribute('share_path',
                                                      remoteMountPoint)
                    self.resultVector.add(remoteShareOsh)

                    self.resultVector.add(
                        modeling.createLinkOSH('realization', remoteShareOsh,
                                               diskOsh))
            except:
                stackTrace = logger.prepareFullStackTrace(
                    'Failed to link disk to the remote share.')
                logger.warn(stackTrace)
コード例 #13
0
ファイル: storage_topology.py プロジェクト: deezeesms/dd-git
def createStorageTopology(volumeGroupList, logicalVolumeList, physicalVolumeList, scsiAdaptersList, parentOsh):
    """
    Creates Objects State Holders for Volume Groups, Logical Volumes, Physical Volumes, SCSI Adapters 
    and corresponding Use and Depend links among them
    @param volumeGroupList: discovered Volume Groups
    @type volumeGroupList: list of VolumeGroup Data Objects instances
    @param logicalVolumeList: discovered Logical Volumes 
    @type logicalVolumeList: list of LogicalVolume Data Objects instances
    @param physicalVolumeList: discovered Physical Volumes 
    @type physicalVolumeList: list of PhysicalVolume Data Objects instances
    @param scsiAdaptersList: discovered SCSI Adapters
    @type scsiAdaptersList: list of ScsiAdapter Data Objects instances
    @param parentOsh: Object State Holder of the Host this SCSI Adapter belongs to
    @type parentOsh: OSH instance of a Host CI or any of its siblings
    @return: Object State Holder Vector of the discovered topology
    """
    vector = ObjectStateHolderVector()
    vgOshDict = {}
    if volumeGroupList:
        for volumeGroup in volumeGroupList:
            vgOsh = createVolumeGroupOsh(volumeGroup, parentOsh)
            if vgOsh:
                vgOshDict[volumeGroup.vgName] = vgOsh
                vector.add(vgOsh)
    
    scsiAdaptersOshDict = {}
    if scsiAdaptersList:
        for scsiAdapter in scsiAdaptersList:
            scsiOsh = createScsiAdapterOsh(scsiAdapter, parentOsh)
            if scsiOsh:
                scsiAdaptersOshDict[scsiAdapter.slotNumber] = scsiOsh
                vector.add(scsiOsh)
                
    if logicalVolumeList:
        for logicalVolume in logicalVolumeList:
            lvOsh = createLogicalVolumeOsh(logicalVolume, parentOsh)
            if lvOsh:
                if logicalVolume.volumeGroupName and vgOshDict.has_key(logicalVolume.volumeGroupName):
                    vgOsh = vgOshDict.get(logicalVolume.volumeGroupName)
                    linkOsh = modeling.createLinkOSH('contained', vgOsh, lvOsh)
                    vector.add(linkOsh)
                if logicalVolume.scsiAdapterSlotNumber and scsiAdaptersOshDict.has_key(logicalVolume.scsiAdapterSlotNumber):
                    scsiOsh = scsiAdaptersOshDict.get(logicalVolume.scsiAdapterSlotNumber)
                    linkOsh = None
                    if scsiOsh.getAttributeValue("isvirtual"):
                        linkOsh = modeling.createLinkOSH("use", scsiOsh, lvOsh)
                    else:
                        linkOsh = modeling.createLinkOSH("depend", lvOsh, scsiOsh)
                    vector.add(linkOsh)
                if logicalVolume.mountPoint and logicalVolume.lvFsType:
                    fsOsh = modeling.createDiskOSH(parentOsh, logicalVolume.mountPoint, modeling.UNKNOWN_STORAGE_TYPE)
                    linkOsh = modeling.createLinkOSH('depend', fsOsh, lvOsh)
                    vector.add(fsOsh)
                    vector.add(linkOsh)
                vector.add(lvOsh)
    
    if physicalVolumeList:
        for physicalVolume in physicalVolumeList:
            pvOsh = createPhysicalVolumeOsh(physicalVolume, parentOsh)
            if pvOsh:
                if physicalVolume.volumeGroupName and vgOshDict.has_key(physicalVolume.volumeGroupName):
                    vgOsh = vgOshDict.get(physicalVolume.volumeGroupName)
                    linkOsh = modeling.createLinkOSH('contained', vgOsh, pvOsh)
                    vector.add(linkOsh)
                if physicalVolume.scsiAdapterSlotNumber and scsiAdaptersOshDict.has_key(physicalVolume.scsiAdapterSlotNumber):
                    scsiOsh = scsiAdaptersOshDict.get(physicalVolume.scsiAdapterSlotNumber)
                    linkOsh = None
                    if scsiOsh.getAttributeValue("isvirtual"):
                        linkOsh = modeling.createLinkOSH("use", scsiOsh, pvOsh)
                    else:
                        linkOsh = modeling.createLinkOSH("depend", pvOsh, scsiOsh)
                    vector.add(linkOsh)
                vector.add(pvOsh)
    return vector
コード例 #14
0
ファイル: Util.py プロジェクト: deezeesms/dd-git
def getDisk(path,host_id):
    found_disk_drive = re.match('(\w):\\.*', path)
    if found_disk_drive:
        disk_drive = found_disk_drive.group(1).upper()
        type = modeling.UNKNOWN_STORAGE_TYPE
        return modeling.createDiskOSH(host_id, disk_drive, type, name = disk_drive)