Hi,
I am trying to add an existing VM to a new vapp. The problem is, the original vm is connect to a network, which does not exist in the new vapp. I thought, using getNetworkAssignment().clear(); I would be able to remove any connected network before doing recompose. Sadly that is not the case. Any idea why?
Instead I get: "The VCD entity network "sample network" specified for VM "sample machine" does not exist."
Hi,
I was able to unmap a vm's network without removing the nic.
Code snippet for setting the vm's network connection section in the instantiation params:
// vmRef can be a vapp vm or a vapptemplate vm.SourcedCompositionItemParamType vmItem = new SourcedCompositionItemParamType(); vmItem.setSource(vmRef);// get the vm's network connection section.NetworkConnectionSectionType networkConnectionSectionType = vm.getNetworkConnectionSection();MsgType networkInfo = new MsgType();networkConnectionSectionType.setInfo(networkInfo);// iterate through the vm's network connections and set the network name and ip adress allocation mode to none.for(NetworkConnectionType networkConnection : networkConnectionSectionType.getNetworkConnection()){networkConnection.setNetwork("none");networkConnection.setIpAddressAllocationMode(IpAddressAllocationModeType.NONE.value());}// add the network connection section to the vm instantiation params.InstantiationParamsType vmInstantiationParamsType = new InstantiationParamsType();vmInstantiationParamsType.getSection().add(new ObjectFactory().createNetworkConnectionSection(networkConnectionSectionType));vmItem.setInstantiationParams(vmInstantiationParamsType);
Recompose XML - The recompose vApp XML should look something like this,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ns6:RecomposeVAppParams xmlns="http://www.vmware.com/vcloud/versions" xmlns:ns2="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ns3="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:ns4="http://schemas.dmtf.org/ovf/envelope/1" xmlns:ns5="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:ns6="http://www.vmware.com/vcloud/v1.5" xmlns:ns7="http://schemas.dmtf.org/ovf/environment/1" xmlns:ns8="http://www.vmware.com/vcloud/extension/v1.5" name="RecomposedVapp"> <ns6:SourcedItem> <ns6:Source type="application/vnd.vmware.vcloud.vm+xml" name="vapptemplate-vm" href="https://cloud/api/vAppTemplate/vm-e47b2d4b-5b0d-45b0-9dcc-8280435f6b3a"/> <ns6:InstantiationParams> <ns6:NetworkConnectionSection type="application/vnd.vmware.vcloud.networkConnectionSection+xml" href="https://cloud/api/vAppTemplate/vm-e47b2d4b-5b0d-45b0-9dcc-8280435f6b3a/networkConnectionSection/" ns4:required="false"> <ns4:Info/> <ns6:PrimaryNetworkConnectionIndex>0</ns6:PrimaryNetworkConnectionIndex> <ns6:NetworkConnection network="none" needsCustomization="true"> <ns6:NetworkConnectionIndex>0</ns6:NetworkConnectionIndex> <ns6:IsConnected>true</ns6:IsConnected> <ns6:MACAddress>00:50:56:01:00:07</ns6:MACAddress> <ns6:IpAddressAllocationMode>NONE</ns6:IpAddressAllocationMode> </ns6:NetworkConnection> </ns6:NetworkConnectionSection> </ns6:InstantiationParams> </ns6:SourcedItem> </ns6:RecomposeVAppParams>
Regards,
Rajesh Kamal.
Hi,
During reompose, Inorder to remove the vm's network connection. You need to send an updated network connection section as part of the vm's instantiation parameters.
1. Get the vm's network connection section.
2. Remove the network connections which you dont want. (This is where you should remove the "sample network" which is part of the vm)
3. Add the modified network connection section as part of the vm's instantiation params.
Regards,
Rajesh Kamal.
Hi Rajesh,
okay I understand. I took a look into the code samples and for recompose I found this.
if (vm.getNetworkConnectionSection().getNetworkConnection().size() > 0 && vappNetworkName != null) {for (NetworkConnectionType networkConnection : vm.getNetworkConnectionSection().getNetworkConnection()) {if (networkConnection.getNetworkConnectionIndex() == vm.getNetworkConnectionSection().getPrimaryNetworkConnectionIndex()) {NetworkAssignmentType networkAssignment = new NetworkAssignmentType();networkAssignment.setInnerNetwork(networkConnection.getNetwork());networkAssignment.setContainerNetwork(vappNetworkName);List<NetworkAssignmentType> networkAssignments = vmItem.getNetworkAssignment();networkAssignments.add(networkAssignment);}}}
Essentially it is not that much different to the things I want to do. But instead of connection to a network directly I want to set the connection for each NIC to empty. How do I achieve this?
Hi, Not the network assignment. I was talking something like this. This will remove all the vm's network connections or nics from the vm. Regards, Rajesh Kamal.
if (vm.getNetworkConnectionSection().getNetworkConnection().size() > 0 && vappNetworkName == null) { // creating empty network connection section for the vm. NetworkConnectionSectionType networkConnectionSectionType = new NetworkConnectionSect... MsgType networkInfo = new MsgType(); networkConnectionSectionType.setInfo(networkInfo); // adding the network connection section to the instantiation params // of the vapp. InstantiationParamsType vmInstantiationParamsType = new InstantiationParamsType(); vmInstantiationParamsType .getSection() .add( new ObjectFactory() .createNetworkConnectionSection(networkConnectionSectio... vmItem.setInstantiationParams(vmInstantiationParamsType); }
Hi,
that was the other solution I tried, but of I had two nics previously, then I only get one nic after changing the params. That's what I don't want. Is there no other workaround?
Hi,
Adding this empty network connection section to the vm's instantiation params should remove all the nics from your vm.
Regards,
Rajesh Kamal.
Hi Rajesh,
I think we have a misunderstanding here. I don't want to get my nics removed. Only the network connection removed. So and idea?
Hi,
I thought you wanted to remove the nics.
Instead of sending an empty network connection section as part of the vm's instantiation param.s
Try sending the network connection section with all the network connections(modified network name and ip addressing mode set to none)
Something like this,
Regards,
Rajesh Kamal.
for(NetworkConnectionType vmNetworkConnection : vmNetworkConnectionSection.getNetworkConnection()){vmNetworkConnection.setNetwork("none");vmNetworkConnection.setIpAddressAllocationMode(IpAddressAllocationModeType.NONE.value());}
Hi Rajesh,
I tried that already. The solution you provided was my first shot. But it gives me the same exception.
The VCD entity network "sample network" specified for VM "sample machine" does not exist.
Hi,
I was able to unmap a vm's network without removing the nic.
Code snippet for setting the vm's network connection section in the instantiation params:
// vmRef can be a vapp vm or a vapptemplate vm.SourcedCompositionItemParamType vmItem = new SourcedCompositionItemParamType(); vmItem.setSource(vmRef);// get the vm's network connection section.NetworkConnectionSectionType networkConnectionSectionType = vm.getNetworkConnectionSection();MsgType networkInfo = new MsgType();networkConnectionSectionType.setInfo(networkInfo);// iterate through the vm's network connections and set the network name and ip adress allocation mode to none.for(NetworkConnectionType networkConnection : networkConnectionSectionType.getNetworkConnection()){networkConnection.setNetwork("none");networkConnection.setIpAddressAllocationMode(IpAddressAllocationModeType.NONE.value());}// add the network connection section to the vm instantiation params.InstantiationParamsType vmInstantiationParamsType = new InstantiationParamsType();vmInstantiationParamsType.getSection().add(new ObjectFactory().createNetworkConnectionSection(networkConnectionSectionType));vmItem.setInstantiationParams(vmInstantiationParamsType);
Recompose XML - The recompose vApp XML should look something like this,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ns6:RecomposeVAppParams xmlns="http://www.vmware.com/vcloud/versions" xmlns:ns2="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:ns3="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:ns4="http://schemas.dmtf.org/ovf/envelope/1" xmlns:ns5="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:ns6="http://www.vmware.com/vcloud/v1.5" xmlns:ns7="http://schemas.dmtf.org/ovf/environment/1" xmlns:ns8="http://www.vmware.com/vcloud/extension/v1.5" name="RecomposedVapp"> <ns6:SourcedItem> <ns6:Source type="application/vnd.vmware.vcloud.vm+xml" name="vapptemplate-vm" href="https://cloud/api/vAppTemplate/vm-e47b2d4b-5b0d-45b0-9dcc-8280435f6b3a"/> <ns6:InstantiationParams> <ns6:NetworkConnectionSection type="application/vnd.vmware.vcloud.networkConnectionSection+xml" href="https://cloud/api/vAppTemplate/vm-e47b2d4b-5b0d-45b0-9dcc-8280435f6b3a/networkConnectionSection/" ns4:required="false"> <ns4:Info/> <ns6:PrimaryNetworkConnectionIndex>0</ns6:PrimaryNetworkConnectionIndex> <ns6:NetworkConnection network="none" needsCustomization="true"> <ns6:NetworkConnectionIndex>0</ns6:NetworkConnectionIndex> <ns6:IsConnected>true</ns6:IsConnected> <ns6:MACAddress>00:50:56:01:00:07</ns6:MACAddress> <ns6:IpAddressAllocationMode>NONE</ns6:IpAddressAllocationMode> </ns6:NetworkConnection> </ns6:NetworkConnectionSection> </ns6:InstantiationParams> </ns6:SourcedItem> </ns6:RecomposeVAppParams>
Regards,
Rajesh Kamal.
Hi Rajesh,
yes that's the same I went along. Question here is if the OS recognizes that the nic adapters were removed/reattached.