text
stringlengths 1
93.6k
|
|---|
# time.sleep(1)
|
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")
|
# Funcion para crear imagen qcow2 del disco
|
# Function to create qcow file of disk
|
def create_image_bkp(dev,diskname):
|
bckfiledir = bckdir + "/" + vmname + "/" + date
|
mkdir = "mkdir -p " + bckfiledir
|
subprocess.call(mkdir, shell=True)
|
bckfile = bckfiledir + "/" + diskname + ".qcow2"
|
printf.INFO("Creating qcow2 file: " + bckfile)
|
cmd = "qemu-img convert -O qcow2 " + dev + " " +bckfile
|
utils=virtbkp_utils.virtbkp_utils()
|
thread.start_new_thread(run_qemu_convert,(cmd,))
|
utils.progress_bar_qcow(bckfile)
|
# Funcion para obtener el nombre del disco virtual
|
# Function to get virtual disk name
|
def get_disk_name(idvm,snapid,diskid):
|
svc_path = "vms/"+idvm+"/snapshots/"+snapid+"/disks/"
|
disksnap_service = connection.service(svc_path)
|
disks = disksnap_service.list()
|
for disk in disks:
|
if diskid == str(disk.id):
|
return disk.alias
|
def backup(vmid,snapid,disk_id,bkpvm):
|
# Se agrega el disco a la VM que tomara el backup
|
printf.INFO("Attach snap disk to bkpvm")
|
attach_disk(bkpvm,disk_id,snapid)
|
# Se obtiene el nombre del dispositivo
|
printf.INFO("Identifying disk device, this might take a while")
|
dev = get_logical_disk(bkpvm,disk_id)
|
# Se obtiene el nombre del disco
|
diskname = get_disk_name(vmid,snapid,disk_id)
|
# Se crea la image qcow que seria el backup como tal
|
create_image_bkp(dev,diskname)
|
# Se desactiva el disco del cual se hizo el backup
|
deactivate_disk(bkpvm,disk_id)
|
time.sleep(10)
|
# Se detacha el disco de la BKPVM
|
printf.INFO("Dettach snap disk of bkpvm")
|
detach_disk(bkpvm,disk_id)
|
time.sleep(10)
|
def main():
|
## Parte Principal
|
# Se consigue el ID de la VM a la cual se hara backup y la VM donde se montaran sus discos
|
global vmid
|
global vmname
|
global bkpvm
|
vmid = get_id_vm(vmname)
|
bkpvm = get_id_vm(bkpvm)
|
# Se crea el snap y se espera un rato para que termine sin problemas y pueda detectar el nombre del disco en VM de backup
|
create_snap(vmid)
|
#time.sleep(60)
|
# Se obtiene el id del snap
|
snapid = get_snap_id(vmid)
|
# Se obtiene el ID del disco
|
vm_disks = snap_disk_id(vmid,snapid)
|
for disk_id in vm_disks:
|
printf.INFO("Trying to create a qcow2 file of disk " + disk_id)
|
# Backup
|
backup(vmid,snapid,disk_id,bkpvm)
|
printf.INFO("Trying to delete snapshot of " + vmname)
|
delete_snap(vmid,snapid)
|
main()
|
# <FILESEP>
|
#
|
# Copyright (C) 2023 Apple Inc. All rights reserved.
|
#
|
"""Simplified composition of PyTorch transformations from a configuration dictionary."""
|
import math
|
import random
|
from typing import Any, Dict, Optional, OrderedDict, Tuple
|
import numpy as np
|
import timm
|
from timm.data.transforms import str_to_interp_mode
|
import torch
|
from torch import Tensor
|
import torchvision.transforms as T
|
from torch.nn import functional as F
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.