gertvangorp
Enthusiast
Enthusiast

VMware on AWS - Create a logical network using PowerCLI

Jump to solution

Hi,

I am doing a project for a customer and we are working on VMWare on AWS dedicated environment.

I know there are some examples available Getting Started with the VMware Cloud on AWS Module - VMware PowerCLI Blog - VMware Blogs

But what I am missing here is Get-LogicalNetworks, New-Logical-Network, Remove-LogicalNetwork

I alrteady created a get-logicalnetworks function.

This is the code I want to execute

Connect-VMc -RefreshToken ŸourCode

$org = Get-VMCOrg

$SDDCS = Get-VMCSDDC -Org $org.Display_name

$logicalNetworks = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical

$logicalnetworkspec = $logicalNetworks.Help.create.sddc_network.Create()

$logicalnetworkspec.name = "Gert"

$logicalnetworkspec.cgw_id = "edge-2"

$logicalnetworkspec.cgw_name = "SDDC-CGW-1"

$Subnetspec = $logicalNetworks.Help.create.sddc_network.subnets.Create()

$NetworkAddressGroupSpec = $logicalNetworks.Help.create.sddc_network.subnets.address_groups.Create()

$PrefixLength = "24"

$PrimaryAddress = "192.168.100.1"

$networkAddressGroupSpec.Add(@{ help = ""; prefixlengt = $PrefixLength; primary_address = $PrimaryAddress })

$Subnetspec.address_groups.Add($networkAddressGroupSpec)

$logicalnetworkspec.subnets = $Subnetspec

$logicalNetworks.create($org.id, $sddc.id, $logicalnetworkspec)

But I get this error after the last line....

ERROR: userValue

this is the API code needed, but it looks like I am missing something...

SddcNetwork  {

CgwId:   (String)  ID Of The Compute Gateway Edge To Which The Logical Network Is Attached.;

CgwName:   (String)  Name Of The Compute Gateway To Which The Logical Network Is Attached.;

DhcpConfigs:   (Object)  DHCP Configuration For Routed Logical Networks.;

SddcNetworkDhcpConfig  {

IpPools:   (Array)  List Of IP Pools In DHCP Configuration.;

[

SddcNetworkDhcpIpPool  { ... }

]

}

Id:   (String)  ID Of Logical Network.;

L2Extension:   (Object)  Layer 2 Extension For Extended Logical Networks.;

L2Extension  {

TunnelId:   (Integer)  Identifier For Layer 2 Extension Tunnel. Valid Range: 1-4093.;

}

Name:   (String)  Name Of Logical Network. Length Needs To Be Between 1-35 Characters.;

Subnets:   (Object)  Network Address Groups For Routed Logical Networks.;

SddcNetworkAddressGroups  {

AddressGroups:   (Array)  List Of Logical Network Address Groups.;

[

SddcNetworkAddressGroup  {

PrefixLength:   (String)  Prefix Length Of Logical Network.;

PrimaryAddress:   (String)  Primary Address For Logical Network.;

}

]

}

}

1 Solution

Accepted Solutions
kmruddyVMW
Enthusiast
Enthusiast

Here's some sample code I was able to get working:

$logNetSvc = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical

$logNetSpec = $logNetSvc.Help.create.sddc_network.Create()

$logNetSpec.name = "KR-PowerCLI-Network"

$logNetSpec.cgw_id = "edge-2"

$logNetSpec.cgw_name = "SDDC-CGW-1"

$netAddGrpItemSpec = $logNetSvc.Help.create.sddc_network.subnets.address_groups.Element.Create()

$netAddGrpItemSpec.prefix_length = "24"

$netAddGrpItemSpec.primary_address = "10.10.150.1"

$logNetSpec.subnets.address_groups.Add($netAddGrpItemSpec)

$logNetSvc.create($org.id, $sddc.id, $logNetSpec)

Lots of trial and error plus using 'Get-Member' to figure it out

View solution in original post

3 Replies
kmruddyVMW
Enthusiast
Enthusiast

Here's some sample code I was able to get working:

$logNetSvc = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical

$logNetSpec = $logNetSvc.Help.create.sddc_network.Create()

$logNetSpec.name = "KR-PowerCLI-Network"

$logNetSpec.cgw_id = "edge-2"

$logNetSpec.cgw_name = "SDDC-CGW-1"

$netAddGrpItemSpec = $logNetSvc.Help.create.sddc_network.subnets.address_groups.Element.Create()

$netAddGrpItemSpec.prefix_length = "24"

$netAddGrpItemSpec.primary_address = "10.10.150.1"

$logNetSpec.subnets.address_groups.Add($netAddGrpItemSpec)

$logNetSvc.create($org.id, $sddc.id, $logNetSpec)

Lots of trial and error plus using 'Get-Member' to figure it out

View solution in original post

LucD
Leadership
Leadership

Now if only they would give out some free hours of access to some vExperts, perhaps there would be more code in the public domain :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

gertvangorp
Enthusiast
Enthusiast

Thanks,

this is working for me.

gert

0 Kudos