Updated VMware.VMC

Fix issue #176
Added functions:
- Get-VMCEdge
- Get-VMCEdgeNic
- Get-VMCEdgeStatus
- Get-VMCEdgeNicStat
- Get-VMCEdgeUplinkStat
This commit is contained in:
LucD
2018-10-25 10:02:23 +02:00
parent ed5b8eaf5e
commit b68dc6c4e0
2 changed files with 435 additions and 138 deletions

Binary file not shown.

View File

@@ -320,7 +320,6 @@ Function Get-VMCSDDCVersion {
}
}
}
Function Get-VMCFirewallRule {
<#
.NOTES
@@ -394,7 +393,6 @@ Function Get-VMCFirewallRule {
}
$results
}
Function Export-VMCFirewallRule {
<#
.NOTES
@@ -480,7 +478,6 @@ Function Get-VMCFirewallRule {
$results | ConvertTo-Json
}
}
Function Import-VMCFirewallRule {
<#
.NOTES
@@ -637,7 +634,6 @@ Function Get-VMCFirewallRule {
Write-host "Adding VMC Firewall Rules ..."
$firewallRuleAdd = $firewallService.add($orgId,$sddcId,$EdgeId,$firewallRules)
}
Function Remove-VMCFirewallRule {
<#
.NOTES
@@ -687,7 +683,6 @@ Function Get-VMCFirewallRule {
Write-Host "Removing VMC Firewall Rule Id $RuleId ..."
$firewallService.delete($orgId,$sddcId,$EdgeId,$RuleId)
}
Function Get-VMCLogicalNetwork {
<#
.NOTES
@@ -727,9 +722,17 @@ Function Get-VMCLogicalNetwork {
break
}
$logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical
# @LucD22 - 21/10/18 - Fix for issue #176 VMware.VMC module only lists firts 20 Logical networks
# Loop until entries (total_count) are returned
$logicalNetworks = ($logicalNetworkService.get_0($orgId, $sddcId)).data | Sort-Object -Property id
$index = [long]0
$logicalNetworks = do{
$netData = $logicalNetworkService.get_0($orgId,$sddcId,$pagesize,$index)
$netData.data | Sort-Object -Property id
$index = $index + $netdata.paging_info.page_size
}
until($index -ge $netData.paging_info.total_count)
if($LogicalNetworkName) {
$logicalNetworks = $logicalNetworks | Where-Object {$_.Name -eq $LogicalNetworkName}
@@ -751,7 +754,6 @@ Function Get-VMCLogicalNetwork {
}
$results
}
Function Remove-VMCLogicalNetwork {
<#
.NOTES
@@ -799,7 +801,6 @@ Function Remove-VMCLogicalNetwork {
$logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical
$logicalNetworkService.delete($orgId,$sddcId,$lsId)
}
Function New-VMCLogicalNetwork {
<#
.NOTES
@@ -854,7 +855,6 @@ Function New-VMCLogicalNetwork {
$logicalNetworkService.create($orgId, $sddcId, $logicalNetworkSpec)
Get-VMCLogicalNetwork -OrgName $OrgName -SDDCName $SDDCName -LogicalNetworkName $LogicalNetworkName
}
Function Get-VMCSDDCSummary {
<#
.NOTES
@@ -899,7 +899,6 @@ Function Get-VMCSDDCSummary {
$results
}
}
Function Get-VMCPublicIP {
<#
.NOTES
@@ -933,7 +932,6 @@ Function Get-VMCPublicIP {
$publicIPs | select public_ip, name, allocation_id
}
}
Function New-VMCPublicIP {
<#
.NOTES
@@ -972,7 +970,6 @@ Function Get-VMCPublicIP {
$results = $publicIPService.create($orgId,$sddcId,$publicIPSpec)
}
}
Function Remove-VMCPublicIP {
<#
.NOTES
@@ -1007,5 +1004,305 @@ Function Get-VMCPublicIP {
$results = $publicIPService.delete($orgId,$sddcId,$AllocationId)
}
}
Function Get-VMCEdge {
<#
.NOTES
===========================================================================
Created by: Luc Dekens
Date: 23/10/2018
Organization: Community
Blog: http://lucd.info
Twitter: @LucD22
===========================================================================
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'
.SYNOPSIS
Returns all the VMC Edges
.DESCRIPTION
Returns all the VMC Edges
.EXAMPLE
Get-VMCEdge -OrgName $orgName -SddcName $SDDCName -EdgeType gatewayServices
#>
Param (
[Parameter(Mandatory=$True)]
[string]$OrgName,
[Parameter(Mandatory=$True)]
[string]$SDDCName,
[ValidateSet('gatewayServices','distributedRouter')]
[string]$EdgeType = ''
)
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
$edgeService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges'
$index = [long]0
$edges = do{
$edgeData = $edgeService.get($orgId,$sddcId,$EdgeType,'',$index)
$edgeData.edge_page.data | Sort-Object -Property id
$index = $index + $edgeData.edge_page.paging_info.page_size
}
until($index -ge $edgeData.paging_info.total_count)
$edges | %{
[pscustomobject]@{
Name = $_.Name
Id = $_.id
Type = $_.edge_type
State = $_.state
Status = $_.edge_status
VNics = $_.number_of_connected_vnics
TenantId = $_.tenant_id
}
}
}
}
Function Get-VMCEdgeStatus {
<#
.NOTES
===========================================================================
Created by: Luc Dekens
Date: 23/10/2018
Organization: Community
Blog: http://lucd.info
Twitter: @LucD22
===========================================================================
.SYNOPSIS
Returns the status of the gateway
.DESCRIPTION
Retrieve the status of the specified management or compute gateway (NSX Edge).
.EXAMPLE
Get-VMCEdgeStatus -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName
#>
Param (
[Parameter(Mandatory=$True)]
[string]$OrgName,
[Parameter(Mandatory=$True)]
[string]$SDDCName,
[Parameter(Mandatory=$True)]
[string]$EdgeName
)
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
$edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id
$statusService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.status'
$status = $statusService.get($orgId,$sddcId,$edgeId)
$vmStatus = $status.edge_vm_status | %{
[pscustomobject]@{
Name = $_.name
State = $_.edge_VM_status
HAState = $_.ha_state
Index = $_.index
}
}
$featureStatus = $status.feature_statuses | %{
[pscustomobject]@{
Service = $_.service
Status = $_.status
}
}
[pscustomobject]@{
Time = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($status.timestamp/1000))
Status = $status.edge_status
PublishStatus = $status.publish_status
SystemStatus = $_.system_status
NicInUse = $status.ha_vnic_in_use
}
}
}
Function Get-VMCEdgeNic {
<#
.NOTES
===========================================================================
Created by: Luc Dekens
Date: 23/10/2018
Organization: Community
Blog: http://lucd.info
Twitter: @LucD22
===========================================================================
.SYNOPSIS
Returns all interfaces for the gateway
.DESCRIPTION
Retrieve all interfaces for the specified management or compute gateway (NSX Edge).
.EXAMPLE
Get-VMCEdgeNic -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName
#>
Param (
[Parameter(Mandatory=$True)]
[string]$OrgName,
[Parameter(Mandatory=$True)]
[string]$SDDCName,
[Parameter(Mandatory=$True)]
[string]$EdgeName
)
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
$edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id
$vnicService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.vnics'
$vnicService.get($orgId,$sddcId,$edgeId) | select -ExpandProperty vnics | %{
[pscustomobject]@{
Label = $_.label
Name = $_.Name
Type = $_.type
Index = $_.index
IsConnected = $_.is_connected
Portgroup = $_.portgroup_name
}
}
}
}
Function Get-VMCEdgeNicStat {
<#
.NOTES
===========================================================================
Created by: Luc Dekens
Date: 23/10/2018
Organization: Community
Blog: http://lucd.info
Twitter: @LucD22
===========================================================================
.SYNOPSIS
Returns statistics for the gateway interfaces
.DESCRIPTION
Retrieve interface statistics for a management or compute gateway (NSX Edge).
.EXAMPLE
Get-VMCEdgeNicStat -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName
#>
[CmdletBinding(DefaultParameterSetName='Default')]
Param (
[Parameter(Mandatory=$True)]
[string]$OrgName,
[Parameter(Mandatory=$True)]
[string]$SDDCName,
[Parameter(Mandatory=$True)]
[string]$EdgeName
# [DateTime]$Start,
# [DateTime]$Finish
)
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
$edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id
# $epoch = Get-Date 01/01/1970
#
# if($start){
# $startEpoch = (New-TimeSpan -Start $epoch -End $Start.ToUniversalTime()).TotalMilliseconds
# }
# if($Finish){
# $finishEpoch = (New-TimeSpan -Start $epoch -End $Finish.ToUniversalTime()).TotalMilliseconds
# }
$vnicStatService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.statistics.interfaces'
# $stats = $vnicStatService.get($orgId,$sddcId,$edgeId,[long]$startEpoch,[long]$finishEpoch)
$stats = $vnicStatService.get($orgId,$sddcId,$edgeId)
$stats.data_dto | Get-Member -MemberType NoteProperty | where{$_.Name -ne 'Help'} | %{$_.Name} | %{
$stats.data_dto."$_" | %{
[pscustomobject]@{
vNIC = $_.vnic
Timestamp = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($_.timestamp))
In = $_.in
Out = $_.out
Unit = 'Kbps'
Interval = $stats.meta_dto.interval
}
}
}
}
}
Function Get-VMCEdgeUplinkStat {
<#
.NOTES
===========================================================================
Created by: Luc Dekens
Date: 23/10/2018
Organization: Community
Blog: http://lucd.info
Twitter: @LucD22
===========================================================================
.SYNOPSIS
Returns statistics for the uplink interfaces
.DESCRIPTION
Retrieve uplink interface statistics for a management or compute gateway (NSX Edge).
.EXAMPLE
Get-VMCEdgeUplinkStat -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName
#>
Param (
[Parameter(Mandatory=$True)]
[string]$OrgName,
[Parameter(Mandatory=$True)]
[string]$SDDCName,
[Parameter(Mandatory=$True)]
[string]$EdgeName
# [DateTime]$Start,
# [DateTime]$Finish
)
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
$edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id
# $epoch = Get-Date 01/01/1970
#
# if($start){
# $startEpoch = (New-TimeSpan -Start $epoch -End $Start.ToUniversalTime()).TotalMilliseconds
# }
# if($Finish){
# $finishEpoch = (New-TimeSpan -Start $epoch -End $Finish.ToUniversalTime()).TotalMilliseconds
# }
$uplinkStatService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.statistics.interfaces.uplink'
# $stats = $uplinkStatService.get($orgId,$sddcId,$edgeId,[long]$startEpoch,[long]$finishEpoch)
$stats = $uplinkStatService.get($orgId,$sddcId,$edgeId)
$stats.data_dto | Get-Member -MemberType NoteProperty | where{$_.Name -ne 'Help'} | %{$_.Name} | %{
if($stats.data_dto."$_".Count -ne 0){
$stats.data_dto."$_" | %{
[pscustomobject]@{
vNIC = $_.vnic
Timestamp = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($_.timestamp))
In = $_.in
Out = $_.out
Unit = 'Kbps'
Interval = $stats.meta_dto.interval
}
}
}
}
}
}
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',
'Get-VMCEdge', 'Get-VMCEdgeNic', 'Get-VMCEdgeStatus', 'Get-VMCEdgeNicStat', 'Get-VMCEdgeUplinkStat'