use of com.cloud.storage.Volume in project CloudStack-archive by CloudStack-extras.
the class DetachVolumeCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Volume Id: " + getId() + " VmId: " + getVirtualMachineId());
Volume result = _userVmService.detachVolumeFromVM(this);
if (result != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
response.setResponseName("volume");
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to detach volume");
}
}
use of com.cloud.storage.Volume in project CloudStack-archive by CloudStack-extras.
the class CreateTemplateCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Long volumeId = getVolumeId();
Long snapshotId = getSnapshotId();
Long accountId = null;
if (volumeId != null) {
Volume volume = _entityMgr.findById(Volume.class, volumeId);
if (volume != null) {
accountId = volume.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
}
} else {
Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
if (snapshot != null) {
accountId = snapshot.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
}
}
Account account = _accountService.getAccount(accountId);
//Can create templates for enabled projects/accounts only
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
Project project = _projectService.findByProjectAccountId(accountId);
if (project.getState() != Project.State.Active) {
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, project.getId(), "projectId");
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of template is disabled: " + account);
}
return accountId;
}
use of com.cloud.storage.Volume in project CloudStack-archive by CloudStack-extras.
the class CreateVolumeCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Volume Id: " + getEntityId() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
Volume volume = _storageService.createVolume(this);
if (volume != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(volume);
//FIXME - have to be moved to ApiResponseHelper
// if the volume was created from a snapshot, snapshotId will be set so we pass it back in the response
response.setSnapshotId(getSnapshotId());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a volume");
}
}
use of com.cloud.storage.Volume in project CloudStack-archive by CloudStack-extras.
the class UploadVolumeCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
Volume volume = _storageService.uploadVolume(this);
if (volume != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(volume);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upload volume");
}
}
use of com.cloud.storage.Volume in project cloudstack by apache.
the class UserVmManagerImpl method updateVirtualMachine.
@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_UPDATE, eventDescription = "updating Vm")
public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException {
String displayName = cmd.getDisplayName();
String group = cmd.getGroup();
Boolean ha = cmd.getHaEnable();
Boolean isDisplayVm = cmd.getDisplayVm();
Long id = cmd.getId();
Long osTypeId = cmd.getOsTypeId();
String userData = cmd.getUserData();
Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
String hostName = cmd.getHostName();
Map<String, String> details = cmd.getDetails();
Account caller = CallContext.current().getCallingAccount();
List<Long> securityGroupIdList = getSecurityGroupIdList(cmd);
boolean cleanupDetails = cmd.isCleanupDetails();
// Input validation and permission checks
UserVmVO vmInstance = _vmDao.findById(id);
if (vmInstance == null) {
throw new InvalidParameterValueException("unable to find virtual machine with id " + id);
}
_accountMgr.checkAccess(caller, null, true, vmInstance);
//If the flag is specified and is changed
if (isDisplayVm != null && isDisplayVm != vmInstance.isDisplayVm()) {
//update vm
vmInstance.setDisplayVm(isDisplayVm);
// Resource limit changes
ServiceOffering offering = _serviceOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
_resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.user_vm, isDisplayVm);
_resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.cpu, isDisplayVm, new Long(offering.getCpu()));
_resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.memory, isDisplayVm, new Long(offering.getRamSize()));
// Usage
saveUsageEvent(vmInstance);
// take care of the root volume as well.
List<VolumeVO> rootVols = _volsDao.findByInstanceAndType(id, Volume.Type.ROOT);
if (!rootVols.isEmpty()) {
_volumeService.updateDisplay(rootVols.get(0), isDisplayVm);
}
// take care of the data volumes as well.
List<VolumeVO> dataVols = _volsDao.findByInstanceAndType(id, Volume.Type.DATADISK);
for (Volume dataVol : dataVols) {
_volumeService.updateDisplay(dataVol, isDisplayVm);
}
}
if (cleanupDetails) {
_vmDetailsDao.removeDetails(id);
} else if (details != null && !details.isEmpty()) {
vmInstance.setDetails(details);
_vmDao.saveDetails(vmInstance);
}
return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName, cmd.getInstanceName(), securityGroupIdList);
}
Aggregations