Skip to main content
  1. Posts/

Create OrgNetworks in vCloud Director 5.1 with PowerCLI

·489 words·3 mins· loading · loading · ·
Howto Scripts PowerCLI VCloud Director Vmware

So I know I haven’t posted in a little while anything truly useful…well, hopefully, that changes with this one.  I was approached by a colleague with a need for creating OrgNetworks with PowerCLI.  Knowing that things changed from earlier versions when you could create new OrgNetworks with New-OrgNetwork in vCD 1.5, I needed to see how to do it the new way with Cloud Views.  So first, let’s look at what information we need in order to make this work:

  • Org Name
  • New Org Network Name
  • OrgVDC
  • Edge Gateway
  • IP Information (Gateway, Subnet, DNS, IP Ranges)

Here is the information I used for my test:

  • Org Name: 1001
  • New Org Network Name:  1001-Test
  • OrgVDC:  (This is generated in the script for me based on OrgName.)
  • Edge Gateway: (This is generated for me via Search-Cloud and based on OrgName.)
  • IP Information:  Gateway - 192.168.2.1, Netmask: 255.255.255.0, DNS: 192.168.2.1
  • IP Range Information:  192.168.2.100-192.168.2.200

There are a couple of things that you need to step through to gather the data and I won’t go into details of it in this post due to time. There are quite a few good examples to follow out there but nothing specific to creation of natRouted or direct OrgNetworks.  One that I found very useful was Jake Robinson’s post regarding vApp Network creation with PowerCLI, _Deepdive: vCloud vApp Networks.  _This post led me to a good starting point along with a tad more help from him on the VMware vCloud Director PowerCLI VMTN Community Forums.

Before this gets too long winded for the time I have, here is the script:

## Set to 1 for debug output
$debug = "1"

$orgName = "1001"
$orgNetName = "1001-Test"
$org = Get-OrgVdc $orgName | Get-CIView
$edgeGateway = Search-Cloud -QueryType EdgeGateway | Get-CIView | where {$_.name -like "$orgName*"}

$mynetwork = new-object vmware.vimautomation.cloud.views.orgvdcnetwork
$mynetwork.name = $orgNetName
$mynetwork.edgegateway = $edgeGateway.id
$mynetwork.isshared = "True"

$mynetwork.configuration = new-object vmware.vimautomation.cloud.views.networkconfiguration
$mynetwork.configuration.fencemode = "natRouted"

$mynetwork.configuration.ipscopes = new-object vmware.vimautomation.cloud.views.ipscopes
$scope = new-object vmware.vimautomation.cloud.views.ipscope
$scope.gateway = "192.168.2.1"
$scope.netmask = "255.255.255.0"
$scope.dns1 = "192.168.2.1"

$scope.ipranges = new-object vmware.vimautomation.cloud.views.ipranges
$scope.ipranges.iprange = new-object vmware.vimautomation.cloud.views.iprange
$scope.ipranges.iprange[0].startaddress = "192.168.2.100"
$scope.ipranges.iprange[0].endaddress = "192.168.2.200"

$mynetwork.configuration.ipscopes.ipscope += $scope

$result = $org.CreateNetwork($mynetwork)

if ($debug -eq "1"){
write-host "OrgNetwork Name: "$mynetwork.name
write-host "OrgNetwork EdgeGateway Id: "$mynetwork.edgegateway
write-host "OrgNetwork Fence Mode: "$mynetwork.configuration.fencemode
write-host "OrgNetwork Gateway: "$scope.gateway
write-host "OrgNetwork Subnet: "$scope.netmask
write-host "OrgNetwork Dns1: "$scope.dns1
write-host "OrgNetwork IP Range Start: "$scope.ipranges.iprange[0].startaddress
write-host "OrgNetwork IP Range End: "$scope.ipranges.iprange[0].endaddress
}

Anyway, I hope this helps you figure out what you need to do to get OrgNetworks created in vCD 5.1 now.  I didn’t want to go into too much detail because I have heard from a little birdie that there is going to be a deepdive about OrgNetworks on a certain good blog (Geek After Five), so keep your eyes peeled for that.  Also, for a good reference of the Cloud Views since it isn’t well documented, take a look at the vCloud API Schema Reference.  Now back to work for me…

James Bowling
Author
James Bowling
Principal Cloud Engineer @ Global Oil/Gas Drilling Company

Related

PowerCLI One-liner: Check for Fast-Provisioning Enabled/Disabled on Org vDC in vCD
·54 words·1 min· loading · loading
Howto PowerCLI VCloud Director Vmware
vCenter Certificate Automation Tool 1.0
·261 words·2 mins· loading · loading
Tools Security Sso VCenter Vmware
VMworld 2013 Session Voting Open
·283 words·2 mins· loading · loading
Blog Vmworld