Provision virtual machines with vSphere APIs

Using inflate and eagerzero to manipulate virtual disks

In a virtualized VMware cloud environment, you can provision different types of image templates for your unique requirements. VMware provides provisioning techniques for different needs. Two of these techniques, inflate and eagerzero, are described in this article. Learn how to use these methods to manipulate virtual disk and storage size in your VMware environment.

Share:

Bhanu P Tholeti (btholeti@in.ibm.com), Systems Engineer and Architect, IBM

Author photoBhanuprakash has worked in the software industry for the past 10 years on various technologies and products such as application development for Pocket PCs, web-based applications, video streaming solutions, and products like Tivoli Workload Scheduler, WebSphere Data Interchange, Tivoli Service Automation Manager, and Tivoli Provisioning Manager. He is part of IBM SmartCloud Enterprise+, working on cloud infrastructures and hypervisors.



K. Sowjanya Chakravarthi (csowjany@in.ibm.com), Systems Engineer, IBM

Author photoSowjanya CK has worked in IBM for more than 6 years on various products. He is involved in porting of Tivoli Provisioning Manager to z/Linux, Go Symphony plugin development, and SCEplus development.



06 September 2013

Also available in Chinese Russian Japanese

Expand the power of provisioning with SmartCloud Virtual Storage

This article details provisioning techniques for virtual machine storage in a vSphere virtual OS/VMware hypervisor environment. You can expand your cloud storage provisioning power by combining VMware vSphere capabilities with the IBM SmartCloud Virtual Storage Center, a system that provides efficient virtualization and management of heterogeneous storage systems, and makes it easy if you're migrating to an agile cloud architecture or want to convert existing storage to an IBM Smarter Storage environment.

You can use thin provisioning features to automate provisioning processes to help simplify capacity management. The provisioning is self-optimized too: Data is automatically moved to appropriate storage tier — most active data goes to the fastest-access tier, less active data moves to a lower tier, and performance analytics and metrics help determine storage-tier decisions (on a continuous basis).

For more information about combining SmartCloud Virtual Storage Center with VMware:

Thin provisioning is a popular technique for virtual machines (VMs), because it's fast. The problem with such provisioning, however, is that it can lead to overcommitting storage in the data store it uses. To overcome this drawback, you must inflate the disks associated with the VM, a technique explained in this article.

Thick provisioning is one approach for overcoming the problem of overcommitting, but it does so at the price of data security. To achieve data security over thick-provisioned VMs, you can eagerzero the disk associated with the VM.

This article provides technical details about how to inflate the disk associated with a VM provisioned with a thin-provisioning technique and how to eagerzero the disks associated with a VM provisioned with a thick-provisioning technique. Before going into detail on the techniques, however, you must understand how VM provisioning works in VMware vSphere.

VMware vSphere supports three types of VM provisioning:

  • Thick provision lazy zeroed. This type of provisioning creates a virtual disk in a default thick format. Space required for the virtual disk is allocated when the virtual disk is created. Data remaining on the physical device is not erased during creation but is zeroed out on demand on first write from the VM.
  • Thick provision eager zeroed. This type of thick virtual disk supports clustering features such as fault tolerance. Space required for the virtual disk is allocated at creation. In contrast to the flat format, the data remaining on the physical device is zeroed out when the virtual disk is created. It can take much longer to create disks in this format than in other formats.
  • Thin provision. Use this format to save storage space. For the thin disk, provision as much data store space as the disk requires based on the value that you enter for the disk size.

A note on overcommitting

Overcommitting occurs when the storage you designate for a VM in a data store is much less than the size of the VM itself, because storage for the VM increases as data grows. This can be a potential issue for data store selection algorithms while calculating the available space in the data store, because actual available free space can be retrieved at any point. You can end up in a situation where the VM tries to write data to an allocated data store that has no space.

Each provisioning technique requires its own disk type. You can select among the following VMware-supported options:

  • Thick. File blocks are not zeroed out while you are provisioning the VM. VM provisioning is fast.
  • Zeroedthick. File blocks are zeroed on demand on first write to virtual disk. VM provisioning is fast.
  • Thin. File blocks are allocated on demand on first write to the block with zero size on creation. You must inflate the disk after provisioning. VM provisioning is fast.
  • Eagerzeroed thick. File blocks are zeroed out on creation of the VM's virtual disk. VM provisioning is slow.

