Zimeon
Contributor
Contributor

Organization vDC Edge Gateway

Been trying to figure out how to create a edge gateway in a vDC with powershell and have gotten nowhere, perhaps someone else can give a hand?

So i've tried to check an excisting edge gateway to see what's required when creating one, but that hasn't really helped. So here's what i've been trying to do sofar:

$example = search-cloud -QueryType EdgeGateway | where {$_.name -like "*test*"} | Get-CIView

Status          : 1

Configuration   : VMware.VimAutomation.Cloud.Views.GatewayConfiguration

Name            : test

Description     : test edgegw

Tasks           :

Id              : urn:vcloud:gateway:2e062275-a6db-46b4-83ec-170a24b4fe8d

OperationKey    :

Client          : VMware.VimAutomation.Cloud.Views.CloudClient

Href            : https://example.url/api/admin/edgeGateway/2e062275-a6db-46b4-83ec-170a24b4fe8d

Type            : application/vnd.vmware.admin.edgeGateway+xml

Link            : {, , , ...}

AnyAttr         : {xsi:schemaLocation}

VCloudExtension :

Now, i've tried the following:

$externalnetwork = Get-ExternalNetwork | Get-CIView | ?{$_.name -eq $vCDExtNetName}
$myExtNetwork = new-object vmware.vimautomation.cloud.views.Gateway
$myExtNetwork.Name = $vCDEdgeGWName
$myExtNetwork.Description = $vCDEdgeGWDesc
$myEdgeGateway.GatewayConfiguration  = new-object VMware.VimAutomation.Cloud.Views.GatewayConfiguration
$myEdgeGateway.GatewayConfiguration.GatewayBackingConfig = "compact"
$myEdgeGateway.GatewayConfiguration.GatewayInterfaces  = new-object VMware.VimAutomation.Cloud.Views.reference
$myEdgeGateway.GatewayConfiguration.GatewayInterfaces.GatewayInterface  = new-object VMware.VimAutomation.Cloud.Views.reference
$myEdgeGateway.GatewayConfiguration.GatewayInterfaces.GatewayInterface.Name  = "uplink1"
$myEdgeGateway.GatewayConfiguration.GatewayInterfaces.GatewayInterface.DisplayName  = "uplink1"
$myEdgeGateway.GatewayConfiguration.GatewayInterfaces.GatewayInterface.Network  = $externalnetwork.href
$myEdgeGateway.GatewayConfiguration.GatewayInterfaces.GatewayInterface.InterfaceType = "uplink"
$myEdgeGateway.GatewayConfiguration.IpScopes  = new-object VMware.VimAutomation.Cloud.Views.IpScopes
$myEdgeGateway.GatewayConfiguration.IpScopes.IpScope  = new-object VMware.VimAutomation.Cloud.Views.IpScope
$myEdgeGateway.GatewayConfiguration.IpScopes.ipscope[0].Gateway = $vCDExtNetGw
$myEdgeGateway.GatewayConfiguration.IpScopes.ipscope[0].Netmask = $vCDExtNetSubNetmask
$myEdgeGateway.GatewayConfiguration.IpScopes.ipscope[0].IsInherited = "False"
$myEdgeGateway.GatewayConfiguration.IpScopes.ipscope[0].ipranges = new-object vmware.vimautomation.cloud.views.ipranges
$myEdgeGateway.GatewayConfiguration.Ipscopes.ipscope[0].ipranges.iprange = new-object vmware.vimautomation.cloud.views.iprange
$myEdgeGateway.GatewayConfiguration.IpScopes.ipscope[0].IpRanges.IpRange[0].startaddress = $vCDEdgeWanIPStart
$myEdgeGateway.GatewayConfiguration.IpScopes.ipscope[0].IpRanges.IpRange[0].endaddress = $vCDEdgeWanIPEnd
$myEdgeGateway.GatewayConfiguration.IpScopes.ipscope[0].AllocatedIpAddresses = new-object vmware.vimautomation.cloud.views.AllocatedIpAddresses
$myEdgeGateway.GatewayConfiguration.IpScopes.ipscope[0].AllocatedIpAddresses.IpAddress[0] = $vCDEdgeWanIP

Now this gives a lot of errors, but the first:

Property 'GatewayConfiguration' cannot be found on this object; make sure it exists and is settable.

At D:\DC-DEV\Powershell\test.ps1:96 char:17

+     $myEdgeGateway. <<<< GatewayConfiguration  = new-object VMware.VimAutomation.Cloud.Views.GatewayConfiguration

    + CategoryInfo          : InvalidOperation: (GatewayConfiguration:String) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

Property 'GatewayBackingConfig' cannot be found on this object; make sure it exists and is settable.

At D:\DC-DEV\Powershell\test.ps1:97 char:38

+     $myEdgeGateway.GatewayConfiguration. <<<< GatewayBackingConfig = "compact"

    + CategoryInfo          : InvalidOperation: (GatewayBackingConfig:String) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

