Quantcast
Channel: VMware Communities : All Content - vCloud Networking and Security
Viewing all articles
Browse latest Browse all 890

Add vNIC to PortGroup Scope Security Group with REST API

$
0
0

I have created a Security Group with the scope of a PortGroup via the REST API. I am now trying to add a vNIC to it, also via the REST API.

 

To help illustrate I have a VM JMTest1 with 1 vNIC connected to the PortGroup that is the scope of the Security Group. When I edit this Security Group the first item in the list that could be added into the group is the first (and only) vNIC of JMTest1.

 

AddvNICToSecurityGroup.PNG

 

To add it via the REST API I need to supply the following:

 

https://192.168.x.x/api/2.0/services/securitygroup/securitygroup-xx/members/<member-moref>

 

i.e. I need to figure out what is the <member-moref> for the vNIC of JMTest1 and this is what I am having trouble with.

 

If I add the vNIC via the GUI and then query the Security Group it gives me the below response:

 

<securitygroup>

  <objectIdobjectId>securitygroup-xx</objectId>

  <type>

  <typeName>SecurityGroup</typeName>

  </type>

  <name>JMTest7</name>

  <description />

  <revision>9</revision>

  <objectTypeName>SecurityGroup</objectTypeName>

  <scope>

  <id>dvportgroup-xxxxx</id>

  <objectTypeName>DistributedVirtualPortgroup</objectTypeName>

  <name>dv-xxxxx</name>

  </scope>

  <extendedAttributes />

  <inheritanceAllowed>false</inheritanceAllowed>

  <member>

  <objectId>500758f6-b97b-7a79-0c04-996f53edf3f0.000</objectId>

  <type>

  <typeName>Vnic</typeName>

  </type>

  <name>JMTest1 - Network adapter 1</name>

  <revision>6</revision>

  <objectTypeName>Vnic</objectTypeName>

  <scope>

  <id>vm-xxxxx</id>

  <objectTypeName>VirtualMachine</objectTypeName>

  <name>JMTest1</name>

  </scope>

  <extendedAttributes />

  </member>

</securitygroup>

 

 

So it looks like the <member-moref> for the vNIC of JMTest1 is <objectId>500758f6-b97b-7a79-0c04-996f53edf3f0.000</objectId>

 

If I now run:

 

https://192.168.x.x/api/2.0/services/securitygroup/securitygroup-xx/members/500758f6-b97b-7a79-0c04-996f53edf3f0.000

 

then the vNIC is successfully added to the Security Group. (yay!) So I am now left with the task of how to get

 

<objectId>500758f6-b97b-7a79-0c04-996f53edf3f0.000</objectId>

 

from a vNIC?

 

I've examined the object in the vCenter Mob and via PowerCLI, but can't see how to derive it.

 

Anyone know the answer to this?


Viewing all articles
Browse latest Browse all 890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>