Search in sources :

Example 1 with VmwareDatacenterZoneMap

use of com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap in project cloudstack by apache.

the class VmwareManagerImpl method updateVmwareDatacenter.

@Override
@ActionEvent(eventType = EventTypes.EVENT_ZONE_EDIT, eventDescription = "updating VMware datacenter")
public VmwareDatacenter updateVmwareDatacenter(UpdateVmwareDcCmd cmd) {
    final Long zoneId = cmd.getZoneId();
    final String userName = cmd.getUsername();
    final String password = cmd.getPassword();
    final String vCenterHost = cmd.getVcenter();
    final String vmwareDcName = cmd.getName();
    final Boolean isRecursive = cmd.isRecursive();
    final VmwareDatacenterZoneMap vdcMap = vmwareDatacenterZoneMapDao.findByZoneId(zoneId);
    final VmwareDatacenterVO vmwareDc = vmwareDcDao.findById(vdcMap.getVmwareDcId());
    if (vmwareDc == null) {
        throw new CloudRuntimeException("VMWare datacenter does not exist by provided ID");
    }
    final String oldVCenterHost = vmwareDc.getVcenterHost();
    if (StringUtils.isNotEmpty(userName)) {
        vmwareDc.setUser(userName);
    }
    if (StringUtils.isNotEmpty(password)) {
        vmwareDc.setPassword(password);
    }
    if (StringUtils.isNotEmpty(vCenterHost)) {
        vmwareDc.setVcenterHost(vCenterHost);
    }
    if (StringUtils.isNotEmpty(vmwareDcName)) {
        vmwareDc.setVmwareDatacenterName(vmwareDcName);
    }
    vmwareDc.setGuid(String.format("%s@%s", vmwareDc.getVmwareDatacenterName(), vmwareDc.getVcenterHost()));
    return Transaction.execute(new TransactionCallback<VmwareDatacenter>() {

        @Override
        public VmwareDatacenter doInTransaction(TransactionStatus status) {
            if (vmwareDcDao.update(vmwareDc.getId(), vmwareDc)) {
                if (isRecursive) {
                    for (final Cluster cluster : clusterDao.listByDcHyType(zoneId, Hypervisor.HypervisorType.VMware.toString())) {
                        final Map<String, String> clusterDetails = clusterDetailsDao.findDetails(cluster.getId());
                        clusterDetails.put("username", vmwareDc.getUser());
                        clusterDetails.put("password", vmwareDc.getPassword());
                        final String clusterUrl = clusterDetails.get("url");
                        if (!oldVCenterHost.equals(vmwareDc.getVcenterHost()) && StringUtils.isNotEmpty(clusterUrl)) {
                            clusterDetails.put("url", clusterUrl.replace(oldVCenterHost, vmwareDc.getVcenterHost()));
                        }
                        clusterDetailsDao.persist(cluster.getId(), clusterDetails);
                    }
                    for (final Host host : hostDao.listAllHostsByZoneAndHypervisorType(zoneId, HypervisorType.VMware)) {
                        final Map<String, String> hostDetails = hostDetailsDao.findDetails(host.getId());
                        hostDetails.put("username", vmwareDc.getUser());
                        hostDetails.put("password", vmwareDc.getPassword());
                        final String hostGuid = hostDetails.get("guid");
                        if (StringUtils.isNotEmpty(hostGuid)) {
                            hostDetails.put("guid", hostGuid.replace(oldVCenterHost, vmwareDc.getVcenterHost()));
                        }
                        hostDetailsDao.persist(host.getId(), hostDetails);
                    }
                }
                importVsphereStoragePoliciesInternal(zoneId, vmwareDc.getId());
                return vmwareDc;
            }
            return null;
        }
    });
}
Also used : VmwareDatacenterZoneMap(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap) TransactionStatus(com.cloud.utils.db.TransactionStatus) Cluster(com.cloud.org.Cluster) Host(com.cloud.host.Host) ManagementServerHost(org.apache.cloudstack.management.ManagementServerHost) VmwareDatacenterVO(com.cloud.hypervisor.vmware.VmwareDatacenterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VmwareDatacenter(com.cloud.hypervisor.vmware.VmwareDatacenter) VmwareDatacenterZoneMap(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap) Map(java.util.Map) HashMap(java.util.HashMap) ActionEvent(com.cloud.event.ActionEvent)

Example 2 with VmwareDatacenterZoneMap

use of com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap in project cloudstack by apache.

the class VeeamBackupProvider method findVmwareDatacenterForVM.

private VmwareDatacenter findVmwareDatacenterForVM(final VirtualMachine vm) {
    if (vm == null || vm.getHypervisorType() != Hypervisor.HypervisorType.VMware) {
        throw new CloudRuntimeException("The Veeam backup provider is only applicable for VMware VMs");
    }
    final VmwareDatacenterZoneMap zoneMap = vmwareDatacenterZoneMapDao.findByZoneId(vm.getDataCenterId());
    if (zoneMap == null) {
        throw new CloudRuntimeException("Failed to find a mapped VMware datacenter for zone id:" + vm.getDataCenterId());
    }
    final VmwareDatacenter vmwareDatacenter = vmwareDatacenterDao.findById(zoneMap.getVmwareDcId());
    if (vmwareDatacenter == null) {
        throw new CloudRuntimeException("Failed to find a valid VMware datacenter mapped for zone id:" + vm.getDataCenterId());
    }
    return vmwareDatacenter;
}
Also used : VmwareDatacenterZoneMap(com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VmwareDatacenter(com.cloud.hypervisor.vmware.VmwareDatacenter)

Aggregations

VmwareDatacenter (com.cloud.hypervisor.vmware.VmwareDatacenter)2 VmwareDatacenterZoneMap (com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ActionEvent (com.cloud.event.ActionEvent)1 Host (com.cloud.host.Host)1 VmwareDatacenterVO (com.cloud.hypervisor.vmware.VmwareDatacenterVO)1 Cluster (com.cloud.org.Cluster)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ManagementServerHost (org.apache.cloudstack.management.ManagementServerHost)1