cloudstack/server/src/com/cloud/api/AddPxeServerCmd.java

132 lines
4.7 KiB
Java

package com.cloud.api;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.PxeServerResponse;
import com.cloud.baremetal.LinMinPxeServerManager;
import com.cloud.baremetal.PxeServerManager;
import com.cloud.baremetal.PxeServerManager.PxeServerType;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.Host;
import com.cloud.server.ManagementService;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
@Implementation(description="Adds a PXE server appliance", responseObject = PxeServerResponse.class)
public class AddPxeServerCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddPxeServerCmd.class.getName());
private static final String s_name = "addpxeserverresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required = true, description="Zone in which to add the external firewall appliance.")
private Long zoneId;
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, required = true, description="Zone in which to add the external firewall appliance.")
private Long podId;
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the PXE server appliance.")
private String url;
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Username of PXE server appliance.")
private String username;
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Password of the PXE server appliance.")
private String password;
@Parameter(name=ApiConstants.PXE_SERVER_TYPE, type=CommandType.STRING, required = true, description="Type of PXE server. Current values are LinMin, DMCD")
private String type;
@Parameter(name=ApiConstants.LINMIN_USERNAME, type=CommandType.STRING, required = false, description="Optional, username uses to access LinMin API")
private String linminUsername;
@Parameter(name=ApiConstants.LINMIN_PASSWORD, type=CommandType.STRING, required = false, description="Optional, password uses to access LinMin API")
private String linminPassword;
@Parameter(name=ApiConstants.LINMIN_APID, type=CommandType.STRING, required = false, description="Optional, APID uses to access LinMin API")
private String linminApid;
///////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getZoneId() {
return zoneId;
}
public String getUrl() {
return url;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getType() {
return type;
}
public Long getPod() {
return podId;
}
public String getLinMinUsername() {
return linminUsername;
}
public String getLinMinPassword() {
return linminPassword;
}
public String getLinMinApid() {
return linminApid;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException {
try {
PxeServerManager pxeServerMgr;
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
if (getType().equalsIgnoreCase(PxeServerType.LinMin.getName())) {
pxeServerMgr = locator.getManager(LinMinPxeServerManager.class);
} else {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unsupport PXE server type " + getType());
}
Host pxeServer = pxeServerMgr.addPxeServer(this);
PxeServerResponse response = pxeServerMgr.getApiResponse(pxeServer);
response.setObjectName("pxeserver");
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException ipve) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage());
} catch (CloudRuntimeException cre) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage());
}
}
}