use of com.cloud.api.response.HostResponse in project CloudStack-archive by CloudStack-extras.
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(BaseCmd.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(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
}
use of com.cloud.api.response.HostResponse in project CloudStack-archive by CloudStack-extras.
the class ListHostsCmd method execute.
@Override
public void execute() {
List<? extends Host> result = new ArrayList<Host>();
List<? extends Host> hostsWithCapacity = new ArrayList<Host>();
if (getVirtualMachineId() != null) {
Pair<List<? extends Host>, List<? extends Host>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), this.getStartIndex(), this.getPageSizeVal());
result = hostsForMigration.first();
hostsWithCapacity = hostsForMigration.second();
} else {
result = _mgr.searchForServers(this);
}
ListResponse<HostResponse> response = new ListResponse<HostResponse>();
List<HostResponse> hostResponses = new ArrayList<HostResponse>();
for (Host host : result) {
HostResponse hostResponse = _responseGenerator.createHostResponse(host, getDetails());
Boolean suitableForMigration = false;
if (hostsWithCapacity.contains(host)) {
suitableForMigration = true;
}
hostResponse.setSuitableForMigration(suitableForMigration);
hostResponse.setObjectName("host");
hostResponses.add(hostResponse);
}
response.setResponses(hostResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
Aggregations