Thursday, May 26, 2016

Taking backup of virtual machines in VCenter
If you have wanted to automate taking a backup in vCenter, then here is a succinct summary of the steps:
                            vm_is_off = vm.summary.runtime.powerState == "poweredOff"
                            if str2bool(self.halt_vm):
                                vm.ShutdownGuest()
                                vm_is_off = True

                            if  vm_is_off:
                                vmdks = self.export_vmdks(vm)
                                ovf_filename = self.create_ovf(vm, vmdks)
                            else:
                                new_vm = self.clone_vm(vm)
                                vmdks = self.export_vmdks(new_vm)
                                ovf_filename = self.create_ovf(vm, vmdks)
                                self.wait_task(new_vm.Destroy_Task())

                            if str2bool(self.create_ovafile):
                                ova_filename = self.create_ova(vm, vmdks, ovf_filename)

                            if str2bool(self.halt_vm):
                                vm.PowerOnVM()

Essentially, we need all the data flushed to disk as vmdk. This happens when the vm is in the powered off state. If the vm is on, we clone it so as to minimize the disruption to the existing and then export the vmdks.  Additionally we create OVF descriptor and package. OVF is a an open standard developed by Distributed Management Task Force to meet the need of the industry to create a portable format for virtual machines that is vendor and platform independent. An OVF package consists of an OVF descriptor, a set of virtual disks, a set of localization bundles, a manifest and a certificate. The .ovf file is the main document of an OVF package. It contains all the metadata for the OVF package.
Often it is incovenient to transfer multiple files as in the package above. Instead a tarball is made for portability. This is called an OVA (Open Virtualization Format Archive). However, it is not merely a tarball since the order of the files and their naming is controlled.
Courtesy: TISbackup
#codingexercise
Find a number in a rotated sorted array
int GetNumber(List<int> sortedRotated, int num)
{
int n = sortedRotated.Count;
int pivot = find_pivot(sortedRotated, 0, n-1, num); // binary search
if (pivot == -1)
      return binary_search(sortedRotated, 0, n-1);
if (sortedRotated[pivot] == num)
      return pivot;
if (sortedRotated[pivot] <= num)
     return GetNumber(sortedRotated, 0, pivot-1, num);
else
     return GetNumber(sortedRotated, pivot+1, n, num);
}
int find_pivot( List<int> sortedRotated, int start, int end)
{
 if (start < end)
     return -1;
 if (start == end) return start;
int mid = (start + end ) / 2;
if ( mid < end && sortedRotated[mid] > sortedRotated[mid+1]) return mid;
if (mid > start && sortedRotated[mid-1] > sortedRotated[mid]) return mid-1;
if (sortedRotated[low] >= sortedRotated[mid])
    return find_pivot(sortedRotated, start, mid-1);
return  find_pivot(sortedRotated, mid+1, end);
}

#coding exercise
Int isRotated (string a1, string a2)
{
 return a1.length == a2.length && (a1+a1).indexof (a2) != -1;
}
}

No comments:

Post a Comment