VMware Cloud Community
dcarryertoo
Contributor
Contributor

External Networks

Does anyone know of a way to create external networks with PowerCLI?

0 Kudos
8 Replies
CSIEnvironments
Enthusiast
Enthusiast

Unfortunately there is no New-ExternalNetwork, only a New-OrgNetwork cmdlet. It should be possible as there is a cloud view called VMWExternalNetwork, but I've never used it before, but It would start like this:

$mynetwork = new-object vmware.vimautomation.cloud.views.VMWExternalNetwork

$mynetwork.Name = "External_Network_1"

$mynetwork.Description = "My First External Network"

$mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef

$mynetwork.VimPortGroupRef.VimServerRef  = new-object VMware.VimAutomation.Cloud.Views.Reference

$mynetwork.Configuration  = new-object VMware.VimAutomation.Cloud.Views.NetworkConfiguration

$mynetwork.Configuration.IpScopes  = new-object VMware.VimAutomation.Cloud.Views.IpScopes

$mynetwork.Configuration.IpScopes.IpScope  = new-object VMware.VimAutomation.Cloud.Views.IpScope

Then you will have you initial building blocks for your external network. If you can't puzzle together the rest you may need one of the VMWare guys to assist or Jake Robinson is pretty good with Cloud Views. Sadly there is slim to no documentation for the all powerful cloud views.

Cheers!

0 Kudos
dcarryertoo
Contributor
Contributor

I started to piece together a solution to this problem but I am still pretty lost. I think I have some of it correct but the portions in bold are seemingly beyond me? Can anyone lend a hand?

$mynetwork = new-object vmware.vimautomation.cloud.views.VMWExternalNetwork

$mynetwork.Name = "External_Network_1"

$mynetwork.Description = "My First External Network"

$mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef

$mynetwork.VimPortGroupRef.VimServerRef  = new-object VMware.VimAutomation.Cloud.Views.Reference

$mynetwork.Configuration  = new-object VMware.VimAutomation.Cloud.Views.NetworkConfiguration

$mynetwork.Configuration.IpScopes  = new-object VMware.VimAutomation.Cloud.Views.IpScopes

$mynetwork.Configuration.IpScopes.IpScope  = new-object VMware.VimAutomation.Cloud.Views.IpScope

$mynetwork.Configuration.IpScope = new-object vmware.vimautomation.cloud.views.ipscope

$mynetwork.Configuration.IpScope.gateway = "192.168.3.1"

$mynetwork.Configuration.IpScope.Netmask = "255.255.255.0"

$mynetwork.Configuration.IpScope.ipranges = new-object vmware.vimautomation.cloud.views.ipranges

$mynetwork.Configuration.IpScope.IpRanges.IpRange = new-object vmware.vimautomation.cloud.views.iprange

$mynetwork.Configuration.IpScope.IpRanges.IpRange[0].startaddress = "192.168.3.100"

$mynetwork.Configuration.IpScope.IpRanges.IpRange[0].endaddress = "192.168.3.200"

$mynetwork.Configuration.updateserverdata()

0 Kudos
rastarockman
Contributor
Contributor

Were you able to figure out external network creation?

0 Kudos
dcarryertoo
Contributor
Contributor

I think am pretty close now.

The following doesn't throw any errors, but it also doesn't create the external network.

$mynetwork = new-object vmware.vimautomation.cloud.views.VMWExternalNetwork

$mynetwork.Name = "External_Network_1"

$mynetwork.Description = "My First External Network"

$mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef

$vcloud = $DefaultCIServers[0].ExtensionData

$admin = $vcloud.GetAdmin()

$ext = $admin.GetExtension()

$VC = $ext.GetVimServerReferences()

$VimServer = $vc.VimServerReference[0]

$href = $VimServer.href

$mynetwork.VimPortGroupRef.VimServerRef  = new-object VMware.VimAutomation.Cloud.Views.Reference

$mynetwork.VimPortGroupRef.VimServerRef.href = $href

$mynetwork.VimPortGroupRef.VimServerRef.type = "application/vnd.vmware.admin.vmwvirtualcenter+xml"

