alexfear
Contributor
Contributor

Assign network to VM nic at the instantiation step

Hey guys,

I'm stuck with the situation where I'm not able to assign network to VM's nic at the step of vApp instantiation from a template.

I've read this docs VMware vCloud Director 5.6 Documentation Center and tried using the construction:

<?xml version="1.0" encoding="UTF-8"?>

<InstantiateVAppTemplateParams

   xmlns="http://www.vmware.com/vcloud/v1.5"

   name="111VApp"

   deploy="true"

   powerOn="false"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">

   <Description>vApp with the new network</Description>

   <InstantiationParams>

      <NetworkConfigSection>

         <ovf:Info>Configuration parameters for logical networks</ovf:Info>

         <NetworkConfig networkName="net1">

            <Configuration>

               <ParentNetwork href="https://vcloud.com/api/network/15eb0d34-b69c-4e51-89bd-897c70b63615" />

               <FenceMode>bridged</FenceMode>

            </Configuration>

         </NetworkConfig>

      </NetworkConfigSection>

   </InstantiationParams>

   <Source href="https://vcloud.com/api/vAppTemplate/vappTemplate-db2d4ba6-7f36-44be-a2de-50ddff8a3985" />

   <SourcedItem>

      <Source href="https://vcloud.com/api/vAppTemplate/vm-28bfdffa-a75e-4921-9de1-6a3c4fdb8af6"/>

      <VmGeneralParams>

         <Name>111VM</Name>

         <Description>VM with the new network</Description>

         <NeedsCustomization>true</NeedsCustomization>

      </VmGeneralParams>

      <InstantiationParams>

         <NetworkConnectionSection href="https://vcloud.com/api/vAppTemplate/vm-28bfdffa-a75e-4921-9de1-6a3c4fdb8af6/networkConnectionSection..." type="application/vnd.vmware.vcloud.networkConnectionSection+xml" ovf:required="false">

            <ovf:Info>Specifies the available VM network connections</ovf:Info>

            <PrimaryNetworkConnectionIndex>0</PrimaryNetworkConnectionIndex>

            <NetworkConnection needsCustomization="true" network="net1">

               <NetworkConnectionIndex>0</NetworkConnectionIndex>

               <IsConnected>false</IsConnected>

               <MACAddress>00:50:56:01:00:bc</MACAddress>

               <IpAddressAllocationMode>POOL</IpAddressAllocationMode>

            </NetworkConnection>

         </NetworkConnectionSection>

         <ovf:VirtualHardwareSection

            xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"

            xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"

            xmlns:vmw="http://www.vmware.com/schema/ovf"

            xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"

            xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"

            ovf:transport=""

            vcloud:href="https://vcloud.com/api/vAppTemplate/vm-28bfdffa-a75e-4921-9de1-6a3c4fdb8af6/VirtualHardwareSection/"

            vcloud:type="application/vnd.vmware.vcloud.virtualHardwareSection+xml">

            <ovf:Info>Virtual hardware requirements</ovf:Info>

            <ovf:Item>

               <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>

               <rasd:Description>Number of Virtual CPUs</rasd:Description>

               <rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>

               <rasd:InstanceID>41</rasd:InstanceID>

               <rasd:Reservation>0</rasd:Reservation>

               <rasd:ResourceType>3</rasd:ResourceType>

               <rasd:VirtualQuantity>2</rasd:VirtualQuantity>

               <rasd:Weight>0</rasd:Weight>

            </ovf:Item>

         </ovf:VirtualHardwareSection>

      </InstantiationParams>

   </SourcedItem>

   <AllEULAsAccepted>true</AllEULAsAccepted>

</InstantiateVAppTemplateParams>

vCloud Director 5.6 throws the 400 error:

Unsupported instantiation section: {http://www.vmware.com/vcloud/v1.5}NetworkConnectionSection

How is that possible if VMware docs says otherwise? (read InstantiationParamsType)

If I add <ovf:NetworkConnectionSection... then error is 400 Bad Request:<N<NetworkConnectionSection hretworkConnectionSection hr

Bad request

- Unexpected JAXB Exception

- cvc-complex-type.2.4.a: Invalid content was found starting with element 'ovf:NetworkConnectionSection'. One of '{&quot;http://www.vmware.com/vcloud/v1.5":VCloudExtension, &quot;http://schemas.dmtf.org/ovf/envelope/1":Section}' is expected.

The thing is that the request works well with recomposeVApp/reconfigureVm actions.

So am I right that I cannot assign vApp network to VM's nic at the instantiation step? Is this just a vCD API weakness?

Thanks!

0 Kudos
6 Replies
IamTHEvilONE
Immortal
Immortal

can you try omitting everything but the network the NIC is assigned to, and make sure you follow the format and order of the SPEC?

If you are cloning a VM, some of the information you have should be inherited from the Catalog.

Also, i would try posting in the vCloud API forum since this is typically the section of the forums for GUI based issues (and sometimes we can sort the API problems as well).

0 Kudos
onappdev
Enthusiast
Enthusiast

Thanks for the reply!

I tried omitting everything but the NetworkConfigSection at the vApp level and the NetworkConnectionSection at the VM level and nothing changed. The same 400 error "unsupported instantiation section NetworkConnectionSection" occured.

I've googled a lot on this issue and found the several same ones unresolved. I'm not sure, but it seems like impossible to connect vApp network to VM's nic at the instantiation step through the vCD API.

It'd be great if someone could confirm or deny that.

I created the same thread in vCloud API forum, thanks for the suggestion.

0 Kudos
yadavk
Contributor
Contributor

Hi,

Looking at the error which is thrown, it shows that the sections are which are mandatory are not well performed.

Please try with the below provided code snippet.

                Console.WriteLine("Instantiating VappTemplate: "   + vAppTemplateReference.name);

                Console.WriteLine("-----------------------------------");

                NetworkConfigurationType networkConfigurationType = new NetworkConfigurationType();

                if (vdc.GetAvailableNetworkRefs().Count == 0)

                {

                    Console.WriteLine("No Networks in vdc to instantiate the vapp");

                    return null;

                }

                networkConfigurationType.ParentNetwork = vdc.GetAvailableNetworkRefs().FirstOrDefault();

                networkConfigurationType.FenceMode = FenceModeValuesType.BRIDGED.Value();

                VAppNetworkConfigurationType vAppNetworkConfigurationType = new VAppNetworkConfigurationType();

                vAppNetworkConfigurationType.Configuration = networkConfigurationType;

                vAppNetworkConfigurationType.networkName = vdc.GetAvailableNetworkRefs().FirstOrDefault().name;

                NetworkConfigSectionType networkConfigSectionType = new NetworkConfigSectionType();

                Msg_Type networkInfo = new Msg_Type();

                networkConfigSectionType.Info = networkInfo;

                List<VAppNetworkConfigurationType> vAppNetworkConfigs = new List<VAppNetworkConfigurationType>();

                vAppNetworkConfigs.Add(vAppNetworkConfigurationType);

                networkConfigSectionType.NetworkConfig = vAppNetworkConfigs.ToArray();

                InstantiationParamsType instantiationParamsType = new InstantiationParamsType();

                List<Section_Type> sections = new List<Section_Type>();

                sections.Add(networkConfigSectionType);

                instantiationParamsType.Items = sections.ToArray();

                InstantiateVAppTemplateParamsType instVappTemplParamsType = new InstantiateVAppTemplateParamsType();

                instVappTemplParamsType.name = "HellovCloudvAppp";

                instVappTemplParamsType.Source = vAppTemplateReference;

                instVappTemplParamsType.InstantiationParams = instantiationParamsType;

                Vapp vapp = vdc.InstantiateVappTemplate(instVappTemplParamsType);

                Console.WriteLine("Vapp Name: " + vapp.Resource.name);

                Console.WriteLine("--------------------");

                 List<Task> tasks = vapp.Tasks;

                if (tasks.Count > 0)

                tasks[0].WaitForTask(0);                 

             

                // fetch the instantiated vapp

                vapp = Vapp.GetVappByReference(vcloudClient, vapp.Reference);

0 Kudos
yadavk
Contributor
Contributor

Hi Onappdev,

I hope the provided code snippet resolved the issue which you were facing.

Kindly let me know if you are still facing the same issue.

Regards,

Kapil

0 Kudos
onappdev
Enthusiast
Enthusiast

Hey Yadavk,

First of all thanks for the effort!

Unfortunately I don't know how to test your code snippet. All I have is a rest client (lets say "curl"), and I need to instantiate a vApp with VMs inside and connect those VMs to some available org/vapp networks.

0 Kudos
kkeshri
VMware Employee
VMware Employee

This is what I did for similar use case.

Part1:

Added the required network to an existing vApp.

Content type: application/vnd.vmware.vcloud.recomposeVAppParams+xml

<?xml version="1.0" encoding="UTF-8"?>

<RecomposeVAppParams

name="Example Corp’s CRM Appliance"

xmlns="http://www.vmware.com/vcloud/v1.5"

xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">

<Description>Composed CRM Appliance</Description>

<InstantiationParams>

<NetworkConfigSection>

<ovf:Info>Configuration parameters for logical networks</ovf:Info>

<NetworkConfig

networkName="Org1-net">

<Configuration>

<ParentNetwork

href="https://192.168.9.23/api/admin/network/698fff30-b753-4373-a315-17cd9152b10a" />

<FenceMode>Bridged</FenceMode>

</Configuration>

</NetworkConfig>

</NetworkConfigSection>

</InstantiationParams>

<AllEULAsAccepted>true</AllEULAsAccepted>

</RecomposeVAppParams>

Part2:

Once the network is added to the vApp add the template VM in the vApp connect it to the desired network

Content type: application/vnd.vmware.vcloud.recomposeVAppParams+xml


<?xml version="1.0" encoding="UTF-8"?>

<RecomposeVAppParams xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">

<SourcedItem sourceDelete="false">

    <Source href="https://192.168.9.23/api/vAppTemplate/vm-6bf05d97-e720-46f4-8141-78514b07f62e" name="new-vm"/>

<InstantiationParams>

<NetworkConnectionSection>

<ovf:Info/>

<PrimaryNetworkConnectionIndex>0</PrimaryNetworkConnectionIndex>

<NetworkConnection network="Org1-net">

<NetworkConnectionIndex>0</NetworkConnectionIndex>

<IsConnected>true</IsConnected>

<IpAddressAllocationMode>POOL</IpAddressAllocationMode>

</NetworkConnection>

</NetworkConnectionSection>

<GuestCustomizationSection>

<ovf:Info/>

<Enabled>true</Enabled>

<ChangeSid>false</ChangeSid>

<AdminPasswordEnabled>false</AdminPasswordEnabled>

<ComputerName>win12</ComputerName>

</GuestCustomizationSection>

</InstantiationParams>

</SourcedItem>

<AllEULAsAccepted>true</AllEULAsAccepted>

<CreateItem name="NIC Test VM"/>

</RecomposeVAppParams>




0 Kudos