aleti
Enthusiast
Enthusiast

How to add Network card for all VMs in vApp using JAVA SDK

I am trying to add network card for a VM in vCloud director1.5 wtih the help of smaple to add new disk but not able, is any one having simple code to add and delete virutal network card using java sdk. If yes can you share me.

--Kiran

0 Kudos
3 Replies
aleti
Enthusiast
Enthusiast

I am trying below code to Add NIC for vApp VM. Code is executing witout error but not performing additing of NIC card.

public static VirtualNetworkCard addNewNic() {

            CimString cimString = new CimString();

            Map<QName, String> cimAttributes = cimString.getOtherAttributes();

            cimAttributes.put(new QName("http://www.vmware.com/vcloud/v1.5",

                        "primaryNetworkConnection", "vcloud"), "false");

            cimAttributes.put(new QName("http://www.vmware.com/vcloud/v1.5",

                        "ipAddressingMode", "vcloud"), "NONE");

            //cimAttributes.put(new QName("http://www.vmware.com/vcloud/v1.5",

            CimString address = new CimString();

            address.setValue("00:50:56:01:03:86");

            CimString addressonP = new CimString();

            addressonP.setValue("4");

            //CimString autoAlloc = new CimString();

            //autoAlloc.setValue("false");

            CimBoolean  autoAlloc = new CimBoolean();

            autoAlloc.setValue(false);

            CimString description = new CimString();

            description.setValue("PCNet32 ethernet adapter");

            CimString setElementName = new CimString();

            setElementName.setValue("Network adapter 4");

            CimString setInstanceID = new CimString();

            setInstanceID.setValue("5");

            CimString subresource = new CimString();

            subresource.setValue("PCNet32");

            ResourceType setResourceType = new ResourceType();

            setResourceType.setValue("10");

            RASDType diskItemType = new RASDType();

            diskItemType.setAddress(address);

            diskItemType.setAddressOnParent(addressonP);

            diskItemType.setAutomaticAllocation(autoAlloc);

            List<CimString> diskAttributes = diskItemType.getConnection();

            diskAttributes.add(cimString);

            diskItemType.setDescription(description);

        diskItemType.setElementName(setElementName);

            diskItemType.setInstanceID(setInstanceID);

            diskItemType.setResourceSubType(subresource);

            diskItemType.setResourceType(setResourceType);

            //List<CimString> diskAttributes = diskItemType.getConnection();

            //diskAttributes.add(cimString);

            System.out.println("    Adding New Network Card");

            return new VirtualNetworkCard(diskItemType);

      }

0 Kudos
rkamal
VMware Employee
VMware Employee

Hi,

Try this code snippet.

Regards,

Rajesh Kamal.

public static VirtualNetworkCard createNic(Integer nicId,
Boolean isConnected, String networkName,
Boolean isPrimaryNetworkConnection,
IpAddressAllocationModeType ipAddressingMode, String ipAddress) {
// network name
CimString networkConfig = new CimString();
networkConfig.setValue(networkName);
// ip address
Map<QName, String> cimAttributes = networkConfig.getOtherAttributes();
cimAttributes.put(new QName("http://www.vmware.com/vcloud/v1.5",
"ipAddress", "vcloud"), ipAddress);
// is this nic a primary network connection.
cimAttributes.put(new QName("http://www.vmware.com/vcloud/v1.5",
"primaryNetworkConnection", "vcloud"),
isPrimaryNetworkConnection.toString());
// ip addressing mode
cimAttributes.put(new QName("http://www.vmware.com/vcloud/v1.5",
"ipAddressingMode", "vcloud"), ipAddressingMode.value());
CimString elementName = new CimString();
elementName.setValue("");
CimString instanceId = new CimString();
instanceId.setValue("");
CimString nicIndex = new CimString();
// nic id
nicIndex.setValue(nicId.toString());
CimBoolean connected = new CimBoolean();
connected.setValue(isConnected);
ResourceType networkResourceType = new ResourceType();
// nic resource type - 10
networkResourceType.setValue("10");
RASDType nic = new RASDType();
nic.setElementName(elementName);
nic.setInstanceID(instanceId);
nic.setResourceType(networkResourceType);
nic.setAddressOnParent(nicIndex);
nic.setAutomaticAllocation(connected);
List<CimString> networkAttributes = nic.getConnection();
networkAttributes.add(networkConfig);
return new VirtualNetworkCard(nic);
}

aleti
Enthusiast
Enthusiast

Thanks Rajesh i could add nic in vm

0 Kudos