$mynetwork.VimPortGroupRef.VimServerRef.name = ""

$mynetwork.VimPortGroupRef.MoRef = "VLAN100"

$mynetwork.VimPortGroupRef.VimObjectType = "NETWORK"

$mynetwork.Configuration  = new-object VMware.VimAutomation.Cloud.Views.NetworkConfiguration

$mynetwork.Configuration.IpScopes  = new-object VMware.VimAutomation.Cloud.Views.IpScopes

$mynetwork.Configuration.IpScopes.IpScope  = new-object VMware.VimAutomation.Cloud.Views.IpScope

$mynetwork.Configuration.IpScope = new-object vmware.vimautomation.cloud.views.ipscope

$mynetwork.Configuration.IpScope.gateway = "192.168.3.1"

$mynetwork.Configuration.IpScope.Netmask = "255.255.255.0"

$mynetwork.Configuration.IpScope.IsInherited = "False

$mynetwork.Configuration.IpScope.ipranges = new-object vmware.vimautomation.cloud.views.ipranges

$mynetwork.Configuration.IpScope.IpRanges.IpRange = new-object vmware.vimautomation.cloud.views.iprange

$mynetwork.Configuration.IpScope.IpRanges.IpRange[0].startaddress = "192.168.3.100"

$mynetwork.Configuration.IpScope.IpRanges.IpRange[0].endaddress = "192.168.3.200"

$mynetwork.UpdateServerData()

Any help at all would be appreciated.

Thanks!!

0 Kudos
dcarryertoo
Contributor
Contributor

I've almost got it (I think)

Here is the code......

$mynetwork = new-object vmware.vimautomation.cloud.views.VMWExternalNetwork

$mynetwork.Name = "External_Network_1"

$mynetwork.Description = "My First External Network"

$mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef

$vcloud = $DefaultCIServers[0].ExtensionData

$admin = $vcloud.GetAdmin()

$ext = $admin.GetExtension()

$VC = $ext.GetVimServerReferences()

$VimServer = $vc.VimServerReference[0]

$href = $VimServer.href

$mynetwork.VimPortGroupRef.VimServerRef  = new-object VMware.VimAutomation.Cloud.Views.Reference

$mynetwork.VimPortGroupRef.VimServerRef.href = $href

$mynetwork.VimPortGroupRef.VimServerRef.type = "application/vnd.vmware.admin.vmwvirtualcenter+xml"

$mynetwork.VimPortGroupRef.VimServerRef.name = ""

$mynetwork.VimPortGroupRef.MoRef = "VLAN100"

$mynetwork.VimPortGroupRef.VimObjectType = "NETWORK"

$mynetwork.Configuration  = new-object VMware.VimAutomation.Cloud.Views.NetworkConfiguration

$mynetwork.Configuration.IpScopes  = new-object VMware.VimAutomation.Cloud.Views.IpScopes

$mynetwork.Configuration.IpScopes.IpScope  = new-object VMware.VimAutomation.Cloud.Views.IpScope

$mynetwork.Configuration.IpScopes.ipscope[0].gateway = "192.168.3.1"

$mynetwork.Configuration.IpScopes.ipscope[0].Netmask = "255.255.255.0"

$mynetwork.Configuration.IpScopes.ipscope[0].IsInherited = "False"

$mynetwork.Configuration.IpScopes.ipscope[0].ipranges = new-object vmware.vimautomation.cloud.views.ipranges

$mynetwork.Configuration.Ipscopes.ipscope[0].ipranges.iprange = new-object vmware.vimautomation.cloud.views.iprange

$mynetwork.Configuration.IpScopes.ipscope[0].IpRanges.IpRange[0].startaddress = "192.168.3.100"

$mynetwork.Configuration.IpScopes.ipscope[0].IpRanges.IpRange[0].endaddress = "192.168.3.200"

$mynetwork.UpdateServerData()

Everything is fine until the last line which fails with.......

Exception calling "UpdateServerData" with "0" argument(s): "Object reference not set to an instance of an object."

