use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class CreateVPCCmdByAdmin method execute.
@Override
public void execute() {
Vpc vpc = null;
try {
if (isStart()) {
_vpcService.startVpc(getEntityId(), true);
} else {
s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
}
vpc = _entityMgr.findById(Vpc.class, getEntityId());
} catch (final ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (final ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (final InsufficientCapacityException ex) {
s_logger.info(ex.toString());
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
}
if (vpc != null) {
final VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, vpc);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC");
}
}
use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class AssociateIPAddrCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
final Account caller = CallContext.current().getCallingAccount();
if (accountName != null && domainId != null) {
final Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
return account.getId();
} else if (projectId != null) {
final 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) {
final Network network = _networkService.getNetwork(networkId);
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by network id specified");
}
final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
// shared network with EIP/ELB service.
return caller.getAccountId();
}
return network.getAccountId();
} else if (vpcId != null) {
final 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();
}
use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class UpdateVPCCmdByAdmin method execute.
@Override
public void execute() {
final Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), getCustomId(), getDisplayVpc(), getVpcOfferingId(), getSourceNatList(), getSyslogServerList(), getAdvertInterval(), getAdvertMethod(), getComplianceStatus());
if (result != null) {
final VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Full, result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC");
}
}
use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method implementNetworkElementsAndResources.
@Override
public void implementNetworkElementsAndResources(final DeployDestination dest, final ReservationContext context, final Network network, final NetworkOffering offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException {
// Associate a source NAT IP (if one isn't already associated with the network) if this is a
// 1) 'Isolated' or 'Shared' guest virtual network in the advance zone
// 2) network has sourceNat service
// 3) network offering does not support a shared source NAT rule
final boolean sharedSourceNat = offering.getSharedSourceNat();
final Zone zone = _zoneRepository.findById(network.getDataCenterId()).orElse(null);
if (!sharedSourceNat && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && (network.getGuestType() == GuestType.Isolated || network.getGuestType() == GuestType.Shared && zone.getNetworkType() == com.cloud.model.enumeration.NetworkType.Advanced)) {
List<IPAddressVO> ips = null;
final Account owner = _entityMgr.findById(Account.class, network.getAccountId());
if (network.getVpcId() != null) {
ips = _ipAddressDao.listByVpc(network.getVpcId(), true);
if (ips.isEmpty()) {
final Vpc vpc = _vpcMgr.getActiveVpc(network.getVpcId());
s_logger.debug("Creating a source nat ip for vpc " + vpc);
_vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
}
} else {
ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
if (ips.isEmpty()) {
s_logger.debug("Creating a source nat ip for network " + network);
_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
}
}
}
// get providers to implement
final List<Provider> providersToImplement = getNetworkProviders(network.getId());
implementNetworkElements(dest, context, network, offering, providersToImplement);
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
((AggregatedCommandExecutor) element).prepareAggregatedExecution(network, dest);
}
}
try {
// reapply all the firewall/staticNat/lb rules
s_logger.debug("Reprogramming network " + network + " as a part of network implement");
if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) {
s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
// see DataCenterVO.java
final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
throw ex;
}
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
if (!((AggregatedCommandExecutor) element).completeAggregatedExecution(network, dest)) {
s_logger.warn("Failed to re-program the network as a part of network " + network + " implement due to aggregated commands execution failure!");
// see DataCenterVO.java
final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
throw ex;
}
}
}
} finally {
for (final NetworkElement element : networkElements) {
if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
((AggregatedCommandExecutor) element).cleanupAggregatedExecution(network, dest);
}
}
}
}
use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method startVpc.
@Override
public boolean startVpc(final long vpcId, final boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
final CallContext ctx = CallContext.current();
final Account caller = ctx.getCallingAccount();
final User callerUser = _accountMgr.getActiveUser(ctx.getCallingUserId());
// check if vpc exists
final Vpc vpc = getActiveVpc(vpcId);
if (vpc == null) {
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC by id specified");
ex.addProxyObject(String.valueOf(vpcId), "VPC");
throw ex;
}
// permission check
_accountMgr.checkAccess(caller, null, false, vpc);
final Zone zone = zoneRepository.findById(vpc.getZoneId()).orElse(null);
final DeployDestination dest = new DeployDestination(zone, null, null, null);
final ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId()));
boolean result = true;
try {
if (!startVpc(vpc, dest, context)) {
s_logger.warn("Failed to start vpc " + vpc);
result = false;
}
} catch (final Exception ex) {
s_logger.warn("Failed to start vpc " + vpc + " due to ", ex);
result = false;
} finally {
// do cleanup
if (!result && destroyOnFailure) {
s_logger.debug("Destroying vpc " + vpc + " that failed to start");
if (destroyVpc(vpc, caller, callerUser.getId())) {
s_logger.warn("Successfully destroyed vpc " + vpc + " that failed to start");
} else {
s_logger.warn("Failed to destroy vpc " + vpc + " that failed to start");
}
}
}
return result;
}
Aggregations