Merge branch 'master' into master

This commit is contained in:
William Lam
2019-06-19 06:10:10 -07:00
committed by GitHub
9 changed files with 1439 additions and 170 deletions

View File

@@ -36,6 +36,7 @@ Description = 'PowerShell Module for Managing Hybrid Cloud Extension (HCX) on VM
PowerShellVersion = '6.0'
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Connect-HcxServer', 'Get-HcxCloudConfig', 'Get-HcxEndpoint', 'New-HcxMigration', 'Get-HcxMigration', 'Connect-HcxVAMI',
'Get-HcxVCConfig', 'Set-HcxLicense', 'Set-HcxVCConfig', 'Get-HcxNSXConfig', 'Set-HcxNSXConfig', 'Get-HcxCity', 'Get-HcxLocation', 'Set-HcxLocation',
'Get-HcxRoleMapping', 'Set-HcxRoleMapping', 'Get-HcxProxy', 'Set-HcxProxy', 'Remove-HcxProxy', 'Connect-HcxCloudServer', 'Get-HCXCloudActivationKey',

View File

@@ -453,12 +453,23 @@ Function Get-HcxMigration {
Get-HcxMigration -MigrationId <MigrationID>
#>
Param (
[Parameter(Mandatory=$false)][String]$MigrationId,
[Parameter(Mandatory=$false)][String[]]$MigrationId,
[Switch]$RunningMigrations
)
If (-Not $global:hcxConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxManager " } Else {
$spec = @{}
If($PSBoundParameters.ContainsKey("MigrationId")){
$spec = @{
filter = @{
migrationId = $MigrationId
}
paging =@{
pageSize = $MigrationId.Count
}
}
} Else {
$spec = @{}
}
$body = $spec | ConvertTo-Json
$hcxQueryUrl = $global:hcxConnection.Server + "/migrations?action=query"
@@ -468,10 +479,10 @@ Function Get-HcxMigration {
$requests = Invoke-WebRequest -Uri $hcxQueryUrl -Method POST -Headers $global:hcxConnection.headers -UseBasicParsing
}
$migrations = ($requests.content | ConvertFrom-Json).rows
if($PSBoundParameters.ContainsKey("MigrationId")){
$migrations = $migrations | where { $_.migrationId -eq $MigrationId }
$migrations = ($requests.content | ConvertFrom-Json).items
} else {
$migrations = ($requests.content | ConvertFrom-Json).rows
}
if($RunningMigrations){
@@ -559,16 +570,22 @@ Function Get-HcxVCConfig {
#>
If (-Not $global:hcxVAMIConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxVAMI " } Else {
$vcConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/vcenter"
$pscConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/lookupservice"
if($PSVersionTable.PSEdition -eq "Core") {
$vcRequests = Invoke-WebRequest -Uri $vcConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
$ssoRequests = Invoke-WebRequest -Uri $pscConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
} else {
$vcRequests = Invoke-WebRequest -Uri $vcConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
$ssoRequests = Invoke-WebRequest -Uri $pscConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
}
$vcData = ($vcRequests.content | ConvertFrom-Json).data.items
$ssoData = ($ssoRequests.content | ConvertFrom-Json).data.items
$tmp = [pscustomobject] @{
Name = $vcData.config.name;
UserName = $vcData.Config.userName
LookupServiceUrl = $ssoData.config.lookupServiceUrl
Version = $vcData.config.version;
Build = $vcData.config.buildNumber;
UUID = $vcData.config.vcuuid;
@@ -578,6 +595,38 @@ Function Get-HcxVCConfig {
}
}
Function Get-HcxLicense {
<#
.NOTES
===========================================================================
Created by: Mark McGilly
Date: 4/29/2019
Organization: Liberty Mutual Insurance
===========================================================================
.SYNOPSIS
Returns the license key that is registered with HCX Manager
.DESCRIPTION
This cmdlet returns the license key registered with HCX Manager
.EXAMPLE
Get-HcxLicense
#>
If (-Not $global:hcxVAMIConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxVAMI " } Else {
$hcxConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/hcx"
if($PSVersionTable.PSEdition -eq "Core") {
$licenseRequests = Invoke-WebRequest -Uri $hcxConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
} else {
$licenseRequests = Invoke-WebRequest -Uri $hcxConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
}
$license = ($licenseRequests.content | ConvertFrom-Json).data.items
if($licenseRequests) {
$license.config.activationKey
}
}
}
Function Set-HcxLicense {
<#
.NOTES
@@ -789,6 +838,7 @@ Function Get-HcxNSXConfig {
$tmp = [pscustomobject] @{
Name = $nsxData.config.url;
UserName = $nsxData.config.userName
Version = $nsxData.config.version;
HCXUUID = $nsxData.config.uuid;
}
@@ -1200,6 +1250,7 @@ Function Set-HcxProxy {
[Parameter(Mandatory=$True)]$ProxyPort,
[Parameter(Mandatory=$False)]$ProxyUser,
[Parameter(Mandatory=$False)]$ProxyPassword,
[Parameter(Mandatory=$False)]$ProxyExclusions,
[Switch]$Troubleshoot
)
@@ -1214,7 +1265,7 @@ Function Set-HcxProxy {
config = @{
proxyHost = "$ProxyServer";
proxyPort = "$ProxyPort";
nonProxyHosts = "";
nonProxyHosts = "$ProxyExclusions";
userName = "$ProxyUser";
password = "$ProxyPassword";
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -690,7 +690,7 @@ Function Get-VMCLogicalNetwork {
Created by: Kyle Ruddy
Date: 03/06/2018
Organization: VMware
Blog: https://thatcouldbeaproblem.com
Blog: https://www.kmruddy.com
Twitter: @kmruddy
===========================================================================
@@ -761,7 +761,7 @@ Function Remove-VMCLogicalNetwork {
Created by: Kyle Ruddy
Date: 03/06/2018
Organization: VMware
Blog: https://thatcouldbeaproblem.com
Blog: https://www.kmruddy.com
Twitter: @kmruddy
===========================================================================
@@ -808,7 +808,7 @@ Function New-VMCLogicalNetwork {
Created by: Kyle Ruddy
Date: 03/06/2018
Organization: VMware
Blog: https://thatcouldbeaproblem.com
Blog: https://www.kmruddy.com
Twitter: @kmruddy
===========================================================================
@@ -1418,11 +1418,205 @@ Twitter: @LucD22
}
}
}
Function New-VMCSDDCCluster {
<#
.NOTES
===========================================================================
Created by: Kyle Ruddy
Date: 03/16/2019
Organization: VMware
Blog: https://www.kmruddy.com
Twitter: @kmruddy
===========================================================================
.SYNOPSIS
Creates a new cluster for the designated SDDC
.DESCRIPTION
Creates a new cluster
.EXAMPLE
New-VMCSDDCCluster -OrgName <Org Name> -SDDCName <SDDC Name> -HostCount 1 -CPUCoreCount 8
#>
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
param(
[Parameter(Mandatory=$true)][String]$OrgName,
[Parameter(Mandatory=$true)][String]$SDDCName,
[Parameter(Mandatory=$true)][Int]$HostCount,
[Parameter(Mandatory=$true)][ValidateSet("8","16","32")]$CPUCoreCount
)
if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
$orgId = Get-VMCOrg -Name $OrgName | Select-Object -ExpandProperty Id
$sddcId = Get-VMCSDDC -Name $SDDCName -Org $OrgName | Select-Object -ExpandProperty Id
if(-not $orgId) {
Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
break
}
if(-not $sddcId) {
Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
break
}
$sddcClusterSvc = Get-VmcService -Name com.vmware.vmc.orgs.sddcs.clusters
$sddcClusterCreateSpec = $sddcClusterSvc.Help.create.cluster_config.Create()
$sddcClusterCreateSpec.host_cpu_cores_count = $CPUCoreCount
$sddcClusterCreateSpec.num_hosts = $HostCount
$sddcClusterTask = $sddcClusterSvc.Create($org.Id, $sddc.Id, $sddcClusterCreateSpec)
$sddcClusterTask | Select-Object Id,Task_Type,Status,Created | Format-Table
}
Function Get-VMCSDDCCluster {
<#
.NOTES
===========================================================================
Created by: Kyle Ruddy
Date: 03/16/2019
Organization: VMware
Blog: https://www.kmruddy.com
Twitter: @kmruddy
===========================================================================
.SYNOPSIS
Retreives cluster information for the designated SDDC
.DESCRIPTION
Lists cluster information for an SDDC
.EXAMPLE
Get-VMCSDDCCluster -OrgName <Org Name> -SDDCName <SDDC Name> -HostCount 1 -CPUCoreCount 8
#>
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='Low')]
param(
[Parameter(Mandatory=$true)][String]$OrgName,
[Parameter(Mandatory=$true)][String]$SddcName
)
if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
$orgId = Get-VMCOrg -Name $OrgName | Select-Object -ExpandProperty Id
$sddcId = Get-VMCSDDC -Name $SDDCName -Org $OrgName | Select-Object -ExpandProperty Id
if(-not $orgId) {
Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
break
}
if(-not $sddcId) {
Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
break
}
$clusterOutput = @()
$sddcClusters = Get-VMCSDDC -Org $OrgName -Name $SDDCName | Select-Object -ExpandProperty resource_config | Select-Object -ExpandProperty clusters
foreach ($c in $sddcClusters) {
$tempCluster = "" | Select-Object Id, Name, State
$tempCluster.Id = $c.cluster_id
$tempCluster.Name = $c.cluster_name
$tempCluster.State = $c.cluster_state
$clusterOutput += $tempCluster
}
return $clusterOutput
}
Function New-VMCSDDCCluster {
<#
.NOTES
===========================================================================
Created by: Kyle Ruddy
Date: 03/16/2019
Organization: VMware
Blog: https://www.kmruddy.com
Twitter: @kmruddy
===========================================================================
.SYNOPSIS
Creates a new cluster for the designated SDDC
.DESCRIPTION
Creates a new cluster
.EXAMPLE
New-VMCSDDCCluster -OrgName <Org Name> -SDDCName <SDDC Name> -HostCount 1 -CPUCoreCount 8
#>
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
param(
[Parameter(Mandatory=$true)][String]$OrgName,
[Parameter(Mandatory=$true)][String]$SddcName,
[Parameter(Mandatory=$true)][Int]$HostCount,
[Parameter(Mandatory=$false)][ValidateSet("8","16","36","48")]$CPUCoreCount
)
if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
$orgId = Get-VMCOrg -Name $OrgName | Select-Object -ExpandProperty Id
$sddcId = Get-VMCSDDC -Name $SDDCName -Org $OrgName | Select-Object -ExpandProperty Id
if(-not $orgId) {
Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
break
}
if(-not $sddcId) {
Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
break
}
$sddcClusterSvc = Get-VmcService -Name com.vmware.vmc.orgs.sddcs.clusters
$sddcClusterCreateSpec = $sddcClusterSvc.Help.create.cluster_config.Create()
$sddcClusterCreateSpec.host_cpu_cores_count = $CPUCoreCount
$sddcClusterCreateSpec.num_hosts = $HostCount
$sddcClusterTask = $sddcClusterSvc.Create($org.Id, $sddc.Id, $sddcClusterCreateSpec)
$sddcClusterTask | Select-Object Id,Task_Type,Status,Created | Format-Table
}
Function Remove-VMCSDDCCluster {
<#
.NOTES
===========================================================================
Created by: Kyle Ruddy
Date: 03/16/2019
Organization: VMware
Blog: https://www.kmruddy.com
Twitter: @kmruddy
===========================================================================
.SYNOPSIS
Removes a specified cluster from the designated SDDC
.DESCRIPTION
Deletes a cluster from an SDDC
.EXAMPLE
Remove-VMCSDDCCluster -OrgName <Org Name> -SDDCName <SDDC Name> -Cluster <Cluster Name>
#>
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
param(
[Parameter(Mandatory=$true)][String]$OrgName,
[Parameter(Mandatory=$true)][String]$SDDCName,
[Parameter(Mandatory=$true)][String]$ClusterName
)
if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
$orgId = Get-VMCOrg -Name $OrgName | Select-Object -ExpandProperty Id
$sddcId = Get-VMCSDDC -Name $SDDCName -Org $OrgName | Select-Object -ExpandProperty Id
$clusterId = Get-VMCSDDCCluster -SddcName $SDDCName -OrgName $OrgName | Where-Object {$_.Name -eq $ClusterName} | Select-Object -ExpandProperty Id
if(-not $orgId) {
Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
break
}
if(-not $sddcId) {
Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
break
}
if(-not $clusterId) {
Write-Host -ForegroundColor red "Unable to find cluster $ClusterName, please verify input"
break
}
$sddcClusterTask = $sddcClusterSvc.Delete($orgId, $sddcId, $clusterId)
$sddcClusterTask | Select-Object Id,Task_Type,Status,Created | Format-Table
}
Export-ModuleMember -Function 'Get-VMCCommand', 'Connect-VMCVIServer', 'Get-VMCOrg', 'Get-VMCSDDC',
'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', 'Set-VMCSDDC',
'Get-VMCEdge', 'Get-VMCEdgeNic', 'Get-VMCEdgeStatus', 'Get-VMCEdgeNicStat', 'Get-VMCEdgeUplinkStat'
'Get-VMCEdge', 'Get-VMCEdgeNic', 'Get-VMCEdgeStatus', 'Get-VMCEdgeNicStat', 'Get-VMCEdgeUplinkStat',
'Get-VMCSDDCCluster', 'New-VMCSDDCCluster', 'Remove-VMCSDDCCluster'