use of org.apache.cloudstack.api.response.VlanIpRangeResponse in project cloudstack by apache.
the class DedicatePublicIpRangeCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
Vlan result = _configService.dedicatePublicIpRange(this);
if (result != null) {
VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate vlan ip range");
}
}
use of org.apache.cloudstack.api.response.VlanIpRangeResponse in project cloudstack by apache.
the class ListVlanIpRangesCmd method execute.
@Override
public void execute() {
Pair<List<? extends Vlan>, Integer> vlans = _mgr.searchForVlans(this);
ListResponse<VlanIpRangeResponse> response = new ListResponse<VlanIpRangeResponse>();
List<VlanIpRangeResponse> vlanResponses = new ArrayList<VlanIpRangeResponse>();
for (Vlan vlan : vlans.first()) {
VlanIpRangeResponse vlanResponse = _responseGenerator.createVlanIpRangeResponse(vlan);
vlanResponse.setObjectName("vlaniprange");
vlanResponses.add(vlanResponse);
}
response.setResponses(vlanResponses, vlans.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.VlanIpRangeResponse in project cloudstack by apache.
the class CreateVlanIpRangeCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
try {
Vlan result = _configService.createVlanAndPublicIpRange(this);
if (result != null) {
VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vlan ip range");
}
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (InsufficientCapacityException ex) {
s_logger.info(ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
}
}
use of org.apache.cloudstack.api.response.VlanIpRangeResponse in project cloudstack by apache.
the class ApiResponseHelper method createVlanIpRangeResponse.
@Override
public VlanIpRangeResponse createVlanIpRangeResponse(Class<? extends VlanIpRangeResponse> subClass, Vlan vlan) {
try {
Long podId = ApiDBUtils.getPodIdForVlan(vlan.getId());
VlanIpRangeResponse vlanResponse = subClass.newInstance();
vlanResponse.setId(vlan.getUuid());
if (vlan.getVlanType() != null) {
vlanResponse.setForVirtualNetwork(vlan.getVlanType().equals(VlanType.VirtualNetwork));
}
vlanResponse.setVlan(vlan.getVlanTag());
DataCenter zone = ApiDBUtils.findZoneById(vlan.getDataCenterId());
if (zone != null) {
vlanResponse.setZoneId(zone.getUuid());
}
if (podId != null) {
HostPodVO pod = ApiDBUtils.findPodById(podId);
if (pod != null) {
vlanResponse.setPodId(pod.getUuid());
vlanResponse.setPodName(pod.getName());
}
}
vlanResponse.setGateway(vlan.getVlanGateway());
vlanResponse.setNetmask(vlan.getVlanNetmask());
// get start ip and end ip of corresponding vlan
String ipRange = vlan.getIpRange();
if (ipRange != null) {
String[] range = ipRange.split("-");
vlanResponse.setStartIp(range[0]);
vlanResponse.setEndIp(range[1]);
}
vlanResponse.setIp6Gateway(vlan.getIp6Gateway());
vlanResponse.setIp6Cidr(vlan.getIp6Cidr());
String ip6Range = vlan.getIp6Range();
if (ip6Range != null) {
String[] range = ip6Range.split("-");
vlanResponse.setStartIpv6(range[0]);
vlanResponse.setEndIpv6(range[1]);
}
if (vlan.getNetworkId() != null) {
Network nw = ApiDBUtils.findNetworkById(vlan.getNetworkId());
if (nw != null) {
vlanResponse.setNetworkId(nw.getUuid());
}
}
Account owner = ApiDBUtils.getVlanAccount(vlan.getId());
if (owner != null) {
populateAccount(vlanResponse, owner.getId());
populateDomain(vlanResponse, owner.getDomainId());
} else {
Domain domain = ApiDBUtils.getVlanDomain(vlan.getId());
if (domain != null) {
populateDomain(vlanResponse, domain.getId());
} else {
Long networkId = vlan.getNetworkId();
if (networkId != null) {
Network network = _ntwkModel.getNetwork(networkId);
if (network != null) {
Long accountId = network.getAccountId();
populateAccount(vlanResponse, accountId);
populateDomain(vlanResponse, ApiDBUtils.findAccountById(accountId).getDomainId());
}
}
}
}
if (vlan.getPhysicalNetworkId() != null) {
PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(vlan.getPhysicalNetworkId());
if (pnw != null) {
vlanResponse.setPhysicalNetworkId(pnw.getUuid());
}
}
vlanResponse.setObjectName("vlan");
return vlanResponse;
} catch (InstantiationException | IllegalAccessException e) {
throw new CloudRuntimeException("Failed to create Vlan IP Range response", e);
}
}
Aggregations