VMware Cloud Community
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

Adding a vApp to Catalog in vCD with PowerCLI

I would like add a vApp to a Catalog via PowerCLI. I can't see any methods under the extensiondata of the vApp that allow for this.

Then I thought maybe I need to look from the Catalog side and could only find CatalogItems in the GetCIView() of the org and don't know how to edit it:

$ciorg.ExtensionData.Catalogs.CatalogReference[0].GetCIView().CatalogItems

So then I tried scripting out the creation of a new catalog...It works but I still don't know to add vApps to it.

$ciorg = get-org "Org Name"

$cat = New-Object vmware.vimautomation.cloud.views.AdminCatalog
$cat.Owner = New-Object VMware.VimAutomation.Cloud.Views.Owner
$cat.Owner.User = New-Object VMware.VimAutomation.Cloud.Views.Reference
$cat.Owner.User = (get-org).ExtensionData.Users.UserReference[0]
$cat.CatalogItems = New-Object VMware.VimAutomation.Cloud.Views.CatalogItems
$cat.IsPublished = $True
$cat.Name = "Catalog Name"
$cat.Description = "Created with PowerCLI"
$ciorg.ExtensionData.CreateCatalog($cat)

*Entries in bold need refining. Didn't know how to search for a specific user so I used the first entry which is mine in the User array.

So currently I'm stumped. Alan, LucD or Jake...Ideas?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
AtanasAtanasov
VMware Employee
VMware Employee
Jump to solution

The ExtensionData and Get-CIView are exposing the vCloud REST API. The documentation is available here: https://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/index.html. What PowerCLI exposes is slightly different though. We are going to publish a separate documentation at some later point that would be more accurate.

Note that the interface PowerCLI exposes to .Net is not the same as the C# SDK for vCloud.

To get to the documentation of the 2 operations, you should set the search scope to All Operations and search for InstantiateVAppTemplate or ComposeVApp, follow the Input type link to InstantiateVAppTemplateParams/ComposeVAppParams.

Creating a vApp out of a vApp template is done with InstantiateVAppTemplate. ComposeVApp is for creating a vApp from scratch.

Just a side note: take a look at Import-CIVApp and Import-CIVAppTemplate, those are capable of "registering" a VM from vSphere in vCloud. That may be a faster way of migrating vSphere VMs to vCloud vApp templates as they can do the conversion without coping the VM.

View solution in original post

0 Kudos
9 Replies
AtanasAtanasov
VMware Employee
VMware Employee
Jump to solution

Hi,

Catalogs contain only templates and media. Are you trying to convert/copy a vApp to a vApp template and add that to a catalog or something else?

0 Kudos
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

For sure you can add vApps to Catalog. Shutdown the vApp, right click add to Catalog. I want to know how to script that via PowerCLI.

0 Kudos
AtanasAtanasov
VMware Employee
VMware Employee
Jump to solution

What that operation does is copy the vApp to a template and register the template in the catalog.

Here is a script to do this:


$vapp = Get-CIVApp <your vApp name>
$orgVdc = Get-OrgVdc <your org vDC name>
$catalog = Get-Catalog <destination catalog name>

#copy $vapp to $catalog while storing the resulting template at $orgVdc

#create a template base on $vapp
$vappRef = New-Object VMware.VimAutomation.Cloud.Views.Reference
$vappRef.Href = $vapp.Href
$vAppTemplate = $orgVdc.ExtensionData.CaptureVApp($vappRef, $null, $vapp.Name, $vapp.Description)

#wait for the capture operation to complete
foreach($task in $vAppTemplate.Tasks.Task) {
    $task.Wait()
}

try {
    #attach the template to a catalog
    $catalogItem = New-Object VMware.VimAutomation.Cloud.Views.CatalogItem
    $catalogItem.Entity = New-Object VMware.VimAutomation.Cloud.Views.Reference
    $catalogItem.Entity.Href = $vAppTemplate.Href
    $catalogItem.Name = $vapp.Name
    $catalogItem.Description = $vapp.Description
    $catalog.ExtensionData.CreateCatalogItem($catalogItem)
} catch {
    #if the attaching failed (e.g. a name conflict), clean-up the orphan template
    $vAppTemplate.Delete()
    throw;
}

Note that if you navigate to an Org vDC, there is a section "vApp Template" where you can see templates that are not part of a catalog ("orphan" templates).

CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

Thanks for this! Will try this out asap Smiley Happy

How did you go about getting this done? Did you need to do the same in your organization? Did you get the code from trial and error?

Thanks again!

0 Kudos
AtanasAtanasov
VMware Employee
VMware Employee
Jump to solution

I am part of the PowerCLI team, just haven't got my VMware icon yet.

Can you share some info on the context where you would use this script - like why would you want this done with a script and not the GUI?

Brox
Contributor
Contributor
Jump to solution

Nice! We can use these for our migration to vCD. This will be the final piece of my Migration script. Thanks

0 Kudos
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

Thanks AtanasAtanasov! We currently use LabManager and are prepping the migration to vCD and Since we will be provisioning out 100 odd vApps every few months, I need to be able to script everything.Your bit of code worked great for capturing the vApp to template and adding it to the catalog created with my code above.

Now how do go about adding a template in a Catalog to "My Cloud" ? $orgvdc.ExtensionData.InstantiateVAppTemplate() or $orgvdc.ExtensionData.ComposeVApp()?

Also how do I get what paramaters are expected for the methods like ExtensionData.InstantiateVAppTemplate() ? Is there a doc I can look at so I know what parameters to pass to all these ExtensionData methods.


Thanks for the input, it's all helpful!

0 Kudos
AtanasAtanasov
VMware Employee
VMware Employee
Jump to solution

The ExtensionData and Get-CIView are exposing the vCloud REST API. The documentation is available here: https://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/index.html. What PowerCLI exposes is slightly different though. We are going to publish a separate documentation at some later point that would be more accurate.

Note that the interface PowerCLI exposes to .Net is not the same as the C# SDK for vCloud.

To get to the documentation of the 2 operations, you should set the search scope to All Operations and search for InstantiateVAppTemplate or ComposeVApp, follow the Input type link to InstantiateVAppTemplateParams/ComposeVAppParams.

Creating a vApp out of a vApp template is done with InstantiateVAppTemplate. ComposeVApp is for creating a vApp from scratch.

Just a side note: take a look at Import-CIVApp and Import-CIVAppTemplate, those are capable of "registering" a VM from vSphere in vCloud. That may be a faster way of migrating vSphere VMs to vCloud vApp templates as they can do the conversion without coping the VM.

0 Kudos
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

What PowerCLI exposes is slightly different though. We are going to  publish a separate documentation at some later point that would be more  accurate. Note that the interface PowerCLI exposes to .Net is not the same as the C# SDK for vCloud.

Thanks! Really looking forward to this documentation. There is lots I would like to Automated with vCloud Director, just never know where to start with a task.

0 Kudos