def run_qemu_convert(self,cmd): out = subprocess.call(cmd, shell=True) qcowfile = cmd.split()[-1] if int(out) == 0: #print "Se creo correctamente la imagen" print printf.OK("qcow2 file creation success") else: print printf.ERROR("qcow2 file creation failed") printf.ERROR("Deleting file %s" % qcowfile) subprocess.call("rm -rf %s" % qcowfile , shell=True)
def backup(self,vmid,snapid,disk_id,bkpvm): # Se agrega el disco a la VM que tomara el backup try: signal.signal(signal.SIGALRM, self.handler_timeout) signal.alarm(self.timeout_detect) printf.INFO("Timeout is defined to %s" % self.timeout_detect) printf.INFO("Attach snap disk to bkpvm") self.attach_disk(bkpvm,disk_id,snapid) # Se obtiene el nombre del dispositivo printf.INFO("Identifying disk device, this might take a while") dev = self.get_logical_disk(bkpvm,disk_id) # Se obtiene el nombre del disco diskname = self.get_disk_name(vmid,snapid,disk_id) time.sleep(10) signal.alarm(0) # Se crea la image qcow que seria el backup como tal self.create_image_bkp(dev,diskname) # Se desactiva el disco del cual se hizo el backup self.deactivate_disk(bkpvm,disk_id) time.sleep(10) # Se detacha el disco de la BKPVM printf.INFO("Dettach snap disk of bkpvm") self.detach_disk(bkpvm,disk_id) except: printf.ERROR("Time Out reached ") self.deactivate_disk(bkpvm,disk_id) time.sleep(10) printf.INFO("Dettach snap disk of bkpvm") self.detach_disk(bkpvm,disk_id)
def run_qemu_convert(cmd): out = subprocess.call(cmd, shell=True) if int(out) == 0: #print "Se creo correctamente la imagen" print printf.OK("qcow2 file creation success") else: print printf.ERROR("qcow2 file creation failed")
def backup_vms_with_tag(self, tag): self.start() for vm in self.get_vms_with_tag(tag): try: printf.OK("Running backup of vm %s with tag %s" % (vm, tag)) b = backup_vm(self.conf_file, vm) b.main() except Exception as ex: printf.ERROR("Backup %s failed!" % vm)
def start(self): try: # Create a connection to the server: self.connection = sdk.Connection(url=self.url, username=self.user, password=self.password, ca_file=self.ca_file) printf.OK("Connection to oVIrt API success %s" % self.url) except Exception as ex: print ex printf.ERROR("Connection to oVirt API has failed")
bkpvm = cfg.get('bkp', 'bkpvm') vmname = sys.argv[2] date = str((time.strftime("%Y-%m-%d-%H"))) vmid = "" snapname = "BACKUP" + "_" + date + "h" try: # Create a connection to the server: connection = sdk.Connection(url=url, username=user, password=password, ca_file=ca_file) printf.OK("Connection to oVIrt API success %s" % url) except Exception as ex: printf.ERROR("Connection to oVirt API has failed") #print "Unexpected error: %s" % ex # Funcion para obtener el id de la vm buscandola por el nombre # Function to get VM_ID from VM name def get_id_vm(vmname): vm_service = connection.service("vms") vms = vm_service.list() for vm in vms: if vm.name == vmname: return vm.id # Funcion para obtener el ID del snapshot creado # Function to get ID of created snapshot
def handler_timeout(): printf.ERROR("Time Out reached ") raise Exception("Time Out")