create_segment
Create a new network segment in VMware NSX by specifying ID, name, transport zone, VLAN IDs, and subnet configuration.
Instructions
Create a new network segment.
Args: segment_id: Unique ID for the segment (used in policy path). display_name: Human-readable name for the segment. transport_zone_path: Full policy path to the transport zone. vlan_ids: VLAN ID(s) for VLAN-backed segments (e.g. "100" or "100-200"). subnet: Gateway CIDR for the segment (e.g. "192.168.1.1/24"). target: Optional NSX Manager target name from config. Uses default if omitted.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| segment_id | Yes | ||
| display_name | Yes | ||
| transport_zone_path | Yes | ||
| vlan_ids | No | ||
| subnet | No | ||
| target | No |
Implementation Reference
- vmware_nsx/ops/segment_mgmt.py:39-86 (handler)Implementation of create_segment, which uses the NSX Policy API PUT method to create a segment.
def create_segment( client: NsxClient, segment_id: str, display_name: str, transport_zone_path: str, gateway_path: str | None = None, subnets: list[dict[str, str]] | None = None, vlan_ids: list[int] | None = None, ) -> dict: """Create a new network segment via Policy API (PUT). Args: client: Authenticated NSX API client. segment_id: Unique segment identifier. display_name: Human-readable name. transport_zone_path: Policy path to the transport zone. gateway_path: Policy path to Tier-0/Tier-1 gateway (for routed segments). subnets: List of subnet dicts, each with "gateway_address" and optionally "dhcp_ranges". vlan_ids: List of VLAN IDs (for VLAN-backed segments). Returns: Created segment dict from NSX API. """ _validate_id(segment_id) body: dict[str, Any] = { "display_name": _sanitize(display_name), "transport_zone_path": transport_zone_path, } if gateway_path: body["connectivity_path"] = gateway_path if subnets: body["subnets"] = [ {"gateway_address": sub["gateway_address"]} for sub in subnets if "gateway_address" in sub ] if vlan_ids: body["vlan_ids"] = vlan_ids path = f"/policy/api/v1/infra/segments/{segment_id}" result = client.put(path, body) _log.info("Created segment %s (%s)", segment_id, display_name) return result