Skip to content

Commit 46c3a91

Browse files
authored
Merge pull request vmware#356 from lamw/master
Add VyOS and VCSA PowerCLI Module
2 parents 1715d94 + 3cf6917 commit 46c3a91

File tree

4 files changed

+537
-3
lines changed

4 files changed

+537
-3
lines changed

Modules/VCSAPasswordPolicy/VCSAPasswordPolicy.psm1 renamed to Modules/VCSA/VCSA.psm1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,33 @@ Function Get-VCSAPasswordPolicy {
3636
} else {
3737
Write-Host "`nUnable to find VCSA named $VCSAName"
3838
}
39+
}
40+
41+
Function Get-VCSAIdentitySource {
42+
<#
43+
.DESCRIPTION Retrieves vCenter Server Appliance Identity Source Configuration
44+
.NOTES Author: William Lam
45+
.PARAMETER VCSAName
46+
Inventory name of the VCSA VM
47+
.PARAMETER VCSARootPassword
48+
Root password for VCSA VM
49+
.EXAMPLE
50+
Get-VCSAIdentitySource -VCSAName "MGMT-VCSA-01" -VCSARootPassword "VMware1!"
51+
#>
52+
Param (
53+
[Parameter(Mandatory=$true)][String]$VCSAName,
54+
[Parameter(Mandatory=$true)][String]$VCSARootPassword
55+
)
56+
57+
$vm = Get-Vm -Name $VCSAName
58+
59+
if($vm) {
60+
$identitySources = Invoke-VMScript -ScriptText "/opt/vmware/bin/sso-config.sh -get_identity_sources 2> /dev/null | sed -ne '/^*/,$ p'" -vm $vm -GuestUser "root" -GuestPassword $VCSARootPassword
61+
62+
Write-Host -ForegroundColor green "`nIdentity Sources: "
63+
$identitySources
64+
65+
} else {
66+
Write-Host "`nUnable to find VCSA named $VCSAName"
67+
}
3968
}

Modules/VMware.VMC.NSXT/VMware.VMC.NSXT.psm1

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ Function Get-NSXTSegment {
120120
$network = $subnets.network
121121
$gateway = $subnets.gateway_address
122122
$dhcpRange = $subnets.dhcp_ranges
123+
$type = $segment.type
123124

124125
$tmp = [pscustomobject] @{
125126
Name = $segment.display_name;
126127
ID = $segment.Id;
128+
TYPE = $type;
127129
Network = $network;
128130
Gateway = $gateway;
129131
DHCPRange = $dhcpRange;
@@ -156,13 +158,16 @@ Function New-NSXTSegment {
156158
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'
157159
.EXAMPLE
158160
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
159163
#>
160164
Param (
161165
[Parameter(Mandatory=$True)]$Name,
162166
[Parameter(Mandatory=$True)]$Gateway,
163167
[Parameter(Mandatory=$False)]$DHCPRange,
164168
[Parameter(Mandatory=$False)]$DomainName,
165169
[Switch]$DHCP,
170+
[Switch]$Disconnected,
166171
[Switch]$Troubleshoot
167172
)
168173

@@ -178,9 +183,21 @@ Function New-NSXTSegment {
178183
}
179184
}
180185

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+
}
184201
}
185202

186203
if($DomainName) {
@@ -221,6 +238,98 @@ Function New-NSXTSegment {
221238
}
222239
}
223240

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 "`nThe 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+
224333
Function Remove-NSXTSegment {
225334
<#
226335
.NOTES

0 commit comments

Comments
 (0)