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;
}
});
}
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;
}
Aggregations