Monday, May 23, 2016

Virtual Machine snapshots on different cloud platforms. 

Cloud providers such as OpenStackVMWare provide their own snapshot services. The snapshot of a Virtual machine is a file itself. Therefore backup of this file is equivalent to taking snapshot of the Virtual Machine. Since Cloud providers are used to create virtual machine instances, they are also the appropriate controllers to take snapshots of the created instances. 

From VMWare documentation: 
On vSphere, backups are usually done by taking a snapshot, to efficiency obtain a static image of the virtual machine. Snapshots are a view of a virtual machine at a certain point in time, and enable quick and clean backup operation. Snapshots also provide an incremental backup mechanism called changed block tracking.  


Let us take a look at how to create the instances for different platforms: 
  1. OpenStack: 
This provides snapshot APIs from the Images library: 
GET /v2/images 
GET /v2/images/{image_id} 
And  
POST /v2/images 
Upload and download of raw image data can be done with:  
PUT /v2/Images/{image_id}/file 
GET /v2/Images/{image_id}/file 
  
  1. VMware: 
This provides workflows that can be used to create snapshot using the VCO client. 
Most of them have a generic signature as follows: 
/workflows/{workflow-id} 
/workflows/{workflow-id}/executions to check the status of the execution 

In addition, VDDK also provides abilities with a different set of API calls.  
On one vCenter Server, the moRef uniquely identifies a virtual machine. If we need to track and inventory virtual machine backups across multiple vCenter Servers, we can use moRef together with instanceUuidWe can see the instanceUuid at the following browser path:  
    https://<vcserver>/mob/?moid=ServiceInstance&doPath=content.about  
The following code sample shows how to create a snapshot on a specific virtual machine:  
    // At this point we assume the virtual machine is identified as ManagedObjectReference vmMoRef.     String SnapshotName = "Backup";     String SnapshotDescription = "Temporary Snapshot for Backup";     boolean memory_files = false;  
boolean quiesce_filesystem = true; ManagedObjectReference taskRef = serviceConnection.getservice().CreateSnapshot_Task(vmMoRef 
SnapshotNameSnapshotDescriptionmemory_filesquiesce_filesystem); 

The following Java code demonstrates how to delete the snapshot:  
ManagedObjectReference removeSnapshotTask; ManagedObjectReference snapshot; // Already initialized. removeSnapshotTask = serviceConnection.getservice().removeSnapshot_Task(snapshot, Boolean FALSE);  

  1. AWS provides a variety of ways to interact with the VMs. While the options 1) and 2) are for the private cloud, this one is for the public cloud and hence comes with rich documentation on steps to create a snapshot. For example, we can do this with a tool, SDK or API. 
Here is an example: 
https://ec2.amazonaws.com/?Action=CreateSnapshot 
&VolumeId=vol-1234567890abcdef0 
&Description=Daily+Backup 
&AUTHPARAMS 


Conclusion: Different cloud providers provide the ability to take snapshots and are tied directly with their abilities to create instances. We leverage these to allow instances to be snapshot in a platform agnostic manner. 

#coding exercise

Level order traversal of a tree in spiral form

Same a level order except that alternate levels are put in a stack and printed.
Void printSpiral (node root)
{

Bool drc = false;
For (int I = 1; I < height (root) I ++){
PrintGivenLevel (root, i, drc);
Drc ~= drc
}
}
void printGivenLevel(Node root, int level, bool direction)
{
   if (root == null) return;
    if (level ==1) print(root.data);
    else if level > 1{
       if (direction){
            printGivenLevel(root.left, level - 1, direction);
            printGivenLevel(root.right, level -1, direction);
       }else{
            printGivenLevel(root.right, level-1, direction);

            printGivenLevel(root.left, level -1, direction);
       }
    }
}

No comments:

Post a Comment