def clone_vm(self, src_vm, dest_name, dest_st, to_temp=False, level='high', del_snapshot='yes', cfg=None): params = {} host_name = src_vm.get_hostname() if self.is_name_dupliacted(dest_name, host_name): raise error.CommonError("Create vm: name duplicated!") params.update(vmd_port.CLONE_VMS) m_vm = vm.VMS(dest_name) if cfg: params.update(cfg) else: dest_path = storage.get_storage_path(host_name, dest_st) dest_uuid = storage.get_storage_uuid(host_name, dest_st) params.update({ 'parentUuid': src_vm.get_parentUuid(), 'targetVmdesc': dest_name, 'targetVmuuid': dest_name, 'bsstorage_uuid': src_vm.get_storage_uuid(), 'bsstorage_path': src_vm.get_storage_path(), 'vmUuid': src_vm.get_vmUuid(), 'storage_path': dest_path, 'storageUuid': dest_uuid, 'copy_level': level, 'del_snapshot': del_snapshot, 'to_template': 'yes' if to_temp else 'no' }) action_id = CODE['clone_vms'] m_id = self.executor.run(action_id, params, host_name, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host_name, 120) m_vm.initialize(host_name, self.executor) return m_vm
def is_mounted(self, storage_name, timeout=120): current = time.time() endtime = current + timeout path = storage.get_storage_path(self.hostname, storage_name) if not path: raise error.TestError("Database query failed, storage dose not exist: %s" % storage_name) while current < endtime: mountlist = self.run("mount").stdout.strip() if mountlist.find(path) >= 0: return True current = time.time() time.sleep(2) raise error.TestError("Mount storage Failed: %s" % storage_name)
def is_storage_deleted(self, storage_name, timeout): current = time.time() endtime = current + timeout path = storage.get_storage_path(self.hostname, storage_name) if path: raise error.TestError("Storage info is not deleted from database: %s" % storage_name) while current < endtime: mountlist = self.run("mount").stdout.strip() if mountlist.find(storage_name) < 0: return True current = time.time() time.sleep(2) raise error.TestError("Delete storage Failed: %s" % storage_name)
def get_storage_path(self, host, storage_name): return storage.get_storage_path(host, storage_name)