Esempio n. 1
0
    def migrate(vmId, azName):
        if not vmId or not azName:
            return False

        nova = GetClientUtil.getNovaClient()
        targetInstance = InstanceUtil.findInstanceById(vmId)
        ips = nova.servers.ips(targetInstance.id)
        innerIP = TomcatInstanceUtil.getInnerIPFromIPInfo(ips)

        targetInstance.delete()

        oldStdout = sys.stdout
        nullFile = open('/dev/null', 'w')
        sys.stdout = nullFile

        while InstanceUtil.findInstanceById(vmId):
            time.sleep(2)

        sys.stdout = oldStdout
        nullFile.close()

        UsingInstancesDBUtil.deleteUsingInstanceByResourceId(targetInstance.id)

        newInstance = TomcatInstanceUtil.createTomcatInstance(azName, innerIP)

        if newInstance:
            while not InstanceUtil.isInstanceStatusActice(newInstance.id):
                time.sleep(2)
            return True
        else:
            return False
Esempio n. 2
0
 def deleteAllTestingInstance():
     nova = GetClientUtil.getNovaClient()
     instancesList = nova.servers.list()
     for instance in instancesList:
         if len(instance.name) > 20:
             instance.delete()
             UsingInstancesDBUtil.deleteUsingInstanceByResourceId(
                 instance.id)
Esempio n. 3
0
    def deleteSpecifyNumberInstances(no):
        if not no:
            return

        nova = GetClientUtil.getNovaClient()
        instancesList = nova.servers.list()
        count = 0
        for instance in instancesList:
            if len(instance.name) > 20:
                instance.delete()
                UsingInstancesDBUtil.deleteUsingInstanceByResourceId(
                    instance.id)
                count += 1

            if count == no:
                break
Esempio n. 4
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