More

vCloud Director 5.x – Creating an External Network with PowerCLI

By Antti Hurme 21/02/2014 1 Comment 2 Min Read

A quick note here regarding how to create an External Network with PowerCLI. This is based on the work of dcarryertoo on the  VMware Community forums here. The method is pretty similar to when creating a Organization Network with mix of creating a new Provider VDC with PowerCLI.

Additional information on how to create a new ProviderVDC can be found here.

And James Bowlings post on how to create organization networks can be found here.

First off you need to connect to your vCloud Director using the following command:

Connect-CIServer -server yyyyy -User aaaaa -Password xxxxx

After that you can use the script below to create an external network based off a dvPG VLAN. You do need to know on which vCenter Server the VLAN is located on as well as what the dvPG is named. Also what to name the new External network an an optional description. Also you do need to fill in the IP addresses as well to make things work as external networks need a IP-Address range when it’s created.

$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 = "NETWORK"
$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.1.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.1.100"
$mynetwork.Configuration.IpScopes.ipscope[0].IpRanges.IpRange[0].endaddress = "192.168.1.199"

$result = $ext.CreateExternalNet($mynetwork)

$result
Written By

Who am I? | Linkedin

View All Articles
v
U
1 Comment
  1. James White says:

    Hi Antti,

    Thank you for your post. I spent about half a day trying to get this to work on vCloud version 8.2. After a lot of piping to Get-Member, I found that the API has changed slightly. I made the following edit:

    Changed this line
    $mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef
    to
    $mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef1

    When I included the 1 on the end it works perfectly. I hope this helps if anyone else comes across the same issue.

    Thanks,
    James

    http://www.eveningit.com

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.