VMware Cloud Community
Gabrie1
Commander
Commander

Need some help to put it all together

Hi

Trying to create a script for vCloud Director automation. For a vApp with a number of networks, I want to create static routes on a vApp. I have found some components to use, but I just can't get the components to work. It isn't really a script yet, I was first playing with the snippets. I have already created some StaticRoutes through the GUI as an example to work with.

The vApp on which I have a number of networks configured is named: vApp_Topdesk

The networks are: vAppNet-10.239.12, vAppNet-172.17.1, vAppNet-172.17.12, vAppNet-10.239.1

Snippets:

$vAppTopdesk = Get-CIVApp -Name vApp_Topdesk

$FirstvNet = $vAppTopdesk | Get-CIVAppNetwork -Name vAppNet-10.239.12

If I now run this:

$FirstNet.ExtensionData.Configuration.features.StaticRoute

The result is:

Name             : To-10.239.1

Network          : 10.239.1.0/24

NextHopIp        : 192.168.0.10

Interface        : External

GatewayInterface :

AnyAttr          :

VCloudExtension  :


Name             : To-172.17.1

Network          : 172.17.1.0/24

NextHopIp        : 192.168.0.124

Interface        : External

GatewayInterface :

AnyAttr          :

VCloudExtension  :

Now I would like to add a static route myself. So I build this:

$routeService = New-Object vmware.vimautomation.cloud.views.staticroutingservice

$routeService.IsEnabled = $true   <---- Not sure if needed because I already have static routes

$routeService.StaticRoute = New-Object vmware.vimautomation.cloud.views.staticroute

$routeService.StaticRoute[0].name = "To-172.17.12"

$routeService.StaticRoute[0].network = "172.17.12.0/24"

$routeService.StaticRoute[0].nexthopip = "192.168.0.21"

$routeService.StaticRoute[0].interface = "External"

But how can I now put the content from $routeService into the vApp?

What I tried:

$vAppNetworks.NetworkConfig += $routeService

Exception setting "NetworkConfig": "Cannot convert the "VMware.VimAutomation.Cloud.Views.StaticRoutingService" value of type "VMware.VimAutomation.Cloud.Views.StaticRoutingService" to type "VMware.VimAutom

ation.Cloud.Views.VAppNetworkConfiguration"."

At line:1 char:1

+ $vAppNetworks.NetworkConfig += $routeService

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

    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException

    + FullyQualifiedErrorId : ExceptionWhenSetting

And also:

$CurrentStaticRoutes += $routeService[0]

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

At line:1 char:1

+ $CurrentStaticRoutes += $routeService[0]

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

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

    + FullyQualifiedErrorId : MethodNotFound

Any tips on how to get this to work would be great 🙂

http://www.GabesVirtualWorld.com
Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

Moved to the vCloud Director PowerCLI community.


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

Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast

Hi,

I always find using the networking properties from the extensiondata of the CIvApp itself a lot easier. Also to add routes you will need to combine them into 1 route service with multiple static routes as you can only have 1 route service per CIvApp,

I wrote the following script now and tested it & it seems to work.

$civapp = get-civapp "dean*"

$net = ($civapp.ExtensionData.Section | Where {$_.GetType() -like "*networkConfig*"})

$network = $net.NetworkConfig |? {$_.NetworkName -like 'MyIntNat'}

$routeService = New-Object vmware.vimautomation.cloud.views.staticroutingservice

$routeService.IsEnabled = $true

$routeService.StaticRoute = New-Object vmware.vimautomation.cloud.views.staticroute

$routeService.StaticRoute[0].name = "route7"

$routeService.StaticRoute[0].network = "192.168.7.0/24"

$routeService.StaticRoute[0].nexthopip = "10.1.160.1"

$routeService.StaticRoute[0].interface = "External"

$routeService.StaticRoute += New-Object vmware.vimautomation.cloud.views.staticroute

$routeService.StaticRoute[1].name = "route8"

$routeService.StaticRoute[1].network = "192.168.8.0/24"

$routeService.StaticRoute[1].nexthopip = "10.1.160.2"

$routeService.StaticRoute[1].interface = "External"

$network.Configuration.Features[1] = $routeService

$Net.UpdateServerData()

That will create a routeservice with 2 static routes on that CIvApp.

If you want to keep the existing static routes in place, you will need to get the existing routes then add them as a new entry in the $routeService.StaticRoute array.

Hope it helps!

Cheers,

Dean

Reply
0 Kudos