def recover_backup(self, name, vm, t_storage, backup_numb=1, netcard=None): vm_uuid = vm.get_vmUuid() backup_id = vm.host.get_backups(vm_uuid, backup_numb)[0] backup_info = vm.host.get_backup_info(backup_id) default_netcard = [{ "pg": "Virtual Machine Network 0", "vnet_type": "Virtio ParaVirtual", "seq": 1 }] params = {} params['baknum'] = str(backup_numb) params['storage_path'] = backup_info['storage_path'] params['storage_uuid'] = backup_info['storage_uuid'] params['target_storage_uuid'] = vm.host.get_storage_uuid(t_storage) params['targetstorage_path'] = vm.host.get_storage_path(t_storage) params['vmUuid'] = backup_info['vm_uuid'] params['backup_type'] = backup_info['baktype'] params['baktim'] = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime(float(backup_info['baktim']))) params['nvmuuid'] = name params['hostUuid'] = vm.host.uuid params['nvmname'] = name params['pcidevice'] = [] if netcard: params['netcardAllPara'] = netcard else: params['netcardAllPara'] = default_netcard action_id = CODE['recover_backup'] host = vm.get_hostname() m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host, timeout=1800)
def recover_backup(self, name, vm, t_storage, backup_numb=1, netcard=None): vm_uuid = vm.get_vmUuid() backup_id = vm.host.get_backups(vm_uuid, backup_numb)[0] backup_info = vm.host.get_backup_info(backup_id) default_netcard = [{"pg":"Virtual Machine Network 0", "vnet_type":"Virtio ParaVirtual", "seq":1}] params = {} params['baknum'] = str(backup_numb) params['storage_path'] = backup_info['storage_path'] params['storage_uuid'] = backup_info['storage_uuid'] params['target_storage_uuid'] = vm.host.get_storage_uuid(t_storage) params['targetstorage_path'] = vm.host.get_storage_path(t_storage) params['vmUuid'] = backup_info['vm_uuid'] params['backup_type'] = backup_info['baktype'] params['baktim'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(float(backup_info['baktim']))) params['nvmuuid'] = name params['hostUuid'] = vm.host.uuid params['nvmname'] = name params['pcidevice'] = [] if netcard: params['netcardAllPara'] = netcard else: params['netcardAllPara'] = default_netcard action_id = CODE['recover_backup'] host = vm.get_hostname() m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host, timeout=1800)
def backup_vm(self, vm, dest, tp=0, level="low", descr="", baktype="manul"): params = {} params['vmUuid'] = vm.get_vmUuid() params['uuid'] = vm.get_storage_uuid() params['parentUuid'] = vm.get_parentUuid() params['storage_path'] = vm.get_storage_path() params['copy_Level'] = level params['bakdsc'] = descr params['baktype'] = baktype if vm.host.get_storage_path(dest): params['targetstorage_path'] = vm.host.get_storage_path(dest) else: raise error.CommonError("Target storage does not exist.") if not tp: params['backup_type'] = "diff_backup" elif tp == 1: params['backup_type'] = "complete_backup" action_id = CODE['backup_vm'] host = vm.get_hostname() m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host, timeout=1800)
def clear_all_snapshot(self, vm): params = {} params['vmUuid'] = vm.get_vmUuid() params['storage_path'] = vm.get_storage_path() host = vm.get_hostname() action_id = CODE['clear_snapshot'] m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host)
def pause_vm(self, vm): params = {} params['vmUuid'] = vm.get_vmUuid() params['parentUuid'] = vm.get_parentUuid() params['storage_path'] = vm.get_storage_path() host = vm.get_hostname() action_id = CODE['vm_pause'] m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host)
def trans_vm(self, vm, storage, level="low", target=None): params = {} params['vmUuid'] = vm.get_vmUuid() params['storage_path'] = vm.get_storage_path() params['target_storage_path'] = vm.host.get_storage_path(storage) params['copy_level'] = level if target: params['target'] = target host = vm.get_hostname() action_id = CODE['vm_trans'] m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host)
def recover_snapshot(self, vm, sn): params = {} params.update(vmd_port.RECOVER_SNAPSHOT) params['parentUuid'] = vm.get_parentUuid() params['storage_uuid'] = vm.get_storage_uuid() params['storage_path'] = vm.get_storage_path() params['vmUuid'] = vm.get_vmUuid() params['snuuid'] = sn host = vm.get_hostname() action_id = CODE['re_snapshot'] m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host)
def snapshot(self, vm, sname, desc=""): params = {} params.update(vmd_port.TAKE_SNAPSHOT) params['parentUuid'] = vm.get_parentUuid() params['storage_uuid'] = vm.get_storage_uuid() params['storage_path'] = vm.get_storage_path() params['vmUuid'] = vm.get_vmUuid() params['snname'] = sname params['sndesc'] = desc host = vm.get_hostname() action_id = CODE['snapshot'] m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host)
def conv_to_template(self, vm, del_snapshot=True): params = {} params['vmUuid'] = vm.get_vmUuid() params['parentUuid'] = vm.get_parentUuid() params['storage_path'] = vm.get_storage_path() host = vm.get_hostname() action_id = CODE['vm2temp'] if del_snapshot: self.clear_all_snapshot(vm) m_id = self.executor.run(action_id, params, host, 'vm', 'VmnoclusterchangeTask') self.executor.wait_for_done(m_id, host)