Sean,

> You can use the vsphere api to get the file names if you really need them.

This is true, and that may very well be the better approach. I am not entirely 
happy with the method I described earlier, which relies on my own observation 
of an apparently undocumented behavior of VMware. There is, for instance, no 
guarantee that VMware won't start truncating virtual disk filenames at 28 
characters at some point in the future. 

On the other hand, if VMware is allowed to (arbitrarily?) truncate values that 
follow an otherwise fairly strict VCL naming convention, there could be 
negative implications for subsequent revisions of a given image. Imagine, for 
instance, a situation with multiple management nodes or at least multiple VM 
host infrastructures. If one infrastructure truncates the imagename value, what 
happens if that image is revised again later in a different VM infrastructure 
(possibly, even, with a different VMware API being used). Would the new 
imagename be generated properly? (This example is not at all hypothetical, 
given the way we have set up our VCL).

Another potential problem is that the VCL database enforces unique imagename 
values. The VCL, however, would not be able to enforce this if VMware is 
allowed to truncate these values according to its own opaque contrivance. In 
fact, it is entirely is possible to construct a scenario in which different 
versions of the same base image are assigned identical paths in a VMware 
datastore. Aside from not suiting the database schema particularly well, this 
could, potentially, overwrite another revision of the same image stored in the 
VCL repository path. 

> Why does vcl write its own vmx instead of using the apis?  vSphere expects 
> programs to use the apis, not to hand craft files.    

I completely agree. I must admit that, when I wrote the vCenter provisioning 
module, I tried to use as much existing VCL code as possible. Rather than 
reimplementing everything to use vSphere managed objects, I rewrote only what 
appeared to be necessary. So for example, in VMWare.pm, the 'load' subroutine 
calls 'prepare_vmx', which generates a vmx text file on the management node. 
This file is then transferred via VIExt::http_put_file into the VMware 
infrastructure. While I managed to make this sequence of commands work in the 
context of vCenter, I agree that it would be far better to implement this 
differently for a vCenter provisioning module.

Within the context of the current VMware module design, the communication with 
the VM host is expected to occur by means of the API object (i.e. 
$self->{api}). So for instance, the creation of the virtual machine via vCenter 
would logically occur when $self->api->vm_register(…) is called. The call to 
$self->prepare_vmx in the preceding lines would be superfluous, and there would 
be no need for that method to write and then transfer a vmx file to the VM host 
infrastructure. In short, there would need to be some way for the vCenter API 
to circumvent that sequence of commands.

Since all the VMware API modules inherit from the base VMware class, there 
could be a new method, such as 'require_prepare_vmx', for which the VMware 
class provides a simple default implementation:

sub require_prepare_vmx {
        return 1;
}

Then, the lines,

