@Override public void create() throws ResourceAllocationException { try { IpAddress ip = null; ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNetworkId(), getDisplayIp()); if (ip != null) { setEntityId(ip.getId()); setEntityUuid(ip.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to allocate IP address"); } } catch (final ConcurrentOperationException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (final InsufficientAddressCapacityException ex) { s_logger.info(ex.toString()); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } }
@Override public void create() { //cidr list parameter is deprecated if (cidrlist != null) { throw new InvalidParameterValueException( "Parameter cidrList is deprecated; if you need to open firewall rule for the specific CIDR, please refer to createFirewallRule command"); } if (lbProtocol != null && !lbProtocol.toLowerCase().startsWith("tcp")) { throw new InvalidParameterValueException( "Only TCP protocol is supported because HAProxy can only do TCP."); } try { final LoadBalancer result = _lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(), getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay(), getClientTimeout(), getServerTimeout()); this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (final NetworkRuleConflictException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } catch (final InsufficientAddressCapacityException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } catch (final InvalidParameterValueException e) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); } }
@Override public void create() { final String ip; final NicSecondaryIp result; if ((ip = getIpaddress()) != null) { if (!NetUtils.isValidIp4(ip)) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid ip address " + ip); } } try { result = _networkService.allocateSecondaryGuestIP(getNicId(), getIpaddress()); if (result != null) { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } } catch (final InsufficientAddressCapacityException e) { throw new InvalidParameterValueException("Allocating guest ip for nic failed : " + e.getMessage()); } if (result == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign secondary ip to nic"); } }