Created
May 8, 2023 16:28
-
-
Save gowatana/b86079231641ff37627d13679962619b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get VDC Edge Gateway DNAT Rules | |
# Author: gowatana | |
# Usage: | |
# PS> Connect-CIServer -Server $vcd_address -Org $org_name -Credential (Get-Credential) | |
# PS> ./11_get_edge_gateway_nat_rules.ps1 ./config.ps1 | |
# API Refelence: | |
# https://developer.vmware.com/apis/vmware-cloud-director/v37.2/edge-gateway-nat-rule/ | |
$config_ps1_file = $args[0] | |
if($args.Count -ne 1){"Config .ps1 NOT found."; exit 1} | |
Get-ChildItem -ErrorAction:Ignore $config_ps1_file | Out-Null | |
if($? -eq $false){"Config $config_ps1_file NOT found."; exit 1} | |
. $config_ps1_file | |
Add-Type @" | |
using System.Net; | |
using System.Security.Cryptography.X509Certificates; | |
public class TrustAllCertsPolicy : ICertificatePolicy { | |
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { | |
return true; | |
} | |
} | |
"@ | |
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy | |
function get_edge_gateway_nat_rules (){ | |
param( | |
[Parameter(Mandatory=$true)]$edge_gateway | |
) | |
$vcd_instance = $global:DefaultCIServers | |
$edge_view = $edge_gateway | Get-CIView | |
$edge_id = $edge_view.id | |
$url = "https://" + $vcd_instance.name + "/cloudapi/1.0.0/edgeGateways/" + $edge_id + "/nat/rules" | |
$headers = @{ | |
"accept"="application/json;version=37.0"; | |
"Authorization" = $global:DefaultCIServers.SessionSecret | |
} | |
$edge_nat_rules = Invoke-WebRequest -Method Get -Headers $headers -Uri $url | |
return ($edge_nat_rules.Content | ConvertFrom-Json).values | |
} | |
$edge_gateway = Get-EdgeGateway -OrgVdc $vdc_name -Name $edge_gateway_name | |
get_edge_gateway_nat_rules $edge_gateway |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記の投稿むけ。
VMware Cloud Director 10.4 を PowerCLI で操作してみる。Part-06 Edge Gateway NAT Rule の操作https://vm.gowatana.jp/entry/2023/05/09/021920