richdenis
Enthusiast
Enthusiast

Reset MAC address using vCloud Java SDK

Here is the scenario:

Taking a running Vapp I want to recompose the Vapp so that it will have a number of VM's (web servers) added.  To do this I get a reference to the Vapp and also the VappTemplate that has the additional web servers.  I then use that reference and create a CompositionItemParamTypeObject and set it up such that the template is then added to Recompose parameters.  While setting up the network I make the call to setMacAddress and try to set it to both "" and null. 

When the Vapp is recomposed, the additional web servers are getting the MAC address of the template (which is also the MAC address of the first web server).  Please advise on how this can be done.  I see that in   http://communities.vmware.com/message/1776708 a similar question was asked using the raw API and the guidance was to not send the MAC address at all.  This doesnt seem to lign up with how it would work using the SDK.

Thanks again for your help.  Here is my code:

            //start to build the item we want to compose
            CompositionItemParamType vmItem = new CompositionItemParamType();
            //building a comp item requires a reference type be created
            ReferenceType vmRef = new ReferenceType();
            //set the href of the vmRef Type to the href of the VappTemplate.
            vmRef.setHref(templateToExpand.getReference().getHref());
            //we need to set the name of the new item
            vmRef.setName(templateToExpand.getReference().getName() + "-" + templateCount++);
            //add the reference to the new item.
            vmItem.setSource(vmRef);

            //setup network for new item.
            NetworkConnectionSectionType networkConnectionSectionType = new NetworkConnectionSectionType();
            MsgType networkInfo = new MsgType();
            networkConnectionSectionType.setInfo(networkInfo);
            //set the connection type information.
            NetworkConnectionType networkConnectionType = new NetworkConnectionType();
            networkConnectionType.setNetwork(appNetworkName);
            networkConnectionType.setMACAddress("");
            networkConnectionType.setIpAddressAllocationMode(IpAddressAllocationModeType.POOL);
            networkConnectionSectionType.getNetworkConnection().add(networkConnectionType);
            InstantiationParamsType vmInstantiationParamsType = new InstantiationParamsType();

            List<JAXBElement<? extends SectionType>> vmSections = vmInstantiationParamsType.getSection();
            vmSections.add(new ObjectFactory().createNetworkConnectionSection(networkConnectionSectionType));

            vmItem.setInstantiationParams(vmInstantiationParamsType);
            rvpt.getItem().add(vmItem);

0 Kudos
4 Replies
rkamal
VMware Employee
VMware Employee

Hi,

Looks like you are using vCloud Java SDK 1.0.X.

Are you using it against vCD 1.0 or vCD 1.5.

Regards,

Rajesh Kamal.

0 Kudos
richdenis
Enthusiast
Enthusiast

Hi Rajesh,

Thanks for the quick reply.  I am currently using the 1.0 SDK with 1.0 VCD.

Rich

0 Kudos
rkamal
VMware Employee
VMware Employee

Hi,

Assuming that the recompose doesn't seem to reset the mac addresses of the newly added vms.

Once the recompose operation is done, Can you try updating the network connection section for the those vms.

     networkConnectionType.setMACAddress(null);

Try this and see if this resets the mac addresses of the vms.

Regards,

Rajesh Kamal.

0 Kudos
richdenis
Enthusiast
Enthusiast

Ok, I think I found the issue.  The message I was getting about the duplicate MAC address while looking in vShpere Client was just a warning.  In addition to setting the Mac address to null I also had to specify to connect the nic.  (setIsNicConnected(true)).  Once I did this the reset mac worked as expected and I could ssh to the machines as I would expect.  Here is my new temp code. Note the one line addition to connect the nic.

            //start to build the item we want to compose
            CompositionItemParamType vmItem = new CompositionItemParamType();
            //building a comp item requires a reference type be created
            ReferenceType vmRef = new ReferenceType();
            //set the href of the vmRef Type to the href of the VappTemplate.
            vmRef.setHref(templateToExpand.getReference().getHref());
            //we need to set the name of the new item
            vmRef.setName(templateToExpand.getReference().getName() + "-" + templateCount++);
            //add the reference to the new item.
            vmItem.setSource(vmRef);
            //setup network for new item.
            NetworkConnectionSectionType networkConnectionSectionType = new NetworkConnectionSectionType();
            MsgType networkInfo = new MsgType();
            networkConnectionSectionType.setInfo(networkInfo);
            //set the connection type information.
            NetworkConnectionType networkConnectionType = new NetworkConnectionType();
            networkConnectionType.setNetwork(appNetworkName);
            networkConnectionType.setIsConnected(true);
            networkConnectionType.setMACAddress(null);
            networkConnectionType.setIpAddressAllocationMode(IpAddressAllocationModeType.POOL);
            networkConnectionSectionType.getNetworkConnection().add(networkConnectionType);
            InstantiationParamsType vmInstantiationParamsType = new InstantiationParamsType();

            List<JAXBElement<? extends SectionType>> vmSections = vmInstantiationParamsType.getSection();
            vmSections.add(new ObjectFactory().createNetworkConnectionSection(networkConnectionSectionType));

            vmItem.setInstantiationParams(vmInstantiationParamsType);
            rvpt.getItem().add(vmItem);

0 Kudos