Create/Update Metadata of Cloud Director Objects (KB#00096)

Overview

You can easily create/modify metadata for any Cloud Director object using GUI but it is a challenge if there is no option to modify or create metadata from GUI and according to your requirement. This is the issue with VMware Cloud Director 10.1.2. This version not only doesn't have this option from GUI but also existing metadata entries are not editable from GUI. This is the reason, I had to find some other way out.

As a solution, either you need to do it from APIs or from PowerShell. I will demonstrate both ways here. You may choose which sounds easy for you. Same method will be followed in future versions as well if VMware haven't plan to change the Metadata Format as they did for older versions of vCD. This is the reason that most of the articles on web don't give you exact information as those are outdated now.

Solution 1: From PowerCLI

=======
$vcd = Read-Host "Enter fqdn/IP here"
Connect-CIServer $vcd
#In below line, you need to specifiy the object whether it is VM, vAPP, Org or OrgvDC. Command will change accordingly. For example, for VM, you will use Get-CIVM. For Org, you will use Get-Org and so on...
$vapp = Get-CIVApp -Name testconsole
$metadata = $vapp.extensiondata.GetMetadata()
$metadata.MetadataEntry = New-Object VMware.VimAutomation.Cloud.Views.MetadataEntry
$metadata.MetadataEntry[0].Key = "vCnotes"
$metadata.MetadataEntry[0].TypedValue = New-Object VMware.VimAutomation.Cloud.Views.MetadataStringValue
$metadata.MetadataEntry[0].TypedValue.Value = "test"
$metadata.MetadataEntry[0].Domain = New-Object VMware.VimAutomation.Cloud.Views.MetadataDomainTag
$metadata.MetadataEntry[0].Domain.Visibility = "readonly"
$metadata.MetadataEntry[0].Domain.Value = "SYSTEM" $vapp.ExtensionData.CreateMetadata($metadata)
=======

Copy the above lines and change it according to your environment and run it. You need to modify the yellow highlighted value according to your environment.

Note that : 

1. To update existing entry, you can run above command by keeping key name same. It will update the existing keys.
2. If you are Tenant Administrator then you won't be able to see the private visible keys but still can modify using this commands.

Solution 2: From any API Tool : It is lengthy and complex one.

I will take sometime to update this post. Meanwhile, enjoy using Solution 1 ;)

For any doubt/error in powercli, feel free to comment.

0 Comments:

Post a Comment