I recently created an environment that had a VRA XaaS to apply a security tag to individual virtual machines. I wanted to share the code I wrote to speed up your adoption. In this case we have a scriptable task to do the work. We have one parameter:
We have two attributes:
Here is the code:
Here is the code for cut and paste usage:
//name = ‘dev-214’;
vms = VcPlugin.getAllVirtualMachines();
for each (vm in vms) {
if (vm.Name == name) {
System.log(“VM name: ” + vm.name + ” MOID: ” + vm.id);
machineMOID = vm.id;
}
}
// Apply the tag
NSXSecurityTagManager.applySecurityTagOnVMs(connection, machineMOID, tag);