Hi
We've been making use of a poweshell script to assist us in deploying vcloud VDC's. Unfortunately we've noticed that after upgrading to v10 the script fails when it comes to the stage of creating the external network within cloud director. Has anyone else perhaps encountered the same issue and perhaps solved it?
I've attached a screenshot of the error. Script snippet below as well:
## Step 2, Create distributed port groups in vCenter
# Connect to your vCenter instance
Connect-VIServer -Server $vcenterURI -Credential $vcenterpw
# Declare Public and private vlan name variable to use later on for vCenter/vCloud provisioning
$vlanname = "Public-vlan-$vlanid"
$pnVlanName = "Private-vlan-$pnVlanId"
# Create dvswitch port group
Get-VDSwitch -name $dswitchPublic | New-VDPortgroup -Name $vlanname -NumPorts 256 -VlanId $vlanid
# Set IP hash teaming and failover policy
Get-VDPortgroup $vlanname | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceIP -EnableFailback $true
# Connect to vCloud
Connect-CIServer -Server $vdcHost -Credential $vcloudcreds
# Change with the proper vCenter name (vSphere Resources -> vCenters)
$vCSName = $vcentername
$vcloud = $DefaultCIServers[0].ExtensionData
$admin = $vcloud.GetAdmin()
$ext = $admin.GetExtension()
$vCentervCloud = Search-Cloud VirtualCenter | Get-CIView | where {$_.name -eq $vCSName}
## Step 3, Create external network in vCloud
# Get port group for external network
$dvpgPublic = get-view -viewtype DistributedVirtualPortGroup | where {$_.name -like $vlanname}
$mynetwork = new-object vmware.vimautomation.cloud.views.VMWExternalNetwork
$mynetwork.Name = "$vlanname"
$mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef1
$mynetwork.VimPortGroupRef.MoRef = $dvpgPublic.key
$mynetwork.VimPortGroupRef.VimObjectType = "DV_PORTGROUP"
$mynetwork.VimPortGroupRef.VimServerRef = new-object VMware.VimAutomation.Cloud.Views.Reference
$mynetwork.VimPortGroupRef.VimServerRef.href = $vCentervCloud.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 = "$networkgw"
$mynetwork.Configuration.IpScopes.ipscope[0].Netmask = "$networknm"
$mynetwork.Configuration.IpScopes.ipscope[0].Dns1 = "$networkdns1"
$mynetwork.Configuration.IpScopes.ipscope[0].Dns2 = "$networkdns2"
$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 = "$networkstart"
$mynetwork.Configuration.IpScopes.ipscope[0].IpRanges.IpRange[0].endaddress = "$networkend"
$result = $ext.CreateExternalNet($mynetwork)
I work for a multi-tenant cloud provider and we started having the same issue recently too, not with the move to Cloud Director 10.0, but ever since I think 10.2 came out.
SAME exact error. Weird thing is, we have multiple environments and it only fails on some of them, others it still works, but they're all running Cloud Director 10.3.
Hi.
What version of Powershell and PowerCli do you have?
PSVersion 5.1.19041.1682
VMware.PowerCLI 12.5
VMware.Vim 7.0.3.19093568
VMware.VimAutomation.Cis.Core 12.5.0.19093567
VMware.VimAutomation.Cloud 12.0.0.15940183
VMware.VimAutomation.Common 12.5.0.19093563
VMware.VimAutomation.Core 12.5.0.19093566
VMware.VimAutomation.Sdk 12.5.0.19093564
VMware.VimAutomation.Storage 12.5.0.19106817
VMware.VimAutomation.Vds 12.5.0.19167830
I have it working in vCloud 10.2.2.
I use Powershell 7.2.0 and PowerCLI 12.5.0.
Have you tried rest api requests?
Haven't tried RestAPI yet. I just scrubbed out my entire PowerCLI install and reinstalled.
So now PowerCLI 12.7 and I do have Powershell 7.2.5 installed, I'll try that combo first.
Did then update work, we're working on this same thing and see the error in one environment and not another, exact same versions.
We ended up fixing our issue which was the same error you were having and it was related to a truncated name property, so we changed it to the URL property of the search-cloud get-ciview
Went from :
$vCenter = Search-Cloud VirtualCenter | Get-CIView | Where-Object {$_.name -eq $vCSName}
To:
$vCenter = Search-Cloud VirtualCenter | Get-CIView | Where-Object {$_.url -match $vCSName}
Add an "if" condition to check empty variables.
## Step 2, Create distributed port groups in vCenter
# Connect to your vCenter instance
Connect-VIServer -Server $vcenterURI -Credential $vcenterpw
# Declare Public and private vlan name variable to use later on for vCenter/vCloud provisioning
$vlanname = "Public-vlan-$vlanid"
$pnVlanName = "Private-vlan-$pnVlanId"
# Create dvswitch port group
Get-VDSwitch -name $dswitchPublic | New-VDPortgroup -Name $vlanname -NumPorts 256 -VlanId $vlanid
# Set IP hash teaming and failover policy
Get-VDPortgroup $vlanname | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceIP -EnableFailback $true
# Connect to vCloud
Connect-CIServer -Server $vdcHost -Credential $vcloudcreds
# Change with the proper vCenter name (vSphere Resources -> vCenters)
$vCSName = $vcentername
$vcloud = $DefaultCIServers[0].ExtensionData
$admin = $vcloud.GetAdmin()
$ext = $admin.GetExtension()
$vCentervCloud = Search-Cloud VirtualCenter | Get-CIView | where {$_.name -eq $vCSName}
if (!$vCentervCloud) {
Write-Host "Not found vCenterCloud" -ForegroundColor Red
}
else {
Write-Host "vCenterCloud is $($vCentervCloud.name)" -ForegroundColor Green
}
## Step 3, Create external network in vCloud
# Get port group for external network
$dvpgPublic = get-view -viewtype DistributedVirtualPortGroup | where {$_.name -like $vlanname}
if (!$dvpgPublic) {
Write-Host "Not found dvpgPublic" -ForegroundColor Red
}
else {
Write-Host "dvpgPublic is $($dvpgPublic.name)" -ForegroundColor Green
}
$mynetwork = new-object vmware.vimautomation.cloud.views.VMWExternalNetwork
$mynetwork.Name = "$vlanname"
$mynetwork.VimPortGroupRef = new-object VMware.VimAutomation.Cloud.Views.VimObjectRef1
$mynetwork.VimPortGroupRef.MoRef = $dvpgPublic.key
$mynetwork.VimPortGroupRef.VimObjectType = "DV_PORTGROUP"
$mynetwork.VimPortGroupRef.VimServerRef = new-object VMware.VimAutomation.Cloud.Views.Reference
$mynetwork.VimPortGroupRef.VimServerRef.href = $vCentervCloud.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 = "$networkgw"
$mynetwork.Configuration.IpScopes.ipscope[0].Netmask = "$networknm"
$mynetwork.Configuration.IpScopes.ipscope[0].Dns1 = "$networkdns1"
$mynetwork.Configuration.IpScopes.ipscope[0].Dns2 = "$networkdns2"
$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 = "$networkstart"
$mynetwork.Configuration.IpScopes.ipscope[0].IpRanges.IpRange[0].endaddress = "$networkend"
$result = $ext.CreateExternalNet($mynetwork)