Anything? Anyone?

0 Kudos
Zimeon
Contributor
Contributor

I've been working on this as well and found this post. Did you ever get it to work?

Edit: I've made a few small modifications to it and i think it boils down to the UpdateServerData method. If it's compared to the blog post about creating a provider VDC it should be something like $ext.CreateExternalNetwork but that doesn't exist.

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

Got no clue how to get a list of available methods, that might help.

And here's the vCD API reference: VMware vCloud Director Documentation Center

My small changes:

I think this: $mynetwork.VimPortGroupRef.VimObjectType should be DV_PORTGROUP and not NETWORK.

Edit: Full code on my next post

0 Kudos
rastarockman
Contributor
Contributor

I tried to work on this for a day and gave up. Instead i deployed a solution using rest API.

I used powercli for getting:

1. VimServerReference

2. VD Port group

Curl for

1. The login token

2. Posting the New External Network

0 Kudos
Zimeon
Contributor
Contributor

I got it to work, the issue was the command. Found after quite some time of digging a post on how to pick up the available methods.

lucd:s old post here: http://www.lucd.info/2012/01/10/powercli-5-0-1-goes-cloud/

has a command like this | get-member

Now this combined with the $ext previously listed a command named CreateExternalNet, which ends up like this:

$dvPG = "dvPG_L2_nnnn"

$vCSName = "VCS1"

$vcloud = $DefaultCIServers[0].ExtensionData

$admin = $vcloud.GetAdmin()

$ext = $admin.GetExtension()

$mynetwork = new-object vmware.vimautomation.cloud.views.VMWExternalNetwork

$mynetwork.Name = "External_Network_1"

$mynetwork.Description = "My First External Network"

$vCenter = Search-Cloud VirtualCenter | Get-CIView | where {$_.name -eq $vCSName}

$dvpg = get-view -viewtype DistributedVirtualPortGroup | where {$_.name -like $dvPG}

write-host "vCenter href: "$vCenter.href

write-host "dvPG Key: " $dvPG.key

$mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef

$mynetwork.VimPortGroupRef.MoRef = $dvPG.key

$mynetwork.VimPortGroupRef.VimObjectType = "DV_PORTGROUP"

$mynetwork.VimPortGroupRef.VimServerRef  = new-object VMware.VimAutomation.Cloud.Views.Reference

$mynetwork.VimPortGroupRef.VimServerRef.href = $vCenter.href

#$mynetwork.VimPortGroupRef.VimServerRef.type = "application/vnd.vmware.admin.vmwvirtualcenter+xml"

$mynetwork.Configuration  = new-object VMware.VimAutomation.Cloud.Views.NetworkConfiguration

$mynetwork.configuration.fencemode = "isolated"

$mynetwork.Configuration.IpScopes  = new-object VMware.VimAutomation.Cloud.Views.IpScopes

$mynetwork.Configuration.IpScopes.IpScope  = new-object VMware.VimAutomation.Cloud.Views.IpScope

$mynetwork.Configuration.IpScopes.ipscope[0].Gateway = "192.168.3.1"

$mynetwork.Configuration.IpScopes.ipscope[0].Netmask = "255.255.255.0"

$mynetwork.Configuration.IpScopes.ipscope[0].IsInherited = "False"

$mynetwork.Configuration.IpScopes.ipscope[0].ipranges = new-object vmware.vimautomation.cloud.views.ipranges

$mynetwork.Configuration.Ipscopes.ipscope[0].ipranges.iprange = new-object vmware.vimautomation.cloud.views.iprange

$mynetwork.Configuration.IpScopes.ipscope[0].IpRanges.IpRange[0].startaddress = "192.168.3.100"

$mynetwork.Configuration.IpScopes.ipscope[0].IpRanges.IpRange[0].endaddress = "192.168.3.200"

$result = $ext.CreateExternalNet($mynetwork)

$result

And a quick post about this as well: http://www.null-byte.org/vmware/vcloud-director-5-x-creating-an-external-network-with-powercli/

0 Kudos