# Generate the .vmx file
if (!$self->prepare_vmx()) {
        notify($ERRORS{'WARNING'}, 0, "failed to prepare vmx file for 
$computer_name on VM host: $vmhost_name");
        return;
}
could be enclosed by a conditional block:

if ($self->api->require_prepare_vmx){
        # Generate the .vmx file
        if (!$self->prepare_vmx()) {
                notify($ERRORS{'WARNING'}, 0, "failed to prepare vmx file for 
$computer_name on VM host: $vmhost_name");
                return;
        }
}
which would provide the vCenter module the hooks it needs in order to skip this 
step entirely.

Andy, how would this fit into the current design of the VMware module?

Aaron


> When I wrote Duke's provisioning module to work with vCenter I found it much 
> easier to use the apis instead of going through the extra work to get a 
> custom vmx created/uploaded/etc.
> 
> Aaron Coburn <acob...@amherst.edu> wrote:
> 
>> Andy, I can certainly make the initial commit of the module. 
>> 
>> An interesting problem I have had with this module, however, is that when I 
>> clone a VM (which is the only way to move a virtual disk using the vSphere 
>> API while preserving thin provisioning), VMWare would silently truncate the 
>> name and enclosing directory of the virtual disk -- though only if the 
>> basename of the VM is longer than 29 characters. The actual name of the VM 
>> can still be up to 80 characters, but the location of the virtual disk, it 
>> appears, cannot. And since the VCL crafts its own *.VMX files, it needs to 
>> know precisely where to find the *.VMDKs.
>> 
>> For example, a virtual disk with this name: vmwarewinxp-WindowsNoApps82-v3 
>> (basename has 30 chars) would be saved in this location: 
>> vmwarewinxp-WindowsNoApps82-v/vmwarewinxp-WindowsNoApps82-v.vmdk
>> 
>> As another example, vmwarewin7-WindowsNoApps52-v0 would not have a problem 
>> until it hit version 10 (basename has 29 chars), at which point it would be 
>> put in this location:
>> 
>> vmwarewin7-WindowsNoApps52-v1_X/vmwarewin7-WindowsNoApps52-v1_X.vmdk 
>> (where X would be some number that VMware appends to the virtual disk if 
>> version1 is still available on the datastore -- X will increment on 
>> subsequent attempts -- note that the basename is now more than 29 total 
>> characters)
>> 
>> With the VCL naming conventions (ostype-imagenameID-version), it is, of 
>> course, easy to exceed the 29-character limit. I was unsuccessful in 
>> locating any documentation from VMware about this. The work-around, though, 
>> was to add a few lines in the web code to keep the value of 
>> vcl.revision.imagename limited to 29 chars. Clearly, it is necessary to 
>> retain the version suffix as well as the imageID, so the code pulls apart 
>> the imagename clauses, shortens the middle clause and reassembles them into 
>> a 29-character-or-less string. Similar code would need to be added to the 
>> "-setup" part of vcld.
>> 
>> As you know, this imagename value is never actually seen by a user, so I 
>> felt at some liberty in modifying how it is generated. Does that seem like a 
>> reasonable tact?
>> 
>> Aaron
>> 
>> 
>> On Jan 30, 2012, at 2:36 PM, Andy Kurth wrote:
>> 
>>> Hi Aaron,
>>> How would you like to proceed with your vCenter modules now that
>>> you're a committer?  You can make the initial commit if you're
>>> comfortable with it.  If not, I now have access to a vCenter license
>>> and can incorporate it into the current code in trunk and make the
>>> initial commit.  There have been some minor changes to vSphere.pm so
>>> some changes may be necessary.
>>> 
>>> Thanks,
>>> Andy
>>> 
>>>> On Aug 17, 2011, at 8:52 PM, Andy Kurth wrote:
>>>> 
>>>>> This is wonderful.  Thank You.  I will try to incorporate it over the
>>>>> next few weeks.  For anyone interested, the Jira issue is:
>>>>> https://issues.apache.org/jira/browse/VCL-499
>>>>> 
>>>>> Also, I committed your improvements in VCL-470 and VCL-471 on 8/4.
>>>>> 
>>>>> I'd suggest working off of trunk in Subversion and svn updating it
>>>>> regularly if you aren't already doing so.  I've made some changes to
>>>>> the VMware code over the past few weeks.  The vSphere.pm module has
>>>>> been improved to execute much faster.  Rather than calling the VMware
>>>>> API every time something such as a datastore object is needed, it is
>>>>> only called once per object and this reference is then stored in the
>>>>> vSphere.pm object for later use.  It will probably be easier to
>>>>> incorporate your changes because of this.  All calls to get_host_view
>>>>> are funneled through a single subroutine.
>>>>> 
>>>>> Also, the method of handling vmdk's has changed after being inspired
>>>>> by ideas shared by Dr. Masoud Sadjadi from Florida International
>>>>> University at the VCL bootcamp last month.  Josh Thompson did some
>>>>> research and then I incorporated the findings. It is no longer
>>>>> necessary to create an entire copy of the vmdk for imaging and
>>>>> long-term reservations.  All VMs are now configured to use the vmdk in
>>>>> persistent mode instead of independent-persistent or
>>>>> independent-nonpersistent mode.  Before a VM is powered on a snapshot
>>>>> is now taken.  This causes the VM to write changes to a delta file in
>>>>> the directory where the vmx is located and the master/golden vmdk
>>>>> isn't altered.  If the snapshot fails for some reason, the VM is
>>>>> immediately deleted to prevent the possibility of it being powered on
>>>>> and altering the master image.
>>>>> 
>>>>> The benefits are:
>>>>> -Full copies of the vmdk don't need to be made when a VM is loaded
>>>>> -Load time for imaging and long-term reservations is ~1-3 minutes
>>>>> -Load on the storage system is reduced
>>>>> -Storage consumption is reduced
>>>>> -Normal, short-term VMs can be shut down without losing the state
>>>>> -Images can be created from normal reservations
>>>>> 
>>>>> For imaging reservations, the path within the vmx file is
>>>>> automatically changed when the snapshot is created to a file within
>>>>> the vmx directory.  Running vmkfstools or calling the vSphere SDK to
>>>>> copy/move this vmdk causes a new, complete vmdk to be created
>>>>> containing the master image with the delta changed incorporated.
>>>>> 
>>>>> The code to create a full independent-persistent copy is still intact.
>>>>> This mode is currently only used if a reservation is a server request
>>>>> -- a major new feature in VCL 2.3.  There is supposed to be a slight
>>>>> performance benefit of using this mode so I want to keep it as an
>>>>> option.
>>>>> 
>>>>> Thanks for your contributions.  Would you be interested in becoming a
>>>>> committer to the project?
>>>>> 
>>>>> Regards,
>>>>> Andy
>>>>> 
>>>>> On Tue, Aug 16, 2011 at 1:04 PM, Aaron Coburn <acob...@amherst.edu> wrote:
>>>>>> Hello,
>>>>>> In our VCL implementation at Amherst College, we are using a VMware 
>>>>>> cluster for our virtual machine infrastructure. Because we wanted to 
>>>>>> allow VMs to float between physical hosts according to how VMware 
>>>>>> prefers to balance resource use (VMware calls this distributed resource 
>>>>>> scheduling), I wanted to access the cluster as a single datacenter 
>>>>>> through the vCenter interface. From VCL's perspective, this allows me to 
>>>>>> put all of my virtual computers on a single VM Host, when in reality 
>>>>>> each of those VMs is located on one of any number of physical machines 
>>>>>> that the VCL can remain blithely ignorant about.
>>>>>> 
>>>>>> The vSphere_SDK package, however, requires that vcld access a physical 
>>>>>> host directly, so I wrote a new provisioning module called 
>>>>>> VMware::vCenter. This module is a subclass of the vSphere_SDK package 
>>>>>> and works with version 2.2.1 of the VCL. The new module reimplements the 
>>>>>> vSphere_SDK subroutines that are incompatible with a datacenter-based 
>>>>>> connection, primarily anything that calls the VIExt::get_host_view() 
>>>>>> method or tries to copy or move virtual disks to new locations. There 
>>>>>> are a few other changes that are explained in the JIRA issue I created 
>>>>>> for this. I have included the relevant code in JIRA, but let me know if 
>>>>>> there is anything else I should do to help this along.
>>>>>> 
>>>>>> Best regards,
>>>>>> 
>>>>>> Aaron Coburn
>>>>>> Systems Administrator and Programmer
>>>>>> Academic Technology Services, Amherst College
>>>>>> (413) 542-5451 acob...@amherst.edu
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>> 
>> 

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to