VMware Cloud Community
JasonGillis
Enthusiast
Enthusiast
Jump to solution

How to change Storage Profile of VM in vAppTemplate?

Hi everyone,

I've got a project in front of me to migrate existing VMs from an existing storage profile or the * profile to a newly created storage profile.  I've determined how to get this done for VMs in vApps already and am able to update the storage profiles for those VMs and see them migrate to the datastores associated with the new storage profile.  I'm currently stuck trying to figure out how to update the VMs in vApp Templates.  I can retrieve the vApp Template using Get-CIVAppTemplate, but I'm not able to iterate through the VMs contained within.

So, my question is:  How can I operate on the VMs in a vApp Template to be able to change the storage profile?

Alternatively, is there a method for achieving my goal (move everything to a new storage profile) that I'm not seeing?  I am concerned that I'm going to make a mess of things in the storage by updating VMs individually.  If there was a way to lift and move a whole tree (similar to SSMove from Lab Manager), that would be great!

Thanks,

Jason

0 Kudos
1 Solution

Accepted Solutions
JasonGillis
Enthusiast
Enthusiast
Jump to solution

I wasn't ever able to resolve this via PowerCLI.  My eventual solution was to manually copy/move the vApp Template in the catalog and choose the correct Storage Profile in the process.  Luckily, we didn't have many vApp Templates and this didn't take more than a couple days.

Jason

View solution in original post

0 Kudos
7 Replies
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

Hi,

To get the VM's of a vAppTemplate in the catalog you can look at the "Children.VM"  property of extensiondata. Then you can perform specific actions to the VM's.

Eg: To consolidate all the VMs you could do the following:

$vAppTemplate = get-CIvAppTemplate "TemplateA"

$vms = $vAppTemplate.ExtensionData.Children.Vm

Foreach ($vm in $vms) {

  $vm.Consolidate_Task()

  start-sleep 60

}

If you wish to move an entire vAppTemplate to another storage profile, just add the new storage profile to your ProviderVDC, then add it to your OrgVDC, then right click on the vAppTemplate and choose "Move to Catalog" or "Copy to Catalog" and change the storage profile in the drop down list. I'm not sure how to achieve this with PowerCLI.

Cheers,

DeanH

JasonGillis
Enthusiast
Enthusiast
Jump to solution

Thanks!

That's got me a step further:  I can inspect the VMs in the vAppTemplate, but I can't seem to find where I can modify the current storage profile of the VM.  For a vApp VM, I'm able to modify $VM.ExtensionData.StorageProfile.Name and .Href and then call UpdateServerData().  But, in the vAppTemplate VM, .ExtensionData doesn't exist, so I can't use that for changing the storage profile. 

I see that there's a .Relocation_Task() method defined in the vAppTemplate VM.  That looks like it would push the VM to a different datastore, but it's unclear that this would alter the current StorageProfile information in the VM.  (I assume not.)

I also see a link to storageProfile under the .Link property of the vAppTemplate VM, but I'm not sure whether that's helpful to me yet.

Jason

0 Kudos
JasonGillis
Enthusiast
Enthusiast
Jump to solution

After some investigation, I've realized that I can achieve my end result with vApp Templates by moving them to the same catalog and choosing the correct storage profile during that process.  I can definitely do that via the GUI, but I don't seem to be able to figure out how to move a vApp Template via PowerCLI.

So, does anyone know if there's a method for initiating a "Move to Catalog..." operation via PowerCLI?

Jason

0 Kudos
Cyren
Contributor
Contributor
Jump to solution

