Merge pull request #260 from lamw/master

Added Set-VMCSDDC function to rename SDDC
This commit is contained in:
Kyle Ruddy
2019-02-04 12:36:48 -05:00
committed by GitHub
3 changed files with 1581 additions and 1309 deletions

View File

@@ -476,7 +476,7 @@ Function New-NSXTFirewall {
$services = @()
foreach ($serviceName in $Service) {
if($group -eq "ANY") {
if($serviceName -eq "ANY") {
$services = @("ANY")
} else {
$tmp = "/infra/services/$serviceName"
@@ -1362,3 +1362,82 @@ Function Remove-NSXTDistFirewall {
}
}
}
Function Get-NSXTRouteTable {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 02/02/2019
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Retrieves NSX-T Routing Table
.DESCRIPTION
This cmdlet retrieves NSX-T Routing Table. By default, it shows all routes but you can filter by BGP, CONNECTED or STATIC routes
.EXAMPLE
Get-NSXTRouteTable
.EXAMPLE
Get-NSXTRouteTable -RouteSource BGP
.EXAMPLE
Get-NSXTRouteTable -RouteSource CONNECTED
.EXAMPLE
Get-NSXTRouteTable -RouteSource STATIC
.EXAMPLE
Get-NSXTRouteTable -RouteSource BGP -Troubleshoot
#>
Param (
[Parameter(Mandatory=$False)][ValidateSet("BGP","CONNECTED","STATIC")]$RouteSource,
[Switch]$Troubleshoot
)
If (-Not $global:nsxtProxyConnection) { Write-error "No NSX-T Proxy Connection found, please use Connect-NSXTProxy" } Else {
$method = "GET"
$routeTableURL = $global:nsxtProxyConnection.Server + "/policy/api/v1/infra/tier-0s/vmc/routing-table?enforcement_point_path=/infra/deployment-zones/default/enforcement-points/vmc-enforcementpoint"
if($RouteSource) {
$routeTableURL = $routeTableURL + "&route_source=$RouteSource"
}
if($Troubleshoot) {
Write-Host -ForegroundColor cyan "`n[DEBUG] - $method`n$routeTableURL`n"
}
try {
if($PSVersionTable.PSEdition -eq "Core") {
$requests = Invoke-WebRequest -Uri $routeTableURL -Method $method -Headers $global:nsxtProxyConnection.headers -SkipCertificateCheck
} else {
$requests = Invoke-WebRequest -Uri $routeTableURL -Method $method -Headers $global:nsxtProxyConnection.headers
}
} catch {
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
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"
break
} else {
Write-Error "Error in retrieving NSX-T Routing Table"
Write-Error "`n($_.Exception.Message)`n"
break
}
}
if($requests.StatusCode -eq 200) {
Write-Host "Succesfully retrieved NSX-T Routing Table`n"
$routeTables = ($requests.Content | ConvertFrom-Json).results
foreach ($routeTable in $routeTables) {
Write-Host "EdgeNode: $($routeTable.edge_node)"
Write-Host "Entries: $($routeTable.count)"
$routeEntries = $routeTable.route_entries
$routeEntryResults = @()
foreach ($routeEntry in $routeEntries) {
$routeEntryResults += $routeEntry
}
$routeEntryResults | select network,next_hop,admin_distance,route_type | ft
}
}
}
}

View File

@@ -917,21 +917,133 @@ Function Get-VMCPublicIP {
.EXAMPLE
Get-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName
#>
Param (
[Parameter(Mandatory=$True)]$OrgName,
[Parameter(Mandatory=$True)]$SDDCName
)
Param (
[Parameter(Mandatory=$True)]$OrgName,
[Parameter(Mandatory=$True)]$SDDCName
)
If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
$orgId = (Get-VMCOrg -Name $OrgName).Id
$sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
$orgId = (Get-VMCOrg -Name $OrgName).Id
$sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
$publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips"
$publicIPs = $publicIPService.list($orgId,$sddcId)
$publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips"
$publicIPs = $publicIPService.list($orgId,$sddcId)
$publicIPs | select public_ip, name, allocation_id
$publicIPs | select public_ip, name, allocation_id
}
}
Function New-VMCPublicIP {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 09/12/2018
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Request a new public IP Address for a given SDDC
.DESCRIPTION
This cmdlet requests a new public IP Address for a given SDDC
.EXAMPLE
New-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -Description "Test for Randy"
#>
Param (
[Parameter(Mandatory=$True)]$OrgName,
[Parameter(Mandatory=$True)]$SDDCName,
[Parameter(Mandatory=$False)]$Description
)
If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
$orgId = (Get-VMCOrg -Name $OrgName).Id
$sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
$publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips"
$publicIPSpec = $publicIPService.Help.create.spec.Create()
$publicIPSpec.count = 1
$publicIPSpec.names = @($Description)
Write-Host "Requesting a new public IP Address for your SDDC ..."
$results = $publicIPService.create($orgId,$sddcId,$publicIPSpec)
}
}
Function Remove-VMCPublicIP {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 09/12/2018
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Removes a specific public IP Addresses for a given SDDC
.DESCRIPTION
This cmdlet removes a specific public IP Address for a given SDDC
.EXAMPLE
Remove-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -AllocationId "eipalloc-0567acf34e436c01f"
#>
Param (
[Parameter(Mandatory=$True)]$OrgName,
[Parameter(Mandatory=$True)]$SDDCName,
[Parameter(Mandatory=$True)]$AllocationId
)
If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
$orgId = (Get-VMCOrg -Name $OrgName).Id
$sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
$publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips"
Write-Host "Deleting public IP Address with ID $AllocationId ..."
$results = $publicIPService.delete($orgId,$sddcId,$AllocationId)
}
}
Function Set-VMCSDDC {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 01/12/2019
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Rename an SDDC
.DESCRIPTION
This cmdlet renames an SDDC
.EXAMPLE
Set-VMCSDDC -SDDC $SDDCName -OrgName $OrgName -Name $NewSDDCName
#>
Param (
[Parameter(Mandatory=$True)]$SDDCName,
[Parameter(Mandatory=$True)]$OrgName,
[Parameter(Mandatory=$True)]$Name
)
If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
$sddc = Get-VMCSDDC -Org $OrgName -Name $SDDCName
if($sddc) {
$sddcService = Get-VmcService com.vmware.vmc.orgs.sddcs
$renameSpec = $sddcService.help.patch.sddc_patch_request.Create()
$renameSpec.name = $Name
Write-Host "`nRenaming SDDC `'$SDDCName`' to `'$Name`' ...`n"
$results = $sddcService.patch($sddc.org_id,$sddc.id,$renameSpec)
}
}
}
Function New-VMCPublicIP {
<#
.NOTES
@@ -970,6 +1082,7 @@ Function New-VMCPublicIP {
$results = $publicIPService.create($orgId,$sddcId,$publicIPSpec)
}
}
Function Remove-VMCPublicIP {
<#
.NOTES
@@ -1004,6 +1117,7 @@ Function Remove-VMCPublicIP {
$results = $publicIPService.delete($orgId,$sddcId,$AllocationId)
}
}
Function Get-VMCEdge {
<#
.NOTES
@@ -1059,6 +1173,7 @@ Twitter: @LucD22
}
}
}
Function Get-VMCEdgeStatus {
<#
.NOTES
@@ -1120,6 +1235,7 @@ Twitter: @LucD22
}
}
}
Function Get-VMCEdgeNic {
<#
.NOTES
@@ -1168,6 +1284,7 @@ Twitter: @LucD22
}
}
}
Function Get-VMCEdgeNicStat {
<#
.NOTES
@@ -1233,6 +1350,7 @@ Twitter: @LucD22
}
}
}
Function Get-VMCEdgeUplinkStat {
<#
.NOTES
@@ -1304,5 +1422,6 @@ Export-ModuleMember -Function 'Get-VMCCommand', 'Connect-VMCVIServer', 'Get-VMCO
'Get-VMCTask', 'Get-VMCSDDCDefaultCredential', 'Get-VMCSDDCPublicIP', 'Get-VMCVMHost',
'Get-VMCSDDCVersion', 'Get-VMCFirewallRule', 'Export-VMCFirewallRule', 'Import-VMCFirewallRule',
'Remove-VMCFirewallRule', 'Get-VMCLogicalNetwork', 'Remove-VMCLogicalNetwork', 'New-VMCLogicalNetwork',
'Get-VMCSDDCSummary', 'Get-VMCPublicIP', 'New-VMCPublicIP', 'Remove-VMCPublicIP',
'Get-VMCSDDCSummary', 'Get-VMCPublicIP', 'New-VMCPublicIP', 'Remove-VMCPublicIP', 'Set-VMCSDDC',
'Get-VMCEdge', 'Get-VMCEdgeNic', 'Get-VMCEdgeStatus', 'Get-VMCEdgeNicStat', 'Get-VMCEdgeUplinkStat'

View File

@@ -0,0 +1,74 @@
Function Get-VCenterCEIP {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 01/23/2019
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Retrieves the the Customer Experience Improvement Program (CEIP) setting for vCenter Server
.DESCRIPTION
This cmdlet retrieves the the CEIP setting for vCenter Server
.EXAMPLE
Get-VCenterCEIP
#>
If (-Not $global:DefaultVIServer.IsConnected) { Write-error "No valid VC Connection found, please use the Connect-VIServer to connect"; break } Else {
$ceipSettings = (Get-AdvancedSetting -Entity $global:DefaultVIServer -Name VirtualCenter.DataCollector.ConsentData).Value.toString() | ConvertFrom-Json
$ceipEnabled = $ceipSettings.consentConfigurations[0].consentAccepted
$tmp = [pscustomobject] @{
VCENTER = $global:DefaultVIServer.Name;
CEIP = $ceipEnabled;
}
$tmp
}
}
Function Set-VCenterCEIP {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 01/23/2019
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Enables or Disables the Customer Experience Improvement Program (CEIP) setting for vCenter Server
.DESCRIPTION
This cmdlet enables or disables the CEIP setting for vCenter Server
.EXAMPLE
Set-VCenterCEIP -Enabled
.EXAMPLE
Set-VCenterCEIP -Disabled
#>
Param (
[Switch]$Enabled,
[Switch]$Disabled
)
If (-Not $global:DefaultVIServer.IsConnected) { Write-error "No valid VC Connection found, please use the Connect-VIServer to connect"; break } Else {
$ceipSettings = (Get-AdvancedSetting -Entity $global:DefaultVIServer -Name VirtualCenter.DataCollector.ConsentData).Value.toString() | ConvertFrom-Json
If($Enabled) {
$originalVersion = $ceipSettings.version
$ceipSettings.version = [int]$originalVersion + 1
$ceipSettings.consentConfigurations[0].consentAccepted = $True
$ceipSettings.consentConfigurations[1].consentAccepted = $True
$updatedceipSettings = $ceipSettings | ConvertTo-Json
Write-Host "Enabling Customer Experience Improvement Program (CEIP) ..."
Get-AdvancedSetting -Entity $global:DefaultVIServer -Name VirtualCenter.DataCollector.ConsentData | Set-AdvancedSetting -Value $updatedceipSettings -Confirm:$false
} else {
$originalVersion = $ceipSettings.version
$ceipSettings.version = [int]$originalVersion + 1
$ceipSettings.consentConfigurations[0].consentAccepted = $False
$ceipSettings.consentConfigurations[1].consentAccepted = $False
$updatedceipSettings = $ceipSettings | ConvertTo-Json
Write-Host "Disablng Customer Experience Improvement Program (CEIP) ..."
Get-AdvancedSetting -Entity $global:DefaultVIServer -Name VirtualCenter.DataCollector.ConsentData | Set-AdvancedSetting -Value $updatedceipSettings -Confirm:$false
}
}
}