The inflate technique

Inflating a thin disk is simply zeroing the whole unused disk while expanding the allocated size. VMware vSphere provides an application programming interface (API) that you can use to zero the whole disk.

Step 1: Associate a data store with the VM

To associate a data store with your VM, run the following command:

Object datastoreObject = this.getSingleProperty("datastore", vmMor); 
// get the datastore property associated with virtual machine object

Note: You can use your own methods, such as the above getSingelProperty, to retrieve properties from vSphere for any specified vSphere-managed object references.

To get all the data stores associated with the VM in a particular data center, run the following command:

ArrayOfManagedObjectReference datastoreMorArray = 
    (ArrayOfManagedObjectReference) datastoreOb-ject;

After associating all the data stores, you must find the specific Virtual Machine Disk (VMDK) files to inflate for the VM. Because these VMDK files might be scattered across the data stores, you must search in all the data stores with the VM name and retrieve their absolute path.

Step2: Get the path of the VMDK

Use the searchDatastoreSubFolders_Task method to find the path of the VMDK files associated with the VM. To search all the data stores obtained in Step 1, you must have a data store browser associated with the host platform. Listing 1 shows the search.

Listing 1. Searching data stores for the path to VMDK files
VirtualMachineRuntimeInfo vmRunInfo = 
    (VirtualMachineRuntimeInfo) this.getSingleProperty("runtime", vmMor);
ManagedObjectReference hostMor = vmRunInfo.getHost();
ManagedObjectReference datastoreBrowserMor = 
    (ManagedObjectReference) this.getSingleProperty("datastoreBrowser", hostMor);
path = new ArrayList<String>();
for (int i = 0; i < datastoreMor.length; i++) {
String dsName = (String) this.getSingleProperty("name",datastoreMor[i]);
HostDatastoreBrowserSearchSpec hostDatastoreBrowserSearchSpec = 
    new HostDatastoreBrows-erSearchSpec();
hostDatastoreBrowserSearchSpec.setMatchPattern(new String[] { vmName + ".vmdk" });
    // vmName here refers to the name of the virtual disk for that virtual machine 
    in the hypervisor
	ManagedObjectReference taskMor = 
	this.vimPort.searchDatastoreSubFolders_Task(datastoreBrowserMor,"[" + 
	dsName + "]",hostDatastoreBrowserSearchSpec);
	if (taskMor != null) {
		taskResult = "queued";
		while ((!taskResult.equals("success")) && 
		    (!taskResult.equals("error"))) {
			try {
				TaskInfo taskInfo = 
				    (TaskInfo) this.getSingleProperty("info", task-Mor);
				System.out.println("state:"	+ 
				    taskInfo.getState().getValue());
				taskResult = taskInfo.getState().getValue();
				Thread.sleep(5000L);
			} catch (InterruptedException localInterruptedException) {
				throw localInterruptedException;
			}
			if (taskResult.equals("error")) {
				return "FAILED";
			}
			if (taskResult.equals("success")) {
				TaskInfo taskInfo = 
				    (TaskInfo) this.getSingleProperty("info",taskMor);
				ArrayOfHostDatastoreBrowserSearchResults res = 
				    (ArrayOfHost-DatastoreBrowserSearchResults) 
				    taskInfo.getResult();
				HostDatastoreBrowserSearchResults[] resArray = 
				    res.getHostDatastoreBrowserSearchResults();
				for (int j = 0; j < resArray.length; j++) {
					System.out.println("folderpath:"+
					    resArray[j].getFolderPath());
					for (int k = 
					    0; k < resArray[j].getFile().length; k++) {
						System.out.println("filePath:"+ 
						    resAr-ray[j].getFile()[k].getPath());
						String tempstr = 
						    resArray[j].getFolderPath()	
						    + resAr-ray[j].getFile()[k].getPath();
						path.add(tempstr);
					}//end for
				}//end for
			}//end if
		}//end while

	}//endif
}//end for

After getting all the paths of the VMDK files associated with the VM, invoke inflation on each disk using the vSphere inflate API, as shown in Step 3.

