use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class AddHostCmd method execute.
@Override
public void execute() {
try {
List<? extends Host> result = _resourceService.discoverHosts(this);
ListResponse<HostResponse> response = new ListResponse<HostResponse>();
List<HostResponse> hostResponses = new ArrayList<HostResponse>();
if (result != null && result.size() > 0) {
for (Host host : result) {
HostResponse hostResponse = _responseGenerator.createHostResponse(host);
hostResponses.add(hostResponse);
}
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add host");
}
response.setResponses(hostResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (DiscoveryException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class ListRolesCmd method setupResponse.
private void setupResponse(final List<Role> roles) {
final ListResponse<RoleResponse> response = new ListResponse<>();
final List<RoleResponse> roleResponses = new ArrayList<>();
for (final Role role : roles) {
if (role == null) {
continue;
}
final RoleResponse roleResponse = new RoleResponse();
roleResponse.setId(role.getUuid());
roleResponse.setRoleName(role.getName());
roleResponse.setRoleType(role.getRoleType());
roleResponse.setDescription(role.getDescription());
roleResponse.setObjectName("role");
roleResponses.add(roleResponse);
}
response.setResponses(roleResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class ListTrafficTypeImplementorsCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
List<Pair<TrafficType, String>> results = _networkService.listTrafficTypeImplementor(this);
ListResponse<TrafficTypeImplementorResponse> response = new ListResponse<TrafficTypeImplementorResponse>();
List<TrafficTypeImplementorResponse> responses = new ArrayList<TrafficTypeImplementorResponse>();
for (Pair<TrafficType, String> r : results) {
TrafficTypeImplementorResponse p = new TrafficTypeImplementorResponse();
p.setTrafficType(r.first().toString());
p.setImplementor(r.second());
p.setObjectName("traffictypeimplementorresponse");
responses.add(p);
}
response.setResponses(responses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of org.apache.cloudstack.api.response.ListResponse in project cloudstack by apache.
the class ListTrafficTypesCmd method execute.
@Override
public void execute() {
Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(getPhysicalNetworkId());
ListResponse<TrafficTypeResponse> response = new ListResponse<TrafficTypeResponse>();
List<TrafficTypeResponse> trafficTypesResponses = new ArrayList<TrafficTypeResponse>();
if (trafficTypes != null) {
for (PhysicalNetworkTrafficType trafficType : trafficTypes.first()) {
TrafficTypeResponse trafficTypeResponse = _responseGenerator.createTrafficTypeResponse(trafficType);
trafficTypesResponses.add(trafficTypeResponse);
}
response.setResponses(trafficTypesResponses, trafficTypes.second());
response.setResponseName(getCommandName());
}
this.setResponseObject(response);
}
use of org.apache.cloudstack.api.response.ListResponse 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);
}
Aggregations