This is an automated email from the ASF dual-hosted git repository.

pearl11594 pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit 0785ba046e9e135bfd14ed31a8dce73e30a31b5d
Merge: 5d28e66b521 9d9737ae040
Author: Pearl Dsilva <[email protected]>
AuthorDate: Mon Apr 28 11:10:08 2025 +0530

    Merge branch '4.19' of https://github.com/apache/cloudstack into 4.20

 .../org/apache/cloudstack/api/ApiConstants.java    |   7 +-
 .../cloudstack/api/response/HostResponse.java      |   8 +-
 .../main/java/com/cloud/event/UsageEventUtils.java |  24 +-
 .../engine/orchestration/NetworkOrchestrator.java  |  21 +-
 .../orchestration/NetworkOrchestratorTest.java     |   2 +-
 .../acl/DynamicRoleBasedAPIAccessChecker.java      |   4 +-
 .../hypervisor/vmware/VmwareDatacenterService.java |   7 +-
 .../vmware/manager/VmwareManagerImpl.java          | 258 ++++-----
 .../api/command/admin/zone/AddVmwareDcCmd.java     |  12 +-
 .../zone/ImportVsphereStoragePoliciesCmd.java      |  11 +-
 .../command/admin/zone/ListVmwareDcHostsCmd.java   | 144 -----
 .../api/command/admin/zone/ListVmwareDcItems.java  |  29 -
 .../api/command/admin/zone/ListVmwareDcVmsCmd.java |  52 +-
 .../api/command/admin/zone/ListVmwareDcsCmd.java   |  26 +-
 .../admin/zone/ListVsphereStoragePoliciesCmd.java  |  13 +-
 ...ListVsphereStoragePolicyCompatiblePoolsCmd.java |   2 +-
 .../api/command/admin/zone/RemoveVmwareDcCmd.java  |   6 +-
 .../api/command/admin/zone/UpdateVmwareDcCmd.java  |   8 +-
 .../command/admin/zone/VmwareRequestResponse.java  |  38 --
 .../java/com/cloud/network/NetworkServiceImpl.java |  14 +-
 test/integration/smoke/test_certauthority_root.py  |  36 +-
 test/integration/smoke/test_cluster_drs.py         |  13 +-
 test/integration/smoke/test_dynamicroles.py        |   1 -
 test/integration/smoke/test_events_resource.py     |   5 +-
 test/integration/smoke/test_network_permissions.py |  15 +-
 .../smoke/test_nonstrict_affinity_group.py         |  10 +-
 ui/src/views/tools/ManageInstances.vue             |   1 -
 ui/src/views/tools/SelectVmwareVcenter.vue         |  66 +--
 .../com/cloud/hypervisor/vmware/mo/BaseMO.java     |  54 +-
 .../vmware/mo/CustomFieldsManagerMO.java           |   7 +-
 .../cloud/hypervisor/vmware/mo/DatacenterMO.java   | 157 +++---
 .../com/cloud/hypervisor/vmware/mo/HostMO.java     |  98 +---
 .../hypervisor/vmware/mo/VirtualMachineMO.java     | 626 +++++++++++++++++----
 .../cloud/hypervisor/vmware/util/VmwareClient.java |  22 +-
 .../vmware/util/VmwareClientException.java         |  33 --
 35 files changed, 868 insertions(+), 962 deletions(-)

diff --cc 
engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java
index 51d0846fafb,547663fd1b9..94fbb7a80af
--- a/engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java
+++ b/engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java
@@@ -25,14 -25,15 +25,16 @@@ import java.util.Map
  import javax.annotation.PostConstruct;
  import javax.inject.Inject;
  
+ import com.cloud.network.Network;
+ import org.apache.commons.collections.MapUtils;
 -import org.apache.log4j.Logger;
+ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+ 
  import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
  import org.apache.cloudstack.framework.events.Event;
  import org.apache.cloudstack.framework.events.EventBus;
 -import org.apache.cloudstack.framework.events.EventBusException;
 +import org.apache.cloudstack.framework.events.EventDistributor;
- import org.apache.commons.collections.MapUtils;
 +import org.apache.logging.log4j.LogManager;
 +import org.apache.logging.log4j.Logger;
- import org.springframework.beans.factory.NoSuchBeanDefinitionException;
  
  import com.cloud.dc.DataCenterVO;
  import com.cloud.dc.dao.DataCenterDao;
diff --cc 
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index 5106fd824c7,2ec79bc80f1..22ec005a8d1
--- 
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ 
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@@ -1526,10 -1459,8 +1526,8 @@@ public class NetworkOrchestrator extend
          NetworkVO network = _networksDao.findById(networkId);
          final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, 
network.getGuruName());
          if (isNetworkImplemented(network)) {
 -            s_logger.debug("Network id=" + networkId + " is already 
implemented");
 +            logger.debug("Network {} is already implemented", network);
              implemented.set(guru, network);
-             
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, 
network.getAccountId(), network.getDataCenterId(), network.getId(),
-                     network.getName(), network.getNetworkOfferingId(), null, 
network.getState().name(), Network.class.getName(), network.getUuid(), true);
              return implemented;
          }
  
@@@ -1585,15 -1520,14 +1583,14 @@@
  
              network.setRestartRequired(false);
              _networksDao.update(network.getId(), network);
+             UsageEventUtils.publishNetworkUpdate(network);
              implemented.set(guru, network);
