可以使用 NSX-T Data Center API 为主机上运行的应用程序配置网络和带宽。

过程

  1. 查询主机以同时显示系统定义的和用户定义的主机交换机配置文件。
  2. GET https://<nsx-mgr>/api/v1/host-switch-profiles?include_system_owned=true

    示例响应显示应用于主机的 NIOC 配置文件。

    { 
      "description": "This profile is created for Network I/O Control (NIOC).",  
      "extends": { 
      "$ref": "BaseHostSwitchProfile"+ 
      },  
      "id": "NiocProfile",  
      "module_id": "NiocProfile",  
      "polymorphic-type-descriptor": { 
      "type-identifier": "NiocProfile" 
      },  
      "properties": { 
      "_create_time": { 
      "$ref": "EpochMsTimestamp"+,  
      "can_sort": true,  
      "description": "Timestamp of resource creation",  
      "readonly": true 
        },  
      "_create_user": { 
      "description": "ID of the user who created this resource",  
      "readonly": true,  
      "type": "string" 
        },  
      "_last_modified_time": { 
      "$ref": "EpochMsTimestamp"+,  
      "can_sort": true,  
      "description": "Timestamp of last modification",  
      "readonly": true 
        },  
    
      "_last_modified_user": { 
      "description": "ID of the user who last modified this resource",  
      "readonly": true,  
      "type": "string" 
        },  
    
      "_links": { 
      "description": "The server will populate this field when returning the resource. Ignored on PUT and POST.",  
      "items": { 
      "$ref": "ResourceLink"+ 
        },  
    
      "readonly": true,  
      "title": "References related to this resource",  
      "type": "array" 
        },  
      "_protection": { 
      "description": "Protection status is one of the following: 
         PROTECTED - the client who retrieved the entity is not allowed to modify it. 
         NOT_PROTECTED - the client who retrieved the entity is allowed to modify it 
         REQUIRE_OVERRIDE - the client who retrieved the entity is a super user and can modify it,  
         but only when providing the request header X-Allow-Overwrite=true. 
         UNKNOWN - the _protection field could not be determined for this entity.", 
      "readonly": true,  
      "title": "Indicates protection status of this resource",  
      "type": "string" 
        },  
    
      "_revision": { 
      "description": "The _revision property describes the current revision of the resource.  
        To prevent clients from overwriting each other's changes, PUT operations must include the 
    			 current _revision of the resource, 
        which clients should obtain by issuing a GET operation. 
    				If the _revision provided in a PUT request is missing or stale, the operation will be rejected.",  
      "readonly": true,  
      "title": "Generation of this resource config",  
      "type": "int" 
        },  
    
      "_schema": { 
      "readonly": true,  
      "title": "Schema for this resource",  
      "type": "string" 
        },  
    
      "_self": { 
      "$ref": "SelfResourceLink"+,  
      "readonly": true,  
      "title": "Link to this resource" 
        },  
    
      "_system_owned": { 
      "description": "Indicates system owned resource",  
      "readonly": true,  
      "type": "boolean" 
        },  
    
      "description": { 
      "can_sort": true,  
      "maxLength": 1024,  
      "title": "Description of this resource",  
      "type": "string" 
        },  
    
      "display_name": { 
      "can_sort": true,  
      "description": "Defaults to ID if not set",  
      "maxLength": 255,  
      "title": "Identifier to use when displaying entity in logs or GUI",  
      "type": "string" 
        },  
    
      "enabled": { 
      "default": true,  
      "description": "The enabled property specifies the status of NIOC feature.  
    
      When enabled is set to true, NIOC feature is turned on and the bandwidth allocations
    	 specified for the traffic resources are enforced.
      When enabled is set to false, NIOC feature is turned off and no bandwidth allocation is guaranteed. 
    
      By default, enabled will be set to true.",  
    
      "nsx_feature": "Nioc",  
      "required": false,  
      "title": "Enabled status of NIOC feature",  
      "type": "boolean" 
        },  
    
      "host_infra_traffic_res": { 
      "description": "host_infra_traffic_res specifies bandwidth allocation for various traffic    resources.",  
      "items": { 
      "$ref": "ResourceAllocation"+ 
        },  
      "nsx_feature": "Nioc",  
      "required": false,  
      "title": "Resource allocation associated with NiocProfile",  
      "type": "array" 
        },  
    
      "id": { 
      "can_sort": true,  
      "readonly": true,  
      "title": "Unique identifier of this resource",  
      "type": "string" 
        },  
    
      "required_capabilities": { 
      "help_summary": 
    							"List of capabilities required on the fabric node if this profile is used. 
          	The required capabilities is determined by whether specific features are enabled in the profile.",  
      "items": { 
      "type": "string" 
        },  
      "readonly": true,  
      "required": false,  
      "type": "array" 
        },  
    
      "resource_type": { 
      "$ref": "HostSwitchProfileType"+,  
      "required": true 
        },  
    
      "tags": { 
      "items": { 
      "$ref": "Tag"+ 
          },  
    
      "maxItems": 30,  
      "title": "Opaque identifiers meaningful to the API user",  
      "type": "array" 
        } 
      },  
      "title": "Profile for Nioc",  
      "type": "object" 
      } 
  3. 如果 NIOC 配置文件不存在,则创建一个 NIOC 配置文件。
    POST https://<nsx-mgr>/api/v1/host-switch-profiles
    { 
      "description": "Specify limit, shares and reservation for all kinds of traffic. 
       Values for limit and reservation are expressed in percentage. And for shares, 
       the value is expressed as a number between 1-100.\nThe overall reservation among all traffic types should not exceed 75%. 
       Otherwise, the API request will be rejected.",  
    
      "id": "ResourceAllocation",  
      "module_id": "NiocProfile",  
      "nsx_feature": "Nioc",  
      "properties": { 
        "limit": { 
          "default": -1.0,  
          "description": "The limit property specifies the maximum bandwidth allocation for a given 
          traffic type and is expressed in percentage. The default value for this 
          field is set to -1 which means the traffic is unbounded for the traffic 
          type. All other negative values for this property is not supported\nand will be rejected by the API.",  
          "maximum": 100,  
          "minimum": -1,  
          "required": true,  
          "title": "Maximum bandwidth percentage",  
          "type": "number" 
        },  
    
        "reservation": { 
          "default": 0.0,  
          "maximum": 75,  
          "minimum": 0,  
          "required": true,  
          "title": "Minimum guaranteed bandwidth percentage",  
          "type": "number" 
        },  
    
        "shares": { 
          "default": 50,  
          "maximum": 100,  
          "minimum": 1,  
          "required": true,  
          "title": "Shares",  
          "type": "int" 
        },  
    
        "traffic_type": { 
          "$ref": "HostInfraTrafficType"+,  
          "required": true,  
          "title": "Resource allocation traffic type" 
        } 
    
      },  
    
      "title": "Resource allocation information for a host infrastructure traffic type",  
      "type": "object"
  4. 使用新创建的 NIOC 配置文件的 NIOC 配置文件 ID,更新传输节点配置。
    PUT https://<nsx-mgr>/api/v1/transport-nodes/<TN-id>
    { 
        "resource_type": "TransportNode", 
        "description": "Updated NSX configured Test Transport Node", 
        "id": "77816de2-39c3-436c-b891-54d31f580961", 
        "display_name": "NSX Configured TN", 
        "host_switch_spec": { 
          "resource_type": "StandardHostSwitchSpec", 
          "host_switches": [ 
            { 
            "host_switch_profile_ids": [ 
              { 
                "value": "e331116d-f59e-4004-8cfd-c577aefe563a", 
                "key": "UplinkHostSwitchProfile" 
              }, 
            { 
           "value": "9e0b4d2d-d155-4b4b-8947-fbfe5b79f7cb", 
           "key": "LldpHostSwitchProfile" 
            } 
           {  
            "value": "b0185099-8003-4678-b86f-edd47ca2c9ad",  
            "key": "NiocProfile"  
           } 
            ], 
           "host_switch_name": "nsxvswitch", 
           "pnics": [ 
          { 
           "device_name": "vmnic1", 
           "uplink_name": "uplink1" 
          } 
          ], 
          "ip_assignment_spec": { 
          "resource_type": "StaticIpPoolSpec", 
          "ip_pool_id": "ecddcdde-4dc5-4026-ad4f-8857995d4c92" 
          } 
           } 
          ] 
        }, 
         "transport_zone_endpoints": [ 
          { 
          "transport_zone_id": "e14c6b8a-9edd-489f-b624-f9ef12afbd8f", 
          "transport_zone_profile_ids": [ 
            { 
              "profile_id": "52035bb3-ab02-4a08-9884-18631312e50a", 
              "resource_type": "BfdHealthMonitoringProfile" 
            } 
          ] 
          } 
        ], 
    
         "host_switches": [ 
          { 
            "host_switch_profile_ids": [ 
              { 
              "value": "e331116d-f59e-4004-8cfd-c577aefe563a", 
              "key": "UplinkHostSwitchProfile" 
             }, 
              { 
              "value": "9e0b4d2d-d155-4b4b-8947-fbfe5b79f7cb", 
              "key": "LldpHostSwitchProfile" 
              } 
            ], 
    
            "host_switch_name": "nsxvswitch", 
            "pnics": [ 
            { 
              "device_name": "vmnic1", 
              "uplink_name": "uplink1" 
              } 
            ], 
            "static_ip_pool_id": "ecddcdde-4dc5-4026-ad4f-8857995d4c92" 
          } 
        ], 
        "node_id": "41a4eebd-d6b9-11e6-b722-875041b9955d", 
        "_revision": 0 
      } 
  5. 确认在 com.vmware.common.respools.cfg 文件中已更新 NIOC 配置文件参数。
    # [root@ host:] net-dvs -l
    			switch 1d 73 f5 58 99 7a 46 6a-9c cc d0 93 17 bb 2a 48 (vswitch) 
       max ports: 2560 
       global properties: 
    
       com.vmware.common.opaqueDvs = true ,     propType = CONFIG 
       com.vmware.nsx.kcp.enable = true ,     propType = CONFIG 
       com.vmware.common.alias = nsxvswitch ,     propType = CONFIG 
       com.vmware.common.uplinkPorts: uplink1   propType = CONFIG 
       com.vmware.common.portset.mtu = 1600, propType = CONFIG 
       com.vmware.etherswitch.cdp = LLDP, listen  propType = CONFIG 
       com.vmware.common.respools.version = version3,   propType = CONFIG 
       com.vmware.common.respools.cfg: 
       netsched.pools.persist.ft:0:50:-1:255 
       netsched.pools.persist.hbr:0:50:-1:255 
       netsched.pools.persist.vmotion:0:50:-1:255 
       netsched.pools.persist.vm:0:100:-1:255 
       netsched.pools.persist.iscsi:0:50:-1:255 
       netsched.pools.persist.nfs:0:50:-1:255 
       netsched.pools.persist.mgmt:0:50:-1:255 
       netsched.pools.persist.vdp:0:50:-1:255 
       netsched.pools.persist.vsan:0:50:-1:255 
       propType = CONFIG
  6. 确认主机内核中的 NIOC 配置文件。
    # [root@ host:] vsish
    / > get /net/portsets/DvsPortset-1/ports/50335755/niocVnicInfo
    Vnic NIOC Info 
    					{ 
          Uplink reserved on:vmnic4 
          Reservation in Mbps:200 
          Shares:50 
          Limit in Mbps:4294967295 
          World ID:1001400726 
          vNIC Index:0 
          Respool Tag:0 
          NIOC Version:3 
          Active Uplink Bit Map:15 
          Parent Respool ID:netsched.pools.persist.vm 
         } 
  7. 确认 NIOC 配置文件信息。
    # [root@ host:] vsish
    / > get /net/portsets/DvsPortset-1/uplinks/vmnic4/niocInfo
    Uplink NIOC Info 
    			{ 
        Uplink device:vmnic4 
        Link Capacity in Mbps:750 
        vm respool reservation:275 
        link status:1 
        NetSched Ready:1 
        Infrastructure reservation:0 
        Total VM reservation:200 
        Total vnics on this uplink:1 
        NIOC Version:3 
        Uplink index in BitMap:0 
       }

结果

NIOC 配置文件将配置有 NSX-T Data Center 主机上运行的应用程序的预定义带宽分配。