use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class RemoveIpFromVmNicCmd method execute.
@Override
public void execute() throws InvalidParameterValueException {
CallContext.current().setEventDetails("Ip Id: " + id);
final NicSecondaryIp nicSecIp = getIpEntry();
if (nicSecIp == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid IP id is passed");
}
try {
final boolean result = _networkService.releaseSecondaryIpFromNic(id);
if (result) {
final SuccessResponse response = new SuccessResponse(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove secondary ip address for the nic");
}
} catch (final InvalidParameterValueException e) {
throw new InvalidParameterValueException("Removing guest ip from nic failed");
}
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class EnableStaticNatCmd method getNetworkId.
public long getNetworkId() {
final IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId());
Long ntwkId = null;
if (ip.getAssociatedWithNetworkId() != null) {
ntwkId = ip.getAssociatedWithNetworkId();
} else {
ntwkId = networkId;
}
if (ntwkId == null) {
throw new InvalidParameterValueException("Unable to enable static NAT for the ipAddress id=" + ipAddressId + " as IP is not associated with any network and no networkId is passed in");
}
return ntwkId;
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class UpgradeVMCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
CallContext.current().setEventDetails("Vm Id: " + getId());
final ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
final UserVm result = _userVmService.upgradeVirtualMachine(this);
if (result != null) {
final UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade vm");
}
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class CreateSnapshotCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
final Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
if (volume == null) {
throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
}
final Account account = _accountService.getAccount(volume.getAccountId());
// Can create templates 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 the 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 template is disabled: " + account);
}
return volume.getAccountId();
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class CreateSnapshotFromVMSnapshotCmd method getHostId.
private Long getHostId() {
final VMSnapshot vmsnapshot = _entityMgr.findById(VMSnapshot.class, getVMSnapshotId());
if (vmsnapshot == null) {
throw new InvalidParameterValueException("Unable to find vm snapshot by id=" + getVMSnapshotId());
}
final UserVm vm = _entityMgr.findById(UserVm.class, vmsnapshot.getVmId());
if (vm != null) {
if (vm.getHostId() != null) {
return vm.getHostId();
} else if (vm.getLastHostId() != null) {
return vm.getLastHostId();
}
}
return null;
}
Aggregations