Hello,
I am not a developer, and have very limited experience using VMware APIs. I've looked at the Developer's Guide, and many other resources online, but I'm failing to understand how to properly use the API to automate adding network mappings in SRM. Thus far I have tried a command like:
$defaultsrmservers.extensiondata.InventoryMapping.AddNetworkMapping($vdpg_moref.value, $vdpg_adc_moref.value)
where the argument values are the MoRef value for local and remote distributed port groups (i.e. something like dvportgroup-000000), but I get an error:
Exception calling "AddNetworkMapping" with "2" argument(s):
Error processing attribute "type" with value "dvportgroup"
while parsing MoRef for ManagedObject of type vim.Network
at line 1, column 268
while parsing call information for method AddNetworkMapping
at line 1, column 171
while parsing SOAP body
at line 1, column 64
while parsing SOAP envelope
at line 1, column 0
while parsing HTTP request for method addNetworkMapping
on object of type drextapi.InventoryMapping
at line 1, column 0"
At line:1 char:1
+ $defaultsrmservers.extensiondata.InventoryMapping.AddNetworkMapping($ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : VimException
As I understand it, this is happening because the object type of the arguments I'm passing is not vim.Network, but I'm having trouble understanding how I can convert the object types. I've tried creating a new object with type vim.Network with
new-object -typename vim.Network
but I get the following error:
Cannot find type [vim.Network]: verify that the assembly containing this type is loaded.
At line:1 char:15
+ $networkobj = new-object -TypeName vim.Network
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
I've gone so far as to look at my loaded assemblies with [appdomain]::CurrentDomain.GetAssemblies(), which there is no assembly for vim.Network and I have no idea how to load it if that is indeed my problem. The only documentation I can find on vim.Network just confuses me further.
Am I on the right track here, or totally shooting in the dark? Can anyone help shed light on this? I'd be extremely grateful if someone could give me an example of how to properly use the AddNetworkMapping method with PowerCLI to map distributed port groups in SRM.
Please advise.
Thanks!
You didn't show how you got the content for
$vdpg_moref
but I'm assuming it is the MoRef of a Distributed Portgroup.
Instead of using the Value property, try using the fill MoRef object ($vdpg_moref).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You didn't show how you got the content for
$vdpg_moref
but I'm assuming it is the MoRef of a Distributed Portgroup.
Instead of using the Value property, try using the fill MoRef object ($vdpg_moref).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucD Thanks for taking the time to respond. Also let it be known you have helped me numerous times over the years with your responses to other people's posts and for that I sincerely thank you! Keep up the great work!
I used the below code to get the MoRef for the distributed port group.
$vdpg_primary = Get-VDPortgroup -Server $primary_vcsa -VDSwitch $primary_vdswitch -Name $vdpg
$vdpg_primary_moref = $vdpg_primary.extensiondata.moref
FWIW, I had tried using just $vdpg_moref before adding the ".value" to the end of it and got an error, so I had pivoted to trying with ".value" at the end of that variable.
Of course, now that I spent hours wracking my brain on this and finally decided to reach out for help, it is working as you suggested using the following command:
$defaultsrmservers.extensiondata.InventoryMapping.AddNetworkMapping($vdpg_primary_moref, $vdpg_secondary_moref)
I'm not sure why this wasn't working when I tried it the first time.
$defaultsrmservers.extensiondata.InventoryMapping.AddTestNetworkMapping($vdpg_secondary_moref, $vdpg_secondary_moref)
$vdpg_secondary_moref was captured using:
$vdpg_secondary = Get-VDPortgroup -Server $secondary_vcsa -VDSwitch $secondary_vdswitch -Name $vdpg
$vdpg_secondary_moref = $vdpg_secondary.extensiondata.moref
Thanks again @LucD !