How to Export Running VM from vCloud Director

In the past I have wrote how to import running VM to vCloud Director: here and here. Today, I will describe how to export running VM.

Let us first discuss why you would do it. There are several use cases:

  • you want to manage the VM by a different Cloud Management Platform (for example vRealize Automation)
  • you want to migrate (utilizing cross VC vMotion) to a different vCloud Director
  • you want to move the VM to a different Org VDC

Currently (as of vCloud Director 8.20) there is no direct way to export running VM. So the procedure I will describe below is kind of a workaround. But let me first describe, what it means for a VM to be managed by vCloud Director.

  • VM is ‘marked’ at vSphere level with Custom Attributes and ManagedBy extension.
  • VM has its cloud_uuid stored in its configuration parameters
  • VM has assigned CPU/RAM reservations and limits depending on its Org VDC allocation model
  • VM is running in resource pool and folder based on its Org VDC/vApp
  • VM has a name that includes its UUID
  • vCloud Director is tracking the VM in vSphere inventory even if it changes its name, location and MoRef ID.
  • vCloud Director is reserving VMsĀ IP and MAC addresses in its IPAM.
  • vCloud Director is counting VMs resources to its Org VDC allocation.

In order to remove the VM from vCloud Director management we must take care of all these points.

Here comes the procedure I came up with. It can obviously be automated with vSphere and vCloud APIs if needed for export of large amount ofĀ VMs.

First we clean up VM at vSphere level in vCenter Server:

  1. Move VM outside the vCloud Director managed Resource Pool (this is to avoid auto-import of the VM)
  2. If necessary reconnect VM to network not managed by vCloud Director (this is for situations where the vApp or Org VDC network is going to be deleted later). Obviously as the VM is running, the new network shouldĀ provide equivalentĀ connectivity as the original one (either with L2 bridging or routing).
  3. Remove cloud-uuid from the VM configuration parameters. This can be done on running VM with PowerCLI:
    (Get-AdvancedSetting -entity $vm -Name cloud.uuid)|Remove-AdvancedSetting
  4. Remove vCloud Director related Custom Attribute values (in my case VCD_fojta_01). Do not remove the whole Custom Attribute, just the value.
  5. Remove ManagedBy extension from the VM. The easiest to do is leveraging PowerCLI script attached to KB 2032366. You will see the VM icon has changed after the extension has been removed.
    \ManagedBy.ps1 -Cmd Clear -VMs $vm
  6. Remove VM resource reservation and limits (if applicable).
  7. Rename VM (to get rid of UUID in the name).
    Now we need to take care of removing VM in vCloud Director, however even though we removed its cloud-uuid vCloud Director still sees the VM through its vCenter MoRef ID. And we cannot change MoRef ID of running VM. So here comes the workaround:
  8. Temporarily remove access to the VM for vCloud Director service account (account configured in vCloud Director for the particular vCenter Server). To do so, you assign No Access role permission on the VM object for the service account user.
  9. Now the VM has become invisible for vCloud Director and we can clean it up in vCloud Director. First Force-Stop its vApp.
  10. Now Delete the vApp. Ignore the error.
  11. Purge the vApp from stranded items with Force Delete.
  12. Now we can remove the temporary no access role permission from step #8.
  13. Clean up the vApp folder in vCenter Server if it was not removed.

Quite lengthy and not pretty procedure, however we did not do anything unsupported (like editing vCloud database) and the VM has been properly removed from vCloud Director inventory.

Last comment is about VM MAC addresses. If the VM was created in vCloud Director it will have MAC addresses from the vCloud Director range based on VCD installation ID. Have that in mind when moving VM around as duplicate MACs could be generated.

6 thoughts on “How to Export Running VM from vCloud Director

  1. Hello Tom

    Thanks so much for this procedure !!

    I’m not sure to understand in step 4 for which object you change the vCD related custom attribute value. Is that only for the VM? I can’t find where to edit custom attribute in web client.

    My understanding was that this custom attribute was set on all hosts prepared for vCD. When I had previously tried to modify it, I could not narrow the change to a VM.

    thanks

      1. Thanks again.

        Sorry to be a pain but would you be able to direct me in the vsphere client ? Which powercli command shall I use as set-customattribute doesn’t seem to be applicable to a particular VM(unless I’m wrong which is very possible) ?

        Thanks

  2. The powercli command for step 4 is Set-Annotation.

    I’m in your 2nd use case “you want to migrate (utilizing cross VC vMotion) to a different vCloud Director”.

    After I applied the procedure and VM appears as not managed by vCD anymore, cross VC vMotion still fails with the error that the proper vsla custom attribute is missing on target host.

    1. In vSphere Client the Custom Attributes are visible in Summary page of the VM under Annotations.

      You must remove the Custom Attribute from the VM otherwise it will be marked as incompatible if the host where you want to move the VM does not have the same attribute starting with system.service…

      Removing with PowerCLI can be done with $vm.CustomFields.Remove(“system.service.vmware.VSLA…”)

  3. Thanks Tomas. This gives the below error to me, whether the VM is powered on or off.

    PowerCLI E:\LabShare\Scripts> $vm.CustomFields.remove(“system.service.vmware.vsla.fraise”)

    Exception calling “Remove” with “1” argument(s): “Cannot remove value from a
    read-only dictionary.”
    At line:1 char:1
    + $vm.CustomFields.remove(“system.service.vmware.vsla.fraise”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidOperationException

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.