def testAddVM(self): policys = self.connection.listAllSecurityGroup() self.vms = self.connection.listAllVM() default_policy = None test_policy = None for policy in policys: sec = self.connection.getSecurityGroup(policy.id) self.assertEqual(policy.id, sec.id) if policy.name == "Default Policy": default_policy = sec elif policy.name == "TESTING": test_policy = sec # move all vm into test policy for vm in self.vms: new_vm = VirtualMachine(self.connection) new_vm.imageGUID = vm.imageGUID test_policy.addVM(new_vm) response = None response = test_policy.update() self.assertEqual(response, 200) # move all vm back to default policy default = self.connection.getSecurityGroup(default_policy.id) for vm in self.vms: new_vm = VirtualMachine(self.connection) new_vm.imageGUID = vm.imageGUID default.vmList.append(new_vm) response = default.update() self.assertEqual(response, 200)
def __init__(self, connection, tag="runningVM"): VirtualMachine.__init__(self, connection, tag) self.providerName = None self.providerLocation = None # KeyRequest list self.runningVMKeyRequest = None # running Device list self.runningVMDevices = ResultSet([("runningVMDevices", RunningDevice)], "runningVMDevice")
def addVM(policy, vmid): # add new vm into a Policy if isinstance(policy, SecurityGroup): new = VirtualMachine(policy.connection) new.imageGUID = vmid policy.addVM(new) policy.update() printPolicy(policy)
def __init__(self, connection, tag='runningVM'): VirtualMachine.__init__(self, connection, tag) self.providerName = None self.providerLocation = None # KeyRequest list self.runningVMKeyRequest = None # running Device list self.runningVMDevices = ResultSet( [('runningVMDevices', RunningDevice)], 'runningVMDevice')
def testCase2940(self): policy = SecurityGroup(self) policy.name = "testCase2940" # default values vm = VirtualMachine(self) vm.imageGUID = '245e35df-492a-40c8-8543-b07e1e252744' policy.addVM(vm) data = policy.tostring() policy = self.connection.get_object('%s/' % (self.connection.REST_SECURITY_GROUP), SecurityGroup, data=data, method='POST') # create policy self.assertEqual(policy, None)
def testCase2940(self): policy = SecurityGroup(self) policy.name = "testCase2940" # default values vm = VirtualMachine(self) vm.imageGUID = '245e35df-492a-40c8-8543-b07e1e252744' policy.addVM(vm) data = policy.tostring() policy = self.connection.get_object( '%s/' % (self.connection.REST_SECURITY_GROUP), SecurityGroup, data=data, method='POST') # create policy self.assertEqual(policy, None)
def testAddVM(self): policys = self.connection.listAllSecurityGroup() self.vms = self.connection.listAllVM() default_policy = None test_policy = None for policy in policys: sec = self.connection.getSecurityGroup(policy.id) self.assertEqual(policy.id, sec.id) if policy.name == 'Default Policy': default_policy = sec elif policy.name == 'TESTING': test_policy = sec # move all vm into test policy for vm in self.vms: new_vm = VirtualMachine(self.connection) new_vm.imageGUID = vm.imageGUID test_policy.addVM(new_vm) response = None response = test_policy.update() self.assertEqual(response, 200) # move all vm back to default policy default = self.connection.getSecurityGroup(default_policy.id) for vm in self.vms: new_vm = VirtualMachine(self.connection) new_vm.imageGUID = vm.imageGUID default.vmList.append(new_vm) response = default.update() self.assertEqual(response, 200)
def testUpdateVM(self): self.vms = self.connection.listAllVM() for vm in self.vms: newvm = self.connection.getVM(vm.imageGUID) target = VirtualMachine(self.connection) target.imageGUID = newvm.imageGUID target.href = newvm.href target.imageDescription = ''.join( random.choice(string.ascii_uppercase + string.digits) for x in range(360)) target.SecurityGroupGUID = newvm.SecurityGroupGUID target.autoProvision = newvm.autoProvision updated = target.update() self.assertEqual(updated.imageGUID, target.imageGUID)
def testCase2903(self): newvm = self.connection.getVM(self.TestVM_ID) target = VirtualMachine(self.connection) target.imageGUID = newvm.imageGUID # should be removed target.SecurityGroupGUID = newvm.SecurityGroupGUID target.autoProvision = newvm.autoProvision target.imageName = testlib.RandomString( string.ascii_uppercase + string.digits, 36) updated = target.update() self.assertEqual(updated.imageName, target.imageName)
def testUpdateVM(self): self.vms = self.connection.listAllVM() for vm in self.vms: newvm = self.connection.getVM(vm.imageGUID) target = VirtualMachine(self.connection) target.imageGUID = newvm.imageGUID target.href = newvm.href target.imageDescription = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(360)) target.SecurityGroupGUID = newvm.SecurityGroupGUID target.autoProvision = newvm.autoProvision updated = target.update() self.assertEqual(updated.imageGUID, target.imageGUID)
def testCase2904(self): newvm = self.connection.getVM(self.TestVM_ID) target = VirtualMachine(self.connection) target.imageGUID = newvm.imageGUID # should be removed target.SecurityGroupGUID = newvm.SecurityGroupGUID target.autoProvision = newvm.autoProvision target.imageDescription = ''.join( random.choice(string.ascii_uppercase + string.digits) for x in range(361)) updated = target.update() self.assertEqual(updated, None)
def startElement(self, name, attrs, connection): ret = VirtualMachine.startElement(self, name, attrs, connection) if ret is not None: return ret if name == self.tag: for key, value in attrs.items(): setattr(self, key, value) elif name == "runningVMKeyRequest": self.runningVMKeyRequest = KeyRequest(connection) self.runningVMKeyRequest.startElement(name, attrs, connection) return self.runningVMKeyRequest elif name == "runningVMDevices": self.runningVMDevices = ResultSet([("runningVMDevice", RunningDevice)], name) return self.runningVMDevices else: return None
def startElement(self, name, attrs, connection): ret = VirtualMachine.startElement(self, name, attrs, connection) if ret is not None: return ret if name == self.tag: for key, value in attrs.items(): setattr(self, key, value) elif name == 'runningVMKeyRequest': self.runningVMKeyRequest = KeyRequest(connection) self.runningVMKeyRequest.startElement(name, attrs, connection) return self.runningVMKeyRequest elif name == 'runningVMDevices': self.runningVMDevices = ResultSet( [('runningVMDevice', RunningDevice)], name) return self.runningVMDevices else: return None