We are facing issue at cloning VM stage while creating Vapp from Template on the below condition
Vapp Template is having 2 Nic cards and both are pointing to two different networks(only this particular case we are getting Issue)
We are trying to create Vapp from Template using InstantiationParamsType .
We are using VCD SDK (VcloudSDK_V5_1.dll) to achieve this .
We integrated VCD SDK in VCAC.
We are getting exception only When template is having more than one Nic card and both are pointing to different network.
But in VCD UI side Vapp got created from template.
Exception from VCAC:
com.vmware.vcloud.sdk.utility.VCloudException: validation error : may not be null
at com.vmware.vcloud.sdk.Task.GetTaskByReference(vCloudClient client, ReferenceType taskRef)
The below client code used .
==============================
Vdc vdc = this.GetOrgVdcById(vdcId);
VappTemplate template = this.GetVappTemplate(templateid);
InstantiationParamsType instantiationParamsType = new InstantiationParamsType();
List<Section_Type> sections = new List<Section_Type>();
List<VAppTemplateType> templateVms = template.Resource.Children.Vm.ToList();
NetworkConfigurationType networkConfigurationType = new NetworkConfigurationType();
ReferenceType networkRef = vdc.Resource.AvailableNetworks.Network.Where(n => n.name == networkName).FirstOrDefault();
if (networkRef == null)
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Messages.ErrorGettingNetworkRef, networkName, vdc.Resource.name));
}
networkConfigurationType.ParentNetwork = networkRef;
networkConfigurationType.FenceMode = FenceModeValuesType.BRIDGED.Value();
List<VAppNetworkConfigurationType> appNetworkConfigs = new List<VAppNetworkConfigurationType>();
foreach (VAppTemplateType templateVm in templateVms)
{
NetworkConnectionSectionType networkSection = new NetworkConnectionSectionType();
networkSection = (NetworkConnectionSectionType)templateVm.Items.Where(i => i.GetType().FullName == networkSection.GetType().FullName).FirstOrDefault();
// vApp network is added from template VM's network connections.
string vappNetworkName = networkName;
if (networkSection != null && networkSection.NetworkConnection != null && networkSection.NetworkConnection.Length > 0)
{
foreach (NetworkConnectionType networkConnection in networkSection.NetworkConnection)
{
VAppNetworkConfigurationType appNetworkConfigurationType = new VAppNetworkConfigurationType();
appNetworkConfigurationType.Configuration = networkConfigurationType;
vappNetworkName = networkConnection != null ? networkConnection.network : networkName;
appNetworkConfigurationType.networkName = vappNetworkName;
appNetworkConfigurationType.IsDeployed = true;
appNetworkConfigs.Add(appNetworkConfigurationType);
}
}
else
{
/VAppNetworkConfigurationType appNetworkConfigurationType = new VAppNetworkConfigurationType();
/appNetworkConfigurationType.Configuration = networkConfigurationType;
/appNetworkConfigurationType.networkName = vappNetworkName;
/appNetworkConfigurationType.IsDeployed = true;
/appNetworkConfigs.Add(appNetworkConfigurationType);
}
}
NetworkConfigSectionType networkConfigSectionType = new NetworkConfigSectionType();
networkConfigSectionType.Info = new Msg_Type();
networkConfigSectionType.NetworkConfig = appNetworkConfigs.ToArray();
sections.Add(networkConfigSectionType);
LeaseSettingsSectionType leaseSettingsSectionType = new LeaseSettingsSectionType();
leaseSettingsSectionType.DeploymentLeaseExpiration = new DateTime();
leaseSettingsSectionType.DeploymentLeaseExpirationSpecified = true;
leaseSettingsSectionType.StorageLeaseExpiration = new DateTime();
leaseSettingsSectionType.StorageLeaseExpirationSpecified = true;
leaseSettingsSectionType.Info = new Msg_Type();
sections.Add(leaseSettingsSectionType);
instantiationParamsType.Items = sections.ToArray();
instVappTemplParamsType.name = appName;
instVappTemplParamsType.Source = template.Reference;
instVappTemplParamsType.InstantiationParams = instantiationParamsType;
List<SourcedVmInstantiationParamsType> sourcedVmInstantiationParamsType = new List<SourcedVmInstantiationParamsType>();
foreach (VAppTemplateType templateVm in templateVms)
{
string storageName = vmStorageProfile[templateVm.id];
ReferenceType storageProfileRef = vdc.Resource.VdcStorageProfiles.VdcStorageProfile.Where(r => r.name == storageName).FirstOrDefault();
if (storageProfileRef == null)
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Messages.ErrorStorageNotFoundForProvisioning, storageName));
}
SourcedVmInstantiationParamsType sourcedVmInstatntiationParam = new SourcedVmInstantiationParamsType();
sourcedVmInstatntiationParam.StorageProfile = storageProfileRef;
sourcedVmInstatntiationParam.Source = new ReferenceType() { href = templateVm.href, name = templateVm.name, id = templateVm.id, type = templateVm.type };
sourcedVmInstantiationParamsType.Add(sourcedVmInstatntiationParam);
}
instVappTemplParamsType.SourcedVmInstantiationParams = sourcedVmInstantiationParamsType.ToArray();
Vapp vapp = null;
try
{
vapp = vdc.InstantiateVappTemplate(instVappTemplParamsType);
List<Task> cloneTasks = vapp.Tasks;
foreach (Task cloneTask in cloneTasks)
{
this.WaitForTask(cloneTask, 30);
}
}
catch (VCloudException vcex)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Messages.ErrorCloningMachine, appName, templateName), vcex);
}
↧
could not create Vapp from template which is having more than Nic card both are pointing to two different network
↧