use of com.cloud.projects.Project in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createVMSnapshotResponse.
@Override
public VMSnapshotResponse createVMSnapshotResponse(final VMSnapshot vmSnapshot) {
final VMSnapshotResponse vmSnapshotResponse = new VMSnapshotResponse();
vmSnapshotResponse.setId(vmSnapshot.getUuid());
vmSnapshotResponse.setName(vmSnapshot.getName());
vmSnapshotResponse.setState(vmSnapshot.getState());
vmSnapshotResponse.setCreated(vmSnapshot.getCreated());
vmSnapshotResponse.setDescription(vmSnapshot.getDescription());
vmSnapshotResponse.setDisplayName(vmSnapshot.getDisplayName());
final UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
if (vm != null) {
vmSnapshotResponse.setVirtualMachineid(vm.getUuid());
}
if (vmSnapshot.getParent() != null) {
final VMSnapshot vmSnapshotParent = ApiDBUtils.getVMSnapshotById(vmSnapshot.getParent());
if (vmSnapshotParent != null) {
vmSnapshotResponse.setParent(vmSnapshotParent.getUuid());
vmSnapshotResponse.setParentName(vmSnapshotParent.getDisplayName());
}
}
populateOwner(vmSnapshotResponse, vmSnapshot);
final Project project = ApiDBUtils.findProjectByProjectAccountId(vmSnapshot.getAccountId());
if (project != null) {
vmSnapshotResponse.setProjectId(project.getUuid());
vmSnapshotResponse.setProjectName(project.getName());
}
vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent());
vmSnapshotResponse.setType(vmSnapshot.getType().toString());
vmSnapshotResponse.setObjectName("vmsnapshot");
return vmSnapshotResponse;
}
use of com.cloud.projects.Project in project cosmic by MissionCriticalCloud.
the class SuspendProjectCmd method execute.
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
CallContext.current().setEventDetails("Project Id: " + id);
final Project project = _projectService.suspendProject(id);
if (project != null) {
final ProjectResponse response = _responseGenerator.createProjectResponse(project);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to suspend a project");
}
}
use of com.cloud.projects.Project in project cosmic by MissionCriticalCloud.
the class ResizeVolumeCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
final Volume volume = _entityMgr.findById(Volume.class, getEntityId());
if (volume == null) {
throw new InvalidParameterValueException("Unable to find volume by id=" + id);
}
final Account account = _accountService.getAccount(volume.getAccountId());
// Can resize volumes for enabled projects/accounts only
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
final Project project = _projectService.findByProjectAccountId(volume.getAccountId());
if (project.getState() != Project.State.Active) {
throw new PermissionDeniedException("Can't add resources to project id=" + project.getId() + " in state=" + project.getState() + " as it's no longer active");
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of volume " + id + " is disabled: " + account);
}
return volume.getAccountId();
}
use of com.cloud.projects.Project in project cosmic by MissionCriticalCloud.
the class ActivateProjectCmd method execute.
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
CallContext.current().setEventDetails("Project id: " + getId());
final Project project = _projectService.activateProject(getId());
if (project != null) {
final ProjectResponse response = _responseGenerator.createProjectResponse(project);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to activate a project");
}
}
use of com.cloud.projects.Project in project cloudstack by apache.
the class AssociateIPAddrCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Account caller = CallContext.current().getCallingAccount();
if (accountName != null && domainId != null) {
Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
return account.getId();
} else if (projectId != null) {
Project project = _projectService.getProject(projectId);
if (project != null) {
if (project.getState() == Project.State.Active) {
return project.getProjectAccountId();
} else {
throw new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
}
} else {
throw new InvalidParameterValueException("Unable to find project by ID");
}
} else if (networkId != null) {
Network network = _networkService.getNetwork(networkId);
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by network id specified");
}
NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic && offering.isElasticIp() && offering.isElasticLb()) {
// shared network with EIP/ELB service.
return caller.getAccountId();
}
return network.getAccountId();
} else if (vpcId != null) {
Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId());
if (vpc == null) {
throw new InvalidParameterValueException("Can't find enabled VPC by ID specified");
}
return vpc.getAccountId();
}
return caller.getAccountId();
}
Aggregations