- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wondering has anyone been able to achieve this? I've built a powershell script that goes and adds a group to NSX with one tag and this works fine below is the structure.
$body = @{
"expression" = @(
@{
"member_type" = "VirtualMachine"
"value" = "test|simple"
"key" = "Tag"
"operator" = "EQUALS"
"resource_type" = "Condition"
}
)
"description" = "Simple"
"display_name" = "Simple"
"_revision" = 0
}
The problem arises when I try and add more than one tag. I can't find anything in the documentation. I've queried against the API to see how the data is structure in NSX and it returns the below (sensitive info removed)
{
"expression": [
{
"expressions": [
{
"member_type": "VirtualMachine",
"key": "Tag",
"operator": "EQUALS",
"scope_operator": "EQUALS",
"value": "test|simple"
},
{
"conjunction_operator": "AND",
"resource_type": "ConjunctionOperator"
},
{
"member_type": "VirtualMachine",
"key": "Tag",
"operator": "EQUALS",
"scope_operator": "EQUALS",
"value": "sample|tag
}
I've built queries structured similarly to this request but it seems the it's not a valid expression so wondering how anyone has been able to implement this or if it is at all possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Having read the API documentation in it's fullest, it does not support Conjunction Operator, hopefully be added in the future
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure if this is exactly what you are trying to do, but I was able to create a new group with two expressions using the NSX-T REST API. I'm using a direct rest call from vRO, but the principle should be the same for PowerCLI
var expression = [];
expression.push({
"member_type": "VirtualMachine",
"value": "tag-1",
"key": "Tag",
"operator": "EQUALS",
"resource_type": "Condition"
})
// Not Adding a ConjunctionOperator to the expression list will make the API Call Fail
// The expression array index lenght must always be odd
expression.push({
"conjunction_operator": "AND",
"resource_type": "ConjunctionOperator"
});
expression.push({
"member_type": "VirtualMachine",
"value": "tag-2",
"key": "Tag",
"operator": "EQUALS",
"resource_type": "Condition"
})
// expression.length == 3
var group = {
"expression": expression,
"display_name": "NewGroup",
"description": "Testing Gropu Creation with multiple expressions"
};
var content = JSON.stringify(group);
System.log("Request Body is: " + content);
var restHost = System.getModule("com.domain.basic").getConfigurationElementAttributeValueWithPath("Domain", "NSXT", "restHost");
var restRequest = restHost.createRequest("PUT", "policy/api/v1/infra/domains/{yourdomain]/groups/NewGroup", content);
restRequest.contentType = "application/json";
var requestResponse = restRequest.execute();
Here is the result of the API Call in NSX-T
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It should be possible (the Terraform provider supports it at least).
Make sure you have the syntax completely correct. Based on the output there, you'll need both expression AND expressions in your body.