@@ -120,10 +120,12 @@ Function Get-NSXTSegment {
120
120
$network = $subnets.network
121
121
$gateway = $subnets.gateway_address
122
122
$dhcpRange = $subnets.dhcp_ranges
123
+ $type = $segment.type
123
124
124
125
$tmp = [pscustomobject ] @ {
125
126
Name = $segment.display_name ;
126
127
ID = $segment.Id ;
128
+ TYPE = $type ;
127
129
Network = $network ;
128
130
Gateway = $gateway ;
129
131
DHCPRange = $dhcpRange ;
@@ -156,13 +158,16 @@ Function New-NSXTSegment {
156
158
New-NSXTSegment -Name "sddc-cgw-network-4" -Gateway "192.168.4.1/24" -DHCP -DHCPRange "192.168.4.2-192.168.4.254" -DomainName 'vmc.local'
157
159
. EXAMPLE
158
160
New-NSXTSegment -Name "sddc-cgw-network-5" -Gateway "192.168.5.1/24"
161
+ . EXAMPLE
162
+ New-NSXTSegment -Name "sddc-cgw-network-5" -Gateway "192.168.5.1/24" -Disconnected
159
163
#>
160
164
Param (
161
165
[Parameter (Mandatory = $True )]$Name ,
162
166
[Parameter (Mandatory = $True )]$Gateway ,
163
167
[Parameter (Mandatory = $False )]$DHCPRange ,
164
168
[Parameter (Mandatory = $False )]$DomainName ,
165
169
[Switch ]$DHCP ,
170
+ [Switch ]$Disconnected ,
166
171
[Switch ]$Troubleshoot
167
172
)
168
173
@@ -178,9 +183,21 @@ Function New-NSXTSegment {
178
183
}
179
184
}
180
185
181
- $payload = @ {
182
- display_name = $Name ;
183
- subnets = @ ($subnets )
186
+ if ($Disconnected ) {
187
+ $payload = @ {
188
+ display_name = $Name ;
189
+ subnets = @ ($subnets )
190
+ advanced_config = @ {
191
+ local_egress = " False"
192
+ connectivity = " OFF" ;
193
+ }
194
+ type = " DISCONNECTED" ;
195
+ }
196
+ } else {
197
+ $payload = @ {
198
+ display_name = $Name ;
199
+ subnets = @ ($subnets )
200
+ }
184
201
}
185
202
186
203
if ($DomainName ) {
@@ -221,6 +238,98 @@ Function New-NSXTSegment {
221
238
}
222
239
}
223
240
241
+ Function Set-NSXTSegment {
242
+ <#
243
+ . NOTES
244
+ ===========================================================================
245
+ Created by: William Lam
246
+ Date: 03/04/2018
247
+ Organization: VMware
248
+ Blog: http://www.virtuallyghetto.com
249
+ Twitter: @lamw
250
+ ===========================================================================
251
+
252
+ . SYNOPSIS
253
+ Set a NSX-T Segment (Logical Networks) to either connected or disconnected
254
+ . DESCRIPTION
255
+ This cmdlet set an NSX-T Segment (Logical Networks) to either connected or disconnected
256
+ . EXAMPLE
257
+ New-NSXTSegment -Name "sddc-cgw-network-4" -Disconnected
258
+ . EXAMPLE
259
+ New-NSXTSegment -Name "sddc-cgw-network-4" -Connected
260
+
261
+ #>
262
+ Param (
263
+ [Parameter (Mandatory = $True )]$Name ,
264
+ [Switch ]$Disconnected ,
265
+ [Switch ]$Connected ,
266
+ [Switch ]$Troubleshoot
267
+ )
268
+
269
+ If (-Not $global :nsxtProxyConnection ) { Write-error " No NSX-T Proxy Connection found, please use Connect-NSXTProxy" } Else {
270
+ $SegmentId = (Get-NSXTSegment - Name $Name ).Id
271
+
272
+ if ($Disconnected ) {
273
+ $type = " DISCONNECTED"
274
+ $connectivity = " OFF"
275
+ $localEgress = " False"
276
+ $gateway = (Get-NSXTSegment - Name $Name ).Gateway
277
+ }
278
+
279
+ If ($Connected ) {
280
+ $type = " ROUTED"
281
+ $connectivity = " ON"
282
+ $localEgress = " True"
283
+ $gateway = (Get-NSXTSegment - Name $Name ).Gateway
284
+ }
285
+
286
+ $subnets = @ {
287
+ gateway_address = $gateway ;
288
+ }
289
+
290
+ $payload = @ {
291
+ advanced_config = @ {
292
+ local_egress = $localEgress ;
293
+ connectivity = $connectivity ;
294
+ }
295
+ type = $type ;
296
+ subnets = @ ($subnets )
297
+ }
298
+
299
+ $body = $payload | ConvertTo-Json - depth 4
300
+
301
+ $method = " PATCH"
302
+ $aegmentsURL = $global :nsxtProxyConnection.Server + " /policy/api/v1/infra/tier-1s/cgw/segments/$SegmentId "
303
+
304
+ if ($Troubleshoot ) {
305
+ Write-Host - ForegroundColor cyan " `n [DEBUG] - $method `n $newSegmentsURL `n "
306
+ Write-Host - ForegroundColor cyan " [DEBUG]`n $body `n "
307
+ }
308
+
309
+ try {
310
+ if ($PSVersionTable.PSEdition -eq " Core" ) {
311
+ $requests = Invoke-WebRequest - Uri $aegmentsURL - Body $body - Method $method - Headers $global :nsxtProxyConnection.headers - SkipCertificateCheck
312
+ } else {
313
+ $requests = Invoke-WebRequest - Uri $aegmentsURL - Body $body - Method $method - Headers $global :nsxtProxyConnection.headers
314
+ }
315
+ } catch {
316
+ if ($_.Exception.Response.StatusCode -eq " Unauthorized" ) {
317
+ Write-Host - ForegroundColor Red " `n The NSX-T Proxy session is no longer valid, please re-run the Connect-NSXTProxy cmdlet to retrieve a new token`n "
318
+ break
319
+ } else {
320
+ Write-Error " Error in updating NSX-T Segment connectivity"
321
+ Write-Error " `n ($_ .Exception.Message)`n "
322
+ break
323
+ }
324
+ }
325
+
326
+ if ($requests.StatusCode -eq 200 ) {
327
+ Write-Host " Successfully updated NSX-T Segment $Name "
328
+ ($requests.Content | ConvertFrom-Json ) | select display_name, id
329
+ }
330
+ }
331
+ }
332
+
224
333
Function Remove-NSXTSegment {
225
334
<#
226
335
. NOTES
0 commit comments