cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From likit...@apache.org
Subject [02/13] git commit: updated refs/heads/multiple-disk-ova to 3532ffe
Date Fri, 02 May 2014 12:39:31 GMT
CLOUDSTACK-4787 Support OVA with multiple volumes

Creating OVF file to pack vmdk corresponding to data disk in OVA.

Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6496ccf1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6496ccf1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6496ccf1

Branch: refs/heads/multiple-disk-ova
Commit: 6496ccf184da853e93837665f0910fbdd82b6561
Parents: 11c011d
Author: Sateesh Chodapuneedi <sateesh@apache.org>
Authored: Wed Mar 12 13:33:04 2014 +0530
Committer: Likitha Shetty <likitha.shetty@citrix.com>
Committed: Fri May 2 13:07:05 2014 +0530

----------------------------------------------------------------------
 .../vmware/mo/HypervisorHostHelper.java         | 45 ++++++++++++++++++++
 1 file changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6496ccf1/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
index 8e2254e..ab0ab66 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
@@ -17,6 +17,7 @@
 package com.cloud.hypervisor.vmware.mo;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.security.InvalidParameterException;
@@ -50,8 +51,11 @@ import com.vmware.vim25.LongPolicy;
 import com.vmware.vim25.ManagedObjectReference;
 import com.vmware.vim25.MethodFault;
 import com.vmware.vim25.ObjectContent;
+import com.vmware.vim25.OvfCreateDescriptorParams;
+import com.vmware.vim25.OvfCreateDescriptorResult;
 import com.vmware.vim25.OvfCreateImportSpecParams;
 import com.vmware.vim25.OvfCreateImportSpecResult;
+import com.vmware.vim25.OvfFile;
 import com.vmware.vim25.OvfFileItem;
 import com.vmware.vim25.VMwareDVSConfigSpec;
 import com.vmware.vim25.VMwareDVSPortSetting;
@@ -1255,6 +1259,47 @@ public class HypervisorHostHelper {
         return ovfVolumeInfos;
     }
 
+    public static void createOvfFile(VmwareHypervisorHost host, String diskFileName, String
ovfName, String dir, long size, ManagedObjectReference morDs) throws Exception {
+        VmwareContext context = host.getContext();
+        VirtualMachineMO workerVmMo = HypervisorHostHelper.createWorkerVM(host, new DatastoreMO(context,
morDs), ovfName);
+        if (workerVmMo == null)
+            throw new Exception("Unable to find just-created worker VM");
+
+        String[] disks = {dir + File.separator + diskFileName};
+        boolean bSuccess = false;
+        try {
+            VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
+            VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
+
+            VirtualDevice device = VmwareHelper.prepareDiskDevice(workerVmMo, null, -1, disks,
morDs, -1, 1);
+
+            deviceConfigSpec.setDevice(device);
+            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+            vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
+            workerVmMo.configureVm(vmConfigSpec);
+            bSuccess = true;
+            OvfFile ovfFile = new OvfFile();
+            ovfFile.setPath(diskFileName);
+            ovfFile.setDeviceId("1000");
+            ovfFile.setSize(size);
+            // write OVF descriptor file
+            OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams();
+            ovfDescParams.getOvfFiles().add(ovfFile);
+            ManagedObjectReference morOvf = context.getServiceContent().getOvfManager();
+            OvfCreateDescriptorResult ovfCreateDescriptorResult = context.getService().createDescriptor(morOvf,
workerVmMo.getMor(), ovfDescParams);
+
+            String ovfPath = dir + File.separator + ovfName + ".ovf";
+            FileWriter out = new FileWriter(ovfPath);
+            out.write(ovfCreateDescriptorResult.getOvfDescriptor());
+            out.close();
+        } finally {
+            if (!bSuccess) {
+                workerVmMo.detachAllDisks();
+                workerVmMo.destroy();
+            }
+        }
+    }
+
     public static VirtualMachineMO createWorkerVM(VmwareHypervisorHost hyperHost, DatastoreMO
dsMo, String vmName) throws Exception {
 
         // Allow worker VM to float within cluster so that we will have better chance to


Mime
View raw message