-             
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, 
network.getAccountId(), network.getDataCenterId(), network.getId(),
-                     network.getName(), network.getNetworkOfferingId(), null, 
null, null, network.getState().name(), network.getUuid());
              return implemented;
          } catch (final NoTransitionException e) {
 -            s_logger.error(e.getMessage());
 +            logger.error(e.getMessage());
              return new Pair<NetworkGuru, NetworkVO>(null, null);
          } catch (final CloudRuntimeException | OperationTimedoutException e) {
 -            s_logger.error("Caught exception: " + e.getMessage());
 +            logger.error("Caught exception: {}", e.getMessage());
              return new Pair<NetworkGuru, NetworkVO>(null, null);
          } finally {
              if (implemented.first() == null) {
@@@ -3163,18 -3079,22 +3161,19 @@@
              //do global lock for the network
              network = _networksDao.acquireInLockTable(networkId, 
NetworkLockTimeout.value());
              if (network == null) {
 -                s_logger.warn("Network with id: " + networkId + " doesn't 
exist, or unable to acquire lock for it as a part of network shutdown");
 +                logger.warn("Unable to acquire lock for the network {} as a 
part of network shutdown", network);
                  return false;
              }
 -
 -            if (s_logger.isDebugEnabled()) {
 -                s_logger.debug("Lock is acquired for network " + network + " 
as a part of network shutdown");
 -            }
 +            logger.debug("Lock is acquired for network {} as a part of 
network shutdown", network);
  
-             if (network.getState() == Network.State.Allocated) {
-                 logger.debug("Network is already shutdown: {}", network);
+             final Network.State initialState = network.getState();
+             if (initialState == Network.State.Allocated) {
 -                s_logger.debug(String.format("Network [%s] is in Allocated 
state, no need to shutdown.", network));
++                logger.debug(String.format("Network [%s] is in Allocated 
state, no need to shutdown.", network));
                  return true;
              }
  
-             if (network.getState() != Network.State.Implemented && 
network.getState() != Network.State.Shutdown) {
-                 logger.debug("Network is not implemented: {}", network);
+             if (initialState != Network.State.Implemented && initialState != 
Network.State.Shutdown) {
 -                s_logger.debug("Network is not implemented: " + network);
++                logger.debug("Network is not implemented: " + network);
                  return false;
              }
  
@@@ -3469,11 -3395,10 +3471,10 @@@
                      final Pair<Class<?>, Long> networkMsg = new 
Pair<Class<?>, Long>(Network.class, networkFinal.getId());
                      _messageBus.publish(_name, 
EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
                  }
-                 
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, 
network.getAccountId(), network.getDataCenterId(), network.getId(),
-                         network.getName(), network.getNetworkOfferingId(), 
null, null, null, Network.class.getName(), network.getUuid());
+                 UsageEventUtils.publishNetworkDeletion(network);
                  return true;
              } catch (final CloudRuntimeException e) {
 -                s_logger.error("Failed to delete network", e);
 +                logger.error("Failed to delete network", e);
                  return false;
              }
          }
diff --cc 
plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java
index 6bbd25bb440,1dfe20a10be..030e0bcf014
--- 
a/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java
+++ 
b/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java
@@@ -47,11 -47,9 +47,11 @@@ public class DynamicRoleBasedAPIAccessC
      private RoleService roleService;
  
      private List<PluggableService> services;
-     private Map<RoleType, Set<String>> annotationRoleBasedApisMap = new 
HashMap<>();
+     private Map<RoleType, Set<String>> annotationRoleBasedApisMap = new 
HashMap<RoleType, Set<String>>();
  
 -    private static final Logger LOGGER = 
Logger.getLogger(DynamicRoleBasedAPIAccessChecker.class.getName());
 +    private LazyCache<Long, Account> accountCache;
 +    private LazyCache<Long, Pair<Role, List<RolePermission>>> 
rolePermissionsCache;
 +    private int cachePeriod;
  
      protected DynamicRoleBasedAPIAccessChecker() {
          super();
diff --cc 
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
index b64422482aa,61a949f42d3..730b737e0f4
--- 
a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
+++ 
b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
@@@ -176,15 -172,9 +171,8 @@@ import com.cloud.vm.dao.VMInstanceDao
  import com.vmware.pbm.PbmProfile;
  import com.vmware.vim25.AboutInfo;
  import com.vmware.vim25.ManagedObjectReference;
- import com.vmware.vim25.InvalidLocaleFaultMsg;
- import com.vmware.vim25.InvalidLoginFaultMsg;
- import com.vmware.vim25.RuntimeFaultFaultMsg;
- import com.vmware.vim25.InvalidPropertyFaultMsg;
- import org.jetbrains.annotations.NotNull;
  
  public class VmwareManagerImpl extends ManagerBase implements VmwareManager, 
VmwareStorageMount, Listener, VmwareDatacenterService, Configurable {
 -    private static final Logger s_logger = 
Logger.getLogger(VmwareManagerImpl.class);
  
      private static final long SECONDS_PER_MINUTE = 60;
      private static final int DEFAULT_PORTS_PER_DV_PORT_GROUP_VSPHERE4_x = 256;
@@@ -458,9 -448,9 +446,9 @@@
          vlanId = mgmtTrafficLabelObj.getVlanId();
          vSwitchType = mgmtTrafficLabelObj.getVirtualSwitchType().toString();
  
 -        s_logger.info("Preparing network on host " + 
hostMo.getContext().toString() + " for " + privateTrafficLabel);
 +        logger.info("Preparing network on host " + 
hostMo.getContext().toString() + " for " + privateTrafficLabel);
          VirtualSwitchType vsType = VirtualSwitchType.getType(vSwitchType);
-         //The management network is probably always going to be a physical 
network with isolation type of vlans, so assume BroadcastDomainType VLAN
+         //The management network is probably always going to be a physical 
network with islation type of vlans, so assume BroadcastDomainType VLAN
          if (VirtualSwitchType.StandardVirtualSwitch == vsType) {
              HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", 
hostMo, vlanId, null, null, 180000, false, BroadcastDomainType.Vlan, null, 
null);
          }
@@@ -668,25 -659,25 +657,25 @@@
              return false;
          }
  
-         String[] tokens = workerTag.split("-");
+         String tokens[] = workerTag.split("-");
          if (tokens.length != 3) {
 -            s_logger.error("Invalid worker VM tag " + workerTag);
 +            logger.error("Invalid worker VM tag " + workerTag);
              return false;
          }
  
          long startTick = Long.parseLong(tokens[0]);
-         long msId = Long.parseLong(tokens[1]);
-         long runId = Long.parseLong(tokens[2]);
+         long msid = Long.parseLong(tokens[1]);
+         long runid = Long.parseLong(tokens[2]);
  
-         if (msHostPeerDao.countStateSeenInPeers(msId, runId, 
ManagementServerHost.State.Down) > 0) {
+         if (msHostPeerDao.countStateSeenInPeers(msid, runid, 
ManagementServerHost.State.Down) > 0) {
 -            if (s_logger.isInfoEnabled())
 -                s_logger.info("Worker VM's owner management server node has 
been detected down from peer nodes, recycle it");
 +            if (logger.isInfoEnabled())
 +                logger.info("Worker VM's owner management server node has 
been detected down from peer nodes, recycle it");
              return true;
          }
  
-         if (runId != clusterManager.getManagementRunId(msId)) {
+         if (runid != clusterManager.getManagementRunId(msid)) {
 -            if (s_logger.isInfoEnabled())
 -                s_logger.info("Worker VM's owner management server has 
changed runid, recycle it");
 +            if (logger.isInfoEnabled())
 +                logger.info("Worker VM's owner management server has changed 
runid, recycle it");
              return true;
          }
  
@@@ -782,8 -773,9 +771,9 @@@
              isoFile = new 
File("/usr/share/cloudstack-common/vms/systemvm.iso");
          }
  
+         assert (isoFile != null);
          if (!isoFile.exists()) {
 -            s_logger.error("Unable to locate systemvm.iso in your setup at " 
+ isoFile.toString());
 +            logger.error("Unable to locate systemvm.iso in your setup at " + 
isoFile);
          }
          return isoFile;
      }
@@@ -798,9 -790,9 +788,9 @@@
          if (keyFile == null || !keyFile.exists()) {
              keyFile = new 
File("/usr/share/cloudstack-common/scripts/vm/systemvm/id_rsa.cloud");
          }
- 
+         assert (keyFile != null);
          if (!keyFile.exists()) {
 -            s_logger.error("Unable to locate id_rsa.cloud in your setup at " 
+ keyFile.toString());
 +            logger.error("Unable to locate id_rsa.cloud in your setup at " + 
keyFile);
          }
          return keyFile;
      }
@@@ -860,13 -852,14 +850,14 @@@
          List<String> mounts = _storage.listMountPointsByMsHost(parent, 
mshostId);
          if (mounts != null && !mounts.isEmpty()) {
              for (String mountPoint : mounts) {
 -                s_logger.info("umount NFS mount from previous session: " + 
mountPoint);
 +                logger.info("umount NFS mount from previous session: " + 
mountPoint);
  
+                 String result = null;
 -                Script command = new Script(true, "umount", _timeout, 
s_logger);
 +                Script command = new Script(true, "umount", _timeout, logger);
                  command.add(mountPoint);
-                 String result = command.execute();
+                 result = command.execute();
                  if (result != null) {
 -                    s_logger.warn("Unable to umount " + mountPoint + " due to 
" + result);
 +                    logger.warn("Unable to umount " + mountPoint + " due to " 
+ result);
                  }
                  File file = new File(mountPoint);
                  if (file.exists()) {
@@@ -877,16 -870,17 +868,17 @@@
      }
  
      private void shutdownCleanup() {
 -        s_logger.info("Cleanup mounted NFS mount points used in current 
session");
 +        logger.info("Cleanup mounted NFS mount points used in current 
session");
  
          for (String mountPoint : _storageMounts.values()) {
 -            s_logger.info("umount NFS mount: " + mountPoint);
 +            logger.info("umount NFS mount: " + mountPoint);
  
+             String result = null;
 -            Script command = new Script(true, "umount", _timeout, s_logger);
 +            Script command = new Script(true, "umount", _timeout, logger);
              command.add(mountPoint);
-             String result = command.execute();
+             result = command.execute();
              if (result != null) {
 -                s_logger.warn("Unable to umount " + mountPoint + " due to " + 
result);
 +                logger.warn("Unable to umount " + mountPoint + " due to " + 
result);
              }
              File file = new File(mountPoint);
              if (file.exists()) {
@@@ -902,9 -896,9 +894,9 @@@
              return null;
          }
  
-         Script script;
-         String result;
+         Script script = null;
+         String result = null;
 -        Script command = new Script(true, "mount", _timeout, s_logger);
 +        Script command = new Script(true, "mount", _timeout, logger);
          command.add("-t", "nfs");
          if (nfsVersion != null){
              command.add("-o", "vers=" + nfsVersion);
@@@ -1067,18 -1063,18 +1061,18 @@@
  
      @Override
      public Map<String, String> getNexusVSMCredentialsByClusterId(Long 
clusterId) {
-         CiscoNexusVSMDeviceVO nexusVSM;
-         ClusterVSMMapVO vsmMapVO;
+         CiscoNexusVSMDeviceVO nexusVSM = null;
+         ClusterVSMMapVO vsmMapVO = null;
  
          vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
-         long vsmId;
+         long vsmId = 0;
          if (vsmMapVO != null) {
              vsmId = vsmMapVO.getVsmId();
 -            s_logger.info("vsmId is " + vsmId);
 +            logger.info("vsmId is " + vsmId);
              nexusVSM = _nexusDao.findById(vsmId);
 -            s_logger.info("Fetching nexus vsm credentials from database.");
 +            logger.info("Fetching nexus vsm credentials from database.");
          } else {
 -            s_logger.info("Found empty vsmMapVO.");
 +            logger.info("Found empty vsmMapVO.");
              return null;
          }
  
@@@ -1394,12 -1390,14 +1388,14 @@@
                  throw new DiscoveryException(msg);
              }
  
+             assert (dcMo != null);
+ 
              // Reset custom field property cloud.zone over this DC
              dcMo.setCustomFieldValue(CustomFieldConstants.CLOUD_ZONE, 
"false");
-             logger.info("Sucessfully reset custom field property cloud.zone 
over DC {}", vmwareDcName);
 -            s_logger.info("Sucessfully reset custom field property cloud.zone 
over DC " + vmwareDcName);
++            logger.info("Successfully reset custom field property cloud.zone 
over DC {}", vmwareDcName);
          } catch (Exception e) {
              String msg = "Unable to reset custom field property cloud.zone 
over DC " + vmwareDcName + " due to : " + VmwareHelper.getExceptionMessage(e);
 -            s_logger.error(msg);
 +            logger.error(msg);
              throw new CloudRuntimeException(msg);
          } finally {
              if (context != null) {
@@@ -1506,9 -1505,9 +1503,9 @@@
          String vCenterHost = vmwareDatacenter.getVcenterHost();
          String userName = vmwareDatacenter.getUser();
          String password = vmwareDatacenter.getPassword();
-         List<PbmProfile> storageProfiles;
+         List<PbmProfile> storageProfiles = null;
          try {
 -            s_logger.debug(String.format("Importing vSphere Storage Policies 
for the vmware DC %d in zone %d", vmwareDcId, zoneId));
 +            logger.debug(String.format("Importing vSphere Storage Policies 
for the vmware DC %d in zone %d", vmwareDcId, zoneId));
              VmwareContext context = 
VmwareContextFactory.getContext(vCenterHost, userName, password);
              PbmProfileManagerMO profileManagerMO = new 
PbmProfileManagerMO(context);
              storageProfiles = profileManagerMO.getStorageProfiles();
@@@ -1689,21 -1615,31 +1613,31 @@@
              username = vmwareDc.getUser();
              password = vmwareDc.getPassword();
          }
-         VcenterData vmwaredc = new VcenterData(vcenter, datacenterName, 
username, password);
-         return vmwaredc;
-     }
- 
-     private static class VcenterData {
-         public final String vcenter;
-         public final String datacenterName;
-         public final String username;
-         public final String password;
  
-         public VcenterData(String vcenter, String datacenterName, String 
username, String password) {
-             this.vcenter = vcenter;
-             this.datacenterName = datacenterName;
-             this.username = username;
-             this.password = password;
+         try {
 -            s_logger.debug(String.format("Connecting to the VMware datacenter 
%s at vCenter %s to retrieve VMs",
++            logger.debug(String.format("Connecting to the VMware datacenter 
%s at vCenter %s to retrieve VMs",
+                     datacenterName, vcenter));
+             String serviceUrl = String.format("https://%s/sdk/vimService";, 
vcenter);
+             VmwareClient vimClient = new VmwareClient(vcenter);
+             vimClient.connect(serviceUrl, username, password);
+             VmwareContext context = new VmwareContext(vimClient, vcenter);
+ 
+             DatacenterMO dcMo = new DatacenterMO(context, datacenterName);
+             ManagedObjectReference dcMor = dcMo.getMor();
+             if (dcMor == null) {
+                 String msg = String.format("Unable to find VMware datacenter 
%s in vCenter %s",
+                         datacenterName, vcenter);
 -                s_logger.error(msg);
++                logger.error(msg);
+                 throw new InvalidParameterValueException(msg);
+             }
+             List<UnmanagedInstanceTO> instances = 
dcMo.getAllVmsOnDatacenter();
+             return StringUtils.isBlank(keyword) ? instances :
+                     instances.stream().filter(x -> 
x.getName().toLowerCase().contains(keyword.toLowerCase())).collect(Collectors.toList());
+         } catch (Exception e) {
+             String errorMsg = String.format("Error retrieving stopped VMs 
from the VMware VC %s datacenter %s: %s",
+                     vcenter, datacenterName, e.getMessage());
 -            s_logger.error(errorMsg, e);
++            logger.error(errorMsg, e);
+             throw new CloudRuntimeException(errorMsg);
          }
      }
  
diff --cc 
plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
index aa2e5ac6f3a,9f4985a1363..6f783e0a0fd
--- 
a/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
+++ 
b/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/AddVmwareDcCmd.java
@@@ -43,9 -44,10 +43,9 @@@ public class AddVmwareDcCmd extends Bas
      @Inject
      public VmwareDatacenterService _vmwareDatacenterService;
  
 -    public static final Logger s_logger = 
Logger.getLogger(AddVmwareDcCmd.class.getName());
  
  
-     @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required 
= true, description = "Name of Vmware datacenter to be added to specified 
zone.")
+     @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required 
= true, description = "Name of VMware datacenter to be added to specified 
zone.")
      private String name;
  
      @Parameter(name = ApiConstants.VCENTER,
diff --cc 
plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcsCmd.java
index 9cafda955ca,61b5210bb3a..4c7f2a5c7d8
--- 
a/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcsCmd.java
+++ 
b/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcsCmd.java
@@@ -49,7 -50,9 +49,8 @@@ public class ListVmwareDcsCmd extends B
      @Inject
      public VmwareDatacenterService _vmwareDatacenterService;
  
 -    public static final Logger s_logger = 
Logger.getLogger(ListVmwareDcsCmd.class.getName());
  
+ 
      /////////////////////////////////////////////////////
      //////////////// API parameters /////////////////////
      /////////////////////////////////////////////////////
diff --cc 
plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
index d85fbacf2db,735d00d6ca9..a503d860feb
--- 
a/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
+++ 
b/plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/RemoveVmwareDcCmd.java
@@@ -63,10 -65,10 +63,10 @@@ public class RemoveVmwareDcCmd extends 
                  response.setResponseName(getCommandName());
                  setResponseObject(response);
              } else {
-                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, 
"Failed to remove Vmware datacenter from zone");
+                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, 
"Failed to remove VMware datacenter from zone");
              }
          } catch (ResourceInUseException ex) {
 -            s_logger.warn("The zone has one or more resources (like cluster), 
hence not able to remove VMware datacenter from zone."
 +            logger.warn("The zone has one or more resources (like cluster), 
hence not able to remove VMware datacenter from zone."
                  + " Please remove all resource from zone, and retry. 
Exception: ", ex);
              ServerApiException e = new 
ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
              for (String proxyObj : ex.getIdProxyList()) {
diff --cc server/src/main/java/com/cloud/network/NetworkServiceImpl.java
index 4fbb501e8e4,0b4e2a7db13..2e5308b5bd8
--- a/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/main/java/com/cloud/network/NetworkServiceImpl.java
@@@ -1783,8 -1644,8 +1783,8 @@@ public class NetworkServiceImpl extend
              if (ipv4 && Objects.isNull(startIP)) {
                  throw new CloudRuntimeException("IPv4 address range needs to 
be provided");
              }
-             if (ipv6 && Objects.isNull(startIPv6)) {
-                 throw new CloudRuntimeException("IPv6 address range needs to 
be provided");
+             if (ipv6) {
 -                s_logger.info(String.format("ip range for network '%s' is 
specified as %s - %s", name, startIPv6, endIPv6));
++                logger.info(String.format("ip range for network '%s' is 
specified as %s - %s", name, startIPv6, endIPv6));
              }
          }
          Pair<Integer, Integer> interfaceMTUs = validateMtuConfig(publicMtu, 
privateMtu, zone.getId());
@@@ -2167,21 -1999,16 +2167,16 @@@
          try {
              DeployDestination dest = new DeployDestination(zone, null, null, 
null);
              UserVO callerUser = 
_userDao.findById(CallContext.current().getCallingUserId());
 -            Journal journal = new Journal.LogJournal("Implementing " + 
network, s_logger);
 +            Journal journal = new Journal.LogJournal("Implementing " + 
network, logger);
              ReservationContext context = new 
ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, 
caller);
 -            s_logger.debug("Implementing network " + network + " as a part of 
network provision for persistent network");
 +            logger.debug("Implementing network " + network + " as a part of 
network provision for persistent network");
              Pair<? extends NetworkGuru, ? extends Network> implementedNetwork 
= _networkMgr.implementNetwork(network.getId(), dest, context);
              if (implementedNetwork == null || implementedNetwork.first() == 
null) {
 -                s_logger.warn("Failed to provision the network " + network);
 +                logger.warn("Failed to provision the network " + network);
              }
-             Network implemented = implementedNetwork.second();
-             if (implemented != null) {
-                 
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, 
implemented.getAccountId(), implemented.getDataCenterId(), implemented.getId(),
-                         implemented.getName(), 
implemented.getNetworkOfferingId(), null, null, null, Network.class.getName(), 
implemented.getUuid());
-             }
-             return implemented;
+             return implementedNetwork.second();
          } catch (ResourceUnavailableException ex) {
 -            s_logger.warn("Failed to implement persistent guest network " + 
network + "due to ", ex);
 +            logger.warn("Failed to implement persistent guest network " + 
network + "due to ", ex);
              CloudRuntimeException e = new CloudRuntimeException("Failed to 
implement persistent guest network");
              e.addProxyObject(network.getUuid(), "networkId");
              throw e;
diff --cc vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java
index c0e7f29375f,88f6c871fbd..3568f82f8ef
--- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java
+++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/BaseMO.java
@@@ -16,29 -16,16 +16,17 @@@
  // under the License.
  package com.cloud.hypervisor.vmware.mo;
  
 -import org.apache.log4j.Logger;
 +import org.apache.logging.log4j.Logger;
 +import org.apache.logging.log4j.LogManager;
 +
- import com.cloud.hypervisor.vmware.util.VmwareHelper;
 +import com.cloud.hypervisor.vmware.util.VmwareContext;
- import com.cloud.utils.Pair;
- import 
org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
- import org.apache.cloudstack.vm.UnmanagedInstanceTO;
  
  import com.vmware.vim25.CustomFieldDef;
  import com.vmware.vim25.CustomFieldStringValue;
  import com.vmware.vim25.ManagedObjectReference;
- import com.vmware.vim25.InvalidPropertyFaultMsg;
- import com.vmware.vim25.RuntimeFaultFaultMsg;
- import com.vmware.vim25.ObjectContent;
- import com.vmware.vim25.RetrieveResult;
- 
- import java.lang.reflect.InvocationTargetException;
- import java.util.ArrayList;
- import java.util.List;
  
 -import com.cloud.hypervisor.vmware.util.VmwareContext;
 -
  public class BaseMO {
 -    private static final Logger s_logger = Logger.getLogger(BaseMO.class);
 +    protected static Logger logger = LogManager.getLogger(BaseMO.class);
  
      protected VmwareContext _context;
      protected ManagedObjectReference _mor;
diff --cc 
vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
index 8bb038f3a6d,d8c7e8a61ea..02a4269d4f2
--- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
+++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatacenterMO.java
@@@ -22,9 -21,10 +21,9 @@@ import java.util.ArrayList
  import java.util.Arrays;
  import java.util.List;
  
- import com.cloud.utils.StringUtils;
+ import com.cloud.hypervisor.vmware.util.VmwareHelper;
  import org.apache.cloudstack.vm.UnmanagedInstanceTO;
  import org.apache.commons.collections.CollectionUtils;
 -import org.apache.log4j.Logger;
  
  import com.vmware.vim25.CustomFieldStringValue;
  import com.vmware.vim25.DatacenterConfigInfo;
@@@ -74,10 -88,10 +86,10 @@@ public class DatacenterMO extends BaseM
      public VirtualMachineMO findVm(String vmName) throws Exception {
          int key = getCustomFieldKey("VirtualMachine", 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
          if (key == 0) {
 -            s_logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
 +            logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
          }
          String instanceNameCustomField = "value[" + key + "]";
-         List<ObjectContent> ocs = getVmProperties(new String[] {"name", 
instanceNameCustomField});
+         List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new 
String[] {"name", instanceNameCustomField});
          return HypervisorHostHelper.findVmFromObjectContent(_context, 
ocs.toArray(new ObjectContent[0]), vmName, instanceNameCustomField);
      }
  
@@@ -118,11 -132,11 +130,11 @@@
      public VirtualMachineMO checkIfVmAlreadyExistsInVcenter(String 
vmNameOnVcenter, String vmNameInCS) throws Exception {
          int key = getCustomFieldKey("VirtualMachine", 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
          if (key == 0) {
 -            s_logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
 +            logger.warn("Custom field " + 
CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
          }
  
-         List<ObjectContent> ocs = getVmProperties(new String[] {"name", 
String.format("value[%d]", key)});
-         if (CollectionUtils.isNotEmpty(ocs)) {
+         List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new 
String[] {"name", String.format("value[%d]", key)});
+         if (ocs != null && ocs.size() > 0) {
              for (ObjectContent oc : ocs) {
                  List<DynamicProperty> props = oc.getPropSet();
                  if (props != null) {
@@@ -147,18 -161,31 +159,31 @@@
          return null;
      }
  
-     public Pair<String, List<UnmanagedInstanceTO>> getVms(Integer maxObjects, 
String token) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, 
InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+     public List<UnmanagedInstanceTO> getAllVmsOnDatacenter() throws Exception 
{
          List<UnmanagedInstanceTO> vms = new ArrayList<>();
-         Pair<String, List<ObjectContent>> objectContents = 
getVmProperties(new String[] {"name"}, maxObjects, token);
-         logger.debug("returning token {} for future retrievals, currently {} 
objects retrieved.", objectContents.first(), objectContents.second().size());
-         Pair<String, List<UnmanagedInstanceTO>> retval = new 
Pair<>(objectContents.first(), vms);
- 
-         objectContentToUnmanagedInstanceTO(objectContents, vms);
+         List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new 
String[] {"name"});
+         if (ocs != null) {
+             for (ObjectContent oc : ocs) {
+                 ManagedObjectReference vmMor = oc.getObj();
+                 if (vmMor != null) {
+                     VirtualMachineMO vmMo = new VirtualMachineMO(_context, 
vmMor);
+                     try {
+                         if (!vmMo.isTemplate()) {
+                             HostMO hostMO = vmMo.getRunningHost();
+                             UnmanagedInstanceTO unmanagedInstance = 
VmwareHelper.getUnmanagedInstance(hostMO, vmMo);
+                             vms.add(unmanagedInstance);
+                         }
+                     } catch (Exception e) {
 -                        s_logger.debug(String.format("Unexpected error 
checking unmanaged instance %s, excluding it: %s", vmMo.getVmName(), 
e.getMessage()), e);
++                        logger.debug(String.format("Unexpected error checking 
unmanaged instance %s, excluding it: %s", vmMo.getVmName(), e.getMessage()), e);
+                     }
+                 }
+             }
+         }
  
-         return retval;
+         return vms;
      }
  
-     public List<HostMO> getAllHostsOnDatacenter() throws 
InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
+     public List<HostMO> getAllHostsOnDatacenter() throws Exception {
          List<HostMO> hosts = new ArrayList<>();
  
          List<ObjectContent> ocs = getHostPropertiesOnDatacenterHostFolder(new 
String[] {"name"});
diff --cc vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HostMO.java
index e710adc3b76,3b96e7e1999..189797a3cb2
--- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HostMO.java
+++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/HostMO.java
@@@ -25,19 -24,11 +24,10 @@@ import java.util.List
  import java.util.Map;
  import java.util.regex.Pattern;
  
- import org.apache.cloudstack.vm.UnmanagedInstanceTO;
- 
- import com.cloud.hypervisor.vmware.util.VmwareClientException;
- import com.cloud.hypervisor.vmware.util.VmwareContext;
- import com.cloud.hypervisor.vmware.util.VmwareHelper;
- import com.cloud.utils.LogUtils;
- import com.cloud.utils.Pair;
- import com.cloud.utils.StringUtils;
- 
  import org.apache.commons.collections.CollectionUtils;
+ import org.apache.commons.lang3.StringUtils;
 -import org.apache.log4j.Logger;
  
  import com.google.gson.Gson;
- 
  import com.vmware.vim25.AboutInfo;
  import com.vmware.vim25.AlreadyExistsFaultMsg;
  import com.vmware.vim25.ClusterDasConfigInfo;
@@@ -78,12 -68,14 +67,13 @@@ import com.vmware.vim25.PropertySpec
  import com.vmware.vim25.TraversalSpec;
  import com.vmware.vim25.VirtualMachineConfigSpec;
  import com.vmware.vim25.VirtualNicManagerNetConfig;
+ import com.cloud.hypervisor.vmware.util.VmwareContext;
+ import com.cloud.hypervisor.vmware.util.VmwareHelper;
+ import com.cloud.utils.LogUtils;
+ import com.cloud.utils.Pair;
  
  public class HostMO extends BaseMO implements VmwareHypervisorHost {
 -    private static final Logger s_logger = Logger.getLogger(HostMO.class);
 -    Map<String, VirtualMachineMO> _vmCache = new HashMap<String, 
VirtualMachineMO>();
 +    Map<String, VirtualMachineMO> _vmCache = new HashMap<>();
  
      //Map<String, String> _vmInternalNameMapCache = new HashMap<String, 
String>();
  
@@@ -593,8 -582,9 +579,9 @@@
          }
      }
  
-     private void loadVmCache() throws InvalidPropertyFaultMsg, 
RuntimeFaultFaultMsg, InvocationTargetException, NoSuchMethodException, 
IllegalAccessException {
-         logger.debug("load VM cache on host");
+     private void loadVmCache() throws Exception {
 -        if (s_logger.isDebugEnabled())
 -            s_logger.debug("load VM cache on host");
++        if (logger.isDebugEnabled())
++            logger.debug("load VM cache on host");
  
          _vmCache.clear();
  
@@@ -714,16 -704,11 +701,11 @@@
      }
  
      @Override
-     public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) 
throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
-         List<ObjectContent> properties = getVmProperties(propertyPaths, 
null).second();
-         return properties.toArray(new ObjectContent[properties.size()]);
-     }
- 
-     public Pair<String, List<ObjectContent>> getVmProperties(String[] 
propertyPaths, Integer maxObjects) throws InvalidPropertyFaultMsg, 
RuntimeFaultFaultMsg {
-         if (logger.isTraceEnabled()) {
+     public ObjectContent[] getVmPropertiesOnHyperHost(String[] propertyPaths) 
throws Exception {
 -        if (s_logger.isTraceEnabled())
 -            s_logger.trace("vCenter API trace - retrieveProperties() for VM 
properties. target MOR: " + _mor.getValue() + ", properties: " +
++        if (logger.isTraceEnabled())
 +            logger.trace("vCenter API trace - retrieveProperties() for VM 
properties. target MOR: " + _mor.getValue() + ", properties: " +
                      new Gson().toJson(propertyPaths));
-         }
+ 
          PropertySpec pSpec = new PropertySpec();
          pSpec.setType("VirtualMachine");
          pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
@@@ -741,18 -726,14 +723,14 @@@
          PropertyFilterSpec pfSpec = new PropertyFilterSpec();
          pfSpec.getPropSet().add(pSpec);
          pfSpec.getObjectSet().add(oSpec);
-         List<PropertyFilterSpec> pfSpecArr = new ArrayList<>();
+         List<PropertyFilterSpec> pfSpecArr = new 
ArrayList<PropertyFilterSpec>();
          pfSpecArr.add(pfSpec);
  
-         RetrieveOptions ro = new RetrieveOptions();
-         if (maxObjects != null && maxObjects > 0) {
-             ro.setMaxObjects(maxObjects);
-         }
- 
-         RetrieveResult result = 
_context.getService().retrievePropertiesEx(_context.getPropertyCollector(), 
pfSpecArr, ro);
+         List<ObjectContent> properties = 
_context.getService().retrieveProperties(_context.getPropertyCollector(), 
pfSpecArr);
  
-         logger.trace("vCenter API trace - retrieveProperties() done");
-         return createReturnObjectPair(result);
 -        if (s_logger.isTraceEnabled())
 -            s_logger.trace("vCenter API trace - retrieveProperties() done");
++        if (logger.isTraceEnabled())
++            logger.trace("vCenter API trace - retrieveProperties() done");
+         return properties.toArray(new ObjectContent[properties.size()]);
      }
  
      @Override
@@@ -1337,8 -1318,9 +1315,9 @@@
          return false;
      }
  
-     private synchronized VirtualMachineMO 
findVmOnHyperHostWithHypervisorName(String vmName) throws 
InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvocationTargetException, 
NoSuchMethodException, IllegalAccessException {
-             logger.debug("find VM hypervisor name: {} on host", vmName );
+     private synchronized VirtualMachineMO 
findVmOnHyperHostWithHypervisorName(String vmName) throws Exception {
 -        if (s_logger.isDebugEnabled())
 -            s_logger.debug("find VM hypervisor name: " + vmName + " on host");
++        if (logger.isDebugEnabled())
++            logger.debug("find VM hypervisor name: " + vmName + " on host");
  
          VirtualMachineMO vmMo = getVmWithHypervisorName(_vmCache.values(), 
vmName);
          if (vmMo != null) {
@@@ -1367,25 -1349,5 +1346,4 @@@
          }
          return null;
      }
- 
-     public Pair<String, List<UnmanagedInstanceTO>> getVms(Integer maxObjects, 
String token) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, 
InvocationTargetException, NoSuchMethodException, IllegalAccessException {
-         List<UnmanagedInstanceTO> vms = new ArrayList<>();
-         Pair<String, List<ObjectContent>> objectContents = 
getVmProperties(new String[] {"name"}, maxObjects, token);
-         logger.debug("returning token {} for future retrievals, currently {} 
objects retrieved.", objectContents.first(), objectContents.second().size());
-         Pair<String, List<UnmanagedInstanceTO>> retval = new 
Pair<>(objectContents.first(), vms);
- 
-         objectContentToUnmanagedInstanceTO(objectContents, vms);
- 
-         return retval;
-     }
--
-     public Pair<String, List<ObjectContent>> getVmProperties(String[] 
propertyPaths, Integer maxObjects, String tokenForPriorQuery) throws  
InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
-         if(com.cloud.utils.StringUtils.isNotBlank(tokenForPriorQuery)) {
-             logger.debug("running repeat query with token '{}'", 
tokenForPriorQuery);
-             return retrieveNextSetOfProperties(tokenForPriorQuery);
-         } else {
-             logger.debug("running query for {} propertypaths and max {} 
objects", propertyPaths.length, maxObjects);
-             return getVmProperties(propertyPaths, maxObjects);
-         }
-     }
  }
diff --cc 
vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index 4f3975650a0,dcdeb04734e..7d6cbbaeaed
--- 
a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ 
b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@@ -427,6 -468,39 +466,39 @@@ public class VirtualMachineMO extends B
          return false;
      }
  
+     public boolean changeHost(VirtualMachineRelocateSpec relocateSpec) throws 
Exception {
+         ManagedObjectReference morTask = 
_context.getService().relocateVMTask(_mor, relocateSpec, 
VirtualMachineMovePriority.DEFAULT_PRIORITY);
+         boolean result = _context.getVimClient().waitForTask(morTask);
+         if (result) {
+             _context.waitForTaskProgressDone(morTask);
+             return true;
+         } else {
 -            s_logger.error("VMware RelocateVM_Task to change host failed due 
to " + TaskMO.getTaskFailureInfo(_context, morTask));
++            logger.error("VMware RelocateVM_Task to change host failed due to 
" + TaskMO.getTaskFailureInfo(_context, morTask));
+         }
+         return false;
+     }
+ 
+     public boolean changeDatastore(ManagedObjectReference morDataStore, 
VmwareHypervisorHost targetHost) throws Exception {
+         VirtualMachineRelocateSpec relocateSpec = new 
VirtualMachineRelocateSpec();
+         relocateSpec.setDatastore(morDataStore);
+         if (targetHost != null) {
+             relocateSpec.setHost(targetHost.getMor());
+             relocateSpec.setPool(targetHost.getHyperHostOwnerResourcePool());
+         }
+ 
+         ManagedObjectReference morTask = 
_context.getService().relocateVMTask(_mor, relocateSpec, null);
+ 
+         boolean result = _context.getVimClient().waitForTask(morTask);
+         if (result) {
+             _context.waitForTaskProgressDone(morTask);
+             return true;
+         } else {
 -            s_logger.error("VMware change datastore relocateVM_Task failed 
due to " + TaskMO.getTaskFailureInfo(_context, morTask));
++            logger.error("VMware change datastore relocateVM_Task failed due 
to " + TaskMO.getTaskFailureInfo(_context, morTask));
+         }
+ 
+         return false;
+     }
+ 
      public boolean relocate(ManagedObjectReference morTargetHost) throws 
Exception {
          VirtualMachineRelocateSpec relocateSpec = new 
VirtualMachineRelocateSpec();
          relocateSpec.setHost(morTargetHost);
@@@ -515,6 -589,39 +587,39 @@@
          return false;
      }
  
+     public boolean revertToSnapshot(String snapshotName) throws Exception {
+         ManagedObjectReference morSnapshot = getSnapshotMor(snapshotName);
+         if (morSnapshot == null) {
 -            s_logger.warn("Unable to find snapshot: " + snapshotName);
++            logger.warn("Unable to find snapshot: " + snapshotName);
+             return false;
+         }
+         ManagedObjectReference morTask = 
_context.getService().revertToSnapshotTask(morSnapshot, _mor, null);
+         boolean result = _context.getVimClient().waitForTask(morTask);
+         if (result) {
+             _context.waitForTaskProgressDone(morTask);
+             return true;
+         } else {
 -            s_logger.error("VMware revert to snapshot failed due to " + 
TaskMO.getTaskFailureInfo(_context, morTask));
++            logger.error("VMware revert to snapshot failed due to " + 
TaskMO.getTaskFailureInfo(_context, morTask));
+         }
+ 
+         return false;
+     }
+ 
+     /**
+      * Deletes all of the snapshots of a VM.
+      */
+     public void consolidateAllSnapshots() throws Exception {
+         ManagedObjectReference task = 
_context.getService().removeAllSnapshotsTask(_mor, true);
+ 
+         boolean result = _context.getVimClient().waitForTask(task);
+ 
+         if (result) {
+             _context.waitForTaskProgressDone(task);
+         } else {
+             throw new Exception("Unable to register VM due to the following 
issue: " + TaskMO.getTaskFailureInfo(_context, task));
+         }
+     }
+ 
      public boolean removeAllSnapshots() throws Exception {
          VirtualMachineSnapshotInfo snapshotInfo = getSnapshotInfo();
  
@@@ -1043,6 -1152,61 +1150,61 @@@
          return datastores;
      }
  
+     /**
+      * Retrieve path info to access VM files via vSphere web interface
+      * @return [0] vm-name, [1] data-center-name, [2] datastore-name
+      * @throws Exception
+      */
+     public String[] getHttpAccessPathInfo() throws Exception {
+         String[] pathInfo = new String[3];
+ 
+         Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
+ 
+         VirtualMachineFileInfo fileInfo = getFileInfo();
+         String vmxFilePath = fileInfo.getVmPathName();
+         String vmxPathTokens[] = vmxFilePath.split("\\[|\\]|/");
+         assert (vmxPathTokens.length == 4);
+         pathInfo[1] = vmxPathTokens[1].trim();                            // 
vSphere vm name
+         pathInfo[2] = dcInfo.second();                                    // 
vSphere datacenter name
+         pathInfo[3] = vmxPathTokens[0].trim();                            // 
vSphere datastore name
+         return pathInfo;
+     }
+ 
+     public String getVmxHttpAccessUrl() throws Exception {
+         Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
+ 
+         VirtualMachineFileInfo fileInfo = getFileInfo();
+         String vmxFilePath = fileInfo.getVmPathName();
+         String vmxPathTokens[] = vmxFilePath.split("\\[|\\]|/");
+ 
+         StringBuffer sb = new StringBuffer("https://"; + 
_context.getServerAddress() + "/folder/");
+         sb.append(URLEncoder.encode(vmxPathTokens[2].trim(), "UTF-8"));
+         sb.append("/");
+         sb.append(URLEncoder.encode(vmxPathTokens[3].trim(), "UTF-8"));
+         sb.append("?dcPath=");
+         sb.append(URLEncoder.encode(dcInfo.second(), "UTF-8"));
+         sb.append("&dsName=");
+         sb.append(URLEncoder.encode(vmxPathTokens[1].trim(), "UTF-8"));
+ 
+         return sb.toString();
+     }
+ 
+     public boolean setVncConfigInfo(boolean enableVnc, String vncPassword, 
int vncPort, String keyboard) throws Exception {
+         VirtualMachineConfigSpec vmConfigSpec = new 
VirtualMachineConfigSpec();
+         OptionValue[] vncOptions = VmwareHelper.composeVncOptions(null, 
enableVnc, vncPassword, vncPort, keyboard);
+         vmConfigSpec.getExtraConfig().addAll(Arrays.asList(vncOptions));
+         ManagedObjectReference morTask = 
_context.getService().reconfigVMTask(_mor, vmConfigSpec);
+ 
+         boolean result = _context.getVimClient().waitForTask(morTask);
+         if (result) {
+             _context.waitForTaskProgressDone(morTask);
+             return true;
+         } else {
 -            s_logger.error("VMware reconfigVM_Task failed due to " + 
TaskMO.getTaskFailureInfo(_context, morTask));
++            logger.error("VMware reconfigVM_Task failed due to " + 
TaskMO.getTaskFailureInfo(_context, morTask));
+         }
+         return false;
+     }
+ 
      public boolean configureVm(VirtualMachineConfigSpec vmConfigSpec) throws 
Exception {
          ManagedObjectReference morTask = 
_context.getService().reconfigVMTask(_mor, vmConfigSpec);
  
@@@ -1112,10 -1276,11 +1274,11 @@@
      // vmdkDatastorePath: [datastore name] vmdkFilePath
      public void createDisk(String vmdkDatastorePath, VirtualDiskType 
diskType, VirtualDiskMode diskMode, String rdmDeviceName, long sizeInMb,
                             ManagedObjectReference morDs, int controllerKey, 
String vSphereStoragePolicyId) throws Exception {
 -        s_logger.trace(String.format("Creating disk in target MOR [%s] with 
values: vmdkDatastorePath [%s], sizeInMb [%s], diskType [%s], diskMode [%s], 
rdmDeviceName [%s]"
 -                    + ", datastore [%s], controllerKey [%s].", 
_mor.getValue(), vmdkDatastorePath, sizeInMb, diskType, diskMode, 
rdmDeviceName, morDs.getValue(), controllerKey));
 +        logger.trace("Creating disk in target MOR [{}] with values: 
vmdkDatastorePath [{}], sizeInMb [{}], diskType [{}], diskMode [{}], 
rdmDeviceName [{}], datastore [{}], controllerKey [{}].",
 +                _mor.getValue(), vmdkDatastorePath, sizeInMb, diskType, 
diskMode, rdmDeviceName, morDs.getValue(), controllerKey);
  
          assert (vmdkDatastorePath != null);
+         assert (morDs != null);
  
          int ideControllerKey = getIDEDeviceControllerKey();
          if (controllerKey < 0) {
@@@ -1204,12 -1377,12 +1375,12 @@@
          if (!isVmfsSparseFile) {
              String currentAdapterType = vmdkFileDescriptor.getAdapterType();
              if (!currentAdapterType.equalsIgnoreCase(newAdapterType)) {
 -                s_logger.info("Updating adapter type to " + newAdapterType + 
" for VMDK file " + vmdkFileName);
 +                logger.info("Updating adapter type to " + newAdapterType + " 
for VMDK file " + vmdkFileName);
                  Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
-                 byte[] newVmdkContent = 
VmdkFileDescriptor.changeVmdkAdapterType(vmdkInfo.second(), newAdapterType);
+                 byte[] newVmdkContent = 
vmdkFileDescriptor.changeVmdkAdapterType(vmdkInfo.second(), newAdapterType);
                  String vmdkUploadUrl = 
getContext().composeDatastoreBrowseUrl(dcInfo.first().getName(), vmdkFileName);
                  getContext().uploadResourceContent(vmdkUploadUrl, 
newVmdkContent);
 -                s_logger.info("Updated VMDK file " + vmdkFileName);
 +                logger.info("Updated VMDK file " + vmdkFileName);
              }
          }
      }
@@@ -1231,9 -1404,9 +1402,9 @@@
                  // lsisas1068 (SAS controller) or pvscsi (Vmware Paravirtual) 
only. Valid adapter type for those controllers is lsilogic.
                  // Hence use adapter type lsilogic. Other adapter types ide, 
lsilogic, buslogic are valid and does not need to be modified.
                  VmdkAdapterType newAdapterType = VmdkAdapterType.lsilogic;
 -                s_logger.debug("Updating adapter type to " + newAdapterType + 
" from " + currentAdapterTypeStr + " for VMDK file " + vmdkFileName);
 +                logger.debug("Updating adapter type to " + newAdapterType + " 
from " + currentAdapterTypeStr + " for VMDK file " + vmdkFileName);
                  Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
-                 byte[] newVmdkContent = 
VmdkFileDescriptor.changeVmdkAdapterType(vmdkInfo.second(), 
newAdapterType.toString());
+                 byte[] newVmdkContent = 
vmdkFileDescriptor.changeVmdkAdapterType(vmdkInfo.second(), 
newAdapterType.toString());
                  String vmdkUploadUrl = 
getContext().composeDatastoreBrowseUrl(dcInfo.first().getName(), vmdkFileName);
  
                  getContext().uploadResourceContent(vmdkUploadUrl, 
newVmdkContent);
@@@ -1251,11 -1424,11 +1422,11 @@@
      }
  
      public void attachDisk(String[] vmdkDatastorePathChain, 
ManagedObjectReference morDs, String diskController, String 
vSphereStoragePolicyId, Long maxIops) throws Exception {
 -        if(s_logger.isTraceEnabled())
 -            s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + 
_mor.getValue() + ", vmdkDatastorePath: "
 +        if(logger.isTraceEnabled())
 +            logger.trace("vCenter API trace - attachDisk(). target MOR: " + 
_mor.getValue() + ", vmdkDatastorePath: "
                              + GSON.toJson(vmdkDatastorePathChain) + ", 
datastore: " + morDs.getValue());
-         int controllerKey;
-         int unitNumber;
+         int controllerKey = 0;
+         int unitNumber = 0;
  
          if (DiskControllerType.getType(diskController) == 
DiskControllerType.ide) {
              // IDE virtual disk cannot be added if VM is running
@@@ -1312,10 -1485,25 +1483,25 @@@
              _context.waitForTaskProgressDone(morTask);
          }
  
 -        if(s_logger.isTraceEnabled())
 -            s_logger.trace("vCenter API trace - attachDisk() 
done(successfully)");
 +        if(logger.isTraceEnabled())
 +            logger.trace("vCenter API trace - attachDisk() 
done(successfully)");
      }
  
+     private int getControllerBusNumber(int controllerKey) throws Exception {
+         List<VirtualDevice> devices = 
(List<VirtualDevice>)_context.getVimClient().
+                 getDynamicProperty(_mor, "config.hardware.device");
+ 
+         if (devices != null && devices.size() > 0) {
+             for (VirtualDevice device : devices) {
+                 if (device instanceof VirtualController && device.getKey() == 
controllerKey) {
+                     return ((VirtualController)device).getBusNumber();
+                 }
+             }
+         }
+         throw new Exception("SCSI Controller with key " + controllerKey + " 
is Not Found");
+ 
+     }
+ 
      // vmdkDatastorePath: [datastore name] vmdkFilePath
      public List<Pair<String, ManagedObjectReference>> detachDisk(String 
vmdkDatastorePath, boolean deleteBackingFile) throws Exception {
  
@@@ -1624,10 -1813,10 +1810,10 @@@
          VmdkFileDescriptor descriptor = new VmdkFileDescriptor();
          descriptor.parse(content);
  
-         Pair<VmdkFileDescriptor, byte[]> result = new Pair<>(descriptor, 
content);
-         logger.trace("vCenter API trace - getVmdkFileInfo() done");
+         Pair<VmdkFileDescriptor, byte[]> result = new 
Pair<VmdkFileDescriptor, byte[]>(descriptor, content);
 -        if (s_logger.isTraceEnabled()) {
 -            s_logger.trace("vCenter API trace - getVmdkFileInfo() done");
 -            s_logger.trace("VMDK file descriptor: " + 
GSON.toJson(result.first()));
 +        if (logger.isTraceEnabled()) {
-             logger.trace("VMDK file descriptor: {}", 
GSON.toJson(result.first()));
++            logger.trace("vCenter API trace - getVmdkFileInfo() done");
++            logger.trace("VMDK file descriptor: " + 
GSON.toJson(result.first()));
          }
          return result;
      }
@@@ -1700,14 -1889,14 +1886,14 @@@
                              fileNames.add(diskLocalPath);
  
                              if (!parallelDownload) {
 -                                if (s_logger.isInfoEnabled()) {
 -                                    s_logger.info("Download VMDK file for 
export url: " + deviceUrlStr + ", size: " + diskFileSize);
 +                                if (logger.isInfoEnabled()) {
 +                                    logger.info("Download VMDK file for 
export url: " + deviceUrlStr + ", size: " + diskFileSize);
                                  }
-                                 long lengthOfDiskFile = 
_context.downloadVmdkFile(diskUrlStr, diskLocalPath, totalBytesDownloaded, new 
ActionDelegate<>() {
+                                 long lengthOfDiskFile = 
_context.downloadVmdkFile(diskUrlStr, diskLocalPath, totalBytesDownloaded, new 
ActionDelegate<Long>() {
                                      @Override
                                      public void action(Long param) {
 -                                        if (s_logger.isTraceEnabled()) {
 -                                            s_logger.trace("Download progress 
" + param + "/" + toHumanReadableSize(totalBytes));
 +                                        if (logger.isTraceEnabled()) {
 +                                            logger.trace("Download progress " 
+ param + "/" + toHumanReadableSize(totalBytes));
                                          }
                                          
progressReporter.reportProgress((int)(param * 100 / totalBytes));
                                      }
@@@ -1728,11 -1917,11 +1914,11 @@@
                                  CompletableFuture<Long> future = 
CompletableFuture.supplyAsync(() -> {
                                      long lengthOfDiskFile = 0;
                                      try {
-                                         lengthOfDiskFile = 
_context.downloadVmdkFile(diskUrl, diskLocalPath, totalBytesDownloaded, new 
ActionDelegate<>() {
+                                         lengthOfDiskFile = 
_context.downloadVmdkFile(diskUrl, diskLocalPath, totalBytesDownloaded, new 
ActionDelegate<Long>() {
                                              @Override
                                              public void action(Long param) {
 -                                                if 
(s_logger.isTraceEnabled()) {
 -                                                    s_logger.trace("Download 
progress " + param + "/" + toHumanReadableSize(totalBytes));
 +                                                if (logger.isTraceEnabled()) {
 +                                                    logger.trace("Download 
progress " + param + "/" + toHumanReadableSize(totalBytes));
                                                  }
                                                  
progressReporter.reportProgress((int)(param * 100 / totalBytes));
                                              }
@@@ -1884,6 -2073,70 +2070,70 @@@
          // redoRegistration();
      }
  
+     // destName does not contain extension name
+     public void backupCurrentSnapshot(String deviceName, 
ManagedObjectReference morDestDs, String destDsDirectory, String destName, 
boolean includeBase) throws Exception {
+ 
+         SnapshotDescriptor descriptor = getSnapshotDescriptor();
+         SnapshotInfo[] snapshotInfo = descriptor.getCurrentDiskChain();
+         if (snapshotInfo.length == 0) {
+             String msg = "No snapshot found in this VM";
+             throw new Exception(msg);
+         }
+ 
+         HostMO hostMo = getRunningHost();
+         DatacenterMO dcMo = getOwnerDatacenter().first();
+         List<Pair<ManagedObjectReference, String>> mounts = 
hostMo.getDatastoreMountsOnHost();
+         VirtualMachineFileInfo vmFileInfo = getFileInfo();
+ 
+         List<Ternary<String, String, String>> backupInfo = new 
ArrayList<Ternary<String, String, String>>();
+ 
+         for (int i = 0; i < snapshotInfo.length; i++) {
+             if (!includeBase && i == snapshotInfo.length - 1) {
+                 break;
+             }
+ 
+             SnapshotDescriptor.DiskInfo[] disks = snapshotInfo[i].getDisks();
+             if (disks != null) {
+                 String destBaseFileName;
+                 String destFileName;
+                 String destParentFileName;
+                 for (SnapshotDescriptor.DiskInfo disk : disks) {
+                     if (deviceName == null || 
deviceName.equals(disk.getDeviceName())) {
+                         String srcVmdkFullDsPath = 
getSnapshotDiskFileDatastorePath(vmFileInfo, mounts, disk.getDiskFileName());
+                         Pair<DatastoreMO, String> srcDsInfo = 
getOwnerDatastore(srcVmdkFullDsPath);
+ 
+                         Pair<VmdkFileDescriptor, byte[]> vmdkInfo = 
getVmdkFileInfo(srcVmdkFullDsPath);
+                         String srcVmdkBaseFilePath = 
DatastoreFile.getCompanionDatastorePath(srcVmdkFullDsPath, 
vmdkInfo.first().getBaseFileName());
+ 
+                         destFileName = destName + (snapshotInfo.length - i - 
1) + ".vmdk";
+                         if (vmdkInfo.first().getParentFileName() != null) {
+                             destBaseFileName = destName + 
(snapshotInfo.length - i - 1) + "-delta.vmdk";
+                             destParentFileName = destName + 
(snapshotInfo.length - i - 2) + ".vmdk";
+                         } else {
+                             destBaseFileName = destName + 
(snapshotInfo.length - i - 1) + "-flat.vmdk";
+                             destParentFileName = null;
+                         }
+ 
 -                        s_logger.info("Copy VMDK base file " + 
srcVmdkBaseFilePath + " to " + destDsDirectory + "/" + destBaseFileName);
++                        logger.info("Copy VMDK base file " + 
srcVmdkBaseFilePath + " to " + destDsDirectory + "/" + destBaseFileName);
+                         
srcDsInfo.first().copyDatastoreFile(srcVmdkBaseFilePath, dcMo.getMor(), 
morDestDs, destDsDirectory + "/" + destBaseFileName, dcMo.getMor(), true);
+ 
+                         byte[] newVmdkContent = 
VmdkFileDescriptor.changeVmdkContentBaseInfo(vmdkInfo.second(), 
destBaseFileName, destParentFileName);
+                         String vmdkUploadUrl = 
getContext().composeDatastoreBrowseUrl(dcMo.getName(), destDsDirectory + "/" + 
destFileName);
+ 
 -                        s_logger.info("Upload VMDK content file to " + 
destDsDirectory + "/" + destFileName);
++                        logger.info("Upload VMDK content file to " + 
destDsDirectory + "/" + destFileName);
+                         getContext().uploadResourceContent(vmdkUploadUrl, 
newVmdkContent);
+ 
+                         backupInfo.add(new Ternary<String, String, 
String>(destFileName, destBaseFileName, destParentFileName));
+                     }
+                 }
+             }
+         }
+ 
+         byte[] vdiskInfo = VmwareHelper.composeDiskInfo(backupInfo, 
snapshotInfo.length, includeBase);
+         String vdiskUploadUrl = 
getContext().composeDatastoreBrowseUrl(dcMo.getName(), destDsDirectory + "/" + 
destName + ".vdisk");
+         getContext().uploadResourceContent(vdiskUploadUrl, vdiskInfo);
+     }
+ 
      public String[] getCurrentSnapshotDiskChainDatastorePaths(String 
diskDevice) throws Exception {
          HostMO hostMo = getRunningHost();
          List<Pair<ManagedObjectReference, String>> mounts = 
hostMo.getDatastoreMountsOnHost();
@@@ -1965,6 -2218,19 +2215,19 @@@
          return guestOsDescriptor;
      }
  
+     public void plugDevice(VirtualDevice device) throws Exception {
 -        s_logger.debug(LogUtils.logGsonWithoutException("Pluging device [%s] 
to VM [%s].", device, getVmName()));
++        logger.debug(LogUtils.logGsonWithoutException("Pluging device [%s] to 
VM [%s].", device, getVmName()));
+         VirtualMachineConfigSpec vmConfigSpec = new 
VirtualMachineConfigSpec();
+         VirtualDeviceConfigSpec deviceConfigSpec = new 
VirtualDeviceConfigSpec();
+         deviceConfigSpec.setDevice(device);
+         deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+ 
+         vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
+         if (!configureVm(vmConfigSpec)) {
+             throw new Exception("Failed to add devices");
+         }
+     }
+ 
      public void tearDownDevice(VirtualDevice device) throws Exception {
          VirtualMachineConfigSpec vmConfigSpec = new 
VirtualMachineConfigSpec();
          VirtualDeviceConfigSpec deviceConfigSpec = new 
VirtualDeviceConfigSpec();
@@@ -1997,8 -2263,40 +2260,40 @@@
          }
      }
  
+     public void copyAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, 
boolean followDiskChain) throws Exception {
+         VirtualDevice[] disks = getAllDiskDevice();
+         DatacenterMO dcMo = getOwnerDatacenter().first();
+         if (disks != null) {
+             for (VirtualDevice disk : disks) {
+                 List<Pair<String, ManagedObjectReference>> vmdkFiles = 
getDiskDatastorePathChain((VirtualDisk)disk, followDiskChain);
+                 for (Pair<String, ManagedObjectReference> fileItem : 
vmdkFiles) {
+                     DatastoreMO srcDsMo = new DatastoreMO(_context, 
fileItem.second());
+ 
+                     DatastoreFile srcFile = new 
DatastoreFile(fileItem.first());
+                     DatastoreFile destFile = new 
DatastoreFile(destDsMo.getName(), destDsDir, srcFile.getFileName());
+ 
+                     Pair<VmdkFileDescriptor, byte[]> vmdkDescriptor = null;
+ 
+                     vmdkDescriptor = getVmdkFileInfo(fileItem.first());
+ 
 -                    s_logger.info("Copy VM disk file " + srcFile.getPath() + 
" to " + destFile.getPath());
++                    logger.info("Copy VM disk file " + srcFile.getPath() + " 
to " + destFile.getPath());
+                     srcDsMo.copyDatastoreFile(fileItem.first(), 
dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
+ 
+                     if (vmdkDescriptor != null) {
+                         String vmdkBaseFileName = 
vmdkDescriptor.first().getBaseFileName();
+                         String baseFilePath = 
srcFile.getCompanionPath(vmdkBaseFileName);
+                         destFile = new DatastoreFile(destDsMo.getName(), 
destDsDir, vmdkBaseFileName);
+ 
 -                        s_logger.info("Copy VM disk file " + baseFilePath + " 
to " + destFile.getPath());
++                        logger.info("Copy VM disk file " + baseFilePath + " 
to " + destFile.getPath());
+                         srcDsMo.copyDatastoreFile(baseFilePath, 
dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
+                     }
+                 }
+             }
+         }
+     }
+ 
      public List<String> getVmdkFileBaseNames() throws Exception {
-         List<String> vmdkFileBaseNames = new ArrayList<>();
+         List<String> vmdkFileBaseNames = new ArrayList<String>();
          VirtualDevice[] devices = getAllDiskDevice();
          for(VirtualDevice device : devices) {
              if(device instanceof VirtualDisk) {
@@@ -2033,10 -2331,10 +2328,10 @@@
                      DatastoreFile srcFile = new 
DatastoreFile(fileItem.first());
                      DatastoreFile destFile = new 
DatastoreFile(destDsMo.getName(), destDsDir, srcFile.getFileName());
  
-                     Pair<VmdkFileDescriptor, byte[]> vmdkDescriptor;
+                     Pair<VmdkFileDescriptor, byte[]> vmdkDescriptor = null;
                      vmdkDescriptor = getVmdkFileInfo(fileItem.first());
  
 -                    s_logger.info("Move VM disk file " + srcFile.getPath() + 
" to " + destFile.getPath());
 +                    logger.info("Move VM disk file " + srcFile.getPath() + " 
to " + destFile.getPath());
                      srcDsMo.moveDatastoreFile(fileItem.first(), 
dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
  
                      if (vmdkDescriptor != null) {
@@@ -2302,6 -2633,32 +2630,32 @@@
          }
      }
  
+     public void ensureScsiDeviceControllers(int count, int availableBusNum) 
throws Exception {
+         int scsiControllerKey = getScsiDeviceControllerKeyNoException();
+         if (scsiControllerKey < 0) {
+             VirtualMachineConfigSpec vmConfig = new 
VirtualMachineConfigSpec();
+ 
+             int busNum = availableBusNum;
+             while (busNum < count) {
+             VirtualLsiLogicController scsiController = new 
VirtualLsiLogicController();
+             scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
+                 scsiController.setBusNumber(busNum);
+                 scsiController.setKey(busNum - 
VmwareHelper.MAX_SCSI_CONTROLLER_COUNT);
+             VirtualDeviceConfigSpec scsiControllerSpec = new 
VirtualDeviceConfigSpec();
+             scsiControllerSpec.setDevice(scsiController);
+             
scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+ 
+             vmConfig.getDeviceChange().add(scsiControllerSpec);
+                 busNum++;
+             }
+             if (configureVm(vmConfig)) {
+                 throw new Exception("Unable to add Scsi controllers to the VM 
" + getName());
+             } else {
 -                s_logger.info("Successfully added " + count + " SCSI 
controllers.");
++                logger.info("Successfully added " + count + " SCSI 
controllers.");
+             }
+         }
+     }
+ 
      private boolean isValidScsiDiskController(VirtualSCSIController 
scsiDiskController) {
          if (scsiDiskController == null) {
              return false;
@@@ -2328,12 -2689,12 +2686,12 @@@
          String trimmedSrcBaseName = 
VmwareHelper.trimSnapshotDeltaPostfix(srcBaseName);
          String srcDatastoreName = dsSrcFile.getDatastoreName() != null ? 
dsSrcFile.getDatastoreName() : zeroLengthString;
  
 -        s_logger.info(String.format("Looking for disk device info for volume 
[%s] with base name [%s].", vmdkDatastorePath, srcBaseName));
 +        logger.info(String.format("Looking for disk device info for volume 
[%s] with base name [%s].", vmdkDatastorePath, srcBaseName));
  
-         if (CollectionUtils.isNotEmpty(devices)) {
+         if (devices != null && devices.size() > 0) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualDisk) {
 -                    s_logger.info(String.format("Testing if disk device with 
controller key [%s] and unit number [%s] has backing of type 
VirtualDiskFlatVer2BackingInfo.",
 +                    logger.info(String.format("Testing if disk device with 
controller key [%s] and unit number [%s] has backing of type 
VirtualDiskFlatVer2BackingInfo.",
                              device.getControllerKey(), 
device.getUnitNumber()));
  
                      VirtualDeviceBackingInfo backingInfo = 
device.getBacking();
@@@ -2409,17 -2770,17 +2767,17 @@@
          String trimmedSrcBaseName = 
VmwareHelper.trimSnapshotDeltaPostfix(srcBaseName);
  
          if (matchExactly) {
 -            s_logger.info("Look for disk device info from volume : " + 
vmdkDatastorePath + " with base name: " + srcBaseName);
 +            logger.info("Look for disk device info from volume : " + 
vmdkDatastorePath + " with base name: " + srcBaseName);
          } else {
 -            s_logger.info("Look for disk device info from volume : " + 
vmdkDatastorePath + " with trimmed base name: " + trimmedSrcBaseName);
 +            logger.info("Look for disk device info from volume : " + 
vmdkDatastorePath + " with trimmed base name: " + trimmedSrcBaseName);
          }
  
-         if (CollectionUtils.isNotEmpty(devices)) {
+         if (devices != null && devices.size() > 0) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualDisk) {
 -                    s_logger.info("Test against disk device, controller key: 
" + device.getControllerKey() + ", unit number: " + device.getUnitNumber());
 +                    logger.info("Test against disk device, controller key: " 
+ device.getControllerKey() + ", unit number: " + device.getUnitNumber());
  
-                     VirtualDeviceBackingInfo backingInfo = 
device.getBacking();
+                     VirtualDeviceBackingInfo backingInfo = 
((VirtualDisk)device).getBacking();
                      if (backingInfo instanceof 
VirtualDiskFlatVer2BackingInfo) {
                          VirtualDiskFlatVer2BackingInfo diskBackingInfo = 
(VirtualDiskFlatVer2BackingInfo)backingInfo;
                          do {
@@@ -2430,16 -2791,16 +2788,16 @@@
                              if (matchExactly) {
                                  if 
(backingBaseName.equalsIgnoreCase(srcBaseName)) {
                                      String deviceNumbering = 
getDeviceBusName(devices, device);
 -                                    s_logger.info("Disk backing : " + 
diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
 +                                    logger.info("Disk backing : " + 
diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
  
-                                     return new Pair<>((VirtualDisk)device, 
deviceNumbering);
+                                     return new Pair<VirtualDisk, 
String>((VirtualDisk)device, deviceNumbering);
                                  }
                              } else {
                                  if 
(backingBaseName.contains(trimmedSrcBaseName)) {
                                      String deviceNumbering = 
getDeviceBusName(devices, device);
 -                                    s_logger.info("Disk backing : " + 
diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
 +                                    logger.info("Disk backing : " + 
diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
  
-                                     return new Pair<>((VirtualDisk)device, 
deviceNumbering);
+                                     return new Pair<VirtualDisk, 
String>((VirtualDisk)device, deviceNumbering);
                                  }
                              }
  
@@@ -2455,12 -2816,12 +2813,12 @@@
  
      public String getDiskCurrentTopBackingFileInChain(String deviceBusName) 
throws Exception {
          List<VirtualDevice> devices = 
_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
-         if (CollectionUtils.isNotEmpty(devices)) {
+         if (devices != null && devices.size() > 0) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualDisk) {
 -                    s_logger.info("Test against disk device, controller key: 
" + device.getControllerKey() + ", unit number: " + device.getUnitNumber());
 +                    logger.info("Test against disk device, controller key: " 
+ device.getControllerKey() + ", unit number: " + device.getUnitNumber());
  
-                     VirtualDeviceBackingInfo backingInfo = 
device.getBacking();
+                     VirtualDeviceBackingInfo backingInfo = 
((VirtualDisk)device).getBacking();
                      if (backingInfo instanceof 
VirtualDiskFlatVer2BackingInfo) {
                          VirtualDiskFlatVer2BackingInfo diskBackingInfo = 
(VirtualDiskFlatVer2BackingInfo)backingInfo;
  
@@@ -2500,16 -2877,16 +2874,16 @@@
      }
  
      public List<Pair<Integer, ManagedObjectReference>> getAllDiskDatastores() 
throws Exception {
-         List<Pair<Integer, ManagedObjectReference>> disks = new ArrayList<>();
+         List<Pair<Integer, ManagedObjectReference>> disks = new 
ArrayList<Pair<Integer, ManagedObjectReference>>();
  
          List<VirtualDevice> devices = 
_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
 -        if (devices != null && devices.size() > 0) {
 +        if (devices != null && !devices.isEmpty()) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualDisk) {
-                     VirtualDeviceBackingInfo backingInfo = 
device.getBacking();
+                     VirtualDeviceBackingInfo backingInfo = 
((VirtualDisk)device).getBacking();
                      if (backingInfo instanceof 
VirtualDiskFlatVer2BackingInfo) {
                          VirtualDiskFlatVer2BackingInfo diskBackingInfo = 
(VirtualDiskFlatVer2BackingInfo)backingInfo;
-                         disks.add(new 
Pair<>(Integer.valueOf(device.getKey()), diskBackingInfo.getDatastore()));
+                         disks.add(new Pair<Integer, 
ManagedObjectReference>(new Integer(device.getKey()), 
diskBackingInfo.getDatastore()));
                      }
                  }
              }
@@@ -2712,24 -3091,26 +3086,26 @@@
      }
  
      public VirtualDisk[] getAllIndependentDiskDevice() throws Exception {
 -        List<VirtualDisk> independentDisks = new ArrayList<VirtualDisk>();
 +        List<VirtualDisk> independentDisks = new ArrayList<>();
          VirtualDisk[] allDisks = getAllDiskDevice();
-         for (VirtualDisk disk : allDisks) {
-             String diskMode = "";
-             if (disk.getBacking() instanceof VirtualDiskFlatVer1BackingInfo) {
-                 diskMode = ((VirtualDiskFlatVer1BackingInfo) 
disk.getBacking()).getDiskMode();
-             } else if (disk.getBacking() instanceof 
VirtualDiskFlatVer2BackingInfo) {
-                 diskMode = ((VirtualDiskFlatVer2BackingInfo) 
disk.getBacking()).getDiskMode();
-             } else if (disk.getBacking() instanceof 
VirtualDiskRawDiskMappingVer1BackingInfo) {
-                 diskMode = ((VirtualDiskRawDiskMappingVer1BackingInfo) 
disk.getBacking()).getDiskMode();
-             } else if (disk.getBacking() instanceof 
VirtualDiskSparseVer1BackingInfo) {
-                 diskMode = ((VirtualDiskSparseVer1BackingInfo) 
disk.getBacking()).getDiskMode();
-             } else if (disk.getBacking() instanceof 
VirtualDiskSparseVer2BackingInfo) {
-                 diskMode = ((VirtualDiskSparseVer2BackingInfo) 
disk.getBacking()).getDiskMode();
-             }
+         if (allDisks.length > 0) {
+             for (VirtualDisk disk : allDisks) {
+                 String diskMode = "";
+                 if (disk.getBacking() instanceof 
VirtualDiskFlatVer1BackingInfo) {
+                     diskMode = 
((VirtualDiskFlatVer1BackingInfo)disk.getBacking()).getDiskMode();
+                 } else if (disk.getBacking() instanceof 
VirtualDiskFlatVer2BackingInfo) {
+                     diskMode = 
((VirtualDiskFlatVer2BackingInfo)disk.getBacking()).getDiskMode();
+                 } else if (disk.getBacking() instanceof 
VirtualDiskRawDiskMappingVer1BackingInfo) {
+                     diskMode = 
((VirtualDiskRawDiskMappingVer1BackingInfo)disk.getBacking()).getDiskMode();
+                 } else if (disk.getBacking() instanceof 
VirtualDiskSparseVer1BackingInfo) {
+                     diskMode = 
((VirtualDiskSparseVer1BackingInfo)disk.getBacking()).getDiskMode();
+                 } else if (disk.getBacking() instanceof 
VirtualDiskSparseVer2BackingInfo) {
+                     diskMode = 
((VirtualDiskSparseVer2BackingInfo)disk.getBacking()).getDiskMode();
+                 }
  
-             if (diskMode.contains("independent")) {
-                 independentDisks.add(disk);
+                 if (diskMode.indexOf("independent") != -1) {
+                     independentDisks.add(disk);
+                 }
              }
          }
  
@@@ -2739,10 -3120,10 +3115,10 @@@
      public int tryGetIDEDeviceControllerKey() throws Exception {
          List<VirtualDevice> devices = 
_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
  
 -        if (devices != null && devices.size() > 0) {
 +        if (devices != null && !devices.isEmpty()) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualIDEController) {
-                     return device.getKey();
+                     return ((VirtualIDEController)device).getKey();
                  }
              }
          }
@@@ -2753,10 -3134,10 +3129,10 @@@
      public int getIDEDeviceControllerKey() throws Exception {
          List<VirtualDevice> devices = 
_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
  
 -        if (devices != null && devices.size() > 0) {
 +        if (devices != null && !devices.isEmpty()) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualIDEController) {
-                     return device.getKey();
+                     return ((VirtualIDEController)device).getKey();
                  }
              }
          }
@@@ -2789,10 -3170,10 +3165,10 @@@
  
      public int getNumberOfIDEDevices() throws Exception {
          int ideDeviceCount = 0;
-         List<VirtualDevice> devices = _context.getVimClient().
+         List<VirtualDevice> devices = 
(List<VirtualDevice>)_context.getVimClient().
                  getDynamicProperty(_mor, "config.hardware.device");
  
 -        if (devices != null && devices.size() > 0) {
 +        if (devices != null && !devices.isEmpty()) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualIDEController) {
                      ideDeviceCount += 
((VirtualIDEController)device).getDevice().size();
@@@ -2867,9 -3248,9 +3243,9 @@@
      }
  
      public VirtualDevice getIsoDevice(String filename) throws Exception {
-         List<VirtualDevice> devices = _context.getVimClient().
+         List<VirtualDevice> devices = 
(List<VirtualDevice>)_context.getVimClient().
                  getDynamicProperty(_mor, "config.hardware.device");
 -        if(devices != null && devices.size() > 0) {
 +        if(devices != null && !devices.isEmpty()) {
              long isoDevices = devices.stream()
                      .filter(x -> x instanceof VirtualCdrom && x.getBacking() 
instanceof VirtualCdromIsoBackingInfo)
                      .count();
@@@ -2973,8 -3354,8 +3349,8 @@@
              } else if 
(attachedNetworkSummary.endsWith("DistributedVirtualPortBackingInfo.summary") 
|| attachedNetworkSummary.startsWith("DVSwitch")) {
                  dvPortGroupName = 
getDvPortGroupName((VirtualEthernetCard)nic);
                  if (dvPortGroupName != null && 
dvPortGroupName.startsWith(networkNamePrefix)) {
 -                    s_logger.debug("Found a dvPortGroup already associated 
with public NIC.");
 +                    logger.debug("Found a dvPortGroup already associated with 
public NIC.");
-                     return new Pair<>(index, nic);
+                     return new Pair<Integer, VirtualDevice>(new 
Integer(index), nic);
                  }
              }
              index++;
@@@ -3264,10 -3645,10 +3640,10 @@@
      }
  
      private int getLsiLogicSasDeviceControllerKeyNoException() throws 
Exception {
-         List<VirtualDevice> devices = _context.getVimClient().
+         List<VirtualDevice> devices = 
(List<VirtualDevice>)_context.getVimClient().
                  getDynamicProperty(_mor, "config.hardware.device");
  
 -        if (devices != null && devices.size() > 0) {
 +        if (devices != null && !devices.isEmpty()) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualLsiLogicSASController) {
                      return device.getKey();
@@@ -3307,10 -3688,10 +3683,10 @@@
      }
  
      private int getBusLogicDeviceControllerKeyNoException() throws Exception {
-         List<VirtualDevice> devices = _context.getVimClient().
+         List<VirtualDevice> devices = 
(List<VirtualDevice>)_context.getVimClient().
                  getDynamicProperty(_mor, "config.hardware.device");
  
 -        if (devices != null && devices.size() > 0) {
 +        if (devices != null && !devices.isEmpty()) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualBusLogicController) {
                      return device.getKey();
@@@ -3353,12 -3734,12 +3729,12 @@@
      }
  
      public int getNumberOfVirtualDisks() throws Exception {
-         List<VirtualDevice> devices = 
_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
+         List<VirtualDevice> devices = 
(List<VirtualDevice>)_context.getVimClient().getDynamicProperty(_mor, 
"config.hardware.device");
  
 -        s_logger.info("Counting disk devices attached to VM " + getVmName());
 +        logger.info("Counting disk devices attached to VM " + getVmName());
          int count = 0;
  
 -        if (devices != null && devices.size() > 0) {
 +        if (devices != null && !devices.isEmpty()) {
              for (VirtualDevice device : devices) {
                  if (device instanceof VirtualDisk) {
                      count++;
diff --cc 
vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareClient.java
index 8f2f2888b6c,ccc68283d06..0e46f2e03cd
--- 
a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareClient.java
+++ 
b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareClient.java
@@@ -38,13 -36,9 +36,14 @@@ import javax.xml.ws.handler.Handler
  import javax.xml.ws.handler.HandlerResolver;
  import javax.xml.ws.handler.PortInfo;
  
+ 
  import org.apache.cloudstack.utils.security.SSLUtils;
  import org.apache.cloudstack.utils.security.SecureSSLSocketFactory;
 +
 +import com.cloud.utils.StringUtils;
 +
 +import org.w3c.dom.Element;
 +
  import com.vmware.pbm.PbmPortType;
  import com.vmware.pbm.PbmService;
  import com.vmware.pbm.PbmServiceInstanceContent;
@@@ -193,8 -187,8 +189,8 @@@ public class VmwareClient 
              cookies = responseHeaders.get("Set-cookie");
              if (cookies == null) {
                  String msg = "Login successful, but failed to get server 
cookies from url :[" + url + "]";
 -                s_logger.error(msg);
 +                LOGGER.error(msg);
-                 throw new  VmwareClientException(msg);
+                 throw new Exception(msg);
              }
          }
  
@@@ -352,10 -344,12 +348,10 @@@
       * @param propertyName
       *            property name.
       * @return property value.
 -     * @throws Exception
 -     *             in case of error.
       */
      @SuppressWarnings("unchecked")
-     public <T> T getDynamicProperty(ManagedObjectReference mor, String 
propertyName) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, 
NoSuchMethodException, InvocationTargetException, IllegalAccessException {
-         List<String> props = new ArrayList<>();
+     public <T> T getDynamicProperty(ManagedObjectReference mor, String 
propertyName) throws Exception {
+         List<String> props = new ArrayList<String>();
          props.add(propertyName);
          List<ObjectContent> objContent = retrieveMoRefProperties(mor, props);
  
@@@ -710,8 -704,8 +706,8 @@@
       *
       * @return First ManagedObjectReference of the type / name pair found
       */
-     public ManagedObjectReference getDecendentMoRef(ManagedObjectReference 
root, String type, String name) throws InvalidPropertyFaultMsg, 
RuntimeFaultFaultMsg {
+     public ManagedObjectReference getDecendentMoRef(ManagedObjectReference 
root, String type, String name) throws Exception {
 -        if (name == null || name.length() == 0) {
 +        if (name == null || name.isEmpty()) {
              return null;
          }
  


Reply via email to