1 Reply Latest reply on Aug 5, 2019 6:17 AM by mauricioamorim

    GET logical-switches API with attached VMs and Faliure to attach VMs to a logical switch

    Cloudistan Lurker

      Hello all,

      I have the following issues regarding logical switches in NSX-T:

       

      1.I need to make an API request that will return logical switches and a list of assigned VMs for each switch.

      so far i have tried "/api/v1/logical-switches" but it does not return any assigned VMs, which might be because it just doesn't return that info, or because of the next issue.

       

      2.Failure to define a specific port for a VM:

      • I created a VM instance and a logical switch
      • VSphere - In the VM settings->network adapter i assigned a logical switch (CloudSwitch for example)

      • NSX-T -  In advanced network->networking->switching->ports i created "cloudport" and assigned VIF:22

       

      How do i connect a VM to a specific port in "CloudSwitch"?

       

      Do i have to in order to attach a VM to a specific port, like in NSX-V?

      In NSX-T VSphere i tried to add VM1 to a port and nothing happens, i get no MAC and API still doesn't return VMs with the logical-switch request.

       

       

      Much obliged

        • 1. Re: GET logical-switches API with attached VMs and Faliure to attach VMs to a logical switch
          mauricioamorim Hot Shot
          VMware Employees

          I didn't quite understand what you are trying to do, but let me try answering what I can.

           

          "I need to make an API request that will return logical switches and a list of assigned VMs for each switch."

           

          To list all logical switches you can use GET /api/v1/logical-switches.

           

           

          I tried it out and it works. Here's an example of what I got for one of my logical-switches:

           

          {

           

             "switch_type": "DEFAULT",

             "transport_zone_id": "55d38c20-7187-4f78-a5c9-3395e7705cd8",

             "vni": 73728,

             "admin_state": "UP",

             "replication_mode": "MTEP",

             "address_bindings": [],

             "switching_profile_ids": [

            {

             "key": "SwitchSecuritySwitchingProfile",

             "value": "fbc4fb17-83d9-4b53-a286-ccdf04301888"

            },

            {

             "key": "SpoofGuardSwitchingProfile",

             "value": "fad98876-d7ff-11e4-b9d6-1681e6b88ec1"

            },

            {

             "key": "IpDiscoverySwitchingProfile",

             "value": "64814784-7896-3901-9741-badeff705639"

            },

            {

             "key": "MacManagementSwitchingProfile",

             "value": "1e7101c8-cfef-415a-9c8c-ce3d8dd078fb"

            },

            {

             "key": "PortMirroringSwitchingProfile",

             "value": "93b4b7e8-f116-415d-a50c-3364611b5d09"

            },

            {

             "key": "QosSwitchingProfile",

             "value": "f313290b-eba8-4262-bd93-fab5026e9495"

            }

            ],

             "hybrid": false,

             "resource_type": "LogicalSwitch",

             "id": "37b6b634-bab4-489f-9b37-9b395e734886",

             "display_name": "LS-Host-Overlay",

             "tags": [

            {

             "scope": "policyPath",

             "tag": "/infra/segments/LS-Host-Overlay"

            },

            {

             "scope": "subnet-cidr",

             "tag": "172.29.61.0/24"

            }

            ],

             "_create_user": "nsx_policy",

             "_create_time": 1564661899584,

             "_last_modified_user": "nsx_policy",

             "_last_modified_time": 1564663151560,

             "_system_owned": false,

             "_protection": "REQUIRE_OVERRIDE",

             "_revision": 1,

             "_schema": "/v1/schema/LogicalSwitch"

            },

           

          Then to list what is connected to this logical switch you have to use /api/v1/logical-ports and search for the LogicalSwitch ID you want. In my example above I can find that I have a VM on the logical-switch shown above:

           

          {

           

             "logical_switch_id": "37b6b634-bab4-489f-9b37-9b395e734886",

             "attachment": {

             "attachment_type": "VIF",

             "id": "e02641d1-65e6-48c6-9dfd-aa9af0854a81"

            },

             "admin_state": "UP",

             "address_bindings": [],

             "switching_profile_ids": [

            {

             "key": "SwitchSecuritySwitchingProfile",

             "value": "fbc4fb17-83d9-4b53-a286-ccdf04301888"

            },

            {

             "key": "SpoofGuardSwitchingProfile",

             "value": "fad98876-d7ff-11e4-b9d6-1681e6b88ec1"

            },

            {

             "key": "IpDiscoverySwitchingProfile",

             "value": "64814784-7896-3901-9741-badeff705639"

            },

            {

             "key": "MacManagementSwitchingProfile",

             "value": "1e7101c8-cfef-415a-9c8c-ce3d8dd078fb"

            },

            {

             "key": "PortMirroringSwitchingProfile",

             "value": "93b4b7e8-f116-415d-a50c-3364611b5d09"

            },

            {

             "key": "QosSwitchingProfile",

             "value": "f313290b-eba8-4262-bd93-fab5026e9495"

            }

            ],

             "ignore_address_bindings": [],

             "resource_type": "LogicalPort",

             "id": "a5b3875c-b396-4ed9-a479-fca2ec5e8a51",

             "display_name": "LinuxOverlay/LinuxOverlay.vmx@23008cc0-298d-4dac-b67f-7d8ee751232f",

             "_create_user": "system",

             "_create_time": 1564662492341,

             "_last_modified_user": "system",

             "_last_modified_time": 1564662492341,

             "_system_owned": false,

             "_protection": "NOT_PROTECTED",

             "_revision": 0

            },

           

          The display_name shows what is connected. In my case I have a VM called LinuxOverlay.

           

          These 2 calls together enable you to list all VMs connected to logical-switches, which I understand is what you are ultimately trying to accomplish.