Step 3: Inflate the VMDK files

Now, inflate the VMDK files by passing the path you found in Step 2 to the inflateVirtualDisk_Task method, as shown in Listing 2.

Listing 2. Inflating the VMDK files
for (int i = 0; i < path.size(); i++) {
System.out.println("this.vimPort.inflateVirtualDisk_Task("+ 
    this.virtualDiskManagerMor + "," + path.get(i) + ","+ dataCenterMor + ");");
ManagedObjectReference taskMor = 
    this.vimPort.inflateVirtualDisk_Task(this.virtualDiskManagerMor,(String) 
    path.get(i), dataCenterMor);
	if (taskMor != null) {
		taskResult = "queued";
		while ((!taskResult.equals("success"))&& (!taskResult.equals("error"))) {
			try {
				System.out.println("task type:" + taskMor.getType());
				TaskInfo taskInfo = 
				    (TaskInfo) this.getSingleProperty("info",taskMor);
				System.out.println("state:" + 
				    taskInfo.getState().getValue());
				taskResult = taskInfo.getState().getValue();
				Thread.sleep(5000L);
			} catch (InterruptedException localInterruptedException) {
				throw localInterruptedException;
			}
			if (taskResult.equals("error")) {
				TaskInfo taskInfo = 
				    (TaskInfo) this.getSingleProperty("info",taskMor);
				System.out.println("error in inflateVirtualDisk_Task:" + 
				    taskInfo.getError().getLocalizedMessage());
				return “failed”;
			}
			if (taskResult.equals("success")) {
				return "SUCCESS";
			}
		}//end while
	}//end if
}//end for

The eagerzero technique

Eagerzeroing a thick disk zeroes out the whole unused space allocated for the VM, and VMware vSphere provides an API you can use for this purpose. Complete Steps 1 and 2 of the inflation technique to retrieve the VMDK paths in data stores associated with the VM. Then, invoke an eagerzero thick API from vSphere to zero out the whole disk, as shown in Listing 3.

Listing 3. Invoking the eagerzero thick API to zero the disk
for (int i = 0; i < path.size(); i++) {
System.out.println("this.vimPort.inflateVirtualDisk_Task("+ 
    this.virtualDiskManagerMor + "," + path.get(i) + ","+ 
    dataCenterMor + ");");
ManagedObjectReference taskMor = this.vimPort. eagerZeroVirtualDisk_Task 
    (this.virtualDiskManagerMor,(String) path.get(i), dataCenterMor);
	if (taskMor != null) {
		taskResult = "queued";
		while ((!taskResult.equals("success"))&& 
		    (!taskResult.equals("error"))) {
			try {
				System.out.println("task type:" + taskMor.getType());
				TaskInfo taskInfo = 
				   (TaskInfo) this.getSingleProperty("info",taskMor);
				System.out.println("state:" + 
				    taskInfo.getState().getValue());
				taskResult = taskInfo.getState().getValue();
				Thread.sleep(5000L);
			} catch (InterruptedException localInterruptedException) {
				throw localInterruptedException;
			}
			if (taskResult.equals("error")) {
				TaskInfo taskInfo = 
				   (TaskInfo) this.getSingleProperty("info",taskMor);
				System.out.println("error in inflateVirtualDisk_Task:" + 
				    taskInfo.getError().getLocalizedMessage());
				return “failed”;
			}
			if (taskResult.equals("success")) {
				return "SUCCESS";
			}
		}//end while
	}//end if
}//end for

Conclusion

The techniques provided in this article are the simplest ways to zero out your VM disks. Users can then pay more attention to how they browse the data stores with appropriate search patterns, which might differ by environment.

Resources

Learn

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Cloud computing on developerWorks


  • Bluemix Developers Community

    Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.

  • developerWorks Labs

    Experiment with new directions in software development.

  • DevOps Services

    Software development in the cloud. Register today to create a project.

  • Try SoftLayer Cloud

    Deploy public cloud instances in as few as 5 minutes. Try the SoftLayer public cloud instance for one month.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing
ArticleID=943640
ArticleTitle=Provision virtual machines with vSphere APIs
publish-date=09062013