use of com.cloud.dc.VsphereStoragePolicy in project cloudstack by apache.
the class ImportVsphereStoragePoliciesCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
final DataCenter dataCenter = _resourceService.getZone(getZoneId());
if (dataCenter == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find zone by ID: " + getZoneId());
}
List<? extends VsphereStoragePolicy> storagePolicies = _vmwareDatacenterService.importVsphereStoragePolicies(this);
final ListResponse<VsphereStoragePoliciesResponse> responseList = new ListResponse<>();
final List<VsphereStoragePoliciesResponse> storagePoliciesResponseList = new ArrayList<>();
for (VsphereStoragePolicy storagePolicy : storagePolicies) {
final VsphereStoragePoliciesResponse storagePoliciesResponse = new VsphereStoragePoliciesResponse();
storagePoliciesResponse.setZoneId(dataCenter.getUuid());
storagePoliciesResponse.setId(storagePolicy.getUuid());
storagePoliciesResponse.setName(storagePolicy.getName());
storagePoliciesResponse.setPolicyId(storagePolicy.getPolicyId());
storagePoliciesResponse.setDescription(storagePolicy.getDescription());
storagePoliciesResponse.setObjectName("StoragePolicy");
storagePoliciesResponseList.add(storagePoliciesResponse);
}
responseList.setResponses(storagePoliciesResponseList);
responseList.setResponseName(getCommandName());
setResponseObject(responseList);
}
use of com.cloud.dc.VsphereStoragePolicy in project cloudstack by apache.
the class VmwareManagerImpl method importVsphereStoragePoliciesInternal.
public List<? extends VsphereStoragePolicy> importVsphereStoragePoliciesInternal(Long zoneId, Long vmwareDcId) {
// Get DC associated with this zone
VmwareDatacenterVO vmwareDatacenter = vmwareDcDao.findById(vmwareDcId);
String vmwareDcName = vmwareDatacenter.getVmwareDatacenterName();
String vCenterHost = vmwareDatacenter.getVcenterHost();
String userName = vmwareDatacenter.getUser();
String password = vmwareDatacenter.getPassword();
List<PbmProfile> storageProfiles = null;
try {
s_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();
s_logger.debug(String.format("Import vSphere Storage Policies for the vmware DC %d in zone %d is successful", vmwareDcId, zoneId));
} catch (Exception e) {
String msg = String.format("Unable to list storage profiles from DC %s due to : %s", vmwareDcName, VmwareHelper.getExceptionMessage(e));
s_logger.error(msg);
throw new CloudRuntimeException(msg);
}
for (PbmProfile storageProfile : storageProfiles) {
VsphereStoragePolicyVO storagePolicyVO = vsphereStoragePolicyDao.findByPolicyId(zoneId, storageProfile.getProfileId().getUniqueId());
if (storagePolicyVO == null) {
storagePolicyVO = new VsphereStoragePolicyVO(zoneId, storageProfile.getProfileId().getUniqueId(), storageProfile.getName(), storageProfile.getDescription());
vsphereStoragePolicyDao.persist(storagePolicyVO);
} else {
storagePolicyVO.setDescription(storageProfile.getDescription());
storagePolicyVO.setName(storageProfile.getName());
vsphereStoragePolicyDao.update(storagePolicyVO.getId(), storagePolicyVO);
}
}
List<VsphereStoragePolicyVO> allStoragePolicies = vsphereStoragePolicyDao.listAll();
List<PbmProfile> finalStorageProfiles = storageProfiles;
List<VsphereStoragePolicyVO> needToMarkRemoved = allStoragePolicies.stream().filter(existingPolicy -> !finalStorageProfiles.stream().anyMatch(storageProfile -> storageProfile.getProfileId().getUniqueId().equals(existingPolicy.getPolicyId()))).collect(Collectors.toList());
for (VsphereStoragePolicyVO storagePolicy : needToMarkRemoved) {
vsphereStoragePolicyDao.remove(storagePolicy.getId());
}
List<VsphereStoragePolicyVO> storagePolicies = vsphereStoragePolicyDao.listAll();
return storagePolicies;
}
use of com.cloud.dc.VsphereStoragePolicy in project cloudstack by apache.
the class ListVsphereStoragePoliciesCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
final DataCenter dataCenter = _resourceService.getZone(getZoneId());
if (dataCenter == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find zone by ID: " + getZoneId());
}
List<? extends VsphereStoragePolicy> storagePolicies = _vmwareDatacenterService.listVsphereStoragePolicies(this);
final ListResponse<VsphereStoragePoliciesResponse> responseList = new ListResponse<>();
final List<VsphereStoragePoliciesResponse> storagePoliciesResponseList = new ArrayList<>();
for (VsphereStoragePolicy storagePolicy : storagePolicies) {
final VsphereStoragePoliciesResponse storagePoliciesResponse = new VsphereStoragePoliciesResponse();
storagePoliciesResponse.setZoneId(dataCenter.getUuid());
storagePoliciesResponse.setId(storagePolicy.getUuid());
storagePoliciesResponse.setName(storagePolicy.getName());
storagePoliciesResponse.setPolicyId(storagePolicy.getPolicyId());
storagePoliciesResponse.setDescription(storagePolicy.getDescription());
storagePoliciesResponse.setObjectName("StoragePolicy");
storagePoliciesResponseList.add(storagePoliciesResponse);
}
responseList.setResponses(storagePoliciesResponseList);
responseList.setResponseName(getCommandName());
setResponseObject(responseList);
}
Aggregations