Search in sources :

Example 56 with IpAddress

use of com.cloud.network.IpAddress in project cloudstack by apache.

the class AssociateIPAddrCmd method create.

@Override
public void create() throws ResourceAllocationException {
    try {
        IpAddress ip = null;
        if (!isPortable()) {
            ip = _networkService.allocateIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNetworkId(), getDisplayIp());
        } else {
            ip = _networkService.allocatePortableIP(_accountService.getAccount(getEntityOwnerId()), 1, getZoneId(), getNetworkId(), getVpcId());
        }
        if (ip != null) {
            setEntityId(ip.getId());
            setEntityUuid(ip.getUuid());
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to allocate IP address");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientAddressCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) IpAddress(com.cloud.network.IpAddress) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 57 with IpAddress

use of com.cloud.network.IpAddress in project cloudstack by apache.

the class ListPublicIpAddressesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
    ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
    List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
    for (IpAddress ipAddress : result.first()) {
        IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, ipAddress);
        ipResponse.setObjectName("publicipaddress");
        ipAddrResponses.add(ipResponse);
    }
    response.setResponses(ipAddrResponses, result.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IpAddress(com.cloud.network.IpAddress) IPAddressResponse(org.apache.cloudstack.api.response.IPAddressResponse)

Example 58 with IpAddress

use of com.cloud.network.IpAddress in project cloudstack by apache.

the class UpdateIPAddrCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    if (ownerId == null) {
        IpAddress ip = getIpAddress(id);
        if (ip == null) {
            throw new InvalidParameterValueException("Unable to find IP address by ID=" + id);
        }
        ownerId = ip.getAccountId();
    }
    if (ownerId == null) {
        return Account.ACCOUNT_ID_SYSTEM;
    }
    return ownerId;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) IpAddress(com.cloud.network.IpAddress)

Aggregations

IpAddress (com.cloud.network.IpAddress)58 ArrayList (java.util.ArrayList)26 PublicIpAddress (com.cloud.network.PublicIpAddress)20 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)16 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)16 Network (com.cloud.network.Network)14 FirewallRule (com.cloud.network.rules.FirewallRule)11 HostVO (com.cloud.host.HostVO)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 DataCenterVO (com.cloud.dc.DataCenterVO)7 CiscoVnmcControllerVO (com.cloud.network.cisco.CiscoVnmcControllerVO)7 NetworkAsa1000vMapVO (com.cloud.network.cisco.NetworkAsa1000vMapVO)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 PrivateIpAddress (com.cloud.network.vpc.PrivateIpAddress)7 Answer (com.cloud.agent.api.Answer)6 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)6 PublicIp (com.cloud.network.addr.PublicIp)6 StaticNat (com.cloud.network.rules.StaticNat)6 Account (com.cloud.user.Account)6 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)5