VMware vCloud

 View Only

Network adapters different from what we have in template

  • 1.  Network adapters different from what we have in template

    Posted Dec 19, 2013 12:58 PM

    Hi,

    While trying to deploy a vApp from template, using the SDK, we noticed that the network adapters are different in the resulting VApp's VMs from what we have in the template and . The template had VMX NET3 while the deployed VM had E1000 for a windows OS. Also the DHCP was enabled too which shouldn't be the case.

    For linux OS, we noticed that duplicate IPs were set and no external IP was set.

    Below is the code snippet which I have used:

    public static ComposeVAppParamsType createComposeParams(VappTemplate vappTemplate, Vdc vdc, Map<String, List<String>> networkOptions)

                        throws VCloudException, com.vmware.vcloud.sdk.VCloudException {

            Collection<ReferenceType> networkRefs = vdc.getAvailableNetworkRefs();

            Set<String> networkNamesSelected = new HashSet<String>();

            for (List<String> networkList : networkOptions.values())

            {

                networkNamesSelected.addAll(networkList);

            }

            NetworkConfigSectionType networkConfigSectionType = new NetworkConfigSectionType();

            MsgType networkInfo = new MsgType();

            networkConfigSectionType.setInfo(networkInfo);

            List<VAppNetworkConfigurationType> vAppNetworkConfigs = networkConfigSectionType

                    .getNetworkConfig();

            List<VAppNetworkConfigurationType> templateNetConfigType = vappTemplate.getNetworkConfigSection().getNetworkConfig();

            for (String networkNameSelectedByUser : networkNamesSelected)//We need not add all the networks of the parent vapp. Only the selected networks

            {

                ReferenceType targetNetwork = null;

                for(ReferenceType networkReference : networkRefs){

                    if (networkNameSelectedByUser.equals(networkReference.getName())){

                        targetNetwork = networkReference;

                        break;

                    }

                }

                NetworkConfigurationType newNetworkConfigType = new NetworkConfigurationType();

                VAppNetworkConfigurationType vAppNetworkConfigurationType = new VAppNetworkConfigurationType();

                vAppNetworkConfigurationType.setConfiguration(newNetworkConfigType);

                vAppNetworkConfigs.add(vAppNetworkConfigurationType);

                for( VAppNetworkConfigurationType vAppType : templateNetConfigType ) {

                    NetworkConfigurationType vAppNetworkConfigType = vAppType.getConfiguration();

                    String networkName = vAppType.getNetworkName();

                    NetworkFeaturesType templateFeatures = vAppNetworkConfigType.getFeatures();

                    NetworkFeaturesType features = new NetworkFeaturesType();

                    if (networkNameSelectedByUser.equals(networkName))

                    {

                        List<JAXBElement<? extends NetworkServiceType>> featuresServiceSection = features.getNetworkService();

                        if (null != templateFeatures)

                        {

                            for (JAXBElement<? extends NetworkServiceType> ns : templateFeatures.getNetworkService())

                            {

                                if (ns.getDeclaredType().getName().contains("FirewallServiceType")) {

                                    FirewallServiceType firewallService = (FirewallServiceType) ns.getValue();

                                    FirewallRuleType rule = firewallService.getFirewallRule().get(0);

                                    rule.setDestinationIp("Any");

                                    featuresServiceSection.add(new ObjectFactory().createFirewallService(firewallService));

                                }

                                newNetworkConfigType.setFeatures(features);

                            }

                        }

                        if (null == newNetworkConfigType.getFenceMode())

                        {

                            newNetworkConfigType.setFenceMode(vAppNetworkConfigType.getFenceMode());

                        }

                        if (null != targetNetwork)

                        {

                            newNetworkConfigType.setParentNetwork(targetNetwork);

                        }

                        newNetworkConfigType.setSyslogServerSettings(vAppNetworkConfigType.getSyslogServerSettings());

                        newNetworkConfigType.setIpScopes(vAppNetworkConfigType.getIpScopes());       

                        vAppNetworkConfigurationType.setNetworkName(vAppType.getNetworkName());

                        vAppNetworkConfigurationType.setDescription(vAppType.getDescription());

                        break;

                    }

                }

            }

                   

            // Build the instantion params and add the network settings

            InstantiationParamsType vappOrvAppTemplateInstantiationParamsType = new InstantiationParamsType();

            List<JAXBElement<? extends SectionType>> vappSections = vappOrvAppTemplateInstantiationParamsType

                    .getSection();

            vappSections.add(new ObjectFactory()

                    .createNetworkConfigSection(networkConfigSectionType));

            ComposeVAppParamsType composeVAppParamsType = new ComposeVAppParamsType();

            composeVAppParamsType.setDeploy(false);

            composeVAppParamsType.setAllEULAsAccepted(true);

            composeVAppParamsType

                    .setInstantiationParams(vappOrvAppTemplateInstantiationParamsType);

            String vAppName = "test";

            composeVAppParamsType.setName(vAppName);

            List<SourcedCompositionItemParamType> items = composeVAppParamsType.getSourcedItem();

            for (int i = 0; i < vappTemplate.getChildren().size(); i++) {

                VappTemplate vm = vappTemplate.getChildren().get(i);

                SourcedCompositionItemParamType vappTemplateItem = new SourcedCompositionItemParamType();

                ReferenceType vappTemplateVMRef = new ReferenceType();

                vappTemplateVMRef.setHref(vm.getReference().getHref());

                vappTemplateVMRef.setName(vm.getResource().getName());

               

                vappTemplateItem.setSource(vappTemplateVMRef);

                InstantiationParamsType vmInstantiationParamsType = new InstantiationParamsType();

                /*List<JAXBElement<? extends SectionType>> vmSections = vmInstantiationParamsType.getSection();

                vmSections.add(new ObjectFactory().createNetworkConnectionSection(nwc));

                */vappTemplateItem.setInstantiationParams(vmInstantiationParamsType);

                items.add(vappTemplateItem);

            }

            return composeVAppParamsType;

        }

    What I need is the exact configuration as the template.

    Any help would be much appreciated.

    Thanks,

    Reshmi