For each vm inside your vAppTemplate, do the following steps:

    Step 1 : Do a HTTP GET like https://mycloud.com/api/vAppTemplate/vm-2fce9faa-055c-4461-b5d6-fcfcecdd9ff9

    The response body should look like what follows:

         <?xml version="1.0" encoding="UTF-8"?>  

         <VAppTemplate xmlns="http://www.vmware.com/vcloud/v1.5" xmlns

             <Link rel="up" type="application/vnd.vmware.vcloud.vAppTe

             <Link rel="storageProfile" type="application/vnd.vmware.v

             <Link rel="down" type="application/vnd.vmware.vcloud.meta

             <Link rel="down" type="application/vnd.vmware.vcloud.prod

             <Description>GET </Description>

             <NetworkConnectionSection type="application/vnd.vmware.vc

                 <ovf:Info>Specifies the available VM network connecti

                 <PrimaryNetworkConnectionIndex>0</PrimaryNetworkConne

                 <NetworkConnection network="vApp Internal" needsCusto

                     <NetworkConnectionIndex>0</NetworkConnectionIndex

                     <IpAddress>101.101.101.101</IpAddress>

                     <IsConnected>true</IsConnected>

                     <MACAddress>00:50:56:22:06:33</MACAddress>

                     <IpAddressAllocationMode>MANUAL</IpAddressAllocat

                 </NetworkConnection>

             </NetworkConnectionSection>

             <GuestCustomizationSection type="application/vnd.vmware.v

                 <ovf:Info>Specifies Guest OS Customization Settings</

                 <Enabled>false</Enabled>

                 <ChangeSid>false</ChangeSid>

                 <VirtualMachineId>2fce9faa-055c-4461-b5d6-fcfcecdd9ff

                 <JoinDomainEnabled>false</JoinDomainEnabled>

                 <UseOrgSettings>false</UseOrgSettings>

                 <AdminPasswordEnabled>false</AdminPasswordEnabled>

                 <AdminPasswordAuto>true</AdminPasswordAuto>

                 <ResetPasswordRequired>false</ResetPasswordRequired>

                 <ComputerName>mycomputername</ComputerName>

             </GuestCustomizationSection>

             <VAppScopedLocalId>392fb8df-903e-4ad4-bb5a-bb32dacd5407</

             <DateCreated>2013-08-30T11:23:05.863-04:00</DateCreated>

         </VAppTemplate>

    Step 2: Edit the response body from Step 1 above, by adding the <DefaultStorageProfile> element towards the end between element <<VAppScopedLocalId>> and <<DateCreated>>. For example,

    <VAppTemplate>

           ........

          <VAppScopedLocalId>392fb8df-903e-4ad4-bb5a-bb32dacd5407</VAppScopedLocalId>

         <DefaultStorageProfile>MyStorageProfileName</DefaultStorageProfile>

         <DateCreated>2013-08-30T11:23:05.863-04:00</DateCreated>

   </VAppTemplate>

    Step 3: Using the document from Step 2 above, do a HTTP PUT to the same URL from step 1 like https://mycloud.com/api/vAppTemplate/vm-2fce9faa-055c-4461-b5d6-fcfcecdd9ff9

    * make sure to set Content-type to "application/vnd.vmware.vcloud.vAppTemplate+xml;version=5.1"

That's it.

JasonGillis
Enthusiast
Enthusiast
Jump to solution

Hi Cyren,

Thanks, that info looks promising.  Still working on how to plan this all out to get it done with the least pain so this is good to have.

Jason

0 Kudos
ITSnoesberger
Enthusiast
Enthusiast
Jump to solution

Hi, I found the following script to change the storage profile on vAppTemplates, but for me it's not working.

$templates = Get-org <orgname> | get-catalog | Get-CIVappTemplate

foreach($template in $templates){

        $vms = $template.extensiondata.children.vm

        foreach ($vm in $vms){

            $vm.defaultstorageprofile = "<storage profile>"

            $vm.updateserverdata()

        }

}

When I move the vApp over the GUI to the same catalog, it changes the profile and it's also correctly shown in vCenter. But I'll need a powershell script to change our templates, because we have hundreds of template 🙂

Thanks for your help.

0 Kudos
JasonGillis
Enthusiast
Enthusiast
Jump to solution

I wasn't ever able to resolve this via PowerCLI.  My eventual solution was to manually copy/move the vApp Template in the catalog and choose the correct Storage Profile in the process.  Luckily, we didn't have many vApp Templates and this didn't take more than a couple days.

Jason

0 Kudos