VMware Cloud Community
WillianCardoso
Contributor
Contributor
Jump to solution

How create new TAGs in NSX-T by powercli or API (curl)

Hey guys,

I'm browsing the internet and I still haven't found a way to create new TAGs in NSX-T via the command line with curl or powercli

I found several ways to create segment, group, DFWSecurity, T0 and T1 (link), but not TAG yet.

See, I need to create a NEW TAG and not associate existing TAGs on a virtual machine

In documentation (link), I only list the TAGs. Not see a way to create TAGs

Is this still possible?

NSX-T Version 3.2.3.1.0.22104592

PowerCLI Version 13.1.0 build 21624340

 

tks

Labels (6)
0 Kudos
1 Solution

Accepted Solutions
kjellcomputer
Enthusiast
Enthusiast
Jump to solution

Hi, out of curiosity, what happens when you just try and add a new tag that does not exists to a Virtual Machine?

https://vdc-repo.vmware.com/vmwb-repository/dcr-public/5d1f1d9e-6c0f-4a63-9ca2-5f1bb7b61ea3/c970c79c...

POST https://<nsx-mgr>/api/v1/fabric/virtual-machines?action=add_tags
{
    "external_id": "ID-0",
    "tags": [
        {"scope": "os", "tag": "win32"},
        {"scope": "security", "tag": "PCI"}
    ]
}

 You could perhaps also just skip the scope value if preferred, like this:

POST https://<nsx-mgr>/api/v1/fabric/virtual-machines?action=add_tags
{
    "external_id": "ID-0",
    "tags": [
        {"scope": "", "tag": "My-New-Tag"}
    ]
}

 

View solution in original post

0 Kudos
2 Replies
kjellcomputer
Enthusiast
Enthusiast
Jump to solution

Hi, out of curiosity, what happens when you just try and add a new tag that does not exists to a Virtual Machine?

https://vdc-repo.vmware.com/vmwb-repository/dcr-public/5d1f1d9e-6c0f-4a63-9ca2-5f1bb7b61ea3/c970c79c...

POST https://<nsx-mgr>/api/v1/fabric/virtual-machines?action=add_tags
{
    "external_id": "ID-0",
    "tags": [
        {"scope": "os", "tag": "win32"},
        {"scope": "security", "tag": "PCI"}
    ]
}

 You could perhaps also just skip the scope value if preferred, like this:

POST https://<nsx-mgr>/api/v1/fabric/virtual-machines?action=add_tags
{
    "external_id": "ID-0",
    "tags": [
        {"scope": "", "tag": "My-New-Tag"}
    ]
}

 

0 Kudos
WillianCardoso
Contributor
Contributor
Jump to solution

\o/ it's work !!!

I thought I needed to create first the tag and after associate it with some virtual machine. But not, I create and associate the some time.

it's too bad that this request not return 200 as return code, but resolve my problem.


 

[localhost]$ curl -k -X POST -u 'user:pass' -H 'Content-Type: application/json' https://IP-NSX/api/v1/fabric/virtual-machines?action=add_tags -d '{
> "external_id": "500f5273-7554-5071-450d-1ff47a7d91e4",
> "tags": [
> {"scope": "", "tag": "New-Tag"}
> ]
> }
> '
[localhost]$ 

 

Tks a lot 

0 Kudos