diff --git a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index 76a1023c511..afd13d106b3 100644 --- a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -39,6 +39,7 @@ import com.cloud.agent.api.to.StorageFilerTO; 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.HypervisorHostHelper; import com.cloud.hypervisor.vmware.mo.VirtualMachineMO; import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost; import com.cloud.hypervisor.vmware.util.VmwareContext; @@ -122,11 +123,11 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter()); VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true); - - if (templateMo == null) { - if(s_logger.isInfoEnabled()) - s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName); - ManagedObjectReference morDs = hyperHost.findDatastore(cmd.getPoolUuid()); + + if (templateMo == null) { + if(s_logger.isInfoEnabled()) + s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName); + ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPoolUuid()); assert (morDs != null); DatastoreMO primaryStorageDatastoreMo = new DatastoreMO(context, morDs); @@ -170,10 +171,9 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { VmwareContext context = hostService.getServiceContext(cmd); VirtualMachineMO vmMo = null; - - try { - VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); - morDs = hyperHost.findDatastore(cmd.getPool().getUuid()); + try { + VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); + morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPool().getUuid()); try { vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); @@ -340,79 +340,79 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { hyperHost, cmd, vmName, volumeId, cmd.getPool().getUuid(), volumePath, secondaryStorageURL, hostService.getWorkerName(context, cmd, 0)); - } else { - StorageFilerTO poolTO = cmd.getPool(); + } else { + StorageFilerTO poolTO = cmd.getPool(); + + ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolTO.getUuid()); + if (morDatastore == null) { + morDatastore = hyperHost.mountDatastore( + false, + poolTO.getHost(), 0, poolTO.getPath(), + poolTO.getUuid().replace("-", "")); + + if (morDatastore == null) { + throw new Exception("Unable to mount storage pool on host. storeUrl: " + poolTO.getHost() + ":/" + poolTO.getPath()); + } + } + + result = copyVolumeFromSecStorage( + hyperHost, volumeId, + new DatastoreMO(context, morDatastore), + secondaryStorageURL, volumePath); + } + return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second()); + } catch (Throwable e) { + if (e instanceof RemoteException) { + hostService.invalidateServiceContext(context); + } - ManagedObjectReference morDatastore = hyperHost.findDatastore(poolTO.getUuid()); - if (morDatastore == null) { - morDatastore = hyperHost.mountDatastore( - false, - poolTO.getHost(), 0, poolTO.getPath(), - poolTO.getUuid()); - - if (morDatastore == null) { - throw new Exception("Unable to mount storage pool on host. storeUrl: " + poolTO.getHost() + ":/" + poolTO.getPath()); - } - } - - result = copyVolumeFromSecStorage( - hyperHost, volumeId, - new DatastoreMO(context, morDatastore), - secondaryStorageURL, volumePath); - } - return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second()); - } catch (Throwable e) { - if (e instanceof RemoteException) { - hostService.invalidateServiceContext(context); - } - - String msg = "Unable to execute CopyVolumeCommand due to exception"; - s_logger.error(msg, e); - return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null); - } - } - - @Override - public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCommand cmd) { - - String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel(); - Long accountId = cmd.getAccountId(); - Long volumeId = cmd.getVolumeId(); - String secondaryStorageUrl = cmd.getSecondaryStorageUrl(); - String backedUpSnapshotUuid = cmd.getSnapshotUuid(); - - String details = null; - boolean success = false; - String newVolumeName = UUID.randomUUID().toString().replaceAll("-", ""); - - VmwareContext context = hostService.getServiceContext(cmd); - try { - VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); - - ManagedObjectReference morPrimaryDs = hyperHost.findDatastore(primaryStorageNameLabel); - if (morPrimaryDs == null) { - String msg = "Unable to find datastore: " + primaryStorageNameLabel; - s_logger.error(msg); - throw new Exception(msg); - } - - DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs); - details = createVolumeFromSnapshot(hyperHost, primaryDsMo, - newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid); - if (details == null) { - success = true; - } - } catch (Throwable e) { - if (e instanceof RemoteException) { - hostService.invalidateServiceContext(context); - } - - s_logger.error("Unexpecpted exception ", e); - details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e); - } - - return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName); - } + String msg = "Unable to execute CopyVolumeCommand due to exception"; + s_logger.error(msg, e); + return new CopyVolumeAnswer(cmd, false, "CopyVolumeCommand failed due to exception: " + StringUtils.getExceptionStackInfo(e), null, null); + } + } + + @Override + public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCommand cmd) { + + String primaryStorageNameLabel = cmd.getPrimaryStoragePoolNameLabel(); + Long accountId = cmd.getAccountId(); + Long volumeId = cmd.getVolumeId(); + String secondaryStorageUrl = cmd.getSecondaryStorageUrl(); + String backedUpSnapshotUuid = cmd.getSnapshotUuid(); + + String details = null; + boolean success = false; + String newVolumeName = UUID.randomUUID().toString().replaceAll("-", ""); + + VmwareContext context = hostService.getServiceContext(cmd); + try { + VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); + + ManagedObjectReference morPrimaryDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStorageNameLabel); + if (morPrimaryDs == null) { + String msg = "Unable to find datastore: " + primaryStorageNameLabel; + s_logger.error(msg); + throw new Exception(msg); + } + + DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs); + details = createVolumeFromSnapshot(hyperHost, primaryDsMo, + newVolumeName, accountId, volumeId, secondaryStorageUrl, backedUpSnapshotUuid); + if (details == null) { + success = true; + } + } catch (Throwable e) { + if (e instanceof RemoteException) { + hostService.invalidateServiceContext(context); + } + + s_logger.error("Unexpecpted exception ", e); + details = "CreateVolumeFromSnapshotCommand exception: " + StringUtils.getExceptionStackInfo(e); + } + + return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName); + } // templateName: name in secondary storage // templateUuid: will be used at hypervisor layer @@ -783,7 +783,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { String exportName = UUID.randomUUID().toString(); try { - ManagedObjectReference morDs = hyperHost.findDatastore(poolId); + ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolId); if (morDs == null) { String msg = "Unable to find volumes's storage pool for copy volume operation"; diff --git a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 0a1225616db..18c4de2b9ca 100755 --- a/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1639,7 +1639,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa if (vol.getType() != Volume.Type.ISO) { String poolUuid = vol.getPoolUuid(); if(poolMors.get(poolUuid) == null) { - ManagedObjectReference morDataStore = hyperHost.findDatastore(poolUuid); + ManagedObjectReference morDataStore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolUuid); if (morDataStore == null) { String msg = "Failed to get the mounted datastore for the volume's pool " + poolUuid; s_logger.error(msg); @@ -2303,127 +2303,128 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa if (pool.getType() != StoragePoolType.NetworkFilesystem && pool.getType() != StoragePoolType.VMFS) { throw new Exception("Unsupported storage pool type " + pool.getType()); - } - - ManagedObjectReference morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid()); - - assert (morDatastore != null); - DatastoreSummary summary = new DatastoreMO(getServiceContext(), morDatastore).getSummary(); - long capacity = summary.getCapacity(); - long available = summary.getFreeSpace(); - Map tInfo = new HashMap(); - ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo); - return answer; - } catch (Throwable e) { - if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); - invalidateServiceContext(); - } - - String msg = "ModifyStoragePoolCommand failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg, e); - return new Answer(cmd, false, msg); - } - } - - protected Answer execute(DeleteStoragePoolCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource DeleteStoragePoolCommand: " + _gson.toJson(cmd)); - } - - StorageFilerTO pool = cmd.getPool(); + } + + ManagedObjectReference morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(), + pool.getPort(), pool.getPath(), pool.getUuid().replace("-", "")); + + assert (morDatastore != null); + DatastoreSummary summary = new DatastoreMO(getServiceContext(), morDatastore).getSummary(); + long capacity = summary.getCapacity(); + long available = summary.getFreeSpace(); + Map tInfo = new HashMap(); + ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo); + return answer; + } catch (Throwable e) { + if (e instanceof RemoteException) { + s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + invalidateServiceContext(); + } + + String msg = "ModifyStoragePoolCommand failed due to " + VmwareHelper.getExceptionMessage(e); + s_logger.error(msg, e); + return new Answer(cmd, false, msg); + } + } + + protected Answer execute(DeleteStoragePoolCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource DeleteStoragePoolCommand: " + _gson.toJson(cmd)); + } + + StorageFilerTO pool = cmd.getPool(); try { // We will leave datastore cleanup management to vCenter. Since for cluster VMFS datastore, it will always // be mounted by vCenter. - - // VmwareHypervisorHost hyperHost = this.getHyperHost(getServiceContext()); - // hyperHost.unmountDatastore(pool.getUuid()); - Answer answer = new Answer(cmd, true, "success"); - return answer; - } catch (Throwable e) { - if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); - invalidateServiceContext(); - } - - String msg = "DeleteStoragePoolCommand (pool: " + pool.getHost() + ", path: " + pool.getPath() + ") failed due to " + VmwareHelper.getExceptionMessage(e); - return new Answer(cmd, false, msg); - } - } - - protected Answer execute(AttachVolumeCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource AttachVolumeCommand: " + _gson.toJson(cmd)); - } - - /* - * AttachVolumeCommand { "attach":true,"vmName":"i-2-1-KY","pooltype":"NetworkFilesystem", - * "volumeFolder":"/export/home/kelven/vmware-test/primary", "volumePath":"uuid", - * "volumeName":"volume name","deviceId":1 } - */ - try { - VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); - VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); - if (vmMo == null) { - String msg = "Unable to find the VM to execute AttachVolumeCommand, vmName: " + cmd.getVmName(); - s_logger.error(msg); - throw new Exception(msg); - } - - ManagedObjectReference morDs = hyperHost.findDatastore(cmd.getPoolUuid()); - if (morDs == null) { - String msg = "Unable to find the mounted datastore to execute AttachVolumeCommand, vmName: " + cmd.getVmName(); - s_logger.error(msg); - throw new Exception(msg); - } - - DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDs); - String datastoreVolumePath = String.format("[%s] %s.vmdk", dsMo.getName(), cmd.getVolumePath()); - - AttachVolumeAnswer answer = new AttachVolumeAnswer(cmd, cmd.getDeviceId()); - if (cmd.getAttach()) { - vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs); - } else { - vmMo.removeAllSnapshots(); - vmMo.detachDisk(datastoreVolumePath, false); - } - - return answer; - } catch (Throwable e) { - if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); - invalidateServiceContext(); - } - - String msg = "AttachVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg, e); - return new AttachVolumeAnswer(cmd, msg); - } - } - - protected Answer execute(AttachIsoCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource AttachIsoCommand: " + _gson.toJson(cmd)); - } - - try { - VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); - VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); - if (vmMo == null) { - String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + cmd.getVmName(); - s_logger.error(msg); - throw new Exception(msg); - } - - String storeUrl = cmd.getStoreUrl(); - if (storeUrl == null) { - if (!cmd.getIsoPath().equalsIgnoreCase("vmware-tools.iso")) { - String msg = "ISO store root url is not found in AttachIsoCommand"; - s_logger.error(msg); - throw new Exception(msg); - } else { - if (cmd.isAttach()) { - vmMo.mountToolsInstaller(); + + // VmwareHypervisorHost hyperHost = this.getHyperHost(getServiceContext()); + // hyperHost.unmountDatastore(pool.getUuid()); + Answer answer = new Answer(cmd, true, "success"); + return answer; + } catch (Throwable e) { + if (e instanceof RemoteException) { + s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + invalidateServiceContext(); + } + + String msg = "DeleteStoragePoolCommand (pool: " + pool.getHost() + ", path: " + pool.getPath() + ") failed due to " + VmwareHelper.getExceptionMessage(e); + return new Answer(cmd, false, msg); + } + } + + protected Answer execute(AttachVolumeCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource AttachVolumeCommand: " + _gson.toJson(cmd)); + } + + /* + * AttachVolumeCommand { "attach":true,"vmName":"i-2-1-KY","pooltype":"NetworkFilesystem", + * "volumeFolder":"/export/home/kelven/vmware-test/primary", "volumePath":"uuid", + * "volumeName":"volume name","deviceId":1 } + */ + try { + VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); + VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); + if (vmMo == null) { + String msg = "Unable to find the VM to execute AttachVolumeCommand, vmName: " + cmd.getVmName(); + s_logger.error(msg); + throw new Exception(msg); + } + + ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPoolUuid()); + if (morDs == null) { + String msg = "Unable to find the mounted datastore to execute AttachVolumeCommand, vmName: " + cmd.getVmName(); + s_logger.error(msg); + throw new Exception(msg); + } + + DatastoreMO dsMo = new DatastoreMO(getServiceContext(), morDs); + String datastoreVolumePath = String.format("[%s] %s.vmdk", dsMo.getName(), cmd.getVolumePath()); + + AttachVolumeAnswer answer = new AttachVolumeAnswer(cmd, cmd.getDeviceId()); + if (cmd.getAttach()) { + vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs); + } else { + vmMo.removeAllSnapshots(); + vmMo.detachDisk(datastoreVolumePath, false); + } + + return answer; + } catch (Throwable e) { + if (e instanceof RemoteException) { + s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + invalidateServiceContext(); + } + + String msg = "AttachVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e); + s_logger.error(msg, e); + return new AttachVolumeAnswer(cmd, msg); + } + } + + protected Answer execute(AttachIsoCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource AttachIsoCommand: " + _gson.toJson(cmd)); + } + + try { + VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); + VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); + if (vmMo == null) { + String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + cmd.getVmName(); + s_logger.error(msg); + throw new Exception(msg); + } + + String storeUrl = cmd.getStoreUrl(); + if (storeUrl == null) { + if (!cmd.getIsoPath().equalsIgnoreCase("vmware-tools.iso")) { + String msg = "ISO store root url is not found in AttachIsoCommand"; + s_logger.error(msg); + throw new Exception(msg); + } else { + if (cmd.isAttach()) { + vmMo.mountToolsInstaller(); } else { vmMo.unmountToolsInstaller(); } @@ -2470,224 +2471,223 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa String msg = "AttachIsoCommand(detach) failed due to " + VmwareHelper.getExceptionMessage(e); s_logger.warn(msg, e); return new Answer(cmd, false, msg); - } - } - } - - private synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl) throws Exception { - String storeName = getSecondaryDatastoreUUID(storeUrl); - URI uri = new URI(storeUrl); - - VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); - ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName); - - if (morDatastore == null) { - throw new Exception("Unable to mount secondary storage on host. storeUrl: " + storeUrl); - } - - return morDatastore; - } - - private static String getSecondaryDatastoreUUID(String storeUrl) { - return UUID.nameUUIDFromBytes(storeUrl.getBytes()).toString(); - } - - protected Answer execute(ValidateSnapshotCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource ValidateSnapshotCommand: " + _gson.toJson(cmd)); - } - - // the command is no longer available - String expectedSnapshotBackupUuid = null; - String actualSnapshotBackupUuid = null; - String actualSnapshotUuid = null; - return new ValidateSnapshotAnswer(cmd, false, "ValidateSnapshotCommand is not supported for vmware yet", expectedSnapshotBackupUuid, actualSnapshotBackupUuid, actualSnapshotUuid); - } - - protected Answer execute(ManageSnapshotCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource ManageSnapshotCommand: " + _gson.toJson(cmd)); - } - - long snapshotId = cmd.getSnapshotId(); - - /* - * "ManageSnapshotCommand", - * "{\"_commandSwitch\":\"-c\",\"_volumePath\":\"i-2-3-KY-ROOT\",\"_snapshotName\":\"i-2-3-KY_i-2-3-KY-ROOT_20101102203827\",\"_snapshotId\":1,\"_vmName\":\"i-2-3-KY\"}" - */ - boolean success = false; - String cmdSwitch = cmd.getCommandSwitch(); - String snapshotOp = "Unsupported snapshot command." + cmdSwitch; - if (cmdSwitch.equals(ManageSnapshotCommand.CREATE_SNAPSHOT)) { - snapshotOp = "create"; - } else if (cmdSwitch.equals(ManageSnapshotCommand.DESTROY_SNAPSHOT)) { - snapshotOp = "destroy"; - } - - String details = "ManageSnapshotCommand operation: " + snapshotOp + " Failed for snapshotId: " + snapshotId; - String snapshotUUID = null; + } + } + } + + private synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl) throws Exception { + String storeName = getSecondaryDatastoreUUID(storeUrl); + URI uri = new URI(storeUrl); + + VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); + ManagedObjectReference morDatastore = hyperHost.mountDatastore(false, uri.getHost(), 0, uri.getPath(), storeName.replace("-", "")); + + if (morDatastore == null) + throw new Exception("Unable to mount secondary storage on host. storeUrl: " + storeUrl); + + return morDatastore; + } + + private static String getSecondaryDatastoreUUID(String storeUrl) { + return UUID.nameUUIDFromBytes(storeUrl.getBytes()).toString(); + } + + protected Answer execute(ValidateSnapshotCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource ValidateSnapshotCommand: " + _gson.toJson(cmd)); + } + + // the command is no longer available + String expectedSnapshotBackupUuid = null; + String actualSnapshotBackupUuid = null; + String actualSnapshotUuid = null; + return new ValidateSnapshotAnswer(cmd, false, "ValidateSnapshotCommand is not supported for vmware yet", expectedSnapshotBackupUuid, actualSnapshotBackupUuid, actualSnapshotUuid); + } + + protected Answer execute(ManageSnapshotCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource ManageSnapshotCommand: " + _gson.toJson(cmd)); + } + + long snapshotId = cmd.getSnapshotId(); + + /* + * "ManageSnapshotCommand", + * "{\"_commandSwitch\":\"-c\",\"_volumePath\":\"i-2-3-KY-ROOT\",\"_snapshotName\":\"i-2-3-KY_i-2-3-KY-ROOT_20101102203827\",\"_snapshotId\":1,\"_vmName\":\"i-2-3-KY\"}" + */ + boolean success = false; + String cmdSwitch = cmd.getCommandSwitch(); + String snapshotOp = "Unsupported snapshot command." + cmdSwitch; + if (cmdSwitch.equals(ManageSnapshotCommand.CREATE_SNAPSHOT)) { + snapshotOp = "create"; + } else if (cmdSwitch.equals(ManageSnapshotCommand.DESTROY_SNAPSHOT)) { + snapshotOp = "destroy"; + } + + String details = "ManageSnapshotCommand operation: " + snapshotOp + " Failed for snapshotId: " + snapshotId; + String snapshotUUID = null; // snapshot operation (create or destroy) is handled inside BackupSnapshotCommand(), we just fake // a success return here snapshotUUID = UUID.randomUUID().toString(); success = true; details = null; - - return new ManageSnapshotAnswer(cmd, snapshotId, snapshotUUID, success, details); - } - - protected Answer execute(BackupSnapshotCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource BackupSnapshotCommand: " + _gson.toJson(cmd)); - } - - try { - VmwareContext context = getServiceContext(); - VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - - return 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 details = "BackupSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(details, e); - return new BackupSnapshotAnswer(cmd, false, details, null, true); - } - } - - - protected Answer execute(CreateVolumeFromSnapshotCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource CreateVolumeFromSnapshotCommand: " + _gson.toJson(cmd)); - } - - String details = null; - boolean success = false; - String newVolumeName = UUID.randomUUID().toString(); - - try { - VmwareContext context = getServiceContext(); - VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - return 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(); - } - - details = "CreateVolumeFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(details, e); - } - - return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName); - } - - protected Answer execute(CreatePrivateTemplateFromVolumeCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource CreatePrivateTemplateFromVolumeCommand: " + _gson.toJson(cmd)); - } - - try { - VmwareContext context = getServiceContext(); - VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - - return 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 details = "CreatePrivateTemplateFromVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(details, e); - return new CreatePrivateTemplateAnswer(cmd, false, details); - } - } - - protected Answer execute(final UpgradeSnapshotCommand cmd) { - return new Answer(cmd, true, "success"); - } - - protected Answer execute(CreatePrivateTemplateFromSnapshotCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource CreatePrivateTemplateFromSnapshotCommand: " + _gson.toJson(cmd)); - } - - try { - VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - return 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 details = "CreatePrivateTemplateFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(details, e); - return new CreatePrivateTemplateAnswer(cmd, false, details); - } - } - - protected Answer execute(GetStorageStatsCommand cmd) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Executing resource GetStorageStatsCommand: " + _gson.toJson(cmd)); - } - - try { - VmwareContext context = getServiceContext(); - VmwareHypervisorHost hyperHost = getHyperHost(context); - ManagedObjectReference morDs = hyperHost.findDatastore(cmd.getStorageId()); - - if (morDs != null) { - DatastoreMO datastoreMo = new DatastoreMO(context, morDs); - DatastoreSummary summary = datastoreMo.getSummary(); - assert (summary != null); - - long capacity = summary.getCapacity(); - long free = summary.getFreeSpace(); - long used = capacity - free; - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Datastore summary info, storageId: " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ", capacity: " + capacity - + ", free: " + free + ", used: " + used); - } - - if (summary.getCapacity() <= 0) { - s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help"); - } - - return new GetStorageStatsAnswer(cmd, capacity, used); - } else { - String msg = "Could not find datastore for GetStorageStatsCommand storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype(); - - s_logger.error(msg); - return new GetStorageStatsAnswer(cmd, msg); - } - } catch (Throwable e) { - if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); - invalidateServiceContext(); - } - - String msg = "Unable to execute GetStorageStatsCommand(storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ") due to " - + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg, e); - return new GetStorageStatsAnswer(cmd, msg); - } - } - - protected Answer execute(GetVncPortCommand cmd) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Executing resource GetVncPortCommand: " + _gson.toJson(cmd)); - } - - try { - VmwareContext context = getServiceContext(); + + return new ManageSnapshotAnswer(cmd, snapshotId, snapshotUUID, success, details); + } + + protected Answer execute(BackupSnapshotCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource BackupSnapshotCommand: " + _gson.toJson(cmd)); + } + + try { + VmwareContext context = getServiceContext(); + VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + + return 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 details = "BackupSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e); + s_logger.error(details, e); + return new BackupSnapshotAnswer(cmd, false, details, null, true); + } + } + + + protected Answer execute(CreateVolumeFromSnapshotCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource CreateVolumeFromSnapshotCommand: " + _gson.toJson(cmd)); + } + + String details = null; + boolean success = false; + String newVolumeName = UUID.randomUUID().toString(); + + try { + VmwareContext context = getServiceContext(); + VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + return 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(); + } + + details = "CreateVolumeFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e); + s_logger.error(details, e); + } + + return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName); + } + + protected Answer execute(CreatePrivateTemplateFromVolumeCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource CreatePrivateTemplateFromVolumeCommand: " + _gson.toJson(cmd)); + } + + try { + VmwareContext context = getServiceContext(); + VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + + return 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 details = "CreatePrivateTemplateFromVolumeCommand failed due to " + VmwareHelper.getExceptionMessage(e); + s_logger.error(details, e); + return new CreatePrivateTemplateAnswer(cmd, false, details); + } + } + + protected Answer execute(final UpgradeSnapshotCommand cmd) { + return new Answer(cmd, true, "success"); + } + + protected Answer execute(CreatePrivateTemplateFromSnapshotCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource CreatePrivateTemplateFromSnapshotCommand: " + _gson.toJson(cmd)); + } + + try { + VmwareManager mgr = getServiceContext().getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + return 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 details = "CreatePrivateTemplateFromSnapshotCommand failed due to " + VmwareHelper.getExceptionMessage(e); + s_logger.error(details, e); + return new CreatePrivateTemplateAnswer(cmd, false, details); + } + } + + protected Answer execute(GetStorageStatsCommand cmd) { + if (s_logger.isTraceEnabled()) { + s_logger.trace("Executing resource GetStorageStatsCommand: " + _gson.toJson(cmd)); + } + + try { + VmwareContext context = getServiceContext(); + VmwareHypervisorHost hyperHost = getHyperHost(context); + ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getStorageId()); + + if (morDs != null) { + DatastoreMO datastoreMo = new DatastoreMO(context, morDs); + DatastoreSummary summary = datastoreMo.getSummary(); + assert (summary != null); + + long capacity = summary.getCapacity(); + long free = summary.getFreeSpace(); + long used = capacity - free; + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Datastore summary info, storageId: " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ", capacity: " + capacity + + ", free: " + free + ", used: " + used); + } + + if (summary.getCapacity() <= 0) { + s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help"); + } + + return new GetStorageStatsAnswer(cmd, capacity, used); + } else { + String msg = "Could not find datastore for GetStorageStatsCommand storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype(); + + s_logger.error(msg); + return new GetStorageStatsAnswer(cmd, msg); + } + } catch (Throwable e) { + if (e instanceof RemoteException) { + s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + invalidateServiceContext(); + } + + String msg = "Unable to execute GetStorageStatsCommand(storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ") due to " + + VmwareHelper.getExceptionMessage(e); + s_logger.error(msg, e); + return new GetStorageStatsAnswer(cmd, msg); + } + } + + protected Answer execute(GetVncPortCommand cmd) { + if (s_logger.isTraceEnabled()) { + s_logger.trace("Executing resource GetVncPortCommand: " + _gson.toJson(cmd)); + } + + try { + VmwareContext context = getServiceContext(); VmwareHypervisorHost hyperHost = getHyperHost(context); assert(hyperHost instanceof HostMO); VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); @@ -2756,74 +2756,74 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } protected Answer execute(ModifySshKeysCommand cmd) { - //do not log the command contents for this command. do NOT log the ssh keys - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource ModifySshKeysCommand."); - } - - return new Answer(cmd); - } - - protected Answer execute(PoolEjectCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource PoolEjectCommand: " + _gson.toJson(cmd)); - } - - return new Answer(cmd, false, "PoolEjectCommand is not available for vmware"); - } - - @Override - public PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource PrimaryStorageDownloadCommand: " + _gson.toJson(cmd)); - } - - try { - VmwareContext context = getServiceContext(); - VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - return (PrimaryStorageDownloadAnswer) 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 = "PrimaryStorageDownloadCommand failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg, e); - return new PrimaryStorageDownloadAnswer(msg); - } - } - - @Override - public Answer execute(DestroyCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource DestroyCommand: " + _gson.toJson(cmd)); - } - - /* - * DestroyCommand content example - * - * {"volume": {"id":5,"name":"Volume1", "mountPoint":"/export/home/kelven/vmware-test/primary", - * "path":"6bb8762f-c34c-453c-8e03-26cc246ceec4", "size":0,"type":"DATADISK","resourceType": - * "STORAGE_POOL","storagePoolType":"NetworkFilesystem", "poolId":0,"deviceId":0 } } - * - * {"volume": {"id":1, "name":"i-2-1-KY-ROOT", "mountPoint":"/export/home/kelven/vmware-test/primary", - * "path":"i-2-1-KY-ROOT","size":0,"type":"ROOT", "resourceType":"STORAGE_POOL", "storagePoolType":"NetworkFilesystem", - * "poolId":0,"deviceId":0 } } - */ - - try { - VmwareContext context = getServiceContext(); - VmwareHypervisorHost hyperHost = getHyperHost(context); - VolumeTO vol = cmd.getVolume(); - - ManagedObjectReference morDs = hyperHost.findDatastore(vol.getPoolUuid()); - if (morDs == null) { - String msg = "Unable to find datastore based on volume mount point " + cmd.getVolume().getMountPoint(); - s_logger.error(msg); - throw new Exception(msg); - } - + //do not log the command contents for this command. do NOT log the ssh keys + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource ModifySshKeysCommand."); + } + + return new Answer(cmd); + } + + protected Answer execute(PoolEjectCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource PoolEjectCommand: " + _gson.toJson(cmd)); + } + + return new Answer(cmd, false, "PoolEjectCommand is not available for vmware"); + } + + @Override + public PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource PrimaryStorageDownloadCommand: " + _gson.toJson(cmd)); + } + + try { + VmwareContext context = getServiceContext(); + VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); + return (PrimaryStorageDownloadAnswer) 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 = "PrimaryStorageDownloadCommand failed due to " + VmwareHelper.getExceptionMessage(e); + s_logger.error(msg, e); + return new PrimaryStorageDownloadAnswer(msg); + } + } + + @Override + public Answer execute(DestroyCommand cmd) { + if (s_logger.isInfoEnabled()) { + s_logger.info("Executing resource DestroyCommand: " + _gson.toJson(cmd)); + } + + /* + * DestroyCommand content example + * + * {"volume": {"id":5,"name":"Volume1", "mountPoint":"/export/home/kelven/vmware-test/primary", + * "path":"6bb8762f-c34c-453c-8e03-26cc246ceec4", "size":0,"type":"DATADISK","resourceType": + * "STORAGE_POOL","storagePoolType":"NetworkFilesystem", "poolId":0,"deviceId":0 } } + * + * {"volume": {"id":1, "name":"i-2-1-KY-ROOT", "mountPoint":"/export/home/kelven/vmware-test/primary", + * "path":"i-2-1-KY-ROOT","size":0,"type":"ROOT", "resourceType":"STORAGE_POOL", "storagePoolType":"NetworkFilesystem", + * "poolId":0,"deviceId":0 } } + */ + + try { + VmwareContext context = getServiceContext(); + VmwareHypervisorHost hyperHost = getHyperHost(context); + VolumeTO vol = cmd.getVolume(); + + ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, vol.getPoolUuid()); + if (morDs == null) { + String msg = "Unable to find datastore based on volume mount point " + cmd.getVolume().getMountPoint(); + s_logger.error(msg); + throw new Exception(msg); + } + DatastoreMO dsMo = new DatastoreMO(context, morDs); ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter(); @@ -2980,18 +2980,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa VmwareHypervisorHost hyperHost = getHyperHost(context); DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter()); - VmwareManager vmwareMgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); - - ManagedObjectReference morDatastore = hyperHost.findDatastore(pool.getUuid()); - if (morDatastore == null) { - throw new Exception("Unable to find datastore in vSphere"); - } - DatastoreMO dsMo = new DatastoreMO(context, morDatastore); - - if (cmd.getDiskCharacteristics().getType() == Volume.Type.ROOT) { - if (cmd.getTemplateUrl() == null) { - // create a root volume for blank VM - String dummyVmName = getWorkerName(context, cmd, 0); + ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid()); + if (morDatastore == null) + throw new Exception("Unable to find datastore in vSphere"); + + DatastoreMO dsMo = new DatastoreMO(context, morDatastore); + + if (cmd.getDiskCharacteristics().getType() == Volume.Type.ROOT) { + if (cmd.getTemplateUrl() == null) { + // create a root volume for blank VM + String dummyVmName = getWorkerName(context, cmd, 0); VirtualMachineMO vmMo = null; try { 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 b7a41a4cc86..1bf531a0ccb 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java @@ -43,42 +43,50 @@ import com.vmware.vim25.VirtualMachineConfigSpec; import com.vmware.vim25.VirtualMachineFileInfo; import com.vmware.vim25.VirtualMachineVideoCard; import com.vmware.vim25.VirtualSCSISharing; - -public class HypervisorHostHelper { - private static final Logger s_logger = Logger.getLogger(HypervisorHostHelper.class); - private static final int DEFAULT_LOCK_TIMEOUT_SECONDS = 600; - - // make vmware-base loosely coupled with cloud-specific stuff, duplicate VLAN.UNTAGGED constant here - private static final String UNTAGGED_VLAN_NAME = "untagged"; - - public static VirtualMachineMO findVmFromObjectContent(VmwareContext context, - ObjectContent[] ocs, String name) { - - if(ocs != null && ocs.length > 0) { - for(ObjectContent oc : ocs) { - DynamicProperty prop = oc.getPropSet(0); - assert(prop != null); - if(prop.getVal().toString().equals(name)) - return new VirtualMachineMO(context, oc.getObj()); - } - } - return null; + +public class HypervisorHostHelper { + private static final Logger s_logger = Logger.getLogger(HypervisorHostHelper.class); + private static final int DEFAULT_LOCK_TIMEOUT_SECONDS = 600; + + // make vmware-base loosely coupled with cloud-specific stuff, duplicate VLAN.UNTAGGED constant here + private static final String UNTAGGED_VLAN_NAME = "untagged"; + + public static VirtualMachineMO findVmFromObjectContent(VmwareContext context, + ObjectContent[] ocs, String name) { + + if(ocs != null && ocs.length > 0) { + for(ObjectContent oc : ocs) { + DynamicProperty prop = oc.getPropSet(0); + assert(prop != null); + if(prop.getVal().toString().equals(name)) + return new VirtualMachineMO(context, oc.getObj()); + } + } + return null; } - - public static DatastoreMO getHyperHostDatastoreMO(VmwareHypervisorHost hyperHost, String datastoreName) throws Exception { - ObjectContent[] ocs = hyperHost.getDatastorePropertiesOnHyperHost(new String[] { "name"} ); - if(ocs != null && ocs.length > 0) { - for(ObjectContent oc : ocs) { - DynamicProperty[] objProps = oc.getPropSet(); - if(objProps != null) { - for(DynamicProperty objProp : objProps) { - if(objProp.getVal().toString().equals(datastoreName)) - return new DatastoreMO(hyperHost.getContext(), oc.getObj()); - } - } - } - } - return null; + + public static ManagedObjectReference findDatastoreWithBackwardsCompatibility(VmwareHypervisorHost hyperHost, String uuidName) throws Exception { + ManagedObjectReference morDs = hyperHost.findDatastore(uuidName.replace("-", "")); + if(morDs == null) + morDs = hyperHost.findDatastore(uuidName); + + return morDs; + } + + public static DatastoreMO getHyperHostDatastoreMO(VmwareHypervisorHost hyperHost, String datastoreName) throws Exception { + ObjectContent[] ocs = hyperHost.getDatastorePropertiesOnHyperHost(new String[] { "name"} ); + if(ocs != null && ocs.length > 0) { + for(ObjectContent oc : ocs) { + DynamicProperty[] objProps = oc.getPropSet(); + if(objProps != null) { + for(DynamicProperty objProp : objProps) { + if(objProp.getVal().toString().equals(datastoreName)) + return new DatastoreMO(hyperHost.getContext(), oc.getObj()); + } + } + } + } + return null; } public static String getPublicNetworkNamePrefix(String vlanId) {