cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From likit...@apache.org
Subject git commit: updated refs/heads/ova-multiple-disks to a73df09
Date Wed, 12 Mar 2014 16:24:45 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/ova-multiple-disks 7fb5641f4 -> a73df09b1


Agent command to analyze template


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

Branch: refs/heads/ova-multiple-disks
Commit: a73df09b14d3408d8c71de0da359203d2f62d743
Parents: 7fb5641
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Wed Mar 12 09:39:25 2014 +0530
Committer: Likitha Shetty <likitha.shetty@citrix.com>
Committed: Wed Mar 12 21:45:29 2014 +0530

----------------------------------------------------------------------
 api/src/com/cloud/storage/Storage.java          |   3 +-
 .../api/storage/AnalyzeTemplateCommand.java     |   5 +-
 .../storage/resource/StoragePoolResource.java   |   4 +
 .../storage/image/store/ImageStoreImpl.java     |   1 +
 .../storage/image/BaseImageStoreDriverImpl.java | 119 ++++++++++---------
 .../com/cloud/hypervisor/guru/VMwareGuru.java   |   6 +
 .../manager/VmwareStorageManagerImpl.java       |  82 +++++++++++--
 .../vmware/resource/VmwareResource.java         |  26 ++++
 .../driver/CloudStackImageStoreDriverImpl.java  |   1 +
 .../vmware/mo/HypervisorHostHelper.java         |  89 +-------------
 10 files changed, 180 insertions(+), 156 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/api/src/com/cloud/storage/Storage.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/storage/Storage.java b/api/src/com/cloud/storage/Storage.java
