use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class ListBaremetalRctCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
ListResponse<BaremetalRctResponse> response = new ListResponse<>();
List<BaremetalRctResponse> rctResponses = new ArrayList<>();
BaremetalRctResponse rsp = vlanMgr.listRct();
if (rsp != null) {
rctResponses.add(rsp);
}
response.setResponses(rctResponses);
response.setResponseName(getCommandName());
response.setObjectName("baremetalrcts");
this.setResponseObject(response);
} catch (Exception e) {
s_logger.debug("Exception happened while executing ListBaremetalRctCmd", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class BaremetalDhcpManagerImpl method addVirtualMachineIntoNetwork.
@Override
public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
Long zoneId = profile.getVirtualMachine().getDataCenterId();
Long podId = profile.getVirtualMachine().getPodIdToDeployIn();
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, podId, zoneId);
if (hosts.size() == 0) {
throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId);
}
if (hosts.size() > 1) {
throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId);
}
HostVO h = hosts.get(0);
String dns = nic.getIPv4Dns1();
if (dns == null) {
dns = nic.getIPv4Dns2();
}
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getIPv4Gateway(), null, _ntwkModel.getExecuteInSeqNtwkElmtCmd());
String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName());
// prepareBareMetalDhcpEntry(nic, dhcpCommand);
try {
Answer ans = _agentMgr.send(h.getId(), dhcpCommand);
if (ans.getResult()) {
s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()));
return true;
} else {
s_logger.debug(errMsg + " " + ans.getDetails());
throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId);
}
} catch (Exception e) {
s_logger.debug(errMsg, e);
throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId);
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class AddBaremetalPxeCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
BaremetalPxeVO vo = pxeMgr.addPxeServer(this);
BaremetalPxeResponse rsp = pxeMgr.getApiResponse(vo);
rsp.setResponseName(getCommandName());
this.setResponseObject(rsp);
} catch (Exception e) {
s_logger.warn("Unable to add external pxe server with url: " + getUrl(), e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class AddBaremetalRctCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
BaremetalRctResponse rsp = vlanMgr.addRct(this);
this.setResponseObject(rsp);
} catch (Exception e) {
s_logger.warn(String.format("unable to add baremetal RCT[%s]", getRctUrl()), e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.
the class DeleteBaremetalRctCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
vlanMgr.deleteRct(this);
SuccessResponse response = new SuccessResponse(getCommandName());
setResponseObject(response);
} catch (Exception e) {
s_logger.warn(String.format("unable to delete baremetal RCT[%s]", getId()), e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage(), e);
}
}
Aggregations