From cff2f29b9735408dd6a4ffa6e0ba0ffa5ed57948 Mon Sep 17 00:00:00 2001 From: AndyG Date: Fri, 24 Aug 2018 16:32:35 -0400 Subject: [PATCH 1/6] Added Get-TraceFlows Added Get-TraceFlows. Will add to export list if it looks good. --- Modules/NSXT/NSXT.psm1 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Modules/NSXT/NSXT.psm1 b/Modules/NSXT/NSXT.psm1 index a6afe2d..8616e88 100644 --- a/Modules/NSXT/NSXT.psm1 +++ b/Modules/NSXT/NSXT.psm1 @@ -293,4 +293,37 @@ Function Get-NSXTTransportNodes { } $results +} + +Function Get-NSXTTraceFlows { + Param ( + [parameter(Mandatory=$false,ValueFromPipeline=$true)][string]$Id + ) + + $NSXTraceFlowsService = Get-NsxtService -Name "com.vmware.nsx.traceflows" + + if($Id) { + $NSXTraceFlows = $NSXTraceFlowsService.get($Id) + } else { + $NSXTraceFlows = $NSXTraceFlowsService.list().results + } + + $results = @() + foreach ($NSXTraceFlow in $NSXTraceFlows) { + + $tmp = [pscustomobject] @{ + Id = $NSXTraceFlow.Id; + Operation_State = $NSXTraceFlow.operation_state; + Delivered = $NSXTraceFlow.Counters.delivered_count; + Dropped = $NSXTraceFlow.Counters.dropped_count; + Analysis = $NSXTraceFlow.maintenance_mode; + } + $results+=$tmp + } + + $results + + if ($Id) { + write-output $Id + } } \ No newline at end of file From 3c5e8363ed71db1a850fb6d31ce06a36ca082910 Mon Sep 17 00:00:00 2001 From: AndyG Date: Fri, 24 Aug 2018 16:34:11 -0400 Subject: [PATCH 2/6] Added Get-TraceFlowsObservations Added Get-TraceFlowsObservations. Will add to export if it looks ok. --- Modules/NSXT/NSXT.psm1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Modules/NSXT/NSXT.psm1 b/Modules/NSXT/NSXT.psm1 index 8616e88..bfb320f 100644 --- a/Modules/NSXT/NSXT.psm1 +++ b/Modules/NSXT/NSXT.psm1 @@ -326,4 +326,20 @@ Function Get-NSXTTraceFlows { if ($Id) { write-output $Id } +} + +Function Get-NSXTTraceFlowObservations { + Param ( + [parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Id + ) + + $NSXTraceFlowsObservService = Get-NsxtService -Name "com.vmware.nsx.traceflows.observations" + + if($Id) { + $NSXTraceFlowsObserv = $NSXTraceFlowsObservService.list($Id) + } else { + throw "TraceFlow ID required" + } + + $NSXTraceFlowsObserv.results | select transport_node_name,component_name,@{N='PacketEvent';E={($_.resource_type).TrimStart("TraceflowObservation")}} } \ No newline at end of file From 1f6ec2c2c2188001bad863a36c0083458b42bdb6 Mon Sep 17 00:00:00 2001 From: AndyG Date: Fri, 24 Aug 2018 16:36:48 -0400 Subject: [PATCH 3/6] First try at a set- function - does not work! First try at a set- function. Does not work! Not clear how to resolve, the .create method ignores required parameters; looking for ideas. --- Modules/NSXT/NSXT.psm1 | 128 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/Modules/NSXT/NSXT.psm1 b/Modules/NSXT/NSXT.psm1 index bfb320f..b2f9c3c 100644 --- a/Modules/NSXT/NSXT.psm1 +++ b/Modules/NSXT/NSXT.psm1 @@ -342,4 +342,132 @@ Function Get-NSXTTraceFlowObservations { } $NSXTraceFlowsObserv.results | select transport_node_name,component_name,@{N='PacketEvent';E={($_.resource_type).TrimStart("TraceflowObservation")}} +} + +Function Set-NSXTTraceFlow { + [CmdletBinding()] + + # Paramameter Set variants will be needed Multicast & Broadcast Traffic Types as well as VM & Logical Port Types + Param ( + [parameter(Mandatory=$true, + ParameterSetName='Parameter Set VM Type')] + [ValidateSet("UNICAST")] + [string] + $TrafficType = "UNICAST", + [parameter(Mandatory=$true, + ValueFromPipeline=$true, + ParameterSetName='Parameter Set VM Type')] + [ValidateNotNullOrEmpty()] + #[ValidateScript({Get-NSXTLogicalPort -Id $_}] + [string] + $LPORTID, + [parameter(Mandatory=$true, + ValueFromPipeline=$true, + ParameterSetName='Parameter Set VM Type')] + [ValidateNotNullOrEmpty()] + [ValidateScript({$_ -match [IPAddress]$_})] + [string] + $SIPAddr, + [parameter(Mandatory=$true, + ValueFromPipeline=$true, + ParameterSetName='Parameter Set VM Type')] + [ValidateNotNullOrEmpty()] + [ValidateScript({$pattern = '^(([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2}))|(([0-9A-Fa-f]{2}[-]){5}([0-9A-Fa-f]{2}))$' + if ($_ -match ($pattern -join '|')) {$true} else { + throw "The argument '$_' does not match a valid MAC address format." + } + })] + [string] + $SMAC, + [parameter(Mandatory=$true, + ValueFromPipeline=$true, + ParameterSetName='Parameter Set VM Type')] + [ValidateNotNullOrEmpty()] + [ValidateScript({$_ -match [IPAddress]$_ })] + [string] + $DIPAddr, + [parameter(Mandatory=$true, + ValueFromPipeline=$true, + ParameterSetName='Parameter Set VM Type')] + [ValidateNotNullOrEmpty()] + [ValidateScript({$pattern = '^(([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2}))|(([0-9A-Fa-f]{2}[-]){5}([0-9A-Fa-f]{2}))$' + if ($_ -match ($pattern -join '|')) {$true} else { + throw "The argument '$_' does not match a valid MAC address format." + } + })] + [string] + $DMAC) + + Begin + { + if (-not $global:DefaultNsxtServers.isconnected) + { + + try + { + Connect-NsxtServer -Menu -ErrorAction Stop + } + + catch + { + throw "Could not connect to an NSX-T Manager, please try again" + } + } + + $NSXTraceFlowsService = Get-NsxtService -Name "com.vmware.nsx.traceflows" + + # This is where I need help - the method does not ingest the complete $traceflow_request object! + + # Create the example object + $traceflow_request = $NSXTraceFlowService.help.create.traceflow_request.Create() + $traceflow_request.lport_id = $LPORTID + $traceflow_request.timeout = '15000' + $traceflow_request.packet.routed = 'true' + $traceflow_request.packet.transport_type = $TrafficType.ToUpper() + $traceflow_request.packet.resource_type = 'FieldsPacketData' + $traceflow_request.packet.frame_size = '64' + + # The example object is missing packet data, so we create it. + $eth_header = @{src_mac = $SMAC;eth_type = '2048';dst_mac = $DMAC} + $ip_header = @{src_ip = $SIPAddr;protocol = '1';ttl = '64';dst_ip = $DIPAddr} + $traceflow_request.packet | Add-Member -NotePropertyMembers $eth_header -TypeName eth_header + $traceflow_request.packet | Add-Member -NotePropertyMembers $ip_header -TypeName ip_header + + # Alternative method of creating $traceflow_request (not working either) + <# + $TraceFlow_Request = [PSCustomObject]@{ + packet = @{routed = 'true'; + transport_type = $TrafficType.ToUpper(); + ip_header = @{src_ip = $SIPAddr;dst_ip = $DIPAddr}; + eth_header = @{dst_mac = $DMAC;src_mac = $SMAC}; + payload = 'test_payload'; + resource_type = 'FieldsPacketData'}; + timeout = '10000'; + lport_id = $LPORTID + } + #> + } + + Process + { + try + { + # This does not work, ignores eth_header,ip_header etc.. Not clear why!? + $NSXTraceFlow = $NSXTraceFlowService.create($traceflow_request) + } + + catch + { + $Error[0].Exception.ServerError.data + # more error data found in the NSX-T Manager /var/log/vmware/nsx-manager.log file. Filter by MONITORING. + } + } + + End + { + if ($NSXTraceFlow) + { + Get-NSXttraceflow + } + } } \ No newline at end of file From a753d8251bb756aa3c523302859a95874e87d290 Mon Sep 17 00:00:00 2001 From: AndyG Date: Wed, 12 Sep 2018 13:31:03 -0400 Subject: [PATCH 4/6] Major refactoring Major refactoring - replaced hashtables with classes. Can now accept pipeline input. --- Modules/NSXT/NSXT.psm1 | 342 +++++++++++++++++++++++++++++++---------- 1 file changed, 260 insertions(+), 82 deletions(-) diff --git a/Modules/NSXT/NSXT.psm1 b/Modules/NSXT/NSXT.psm1 index b2f9c3c..d80a565 100644 --- a/Modules/NSXT/NSXT.psm1 +++ b/Modules/NSXT/NSXT.psm1 @@ -259,89 +259,114 @@ Function Get-NSXTManager { $results } -Function Get-NSXTTransportNodes { +Function Get-NSXTTransportNode { Param ( - [parameter(Mandatory=$false,ValueFromPipeline=$true)][string]$Id + [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] + [Alias("Id","Tranportnode_id")] + [string]$transport_node_id ) - $transport_nodesService = Get-NsxtService -Name "com.vmware.nsx.transport_nodes" - $transport_nodesstateService = Get-NsxtService -Name "com.vmware.nsx.transport_nodes.state" - - if($Id) { - $transport_nodes = $transport_nodesService.get($Id) - } else { - $transport_nodes = $transport_nodesService.list().results - } + begin + { + $NSXTransportNodesService = Get-NsxtService -Name "com.vmware.nsx.transport_nodes" - $results = @() - foreach ($transport_node in $transport_nodes) { - - $transport_nodesstate = $transport_nodesstateService.get("$($transport_node.Id)") - - $tmp = [pscustomobject] @{ - Id = $transport_node.Id; - Name = $transport_node.display_name; - Tags = $transport_node.tags; - MaintenanceMode = $transport_node.maintenance_mode; - HostSwitchesName = $transport_node.host_switches.host_switch_name; - Default_gateway = $transport_nodesstate.host_switch_states.endpointsdefault_gateway; - Device_name = $transport_nodesstate.host_switch_states.endpoints.device_name; - Ip = $transport_nodesstate.host_switch_states.endpoints.ip; - Subnet_mask =$transport_nodesstate.host_switch_states.endpoints.subnet_mask + class NSXTransportNode { + [string]$Name + [string]$Tranport_node_id + [string]$maintenance_mode + hidden $tags = [System.Collections.Generic.List[string]]::new() + hidden $host_switches = [System.Collections.Generic.List[string]]::new() + hidden [string]$host_switch_spec + hidden $transport_zone_endpoints = [System.Collections.Generic.List[string]]::new() } - $results+=$tmp } - $results + Process + { + if($transport_node_id) { + $NSXTransportNodes = $NSXTransportNodesService.get($transport_node_id) + } else { + $NSXTransportNodes = $NSXTransportNodesService.list().results + } + + foreach ($NSXTransportNode in $NSXTransportNodes) { + + $results = [NSXTransportNode]::new() + $results.Name = $NSXTransportNode.display_name; + $results.Tranport_node_id = $NSXTransportNode.Id; + $results.maintenance_mode = $NSXTransportNode.maintenance_mode; + $results.Tags = $NSXTransportNode.tags; + $results.host_switches = $NSXTransportNode.host_switches; + $results.host_switch_spec = $NSXTransportNode.host_switch_spec; + $results.transport_zone_endpoints = $NSXTransportNode.transport_zone_endpoints; + $results.host_switches = $NSXTransportNode.host_switches + write-output $results + } + } } -Function Get-NSXTTraceFlows { +Function Get-NSXTTraceFlow { Param ( - [parameter(Mandatory=$false,ValueFromPipeline=$true)][string]$Id + [parameter(Mandatory=$false,ValueFromPipeline=$true)] + [Alias("Id")] + [string]$traceflow_id ) $NSXTraceFlowsService = Get-NsxtService -Name "com.vmware.nsx.traceflows" - if($Id) { - $NSXTraceFlows = $NSXTraceFlowsService.get($Id) + if($traceflow_id) { + $NSXTraceFlows = $NSXTraceFlowsService.get($traceflow_id) } else { $NSXTraceFlows = $NSXTraceFlowsService.list().results } - $results = @() - foreach ($NSXTraceFlow in $NSXTraceFlows) { - - $tmp = [pscustomobject] @{ - Id = $NSXTraceFlow.Id; - Operation_State = $NSXTraceFlow.operation_state; - Delivered = $NSXTraceFlow.Counters.delivered_count; - Dropped = $NSXTraceFlow.Counters.dropped_count; - Analysis = $NSXTraceFlow.maintenance_mode; - } - $results+=$tmp + class NSXTraceFlow { + [string]$traceflow_id + hidden [string]$lport_id + [string]$Operation_State + [int]$Forwarded + [int]$Delivered + [int]$Received + [int]$Dropped + [string]$Analysis } - $results - - if ($Id) { - write-output $Id - } + foreach ($NSXTraceFlow in $NSXTraceFlows) { + + $results = [NSXTraceFlow]::new() + $results.traceflow_id = $NSXTraceFlow.Id; + $results.Operation_State = $NSXTraceFlow.operation_state; + $results.forwarded = $NSXTraceFlow.Counters.forwarded_count; + $results.delivered = $NSXTraceFlow.Counters.delivered_count; + $results.received = $NSXTraceFlow.Counters.received_count; + $results.dropped = $NSXTraceFlow.Counters.dropped_count; + $results.analysis = $NSXTraceFlow.analysis + write-output $results + } } Function Get-NSXTTraceFlowObservations { Param ( - [parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Id + [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] + [Alias("Id")] + [string]$traceflow_id ) - $NSXTraceFlowsObservService = Get-NsxtService -Name "com.vmware.nsx.traceflows.observations" - - if($Id) { - $NSXTraceFlowsObserv = $NSXTraceFlowsObservService.list($Id) - } else { - throw "TraceFlow ID required" + begin + { + $NSXTraceFlowsObservService = Get-NsxtService -Name "com.vmware.nsx.traceflows.observations" } + + Process + { + if($traceflow_id) { + $NSXTraceFlowsObserv = $NSXTraceFlowsObservService.list($traceflow_id) + } else { + throw "TraceFlow ID required" + } - $NSXTraceFlowsObserv.results | select transport_node_name,component_name,@{N='PacketEvent';E={($_.resource_type).TrimStart("TraceflowObservation")}} + $NSXTraceFlowsObserv.results | select transport_node_name,component_name,@{N='PacketEvent';E={($_.resource_type).TrimStart("TraceflowObservation")}} + } } Function Set-NSXTTraceFlow { @@ -416,36 +441,55 @@ Function Set-NSXTTraceFlow { $NSXTraceFlowsService = Get-NsxtService -Name "com.vmware.nsx.traceflows" - # This is where I need help - the method does not ingest the complete $traceflow_request object! + class ip_header { + [string]$src_ip + [string]$dst_ip + } + + class eth_header { + [string]$src_mac + [string]$dst_mac + } + + class packet_data { + [boolean]$routed + [ValidateSet("UNICAST","BROADCAST","MULTICAST","UNKNOWN")] + [string]$transport_type + [ValidateSet("BINARYPACKETDATA","FIELDSPACKETDATA")] + [string]$resource_type + [long]$frame_size + [eth_header]$eth_header = [eth_header]::new() + [ip_header]$ip_header = [ip_header]::new() - # Create the example object - $traceflow_request = $NSXTraceFlowService.help.create.traceflow_request.Create() - $traceflow_request.lport_id = $LPORTID + packet_data(){ + $this.routed = 'true' + $this.transport_type = 'UNICAST' + $this.resource_type = 'FieldsPacketData' + } + } + + class traceflow_request { + [string]$lport_id + [long]$timeout + [packet_data]$packet = [packet_data]::new() + + traceflow_request(){ + $this.timeout = '15000' + } + } + + [traceflow_request]$traceflow_request = [traceflow_request]::new() + + $traceflow_request.lport_id = '8afcd58a-4bdc-483c-97a5-c5f08df7f772' $traceflow_request.timeout = '15000' $traceflow_request.packet.routed = 'true' - $traceflow_request.packet.transport_type = $TrafficType.ToUpper() + $traceflow_request.packet.transport_type = 'UNICAST' $traceflow_request.packet.resource_type = 'FieldsPacketData' - $traceflow_request.packet.frame_size = '64' - - # The example object is missing packet data, so we create it. - $eth_header = @{src_mac = $SMAC;eth_type = '2048';dst_mac = $DMAC} - $ip_header = @{src_ip = $SIPAddr;protocol = '1';ttl = '64';dst_ip = $DIPAddr} - $traceflow_request.packet | Add-Member -NotePropertyMembers $eth_header -TypeName eth_header - $traceflow_request.packet | Add-Member -NotePropertyMembers $ip_header -TypeName ip_header - - # Alternative method of creating $traceflow_request (not working either) - <# - $TraceFlow_Request = [PSCustomObject]@{ - packet = @{routed = 'true'; - transport_type = $TrafficType.ToUpper(); - ip_header = @{src_ip = $SIPAddr;dst_ip = $DIPAddr}; - eth_header = @{dst_mac = $DMAC;src_mac = $SMAC}; - payload = 'test_payload'; - resource_type = 'FieldsPacketData'}; - timeout = '10000'; - lport_id = $LPORTID - } - #> + $traceflow_request.packet.frame_size = '128' + $traceflow_request.packet.eth_header.src_mac = '00:50:56:b3:90:e3' + $traceflow_request.packet.eth_header.dst_mac = '00:50:56:b3:0e:91' + $traceflow_request.packet.ip_header.src_ip = '15.128.160.20' + $traceflow_request.packet.ip_header.dst_ip = '15.128.160.24' } Process @@ -470,4 +514,138 @@ Function Set-NSXTTraceFlow { Get-NSXttraceflow } } -} \ No newline at end of file +} + +Function Get-NSXTEdgeCluster { + Param ( + [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] + [Alias("Id")] + [string]$edge_cluster_id + ) + + Begin + { + $NSXTEdgeClustersService = Get-NsxtService -Name "com.vmware.nsx.edge_clusters" + + class NSXEdgeCluster { + [string]$Name + hidden [string]$Protection + hidden [string]$Tags + [string]$edge_cluster_id + [string]$resource_type + [string]$deployment_type + [string]$member_node_type + $members = [System.Collections.Generic.List[string]]::new() + $cluster_profile_bindings = [System.Collections.Generic.List[string]]::new() + } + } + + Process + { + if ($edge_cluster_id) { + $NSXEdgeClusters = $NSXTEdgeClustersService.get($edge_cluster_id) + } + else { + $NSXEdgeClusters = $NSXTEdgeClustersService.list().results + } + + foreach ($NSXEdgeCluster in $NSXEdgeClusters) { + + $results = [NSXEdgeCluster]::new() + $results.Name = $NSXEdgeCluster.display_name; + $results.Protection = $NSXEdgeCluster.Protection; + $results.edge_cluster_id = $NSXEdgeCluster.Id; + $results.resource_type = $NSXEdgeCluster.resource_type; + $results.Tags = $NSXEdgeCluster.tags; + $results.deployment_type = $NSXEdgeCluster.deployment_type; + $results.member_node_type = $NSXEdgeCluster.member_node_type; + $results.members = $NSXEdgeCluster.members; + $results.cluster_profile_bindings = $NSXEdgeCluster.cluster_profile_bindings + write-output $results + } + } +} + +Function Get-NSXTLogicalRouter { + Param ( + [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] + [Alias("Id")] + [string]$Logical_router_id + ) + + begin + { + $NSXTLogicalRoutersService = Get-NsxtService -Name "com.vmware.nsx.logical_routers" + + class NSXTLogicalRouter { + [string]$Name + [string]$Logical_router_id + hidden [string]$Tags + [string]$edge_cluster_id + [ValidateSet("TIER0","TIER1")] + [string]$router_type + [ValidateSet("ACTIVE_ACTIVE","ACTIVE_STANDBY","")] + [string]$high_availability_mode + [ValidateSet("PREEMPTIVE","NON_PREEMPTIVE","")] + [string]$failover_mode + [string]$external_transit + [string]$internal_transit + } + } + + Process + { + if($Logical_router_id) { + $NSXLogicalRouters = $NSXTLogicalRoutersService.get($Logical_router_id) + } else { + $NSXLogicalRouters = $NSXTLogicalRoutersService.list().results + } + + foreach ($NSXLogicalRouter in $NSXLogicalRouters) { + + $results = [NSXTLogicalRouter]::new() + $results.Name = $NSXLogicalRouter.display_name; + $results.Logical_router_id = $NSXLogicalRouter.Id; + $results.Tags = $NSXLogicalRouter.tags; + $results.edge_cluster_id = $NSXLogicalRouter.edge_cluster_id; + $results.router_type = $NSXLogicalRouter.router_type; + $results.high_availability_mode = $NSXLogicalRouter.high_availability_mode; + $results.failover_mode =$NSXLogicalRouter.failover_mode; + $results.external_transit = $NSXLogicalRouter.advanced_config.external_transit_networks; + $results.internal_transit = $NSXLogicalRouter.advanced_config.internal_transit_network + write-output $results + } + } +} + +Function Get-NSXTRoutingTable { + Param ( + [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] + [string]$Logical_router_id, + [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] + [string]$Tranport_node_id + ) + + Begin + { + $NSXTRoutingTableService = Get-NsxtService -Name "com.vmware.nsx.logical_routers.routing.route_table" + + class NSXTRoutingTable { + [string]$Name + hidden [string]$Id + hidden $tags = [System.Collections.Generic.List[string]]::new() + #more things need to be added when .list actually works + } + } + + Process + { + $NSXTRoutingTable = [NSXTRoutingTable]::new() + + $NSXTRoutingTable = $NSXTRoutingTableService.list($Logical_router_id, $transport_node_id) + + #$NSXTRoutingTable = $NSXTRoutingTableService.list("ca02cb69-0210-4f34-8164-42943a1cc974","309fda89-3439-40ff-996e-b7eb2ec69ace") + + write-output $NSXTRoutingTable + } +} From 75a2562d974f96625c0d4aff7a8be43849362fb6 Mon Sep 17 00:00:00 2001 From: AndyG Date: Wed, 12 Sep 2018 13:45:38 -0400 Subject: [PATCH 5/6] Updates to Set-NSXTraceFlow Updates to Set-NSXTraceFlow. Added more comment and aligned variable names with api --- Modules/NSXT/NSXT.psm1 | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/Modules/NSXT/NSXT.psm1 b/Modules/NSXT/NSXT.psm1 index d80a565..c68b135 100644 --- a/Modules/NSXT/NSXT.psm1 +++ b/Modules/NSXT/NSXT.psm1 @@ -378,21 +378,21 @@ Function Set-NSXTTraceFlow { ParameterSetName='Parameter Set VM Type')] [ValidateSet("UNICAST")] [string] - $TrafficType = "UNICAST", + $transport_type = "UNICAST", [parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName='Parameter Set VM Type')] [ValidateNotNullOrEmpty()] #[ValidateScript({Get-NSXTLogicalPort -Id $_}] [string] - $LPORTID, + $lport_id, [parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName='Parameter Set VM Type')] [ValidateNotNullOrEmpty()] [ValidateScript({$_ -match [IPAddress]$_})] [string] - $SIPAddr, + $src_ip, [parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName='Parameter Set VM Type')] @@ -403,14 +403,14 @@ Function Set-NSXTTraceFlow { } })] [string] - $SMAC, + $src_mac, [parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName='Parameter Set VM Type')] [ValidateNotNullOrEmpty()] [ValidateScript({$_ -match [IPAddress]$_ })] [string] - $DIPAddr, + $dst_ip, [parameter(Mandatory=$true, ValueFromPipeline=$true, ParameterSetName='Parameter Set VM Type')] @@ -421,7 +421,7 @@ Function Set-NSXTTraceFlow { } })] [string] - $DMAC) + $dst_mac) Begin { @@ -477,26 +477,22 @@ Function Set-NSXTTraceFlow { $this.timeout = '15000' } } - - [traceflow_request]$traceflow_request = [traceflow_request]::new() - - $traceflow_request.lport_id = '8afcd58a-4bdc-483c-97a5-c5f08df7f772' - $traceflow_request.timeout = '15000' - $traceflow_request.packet.routed = 'true' - $traceflow_request.packet.transport_type = 'UNICAST' - $traceflow_request.packet.resource_type = 'FieldsPacketData' - $traceflow_request.packet.frame_size = '128' - $traceflow_request.packet.eth_header.src_mac = '00:50:56:b3:90:e3' - $traceflow_request.packet.eth_header.dst_mac = '00:50:56:b3:0e:91' - $traceflow_request.packet.ip_header.src_ip = '15.128.160.20' - $traceflow_request.packet.ip_header.dst_ip = '15.128.160.24' } Process { + [traceflow_request]$traceflow_request = [traceflow_request]::new() + + $traceflow_request.lport_id = $lport_id + $traceflow_request.packet.transport_type = $transport_type + $traceflow_request.packet.eth_header.src_mac = $src_mac + $traceflow_request.packet.eth_header.dst_mac = $dst_mac + $traceflow_request.packet.ip_header.src_ip = $src_ip + $traceflow_request.packet.ip_header.dst_ip = $dst_ip + try { - # This does not work, ignores eth_header,ip_header etc.. Not clear why!? + # This does not work, bug report submitted to PowerCLI team $NSXTraceFlow = $NSXTraceFlowService.create($traceflow_request) } @@ -509,6 +505,7 @@ Function Set-NSXTTraceFlow { End { + # Likely don't need this and will replace with write-output $NSXTraceFlow but I can't test right now due to bug if ($NSXTraceFlow) { Get-NSXttraceflow @@ -642,10 +639,9 @@ Function Get-NSXTRoutingTable { { $NSXTRoutingTable = [NSXTRoutingTable]::new() + # this does not work, bug report submitted to PowerCLI team $NSXTRoutingTable = $NSXTRoutingTableService.list($Logical_router_id, $transport_node_id) - #$NSXTRoutingTable = $NSXTRoutingTableService.list("ca02cb69-0210-4f34-8164-42943a1cc974","309fda89-3439-40ff-996e-b7eb2ec69ace") - write-output $NSXTRoutingTable } } From c34b602bf327bb7afc98e3266b6966561f8565d9 Mon Sep 17 00:00:00 2001 From: AndyG Date: Fri, 14 Sep 2018 08:58:53 -0400 Subject: [PATCH 6/6] Get-NSXTRoutingTable & Get-NSXTForwardingTable now work Get-NSXTRoutingTable & Get-NSXTForwardingTable now work. Thanks for Nick from VMW for pointing out the .help was incorrect and submitting a PR to update the API guide. --- Modules/NSXT/NSXT.psd1 | 18 ++- Modules/NSXT/NSXT.psm1 | 318 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 322 insertions(+), 14 deletions(-) diff --git a/Modules/NSXT/NSXT.psd1 b/Modules/NSXT/NSXT.psd1 index d9e25bc..01b05f0 100644 --- a/Modules/NSXT/NSXT.psd1 +++ b/Modules/NSXT/NSXT.psd1 @@ -7,7 +7,23 @@ Copyright = '(c) 2017. All rights reserved.' Description = 'Powershell Module for NSX-T REST API Functions' PowerShellVersion = '5.0' - FunctionsToExport = 'Get-NSXTComputeManager','Get-NSXTFabricNode','Get-NSXTFirewallRule','Get-NSXTIPPool','Get-NSXTLogicalSwitch','Get-NSXTManager','Get-NSXTTransportZone','Get-NSXTController','Get-NSXTTransportNodes' + FunctionsToExport = 'Get-NSXTComputeManager', + 'Get-NSXTFabricNode', + 'Get-NSXTFirewallRule', + 'Get-NSXTIPPool', + 'Get-NSXTLogicalSwitch', + 'Get-NSXTManager', + 'Get-NSXTTransportZone', + 'Get-NSXTController', + 'Get-NSXTTransportNodes', + 'Get-NSXTTraceFlow', + 'Get-NSXTEdgeCluster', + 'Get-NSXTLogicalRouter', + 'Get-NSXTRoutingTable', + 'Get-NSXTFabricVM', + 'Get-NSXTBGPNeighbors', + 'Get-NSXTForwardingTable', + 'Get-NSXTNetworkRoutes' PrivateData = @{ PSData = @{ Tags = @('NSX-T','REST') diff --git a/Modules/NSXT/NSXT.psm1 b/Modules/NSXT/NSXT.psm1 index c68b135..bc95e6d 100644 --- a/Modules/NSXT/NSXT.psm1 +++ b/Modules/NSXT/NSXT.psm1 @@ -573,10 +573,18 @@ Function Get-NSXTLogicalRouter { begin { $NSXTLogicalRoutersService = Get-NsxtService -Name "com.vmware.nsx.logical_routers" - + $NSXTLogicalRoutersStatusService = Get-NsxtService -Name "com.vmware.nsx.logical_routers.status" + + class per_node_status { + $service_router_id = [System.Collections.ArrayList]::new() + [ValidateSet("ACTIVE","STANDBY","DOWN","SYNC","UNKNOWN")] + $high_availability_status = [System.Collections.ArrayList]::new() + } + class NSXTLogicalRouter { [string]$Name [string]$Logical_router_id + [string]$protection hidden [string]$Tags [string]$edge_cluster_id [ValidateSet("TIER0","TIER1")] @@ -587,6 +595,9 @@ Function Get-NSXTLogicalRouter { [string]$failover_mode [string]$external_transit [string]$internal_transit + hidden [string]$advanced_config = [System.Collections.Generic.List[string]]::new() + hidden [string]$firewall_sections = [System.Collections.Generic.List[string]]::new() + $per_node_status = [per_node_status]::new() } } @@ -600,16 +611,26 @@ Function Get-NSXTLogicalRouter { foreach ($NSXLogicalRouter in $NSXLogicalRouters) { + $NSXTLogicalRoutersStatus = $NSXTLogicalRoutersStatusService.get($NSXLogicalRouter.id) $results = [NSXTLogicalRouter]::new() + + foreach ($NSXTLogicalRouterStatus in $NSXTLogicalRoutersStatus.per_node_status) { + $results.per_node_status.service_router_id.add($NSXTLogicalRouterStatus.service_router_id) 1>$null + $results.per_node_status.high_availability_status.add($NSXTLogicalRouterStatus.high_availability_status) 1>$null + } + $results.Name = $NSXLogicalRouter.display_name; $results.Logical_router_id = $NSXLogicalRouter.Id; + $results.protection = $NSXLogicalRouter.protection; $results.Tags = $NSXLogicalRouter.tags; $results.edge_cluster_id = $NSXLogicalRouter.edge_cluster_id; $results.router_type = $NSXLogicalRouter.router_type; $results.high_availability_mode = $NSXLogicalRouter.high_availability_mode; $results.failover_mode =$NSXLogicalRouter.failover_mode; $results.external_transit = $NSXLogicalRouter.advanced_config.external_transit_networks; - $results.internal_transit = $NSXLogicalRouter.advanced_config.internal_transit_network + $results.internal_transit = $NSXLogicalRouter.advanced_config.internal_transit_network; + $results.advanced_config =$NSXLogicalRouter.advanced_config; + $results.firewall_sections =$NSXLogicalRouter.firewall_sections write-output $results } } @@ -620,28 +641,299 @@ Function Get-NSXTRoutingTable { [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] [string]$Logical_router_id, [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] - [string]$Tranport_node_id + [string]$transport_node_id ) Begin { $NSXTRoutingTableService = Get-NsxtService -Name "com.vmware.nsx.logical_routers.routing.route_table" - class NSXTRoutingTable { - [string]$Name - hidden [string]$Id - hidden $tags = [System.Collections.Generic.List[string]]::new() - #more things need to be added when .list actually works + class NSXTRoutingTable { + hidden [string]$Logical_router_id + [string]$lr_component_id + [string]$lr_component_type + [string]$network + [string]$next_hop + [string]$route_type + hidden [string]$logical_router_port_id + [long]$admin_distance + } + } + + Process + { + $NSXTRoutingTable = $NSXTRoutingTableService.list($Logical_router_id,$transport_node_id,$null,$null,$null,$null,$null,'realtime') + + foreach ($NSXTRoute in $NSXTRoutingTable.results) { + + $results = [NSXTRoutingTable]::new() + $results.Logical_router_id = $Logical_router_id; + $results.lr_component_type = $NSXTRoute.lr_component_type; + $results.lr_component_id = $NSXTRoute.lr_component_id; + $results.next_hop = $NSXTRoute.next_hop; + $results.route_type = $NSXTRoute.route_type; + $results.logical_router_port_id = $NSXTRoute.logical_router_port_id; + $results.admin_distance = $NSXTRoute.admin_distance; + $results.network = $NSXTRoute.network + write-output $results + } + } +} + +Function Get-NSXTFabricVM { + + Begin + { + $NSXTVMService = Get-NsxtService -Name "com.vmware.nsx.fabric.virtual_machines" + + class NSXVM { + [string]$Name + $resource_type + hidden [string]$Tags + hidden $compute_ids + hidden [string]$external_id + [string]$host_id + [string]$power_state + [string]$type + hidden $source + } + } + + Process + { + + $NSXTVMs = $NSXTVMService.list().results + + foreach ($NSXTVM in $NSXTVMs) { + + $results = [NSXVM]::new() + $results.Name = $NSXTVM.display_name; + $results.resource_type = $NSXTVM.resource_type; + $results.compute_ids = $NSXTVM.compute_ids; + $results.resource_type = $NSXTVM.resource_type; + $results.Tags = $NSXTVM.tags; + $results.external_id = $NSXTVM.external_id; + $results.host_id = $NSXTVM.host_id; + $results.power_state = $NSXTVM.power_state; + $results.type = $NSXTVM.type; + $results.source = $NSXTVM.source + write-output $results + } + } +} + +Function Get-NSXTBGPNeighbors { + Param ( + [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] + [Alias("Id")] + [string]$logical_router_id + ) + + begin + { + $NSXTThingsService = Get-NsxtService -Name "com.vmware.nsx.logical_routers.routing.bgp.neighbors" + + class NSXTBGPNeighbors { + [string]$Name + [string]$logical_router_id + hidden $tags = [System.Collections.Generic.List[string]]::new() + [string]$protection + [string]$resource_type + [string]$address_families = [System.Collections.Generic.List[string]]::new() + hidden $bfd_config + [bool]$enable_bfd + [bool]$enabled + hidden $filter_in_ipprefixlist_id + hidden $filter_in_routemap_id + hidden $filter_out_ipprefixlist_id + hidden $filter_out_routemap_id + hidden [long]$hold_down_timer + hidden [long]$keep_alive_timer + hidden [long]$maximum_hop_limit + [string]$neighbor_address + hidden [string]$password + [long]$remote_as + [string]$remote_as_num + [string]$source_address + [string]$source_addresses = [System.Collections.Generic.List[string]]::new() + } + } + + Process + { + $NSXTThings = $NSXTThingsService.list($logical_router_id).results + + foreach ($NSXTThing in $NSXTThings) { + + $results = [NSXTBGPNeighbors]::new() + $results.Name = $NSXTThing.display_name; + $results.logical_router_id = $NSXTThing.logical_router_id; + $results.tags = $NSXTThing.tags; + $results.protection = $NSXTThing.protection; + $results.resource_type = $NSXTThing.resource_type; + $results.address_families = $NSXTThing.address_families; + $results.bfd_config = $NSXTThing.bfd_config; + $results.enable_bfd = $NSXTThing.enable_bfd; + $results.enabled = $NSXTThing.enabled; + $results.filter_in_ipprefixlist_id = $NSXTThing.filter_in_ipprefixlist_id; + $results.filter_in_routemap_id = $NSXTThing.filter_in_routemap_id; + $results.filter_out_ipprefixlist_id = $NSXTThing.filter_out_ipprefixlist_id; + $results.filter_out_routemap_id = $NSXTThing.filter_out_routemap_id; + $results.hold_down_timer = $NSXTThing.hold_down_timer; + $results.keep_alive_timer = $NSXTThing.keep_alive_timer; + $results.maximum_hop_limit = $NSXTThing.maximum_hop_limit; + $results.neighbor_address = $NSXTThing.neighbor_address; + $results.password = $NSXTThing.password; + $results.remote_as = $NSXTThing.remote_as; + $results.remote_as_num = $NSXTThing.remote_as_num; + $results.source_address = $NSXTThing.source_address; + $results.source_addresses = $NSXTThing.source_addresses + write-output $results + } + } +} + +Function Get-NSXTForwardingTable { + Param ( + [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] + [string]$Logical_router_id, + [parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)] + [string]$transport_node_id + ) + + Begin + { + $NSXTForwardingTableService = Get-NsxtService -Name "com.vmware.nsx.logical_routers.routing.forwarding_table" + + class NSXTForwardingTable { + hidden [string]$Logical_router_id + [string]$lr_component_id + [string]$lr_component_type + [string]$network + [string]$next_hop + [string]$route_type + hidden [string]$logical_router_port_id } } Process { - $NSXTRoutingTable = [NSXTRoutingTable]::new() + $NSXTForwardingTable = $NSXTForwardingTableService.list($Logical_router_id,$transport_node_id,$null,$null,$null,$null,$null,$null,'realtime') - # this does not work, bug report submitted to PowerCLI team - $NSXTRoutingTable = $NSXTRoutingTableService.list($Logical_router_id, $transport_node_id) - - write-output $NSXTRoutingTable + foreach ($NSXTForwarding in $NSXTForwardingTable.results) { + + $results = [NSXTForwardingTable]::new() + $results.Logical_router_id = $Logical_router_id; + $results.lr_component_type = $NSXTForwarding.lr_component_type; + $results.lr_component_id = $NSXTForwarding.lr_component_id; + $results.network = $NSXTForwarding.network; + $results.next_hop = $NSXTForwarding.next_hop; + $results.route_type = $NSXTForwarding.route_type; + $results.logical_router_port_id = $NSXTForwarding.logical_router_port_id + write-output $results + } } } + + Function Get-NSXTNetworkRoutes { + Param ( + [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] + [string]$route_id + ) + + Begin + { + $NSXTNetworkRoutesService = Get-NsxtService -Name "com.vmware.nsx.node.network.routes" + + class NSXTNetworkRoutes { + [string]$route_id + $route_type + $interface_id + $gateway + $from_address + $destination + $netmask + $metric + $proto + $scope + $src + } + } + + Process + { + if ($route_id) { + $NSXTNetworkRoutes = $NSXTNetworkRoutesService.get($route_id) + } + else { + $NSXTNetworkRoutes = $NSXTNetworkRoutesService.list().results + } + + foreach ($NSXTRoute in $NSXTNetworkRoutes) { + + $results = [NSXTNetworkRoutes]::new() + $results.route_id = $NSXTRoute.route_id; + $results.route_type = $NSXTRoute.route_type; + $results.interface_id = $NSXTRoute.interface_id; + $results.gateway = $NSXTRoute.gateway; + $results.from_address = $NSXTRoute.from_address; + $results.destination = $NSXTRoute.destination; + $results.netmask = $NSXTRoute.netmask; + $results.metric = $NSXTRoute.metric; + $results.proto = $NSXTRoute.proto; + $results.scope = $NSXTRoute.scope; + $results.src = $NSXTRoute.src + write-output $results + } + } +} + +# Get Template +Function Get-NSXTThingTemplate { + Param ( + [parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)] + [Alias("Id")] + [string]$Thing_id + ) + + begin + { + $NSXTThingsService = Get-NsxtService -Name "com.vmware.nsx.API.Thing" + + class NSXTThing { + [string]$Name + [string]$Thing1 + hidden [string]$Tags = [System.Collections.Generic.List[string]]::new() + [string]$Thing2 + #[ValidateSet("TIER0","TIER1")] + [string]$Thing3 + #[ValidateSet("ACTIVE_ACTIVE","ACTIVE_STANDBY","")] + [string]$Thing4 + #[ValidateSet("PREEMPTIVE","NON_PREEMPTIVE","")] + [string]$Thing5 + [string]$Thing6 + [string]$Thing7 + } + } + + Process + { + if($Thing_id) { + $NSXTThings = $NSXTThingsService.get($Thing_id) + } else { + $NSXTThings = $NSXTThingsService.list().results + } + + foreach ($NSXTThing in $NSXTThings) { + + $results = [NSXTThing]::new() + $results.Name = $NSXTThing.display_name; + $results.Logical_router_id = $NSXTThing.Id; + $results.Tags = $NSXTThing.tags; + $results.thing1 = $NSXTThing.thing1; + $results.thing2 = $NSXTThing.thing2 + + write-output $results + } + } +} \ No newline at end of file