Updated Branches:
  refs/heads/master 93834ea6c -> 3113f32f2

Commit for https://reviews.apache.org/r/6701/


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

Branch: refs/heads/master
Commit: 3113f32f255c3a7e39cbd1d6055b11332d14ae1b
Parents: 93834ea
Author: Kelven Yang <kelven.y...@citrix.com>
Authored: Tue Aug 21 11:55:06 2012 -0700
Committer: Kelven Yang <kelven.y...@citrix.com>
Committed: Tue Aug 21 11:55:06 2012 -0700

----------------------------------------------------------------------
 .../src/com/cloud/hypervisor/vmware/mo/HostMO.java |   60 +++++++++++++-
 1 files changed, 55 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3113f32f/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java 
b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
index fd30399..3557048 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
@@ -59,6 +59,7 @@ import com.vmware.vim25.SelectionSpec;
 import com.vmware.vim25.TraversalSpec;
 import com.vmware.vim25.VirtualMachineConfigSpec;
 import com.vmware.vim25.VirtualNicManagerNetConfig;
+import com.vmware.vim25.NasDatastoreInfo;
 
 public class HostMO extends BaseMO implements VmwareHypervisorHost {
     private static final Logger s_logger = Logger.getLogger(HostMO.class);
@@ -697,6 +698,39 @@ public class HostMO extends BaseMO implements 
VmwareHypervisorHost {
                return result;
        }
 
+       public ManagedObjectReference getExistingDataStoreOnHost(boolean 
vmfsDatastore, String hostAddress,
+                       int hostPort, String path, String uuid, 
HostDatastoreSystemMO hostDatastoreSystemMo) {
+               // First retrieve the list of Datastores on the host.
+               ManagedObjectReference[] morArray;
+               try {
+                       morArray = hostDatastoreSystemMo.getDatastores();
+               } catch (Exception e) {
+                       s_logger.info("Failed to retrieve list of Managed 
Object References");
+                       return null;
+               }
+               // Next, get all the NAS datastores from this array of 
datastores.
+               if (morArray.length > 0) {
+                       int i;
+                       for (i = 0; i < morArray.length; i++) {
+                               NasDatastoreInfo nasDS;
+                               try {
+                                       nasDS = 
hostDatastoreSystemMo.getNasDatastoreInfo(morArray[i]);
+                                       if (nasDS != null) {
+                                               //DatastoreInfo info = 
(DatastoreInfo)_context.getServiceUtil().getDynamicProperty(morDatastore, 
"info");
+                                               if 
(nasDS.getNas().getRemoteHost().equalsIgnoreCase(hostAddress) &&
+                                                               
nasDS.getNas().getRemotePath().equalsIgnoreCase(path)) {
+                                                       return morArray[i];
+                                               }
+                                       }
+                               }  catch (Exception e) {
+                                       s_logger.info("Encountered exception 
when retrieving nas datastore info");
+                                       return null;
+                               }
+                       }
+               }
+               return null;
+       }
+
        @Override
        public ManagedObjectReference mountDatastore(boolean vmfsDatastore, 
String poolHostAddress, 
                int poolHostPort, String poolPath, String poolUuid) throws 
Exception {
@@ -709,11 +743,27 @@ public class HostMO extends BaseMO implements 
VmwareHypervisorHost {
         ManagedObjectReference morDatastore = 
hostDatastoreSystemMo.findDatastore(poolUuid);
         if(morDatastore == null) {
                if(!vmfsDatastore) {
-                       morDatastore = hostDatastoreSystemMo.createNfsDatastore(
-                               poolHostAddress,
-                               poolHostPort, 
-                               poolPath, 
-                               poolUuid);
+                try {
+                    morDatastore = hostDatastoreSystemMo.createNfsDatastore(
+                            poolHostAddress,
+                            poolHostPort,
+                            poolPath,
+                            poolUuid);
+                } catch (com.vmware.vim25.AlreadyExists e) {
+                    s_logger.info("Creation of NFS datastore on vCenter failed 
since datastore already exists." +
+                            " Details: vCenter API trace - mountDatastore(). 
target MOR: " + _mor.get_value() + ", vmfs: " +
+                            vmfsDatastore + ", poolHost: " + poolHostAddress + 
", poolHostPort: " + poolHostPort +
+                            ", poolPath: " + poolPath + ", poolUuid: " + 
poolUuid);
+                    // Retrieve the morDatastore and return it.
+                    return (getExistingDataStoreOnHost(vmfsDatastore, 
poolHostAddress,
+                            poolHostPort, poolPath, poolUuid, 
hostDatastoreSystemMo));
+                } catch (Exception e) {
+                    s_logger.info("Creation of NFS datastore on vCenter 
failed. " +
+                            " Details: vCenter API trace - mountDatastore(). 
target MOR: " + _mor.get_value() + ", vmfs: " +
+                            vmfsDatastore + ", poolHost: " + poolHostAddress + 
", poolHostPort: " + poolHostPort +
+                            ", poolPath: " + poolPath + ", poolUuid: " + 
poolUuid + ". Exception mesg: " + e.getMessage());
+                    throw new Exception("Creation of NFS datastore on vCenter 
failed.");
+                }
                        if(morDatastore == null) {
                                String msg = "Unable to create NFS datastore. 
host: " + poolHostAddress + ", port: " 
                                + poolHostPort + ", path: " + poolPath + ", 
uuid: " + poolUuid;

Reply via email to