HP BL680c XenServer Software Development Kit Guide 4.1.0 - Page 16
Creating a new blank disk image, 3.3.1.2. Attaching the disk image to a VM
UPC - 884420396314
View all HP BL680c manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 16 highlights
Overview of the XenServer API and have a corresponding session reference. Indeed in the rest of this chapter, for the sake of brevity, we will stop mentioning sessions altogether. 3.3.1.1. Creating a new blank disk image The first step is to instantiate the disk image on physical storage. We do this via a call to VDI.create(...). The VDI.create call takes a number of parameters, including: • name_label and name_description: a human-readable name/description for the disk (e.g. for convenient display in the UI etc.). These fields can be left blank if desired. • SR: the object reference of the Storage Repository representing the physical storage in which the VDI's bits will be placed. • read_only: setting this field to true indicates that the VDI can only be attached to VMs in a read-only fashion. (Attempting to attach a VDI with its read_only field set to true in a read/write fashion results in error.) Invoking the VDI.create call causes the XenServer installation to create a blank disk image on physical storage, create an associated VDI object (the datamodel instance that refers to the disk image on physical storage) and return a reference to this newly created VDI object. The way in which the disk image is represented on physical storage depends on the type of the SR in which the created VDI resides. For example, if the SR is of type "lvm" then the new disk image will be rendered as an LVM volume; if the SR is of type "nfs" then the new disk image will be a sparse VHD file created on an NFS filer. (You can query the SR type through the API using the SR.get_type(..) call.) 3.3.1.2. Attaching the disk image to a VM So far we have a running VM (that we assumed the existence of at the start of this example) and a fresh VDI that we just created. Right now, these are both independent objects that exist on the XenServer Host, but there is nothing linking them together. So our next step is to create such a link, associating the VDI with our VM. The attachment is formed by creating a new "connector" object called a VBD (Virtual Block Device). To create our VBD we invoke the VBD.create(...) call. The VBD.create(..) call takes a number of parameters including: • VM: the object reference of the VM to which the VDI is to be attached • VDI: the object reference of the VDI that is to be attached • mode: specifies whether the VDI is to be attached in a read-only or a read-write fashion • userdevice: specifies the block device inside the guest through which applications running inside the VM will be able to read/write the VDI's bits. • type: specifies whether the VDI should be presented inside the VM as a regular disk or as a CD. (Note that this particular field has more meaning for Windows VMs than it does for Linux VMs, but will not explore this level of detail in this chapter.) Invoking VBD.create makes a VBD object on the XenServer installation and returns its object reference. However, this call in itself does not have any side-effects on the running VM (i.e. if you go and look inside the running VM you will see that the block device has not been created). The fact that the VBD object exists but that the block device in the guest is not active, is reflected by the fact that the VBD object's currently_attached field is set to false. 10