Property 'GatewayInterfaces' cannot be found on this object; make sure it exists and is settable.

At D:\DC-DEV\Powershell\test.ps1:100 char:38

+     $myEdgeGateway.GatewayConfiguration. <<<< GatewayInterfaces  = new-object VMware.VimAutomation.Cloud.Views.reference

    + CategoryInfo          : InvalidOperation: (GatewayInterfaces:String) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

Clearly there's a lot things wrong with this, like that GatewayConfiguration doesn't excist and so on. I've also tried "Configuration" with the same error, as stated here: VMware vCloud Director 5.5 Documentation Center

I'm just lost on how should i figure out what to use in this method to get things working? The API documentation gives a hint but doesn't seem to apply 1:1 or then i'm reading it wrong.

0 Kudos
3 Replies
MrBoogiee
Enthusiast
Enthusiast

First thing is that you switch from $myExtNetwork to $myEdgeGateway without any relation between the two. I managed to sort the first error you've got, but ran into some more with my piece of code:

$providerVdc = "Production"

$externalNetwork = Get-ExternalNetwork -ProviderVdc $providerVdc -Name "extNetworkName"

$firewall = New-Object VMware.VimAutomation.Cloud.Views.Gateway

$firewall.Name = $orgName

$firewall.Configuration = New-Object VMware.VimAutomation.Cloud.Views.GatewayConfiguration

$firewall.Configuration.GatewayBackingConfig = "compact"

$firewall.Configuration.GatewayInterfaces = New-Object VMware.VimAutomation.Cloud.Views.GatewayInterfaces

$firewall.Configuration.GatewayInterfaces.GatewayInterface = New-Object VMware.VimAutomation.Cloud.Views.GatewayInterface

$firewall.Configuration.GatewayInterfaces.GatewayInterface.DisplayName = "uplink1"

$firewall.Configuration.GatewayInterfaces.GatewayInterface.Network = $externalNetwork.Href

$firewall.Configuration.GatewayInterfaces.GatewayInterface.InterfaceType = "uplink"

With this bit I run into the following error:

Property 'DisplayName' cannot be found on this object; make sure it exists and is settable.

At line:1 char:1

+ $firewall.configuration.GatewayInterfaces.GatewayInterface.DisplayName = "uplink1"

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyAssignmentException

When I do a get-member on $firewall.configuration.GatewayInterfaces.GatewayInterface I get the following line with regard to the DisplayName field:

DisplayName         Property   string DisplayName {get;set;}

So I should be able to set it, but that turns out to be quite hard... any ideas?

0 Kudos
MrBoogiee
Enthusiast
Enthusiast

got a bit further now with the following:

$firewall = New-Object VMware.VimAutomation.Cloud.Views.Gateway

$firewall.Name = $orgName

$firewall.Configuration = New-Object VMware.VimAutomation.Cloud.Views.GatewayConfiguration

$firewall.Configuration.BackwardCompatibilityMode = $false

$firewall.Configuration.GatewayBackingConfig = "compact"

$firewall.Configuration.UseDefaultRouteForDnsRelay = $true

$firewall.Configuration.HaEnabled = $false

$firewall.Configuration.EdgeGatewayServiceConfiguration = New-Object VMware.VimAutomation.Cloud.Views.GatewayFeatures

$firewall.Configuration.GatewayInterfaces = New-Object VMware.VimAutomation.Cloud.Views.GatewayInterfaces

$firewall.Configuration.GatewayInterfaces.GatewayInterface = New-Object VMware.VimAutomation.Cloud.Views.GatewayInterface

$firewall.Configuration.GatewayInterfaces.GatewayInterface[0].DisplayName = "uplink1"

$firewall.Configuration.GatewayInterfaces.GatewayInterface[0].Network = $externalNetwork.Href

$firewall.Configuration.GatewayInterfaces.GatewayInterface[0].InterfaceType = "uplink"

$firewall.Configuration.GatewayInterfaces.GatewayInterface[0].UseForDefaultRoute = $true

$firewall.Configuration.GatewayInterfaces.GatewayInterface[0].ApplyRateLimit = $false

This no longer gives errors while running this piece of code, but how do I now add the edge gateway? I already tried the following which doesn't work:

$orgvdc = Get-OrgVdc -org $org

$networkConfigSection = $orgvdc.ExtensionData.GetEdgeGateways()

$networkConfigSection += $firewall

This just gives the following error:

Method invocation failed because [VMware.VimAutomation.Cloud.Views.QueryResultRecords] doesn't contain a method named 'op_Addition'.

At line:1 char:25

+ $networkConfigSection += <<<<  $firewall

    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

0 Kudos
MrBoogiee
Enthusiast
Enthusiast

I resolved the last remaining question by using the following line:

$orgvdc.ExtensionData.CreateEdgeGateway($firewall)

0 Kudos