Example #1
0
    def getVMList(self, req):
        pmId = req.params.get('id')
        azName = PMAndAZDBUtil.getAZNameByResourceId(pmId)
        vmList = UsingInstancesDBUtil.getUsingInstancesByAZName(azName)

        if not vmList:
            return []
        else:
            return [vm['id'] for vm in vmList]
    def updateCloudInfo(self, topoFilePath):
        if not topoFilePath:
            raise Exception('no topoFile')

        topoDic = analyseJsonFormatConfigFile(topoFilePath)

        assert topoDic, 'no cloud topo infomation'

        #获取Region和AZ的availability

        nodeAvailabilityFilePath = '/home/sk/openstackPythonSDKTest/ConfigDic/NodeAvailability'
        naf = open(nodeAvailabilityFilePath)
        exec naf
        naf.close()

        cloudRoot = TopoTreeNode('cloudRoot', TopoTreeNodeAvailability)
        azList = []
        for regionName in topoDic:
            regionTreeNode = TopoTreeNode(regionName, RegionAvailability)
            cloudRoot.children.append(regionTreeNode)
            regionAZs = topoDic[regionName]

            for az in regionAZs:
                vmsInAz = UsingInstancesDBUtil.getUsingInstancesByAZName(
                    az['azName'])

                if vmsInAz:
                    azTreeNode = TopoTreeNode(az['azName'], AZAvailability)
                    regionTreeNode.children.append(azTreeNode)
                    newAZ = AvailabilityZone(az['azName'], az['distance'],
                                             regionName, azTreeNode,
                                             regionTreeNode)
                    newAZ.holdVMs = vmsInAz
                else:
                    newAZ = AvailabilityZone(az['azName'], az['distance'],
                                             regionName)

                azList.append(newAZ)

            #如果region下面的az都没有vm,则说明本application还没有部署到本region下的az里,本region对于本application的可用性为0
            if not regionTreeNode.children:
                regionTreeNode.availability = 0

        self.cloudRoot = cloudRoot
        self.azList = sorted(azList, key=attrgetter('distance'))
Example #3
0
    def deleteSpecifyNumberInstancesWithSpecifyAZ(no, azName):
        if not no:
            return

        holdVms = UsingInstancesDBUtil.getUsingInstancesByAZName(azName)
        holdVmsLen = len(holdVms)
        if no > holdVmsLen:
            raise Exception('Could not down ' + str(no) + ' vms in ' +
                            str(azName) + ', it only has ' + str(holdVmsLen) +
                            ' vms!')

        nova = GetClientUtil.getNovaClient()

        count = 0
        for vm in holdVms:
            targetInstance = nova.servers.get(vm['id'])
            targetInstance.delete()
            UsingInstancesDBUtil.deleteUsingInstanceByResourceId(
                targetInstance.id)
            count += 1

            if count == no:
                break