index 8ab2463..5c3e5d8 100755
--- a/api/src/com/cloud/storage/Storage.java
+++ b/api/src/com/cloud/storage/Storage.java
@@ -81,7 +81,8 @@ public class Storage {
         SYSTEM, /* routing, system vm template */
         BUILTIN, /* buildin template */
         PERHOST, /* every host has this template, don't need to install it in secondary storage
*/
-        USER /* User supplied template/iso */
+        USER, /* User supplied template/iso */
+        DATADISK
     }
 
     public static enum StoragePoolType {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java b/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java
index 214d968..918a62b 100644
--- a/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java
+++ b/core/src/com/cloud/agent/api/storage/AnalyzeTemplateCommand.java
@@ -16,10 +16,9 @@
 // under the License.
 package com.cloud.agent.api.storage;
 
-import com.cloud.agent.api.Command;
 import com.cloud.agent.api.to.DataTO;
 
-public final class AnalyzeTemplateCommand extends Command {
+public final class AnalyzeTemplateCommand extends AbstractDownloadCommand {
     private DataTO data;
 
     public AnalyzeTemplateCommand(DataTO data) {
@@ -37,7 +36,7 @@ public final class AnalyzeTemplateCommand extends Command {
     }
 
     public DataTO getData() {
-        return this.data;
+        return data;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/core/src/com/cloud/storage/resource/StoragePoolResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/StoragePoolResource.java b/core/src/com/cloud/storage/resource/StoragePoolResource.java
index 5ec8f0e..86eed44 100644
--- a/core/src/com/cloud/storage/resource/StoragePoolResource.java
+++ b/core/src/com/cloud/storage/resource/StoragePoolResource.java
@@ -17,6 +17,8 @@
 package com.cloud.storage.resource;
 
 import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.storage.AnalyzeTemplateAnswer;
+import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.storage.CopyVolumeAnswer;
 import com.cloud.agent.api.storage.CopyVolumeCommand;
 import com.cloud.agent.api.storage.CreateAnswer;
@@ -35,4 +37,6 @@ public interface StoragePoolResource {
     CopyVolumeAnswer execute(CopyVolumeCommand cmd);
 
     CreateAnswer execute(CreateCommand cmd);
+
+    AnalyzeTemplateAnswer execute(AnalyzeTemplateCommand cmd);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
index 8da7eb7..ba4cc00 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java
@@ -188,6 +188,7 @@ public class ImageStoreImpl implements ImageStoreEntity {
             primaryTO.setRole(getRole());
             primaryTO.setType(getProtocol());
             primaryTO.setUri(getUri());
+            primaryTO.setUuid(getUuid());
             return primaryTO;
         }
         return to;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
index 7401fdb..89a4d12 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
@@ -20,7 +20,9 @@ package org.apache.cloudstack.storage.image;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 import javax.inject.Inject;
@@ -44,17 +46,23 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
+import org.apache.cloudstack.storage.endpoint.DefaultEndPointSelector;
+import org.apache.cloudstack.storage.to.TemplateObjectTO;
 
 import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.storage.AnalyzeTemplateAnswer;
 import com.cloud.agent.api.storage.DownloadAnswer;
 import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.storage.Proxy;
 import com.cloud.agent.api.to.DataObjectType;
 import com.cloud.agent.api.to.DataTO;
+import com.cloud.storage.Storage.TemplateType;
+import com.cloud.storage.VMTemplateDetailVO;
 import com.cloud.storage.VMTemplateStorageResourceAssoc;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.storage.dao.VMTemplateDetailsDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.storage.download.DownloadMonitor;
 
@@ -71,9 +79,13 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver
{
     @Inject
     TemplateDataStoreDao _templateStoreDao;
     @Inject
+    VMTemplateDetailsDao _templateDetailsDao;
+    @Inject
     EndPointSelector _epSelector;
     @Inject
-    ConfigurationDao configDao;
+    ConfigurationDao configDao;;
+    @Inject
+    DefaultEndPointSelector _defaultEpSelector;
     protected String _proxy = null;
 
     protected Proxy getHttpProxy() {
@@ -184,7 +196,55 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver
{
                 templateDaoBuilder.setChecksum(answer.getCheckSum());
                 _templateDao.update(obj.getId(), templateDaoBuilder);
             }
-            analyseTemplate(obj);
+            AnalyzeTemplateCommand cmd = new AnalyzeTemplateCommand(obj.getTO());
+            EndPoint ep = _defaultEpSelector.selectHypervisorHost(store.getScope());
+            Answer tempAnswer = null;
+            if (ep == null) {
+                String errMsg = "No remote endpoint to send command, check if host or ssvm
is down?";
+                s_logger.error(errMsg);
+                tempAnswer = new Answer(cmd, false, errMsg);
+            } else {
+                tempAnswer = ep.sendMessage(cmd);
+            }
+            if (tempAnswer != null && tempAnswer.getResult()) {
+                AnalyzeTemplateAnswer tanswer = (AnalyzeTemplateAnswer)tempAnswer;
+                // Registered template may have data disks - Creating DataDisk template entries
for each of these disks
+                if (tanswer.getNewDataList() != null && !tanswer.getNewDataList().isEmpty())
{
+                    List<TemplateObjectTO> dataDiskTemplates = tanswer.getNewDataList();
+                    VMTemplateVO rootTemplate = _templateDao.findById(obj.getId());
+                    int diskNumber = 1;
+                    for (TemplateObjectTO dataDiskTemplate : dataDiskTemplates) {
+                        if (dataDiskTemplate.isBootable()) // Root disk
+                            continue;
+                        long id = _templateDao.getNextInSequence(Long.class, "id");
+                        VMTemplateVO template = new VMTemplateVO(id, rootTemplate.getName()
+ "-DataDiskTemplate-" + diskNumber, rootTemplate.getFormat(), false,
+                                false, rootTemplate.isExtractable(), TemplateType.DATADISK,
rootTemplate.getUrl(), rootTemplate.requiresHvm(), rootTemplate.getBits(),
+                                rootTemplate.getAccountId(), rootTemplate.getChecksum(),
rootTemplate.getDisplayText() + "-DataDiskTemplate", false, 0, false,
+                                rootTemplate.getHypervisorType(), null, null, false, false);
+                        template = _templateDao.persist(template);
+                        template.setSize(dataDiskTemplate.getSize());
+                        _templateDao.update(template.getId(), template);
+
+                        TemplateDataStoreVO templateStore = new TemplateDataStoreVO(store.getId(),
template.getId(), null, 100, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
+                                null, null, null, dataDiskTemplate.getPath(), tmpltStoreVO.getDownloadUrl());
+                        templateStore.setSize(dataDiskTemplate.getSize());
+                        templateStore.setDataStoreRole(tmpltStoreVO.getDataStoreRole());
+                        templateStore.setPhysicalSize(dataDiskTemplate.getPhysicalSize());
+                        _templateStoreDao.persist(templateStore);
+
+                        List<VMTemplateDetailVO> details = new ArrayList<VMTemplateDetailVO>();
+                        details.add(new VMTemplateDetailVO(rootTemplate.getId(), "child-datadisk-template",
template.getUuid(), true));
+                        details.add(new VMTemplateDetailVO(template.getId(), "parent-vm-template",
rootTemplate.getUuid(), true));
+                        _templateDetailsDao.saveDetails(details);
+                        diskNumber++;
+                    }
+                }
+            } else {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Cannot analyze template " + store.getId());
+                }
+            }
+
             CreateCmdResult result = new CreateCmdResult(null, null);
             caller.complete(result);
         }
@@ -273,59 +333,4 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver
{
     @Override
     public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback)
{
     }
-
-    private void analyseTemplate(DataObject data) {
-        CommandResult result = new CommandResult();
-        DataStore store = data.getDataStore();
-        TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(),
data.getId());
-        try {
-            AnalyzeTemplateCommand cmd = new AnalyzeTemplateCommand(data.getTO());
-            EndPoint ep = _epSelector.select(data);
-            Answer answer = null;
-            if (ep == null) {
-                String errMsg = "No remote endpoint to send command, check if host or ssvm
is down?";
-                s_logger.error(errMsg);
-                answer = new Answer(cmd, false, errMsg);
-            } else {/*
-                (AnalyzeTemplateAnswer)answer = ep.sendMessage(cmd);
-                if (answer != null && !answer.getResult()) {
-                    result.setResult(answer.getDetails());
-                    // Registered template may have data disks - Creating DataDisk template
entries for each of these disks
-                    if (answer.getNewDataList() != null && !answer.getNewDataList().isEmpty())
{
-                        List<TemplateObjectTO> dataDiskTemplates = answer.getNewDataList();
-                        VMTemplateVO rootTemplate = _templateDao.findById(data.getId());
-                        int diskNumber = 1;
-                        for (TemplateObjectTO dataDiskTemplate : dataDiskTemplates) {
-                            if (dataDiskTemplate.isBootable()) // Root disk
-                                continue;
-                            long id = _templateDao.getNextInSequence(Long.class, "id");
-                            VMTemplateVO template = new VMTemplateVO(id, rootTemplate.getName()
+ "-DataDiskTemplate-" + diskNumber, rootTemplate.getFormat(), false,
-                                    false, rootTemplate.isExtractable(), TemplateType.DATADISK,
rootTemplate.getUrl(), rootTemplate.requiresHvm(), rootTemplate.getBits(),
-                                    rootTemplate.getAccountId(), rootTemplate.getChecksum(),
rootTemplate.getDisplayText() + "-DataDiskTemplate", false, 0, false,
-                                    rootTemplate.getHypervisorType(), null, null, false,
false);
-                            template = _templateDao.persist(template);
-                            template.setSize(dataDiskTemplate.getSize());
-                            _templateDao.update(template.getId(), template);
-
-                            TemplateDataStoreVO templateStore = new TemplateDataStoreVO(store.getId(),
template.getId(), null, 100, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
-                                    null, null, null, dataDiskTemplate.getInstallPath(),
tmpltStoreVO.getDownloadUrl());
-                            templateStore.setSize(dataDiskTemplate.getSize());
-                            templateStore.setDataStoreRole(tmpltStoreVO.getDataStoreRole());
-                            templateStore.setPhysicalSize(dataDiskTemplate.getPhysicalSize());
-                            _templateStoreDao.persist(templateStore);
-
-                            List<VMTemplateDetailVO> details = new ArrayList<VMTemplateDetailVO>();
-                            details.add(new VMTemplateDetailVO(rootTemplate.getId(), "child-datadisk-template",
template.getUuid(), true));
-                            details.add(new VMTemplateDetailVO(template.getId(), "parent-vm-template",
rootTemplate.getUuid(), true));
-                            _templateDetailsDao.saveDetails(details);
-                            diskNumber++;
-                        }
-                    }
-                }
-            */}
-        } catch (Exception ex) {
-            s_logger.debug("Unable to analyze " + data.getType().toString() + ": " + data.getId(),
ex);
-            result.setResult(ex.toString());
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
index 9cb37f5..b4ea89a 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
@@ -41,6 +41,7 @@ import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
 import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
 import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
 import com.cloud.agent.api.UnregisterNicCommand;
+import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.storage.CopyVolumeCommand;
 import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
 import com.cloud.agent.api.storage.CreateVolumeOVACommand;
@@ -375,6 +376,11 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru,
Co
                     needDelegation = true;
                 }
             }
+        } else if (cmd instanceof AnalyzeTemplateCommand) {
+            DataTO srcData = ((AnalyzeTemplateCommand)cmd).getData();
+            if ((HypervisorType.VMware == srcData.getHypervisorType())) {
+                needDelegation = true;
+            }
         }
 
         if (!needDelegation) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
index 0b7bf67..e5b6432 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
@@ -55,23 +55,25 @@ import com.cloud.agent.api.DeleteVMSnapshotAnswer;
 import com.cloud.agent.api.DeleteVMSnapshotCommand;
 import com.cloud.agent.api.RevertToVMSnapshotAnswer;
 import com.cloud.agent.api.RevertToVMSnapshotCommand;
+import com.cloud.agent.api.storage.AnalyzeTemplateAnswer;
+import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.storage.CopyVolumeAnswer;
 import com.cloud.agent.api.storage.CopyVolumeCommand;
 import com.cloud.agent.api.storage.CreateEntityDownloadURLCommand;
 import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
 import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
-import com.cloud.agent.api.storage.AnalyzeTemplateAnswer;
-import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.to.DataObjectType;
 import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.DataTO;
 import com.cloud.agent.api.to.NfsTO;
 import com.cloud.agent.api.to.StorageFilerTO;
+import com.cloud.hypervisor.vmware.mo.ClusterMO;
 import com.cloud.hypervisor.vmware.mo.CustomFieldConstants;
 import com.cloud.hypervisor.vmware.mo.DatacenterMO;
 import com.cloud.hypervisor.vmware.mo.DatastoreMO;
 import com.cloud.hypervisor.vmware.mo.HostDatastoreBrowserMO;
+import com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO;
 import com.cloud.hypervisor.vmware.mo.HostMO;
 import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
 import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
@@ -128,6 +130,20 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager
{
         command.execute();
     }
 
+    public void createOvaAnalyze(String path, String ovfName, String diskName) {
+        Script commandSync = new Script(true, "sync", 0, s_logger);
+        commandSync.execute();
+
+        Script command = new Script(false, "tar", 0, s_logger);
+        command.setWorkDir(path);
+        command.add("-cf", ovfName + ".ova");
+        command.add(ovfName + ".ovf");
+        command.add(diskName + ".vmdk");
+
+        s_logger.info("Package OVA with commmand: " + command.toString());
+        command.execute();
+    }
+
     private static final Logger s_logger = Logger.getLogger(VmwareStorageManagerImpl.class);
 
     private final VmwareStorageMount _mountService;
@@ -1518,9 +1534,15 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager
{
         try {
             VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
             ManagedObjectReference morRp = hyperHost.getHyperHostOwnerResourcePool();
-            ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost,
srcStore.getUuid());
-            assert (morDs != null);
+            ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
+            ClusterMO cluster = new ClusterMO(context, morCluster);
+            List<Pair<ManagedObjectReference, String>> lstHosts = cluster.getClusterHosts();
+            HostMO host = new HostMO(context, lstHosts.get(0).first());
+            HostDatastoreSystemMO hostDatastoreSystem = host.getHostDatastoreSystemMO();
+            List<ManagedObjectReference> morDsList = hostDatastoreSystem.getDatastores();
+            ManagedObjectReference morDs = hostDatastoreSystem.getDatastores().get(0);
             DatastoreMO datastoreMo = new DatastoreMO(context, morDs);
+
             String secondaryMountPoint = _mountService.getMountPoint(secondaryStorageUrl);
             s_logger.info("Secondary storage mount point: " + secondaryMountPoint);
 
@@ -1549,14 +1571,52 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager
{
                 throw new Exception(msg);
             }
 
-            // readOVF(hyperHost, srcFileName, datastoreMo, morRp, hyperHost.getMor());
+            List<Ternary<String, Long, Boolean>> templateDetails = HypervisorHostHelper.readOVF(hyperHost,
srcFileName, datastoreMo, morRp, hyperHost.getMor());
+            int diskCount = 1;
+            for (Ternary<String, Long, Boolean> templateDetail : templateDetails) {
+                if(templateDetail.third())
+                    continue;
+                String installPath = templateInfo.first() + diskCount;
+                String installFullPathVMDK = secondaryMountPoint + "/" + installPath;
+                synchronized (installPath.intern()) {
+                    Script command = new Script(false, "mkdir", _timeout, s_logger);
+                    command.add("-p");
+                    command.add(installFullPathVMDK);
+                    String result = command.execute();
+                    if (result != null) {
+                        String msg = "unable to prepare template directory: " + installPath
+ ", storage: " + secondaryStorageUrl + ", error msg: " + result;
+                        s_logger.error(msg);
+                        throw new Exception(msg);
+                    }
+                }
+
+                synchronized (installPath.intern()) {
+                    Script command = new Script(false, "mv", _timeout, s_logger);
+                    command.add(templateDetail.first());
+                    command.add(installFullPathVMDK);
+                    String result = command.execute();
+                    if (result != null) {
+                        String msg = "unable to move vmdk" + ", error msg: " + result;
+                        s_logger.error(msg);
+                        throw new Exception(msg);
+                    }
+                }
 
-            // Temp answer
-            TemplateObjectTO dataDiskTemplate = new TemplateObjectTO();
-            dataDiskTemplate.setPath("temp-path");
-            dataDiskTemplate.setPhysicalSize(1L);
-            dataDiskTemplate.setIsBootable(false);
-            templateList.add(dataDiskTemplate);
+                int index = templateDetail.first().lastIndexOf(File.separator);
+                String vmdkName = templateDetail.first().substring(index+1);
+                int vmdkIndex = vmdkName.indexOf(".");
+                String ovfName = vmdkName.substring(0, vmdkIndex);
+
+                HypervisorHostHelper.createOvfFile(hyperHost, vmdkName, ovfName, installFullPathVMDK,
templateDetail.second(), morDs);
+                createOvaAnalyze(installFullPathVMDK, templateDetail.first().substring(0,
index+1), templateDetail.first());
+
+                TemplateObjectTO dataDiskTemplate = new TemplateObjectTO();
+                dataDiskTemplate.setPath(templateDetail.first());
+                dataDiskTemplate.setPhysicalSize(templateDetail.second());
+                dataDiskTemplate.setIsBootable(templateDetail.third());
+                templateList.add(dataDiskTemplate);
+                diskCount++;
+            }
         } catch (Exception e) {
             String msg = "Analyze template failed due to " + e.getMessage();
             s_logger.error(msg);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 9e12105..10b8ea2 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -202,6 +202,8 @@ import com.cloud.agent.api.routing.IpAssocVpcCommand;
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.routing.SetNetworkACLCommand;
 import com.cloud.agent.api.routing.SetSourceNatCommand;
+import com.cloud.agent.api.storage.AnalyzeTemplateAnswer;
+import com.cloud.agent.api.storage.AnalyzeTemplateCommand;
 import com.cloud.agent.api.storage.CopyVolumeAnswer;
 import com.cloud.agent.api.storage.CopyVolumeCommand;
 import com.cloud.agent.api.storage.CreateAnswer;
@@ -454,6 +456,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 answer = execute((GetStorageStatsCommand)cmd);
             } else if (clz == PrimaryStorageDownloadCommand.class) {
                 answer = execute((PrimaryStorageDownloadCommand)cmd);
+            } else if (clz == AnalyzeTemplateCommand.class) {
+                answer = execute((AnalyzeTemplateCommand)cmd);
             } else if (clz == GetVncPortCommand.class) {
                 answer = execute((GetVncPortCommand)cmd);
             } else if (clz == SetupCommand.class) {
@@ -4158,6 +4162,28 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
         }
     }
 
+    @Override
+    public AnalyzeTemplateAnswer execute(AnalyzeTemplateCommand cmd) {
+        if (s_logger.isInfoEnabled()) {
+            s_logger.info("Executing resource AnalyzeTemplateCommand: " + _gson.toJson(cmd));
+        }
+
+        try {
+            VmwareContext context = getServiceContext();
+            VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
+            return (AnalyzeTemplateAnswer)mgr.getStorageManager().execute(this, cmd);
+        } catch (Throwable e) {
+            if (e instanceof RemoteException) {
+                s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session
context");
+                invalidateServiceContext();
+            }
+
+            String msg = "AnalyzeTemplateCommand failed due to " + VmwareHelper.getExceptionMessage(e);
+            s_logger.error(msg, e);
+            return new AnalyzeTemplateAnswer(msg);
+        }
+    }
+
     protected Answer execute(PvlanSetupCommand cmd) {
         // Pvlan related operations are performed in the start/stop command paths
         // for vmware. This function is implemented to support mgmt layer code

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
index d6e1a01..2114aca 100644
--- a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
+++ b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
@@ -55,6 +55,7 @@ public class CloudStackImageStoreDriverImpl extends BaseImageStoreDriverImpl
{
         NfsTO nfsTO = new NfsTO();
         nfsTO.setRole(store.getRole());
         nfsTO.setUrl(nfsStore.getUri());
+        nfsTO.setUuid(nfsStore.getUuid());
         return nfsTO;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a73df09b/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 8f64a03..989aae4 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
@@ -51,7 +51,6 @@ import com.vmware.vim25.LongPolicy;
 import com.vmware.vim25.ManagedObjectReference;
 import com.vmware.vim25.MethodFault;
 import com.vmware.vim25.ObjectContent;
-import com.vmware.vim25.OptionValue;
 import com.vmware.vim25.OvfCreateDescriptorParams;
 import com.vmware.vim25.OvfCreateDescriptorResult;
 import com.vmware.vim25.OvfCreateImportSpecParams;
@@ -66,14 +65,12 @@ import com.vmware.vim25.VirtualDevice;
 import com.vmware.vim25.VirtualDeviceConfigSpec;
 import com.vmware.vim25.VirtualDeviceConfigSpecOperation;
 import com.vmware.vim25.VirtualDisk;
-import com.vmware.vim25.VirtualIDEController;
 import com.vmware.vim25.VirtualLsiLogicController;
 import com.vmware.vim25.VirtualMachineConfigSpec;
 import com.vmware.vim25.VirtualMachineFileInfo;
 import com.vmware.vim25.VirtualMachineGuestOsIdentifier;
 import com.vmware.vim25.VirtualMachineImportSpec;
 import com.vmware.vim25.VirtualMachineVideoCard;
-import com.vmware.vim25.VirtualSCSIController;
 import com.vmware.vim25.VirtualSCSISharing;
 import com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec;
 import com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec;
@@ -105,7 +102,6 @@ public class HypervisorHostHelper {
     // make vmware-base loosely coupled with cloud-specific stuff, duplicate VLAN.UNTAGGED
constant here
     private static final String UNTAGGED_VLAN_NAME = "untagged";
     private static final String VMDK_PACK_DIR = "ova";
-    private static final String OVA_OPTION_KEY_BOOTDISK = "cloud.ova.bootdisk";
 
     public static VirtualMachineMO findVmFromObjectContent(VmwareContext context, ObjectContent[]
ocs, String name, String instanceNameCustomField) {
 
@@ -1245,27 +1241,17 @@ public class HypervisorHostHelper {
             files.add(absFile);
         }
 
-        int osDiskSeqNumber = 0;
-        VirtualMachineConfigSpec config = importSpec.getConfigSpec();
-        String paramVal = getOVFParamValue(config);
-        if (paramVal != null && !paramVal.isEmpty()) {
-            try {
-                osDiskSeqNumber = getOsDiskFromOvfConf(config, paramVal);
-            } catch (Exception e) {
-                osDiskSeqNumber = 0;
-            }
-        }
-
-        Boolean osDisk = true;
-        List<VirtualDeviceConfigSpec> deviceConfigList = config.getDeviceChange();
+        boolean lookForFirstDisk = true;
+        List<VirtualDeviceConfigSpec> deviceConfigList = importSpec.getConfigSpec().getDeviceChange();
         for (VirtualDeviceConfigSpec deviceSpec : deviceConfigList) {
+            Boolean osDisk = false;
             VirtualDevice device = deviceSpec.getDevice();
             if (device instanceof VirtualDisk) {
                 sizeKb = ((VirtualDisk)device).getCapacityInKB();
-                if (diskCount == osDiskSeqNumber) {
+                if (lookForFirstDisk && diskCount == 0) {
                     osDisk = true;
+                    diskCount++;
                 }
-                diskCount++;
                 ovfVolumeInfo = new Ternary<String, Long, Boolean>(files.get(diskCount),
sizeKb, osDisk);
                 ovfVolumeInfos.add(ovfVolumeInfo);
             }
@@ -1273,71 +1259,6 @@ public class HypervisorHostHelper {
         return ovfVolumeInfos;
     }
 
-    public static int getOsDiskFromOvfConf(VirtualMachineConfigSpec config, String deviceLocation)
{
-        List<VirtualDeviceConfigSpec> deviceConfigList = config.getDeviceChange();
-        int controllerKey = 0;
-        int deviceSeqNumber = 0;
-        int controllerNumber = 0;
-        int deviceNodeNumber = 0;
-        int controllerCount = 0;
-        String[] virtualNodeInfo = deviceLocation.split(":");
-        if (deviceLocation.startsWith("scsi")) {
-
-            controllerNumber = Integer.parseInt(virtualNodeInfo[0].substring(4)); // get
substring excluding prefix scsi
-            deviceNodeNumber = Integer.parseInt(virtualNodeInfo[1]);
-
-            for (VirtualDeviceConfigSpec deviceConfig : deviceConfigList) {
-                VirtualDevice device = deviceConfig.getDevice();
-                if (device instanceof VirtualSCSIController) {
-                    if (controllerNumber == controllerCount) { //((VirtualSCSIController)device).getBusNumber())
{
-                        controllerKey = device.getKey();
-                        break;
-                    }
-                    controllerCount++;
-                }
-            }
-        } else {
-            controllerNumber = Integer.parseInt(virtualNodeInfo[0].substring(3)); // get
substring excluding prefix ide
-            deviceNodeNumber = Integer.parseInt(virtualNodeInfo[1]);
-            controllerCount = 0;
-
-            for (VirtualDeviceConfigSpec deviceConfig : deviceConfigList) {
-                VirtualDevice device = deviceConfig.getDevice();
-                if (device instanceof VirtualIDEController) {
-                    if (controllerNumber == controllerCount) { //((VirtualIDEController)device).getBusNumber())
{
-                        // Only 2 IDE controllers supported and they will have bus numbers
0 and 1
-                        controllerKey = device.getKey();
-                        break;
-                    }
-                    controllerCount++;
-                }
-            }
-        }
-        // Get devices on this controller at specific device node.
-        for (VirtualDeviceConfigSpec deviceConfig : deviceConfigList) {
-            VirtualDevice device = deviceConfig.getDevice();
-            if (device instanceof VirtualDisk) {
-                if (controllerKey == device.getControllerKey() && deviceNodeNumber
== device.getUnitNumber()) {
-                    break;
-                }
-                deviceSeqNumber++;
-            }
-        }
-        return deviceSeqNumber;
-    }
-
-    public static String getOVFParamValue(VirtualMachineConfigSpec config) {
-        String paramVal = "";
-        List<OptionValue> options = config.getExtraConfig();
-        for (OptionValue option : options) {
-            if (OVA_OPTION_KEY_BOOTDISK.equalsIgnoreCase(option.getKey())) {
-                paramVal = (String)option.getValue();
-                break;
-            }
-        }
-        return paramVal;
-    }
-
     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);


Mime
View raw message