There are ways to get all Custom Groups, create new Custom Group definitions, modify existing Custom Group definitions, and more. But it's not clear how to add a VM to a Custom Group. I expected to see a PUT /api/resources/groups/{groupId} or a PUT /api/resources/groups/{groupId}/members, but neither exist.
So, how do we add VMs to Custom Groups via API? Here's how: PUT /api/resources/groups.
The example value isn't exactly what we need, this is.
{
"id": "e8efca27-5291-4687-bbd2-3440393801a7",
"resourceKey": {
"name": "Brocks VMs",
"adapterKindKey": "Container",
"resourceKindKey": "Environment",
"resourceIdentifiers": []
},
"autoResolveMembership": false,
"membershipDefinition": {
"includedResources": [
"7415711c-0212-433c-b548-e9e5116cde49"
],
"excludedResources": [],
"custom-group-properties": [],
"rules": [
{
"resourceKindKey": {
"resourceKind": "VirtualMachine",
"adapterKind": "VMWARE"
},
"statConditionRules": [],
"propertyConditionRules": [],
"resourceNameConditionRules": [
{
"name": "bpeterson",
"compareOperator": "CONTAINS"
}
],
"relationshipConditionRules": [],
"resourceTagConditionRules": []
}
]
}
}
A few things to note here:
"id" in this case is the id of the Custom Group. You can get this via GET /api/resources/groups
The "includedResources" here is the VM id. You can get this via GET /api/resources. In my example, I'd like to add VM mpb-1 to my Custom Group, so I've adjusted includedResources to the VM id.
resourceKind is Virtual Machine, indicating we're adding VMs to the custom group.
resourceNameConditionRules includes the existing Custom Group definition, which is VMs that contain "bpeterson". Without this, the new Custom Group definition will include only the single VM you just added.
Here's my Custom Group before running the PUT /api/resources/groups referenced above.
Here's my Custom Group after running the PUT /api/resources/groups referenced above.
You'll notice VM mpb-1 is now in my Custom Group. This is really less of an "adding VMs to an existing Custom Group" methodology and more of a "creating new Custom Group definition by adjusting our old definition", but serves our purpose. I've asked our API developent team for better documentation on this use case and a specific API endpoint for this use case, something like PUT /api/resources/groups/{groupId} or PUT /api/resources/groups/{groupId}/members. Until then, this will suffice.
Thanks to Broadcom Engineer Lusine Sargsyan for your insight!
Comments