VMware {code} Community
surkude
Contributor
Contributor
Jump to solution

Excluding virtual disk during clone opearation

Hello all,

I'm trying to use vmware vsphere Perl Apis to clone a virtual machine. But during the clone opeation i need to exclude some of the virtual disks that i'm not interested in. Does anyone know how to do that.

I looked at the "deviceChange" field of VirtualMachineConfigSpec. But it looks like these changes are applied only after the VM is cloned. I need these disks to be excluded from cloning process even before it starts.

Anyone has any idea how this can be achieved?

Reply
0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

That looks to be good, after looking at the code and the function call, I think that is the expected behavior. The clone operation allows you to clone from an existing VM and if you need make any changes, it'll be in the form of a reconfigure as you've noticed. I believe this is the expected behavior and the steps I would have taken in the code to do so. You could reconfigure the base VM, but it looks like you're using a template, so you won't have the option. You could however convert the template to VM, remove the disk, clone and then re-add the disk once you're done. Not sure how often you'll be doing something like this where you'll exclude some disks.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

View solution in original post

Reply
0 Kudos
15 Replies
lamw
Community Manager
Community Manager
Jump to solution

I've not personally done this before, but it should be part of the clonespec that's crated when you're cloning from an existing VM. What you would probably do is create a new deviceChange array and copy over only the devices you want in the new VM, in this case everything except for the VirtualDisks you want to exclude. This is not unique in Perl, it's the same across any the SDK's you're using

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

surkude
Contributor
Contributor
Jump to solution

Thanks. I was trying to use deviceChange to specify only the disk that i wanted to be removed. But, i could try the way you have mentioned, basically getting all the devices (vm->config->hardware->device) excluding the ones i do not want. Let me try this and i will update you.

Reply
0 Kudos
surkude
Contributor
Contributor
Jump to solution

This did not help. I copied all the devices from the parent vm except the virtual disks. But during cloning it still copied those Virtual disks. If i specify in the following manner

foreach $device (@$devices) {

if ($device->deviceInfo->label =~ m/$hard_disk_str/) {

print "Excluding " . $device->deviceInfo->label . "\n";

$new_device_spec = VirtualDeviceConfigSpec->new(

device => $device,

fileOperation => VirtualDeviceConfigSpecFileOperation->new('destroy'),

operation => VirtualDeviceConfigSpecOperation->new('remove'));

} else {

print "Device " . $device->deviceInfo->label . "\n";

$new_device_spec = VirtualDeviceConfigSpec->new(

device => $device);

push(@$new_device_list, $new_device_spec);

}

}

Then the virtual disks get cloned for the new VM and then get deleted. So, this doesn't work for me since i want to avoid the virtual disk cloning process.

Any suggestions?

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

Could you please provide the entire script and just attach it versus pasting in the forums? A) it's hard to read and b) Most likely the forum will be mangled

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

surkude
Contributor
Contributor
Jump to solution

I have kept only the relevant parts in the script. Please find the script attached. Thanks.

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

That looks to be good, after looking at the code and the function call, I think that is the expected behavior. The clone operation allows you to clone from an existing VM and if you need make any changes, it'll be in the form of a reconfigure as you've noticed. I believe this is the expected behavior and the steps I would have taken in the code to do so. You could reconfigure the base VM, but it looks like you're using a template, so you won't have the option. You could however convert the template to VM, remove the disk, clone and then re-add the disk once you're done. Not sure how often you'll be doing something like this where you'll exclude some disks.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
surkude
Contributor
Contributor
Jump to solution

Thanks for looking into this. Converting the template to a VM was the last resort that i was going to keep, but i was hoping to have a cleaner solution for this.

While googling around, i came across something interesting like Netapp's flexclone. Do you know how does netapp's flexclone work? they support cloning of templates and virtual machines, and since they use flexclones instead of letting vmware copy the entire virtual disks, they also must be running into the same issue as that of me.

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

I'm not intimate on how it works with NetApp, but in general, offloading this to the array is definitely where the storage vendors are going and will definitely speed things up along with not duplicating the IO to the backend, as it's write once. Both EMC and NetApp have similar technologies and you may want to engage them for more details. The next iteration of vSphere will contain something called VAAI which is vStorage API for Array Integration which will be VMware operations integrated with the major storage vendor to basically offload things like full/linked from data mover within VMkernel out to the storage array. This will allow you to spin up hundreds of VMs in fraction of time versus the traditional cloning methods today. Do a search online for vSphere and VAAI and you'll find some announcement by both EMC and Netapp. Though this is really a separate topic, it gives you an idea if you're looking to spin up for a VDI like environment, that offloading to the array is really the way to go.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
surkude
Contributor
Contributor
Jump to solution

Okay. Thanks.

Btw, i used createVM_Task instead of cloning and passed only the devices that i needed from the parent VM. So, that seems to work for me. However, i'm not running into a customizeVM_task error. I get following error:

SOAP Fault:

-


Fault string: Cannot complete customization.

Fault detail: CustomizationFault while Customize for rhel1

Does anyone know how to debug this? Somehow i do not see any logs for this on the ESX server.

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

For customization errors, you'll need to take a look at the error presented within the task .. most likely it'll be worthless as a generic error. You'll then want to login to the guest ... if' it's gotten as far as provisioning but just failed to customized, there are logs stored in /var/log/vmware/* and those should give you some hints on what might be wrong. My guest is you're probably missing something or not defining something correctly that is causing the customization to fail.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
surkude
Contributor
Contributor
Jump to solution

Somehow hostd* files do not contain any logs for this task. Not even saying that such a task has been created.

Reply
0 Kudos
surkude
Contributor
Contributor
Jump to solution

This time i tried setting all the parameters in CustomizationIPSettings (despite all of them except "ip" being optional) and it worked fine.

Reply
0 Kudos
lamw
Community Manager
Community Manager
Jump to solution

I don't know if it'll make it into hostd* logs, this is a vCenter task. I just never looked in the hostd* logs, the other thing you may want to do is enable further logging on either the ESX/ESXi host or vCenter

Here are the steps for ESX/ESXi host - http://www.doublecloud.org/2010/05/how-to-enable-esx-server-logs-for-troubleshooting/

Here are the steps for vCenter - http://www.lucd.info/2010/05/12/debugging-function-verbose-vpxd-logging/ (basically you'll use the vSphere Client and change the vCenter logging options to something like trivia for full SOAP messages)

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Community

If you find this information useful, please award points for "correct" or "helpful".

Reply
0 Kudos
surkude
Contributor
Contributor
Jump to solution

This is helpful. Thank you so much.

Reply
0 Kudos
VIGuru
Contributor
Contributor
Jump to solution

hello surkude,

can yougive me an example of using c# to connect to sdk and return the virtual center version? I dont want any user input just a simple script I am just new to c# and the sdk.

thanks

Reply
0 Kudos