use of com.emc.storageos.imageservercontroller.ImageServerController in project coprhd-controller by CoprHD.
the class ComputeImageServerService method createComputeImageServer.
/**
* Create the Compute image server
*
* @param createParams
* {@link ComputeImageServerCreate} containing the details
*
* @brief Define a new image server, including TFTP info
* @return {@link TaskResourceRep} instance
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep createComputeImageServer(ComputeImageServerCreate createParams) {
log.info("Create computeImageServer");
String imageServerName = createParams.getName();
String imageServerAddress = createParams.getImageServerIp();
ArgValidator.checkFieldNotEmpty(imageServerName, "imageServerName");
ArgValidator.checkIpIsNotNumeric(imageServerAddress, IMAGESERVER_IP);
checkDuplicateImageServer(null, imageServerAddress, imageServerName);
String bootDir = createParams.getTftpBootDir();
String osInstallAddress = createParams.getImageServerSecondIp();
String username = createParams.getImageServerUser();
String password = createParams.getImageServerPassword();
Integer installTimeout = createParams.getOsInstallTimeout();
Integer sshTimeout = createParams.getSshTimeout();
Integer imageImportTimeout = createParams.getImageImportTimeout();
ArgValidator.checkFieldNotEmpty(bootDir, TFTPBOOTDIR);
ArgValidator.checkIpIsNotNumeric(osInstallAddress, IMAGESERVER_SECONDARY_IP);
ArgValidator.checkFieldNotEmpty(username, IMAGESERVER_USER);
ArgValidator.checkFieldNotEmpty(password, IMAGESERVER_PASSWORD);
ArgValidator.checkFieldNotNull(installTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "osInstallTimeout");
ArgValidator.checkFieldNotNull(sshTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(sshTimeout, 0, 2147483, "seconds", "sshTimeout");
ArgValidator.checkFieldNotNull(imageImportTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "imageImportTimeout");
ComputeImageServer imageServer = new ComputeImageServer();
imageServer.setId(URIUtil.createId(ComputeImageServer.class));
imageServer.setLabel(imageServerName);
imageServer.setImageServerIp(imageServerAddress);
imageServer.setTftpBootDir(bootDir);
imageServer.setImageServerUser(username);
imageServer.setImageServerPassword(password);
imageServer.setOsInstallTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(installTimeout)).intValue());
imageServer.setImageServerSecondIp(osInstallAddress);
imageServer.setImageDir(_coordinator.getPropertyInfo().getProperty(IMAGE_SERVER_IMAGEDIR));
imageServer.setSshTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(sshTimeout)).intValue());
imageServer.setImageImportTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(imageImportTimeout)).intValue());
auditOp(OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, true, null, imageServer.getId().toString(), imageServer.getImageServerIp());
_dbClient.createObject(imageServer);
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
AsyncTask task = new AsyncTask(ComputeImageServer.class, imageServer.getId(), taskId);
tasks.add(task);
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_VERIFY_COMPUTE_IMAGE_SERVER);
_dbClient.createTaskOpStatus(ComputeImageServer.class, imageServer.getId(), taskId, op);
ImageServerController controller = getController(ImageServerController.class, null);
controller.verifyImageServerAndImportExistingImages(task, op.getName());
return toTask(imageServer, taskId, op);
}
use of com.emc.storageos.imageservercontroller.ImageServerController in project coprhd-controller by CoprHD.
the class ComputeImageServerService method updateComputeImageServer.
/**
* Update the Compute image server details
*
* @param id
* the URN of a ViPR compute image server
*
* @brief Change an image server, including TFTP info
* @return Updated compute image server information.
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeImageServerRestRep updateComputeImageServer(@PathParam("id") URI id, ComputeImageServerUpdate param) {
log.info("Update computeImageServer id {} ", id);
ComputeImageServer imageServer = _dbClient.queryObject(ComputeImageServer.class, id);
if (null == imageServer || imageServer.getInactive()) {
throw APIException.notFound.unableToFindEntityInURL(id);
} else {
StringSet availImages = imageServer.getComputeImages();
// make sure there are no active jobs associated with this imageserver
checkActiveJobsForImageServer(id);
String imageServerName = param.getName();
String imageServerAddress = param.getImageServerIp();
String bootDir = param.getTftpBootDir();
String osInstallAddress = param.getImageServerSecondIp();
String username = param.getImageServerUser();
String password = param.getImageServerPassword();
Integer installTimeout = param.getOsInstallTimeout();
Integer sshTimeout = param.getSshTimeout();
Integer imageImportTimeout = param.getImageImportTimeout();
if (StringUtils.isNotBlank(imageServerName) && !imageServerName.equalsIgnoreCase(imageServer.getLabel())) {
checkDuplicateLabel(ComputeImageServer.class, imageServerName);
imageServer.setLabel(param.getName());
}
if (StringUtils.isNotBlank(imageServerAddress) && !imageServerAddress.equalsIgnoreCase(imageServer.getImageServerIp())) {
checkDuplicateImageServer(id, imageServerAddress, null);
disassociateComputeImages(imageServer);
imageServer.setImageServerIp(imageServerAddress);
}
if (StringUtils.isNotBlank(osInstallAddress)) {
imageServer.setImageServerSecondIp(osInstallAddress);
}
if (StringUtils.isNotBlank(username)) {
imageServer.setImageServerUser(username);
}
if (null != installTimeout) {
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "osInstallTimeout");
imageServer.setOsInstallTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(installTimeout)).intValue());
}
if (null != sshTimeout) {
ArgValidator.checkFieldRange(sshTimeout, 0, 2147483, "seconds", "sshTimeout");
imageServer.setSshTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(sshTimeout)).intValue());
}
if (null != imageImportTimeout) {
ArgValidator.checkFieldRange(imageImportTimeout, 0, 2147483, "seconds", "imageImportTimeout");
imageServer.setImageImportTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(imageImportTimeout)).intValue());
}
if (StringUtils.isNotBlank(bootDir)) {
if (!CollectionUtils.isEmpty(availImages) && !imageServer.getTftpBootDir().equals(bootDir)) {
log.info("Cannot update TFTPBOOT directory, while " + "an image server has associated successful import images.");
throw APIException.badRequests.cannotUpdateTFTPBOOTDirectory();
} else {
imageServer.setTftpBootDir(bootDir);
}
}
if (StringUtils.isNotBlank(password)) {
imageServer.setImageServerPassword(password);
}
auditOp(OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, true, null, imageServer.getId().toString(), imageServer.getImageServerIp());
_dbClient.updateObject(imageServer);
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
AsyncTask task = new AsyncTask(ComputeImageServer.class, imageServer.getId(), taskId);
tasks.add(task);
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UPDATE_VERIFY_COMPUTE_IMAGE_SERVER);
_dbClient.createTaskOpStatus(ComputeImageServer.class, imageServer.getId(), taskId, op);
ImageServerController controller = getController(ImageServerController.class, null);
controller.verifyImageServerAndImportExistingImages(task, op.getName());
}
return map(_dbClient, imageServer);
}
use of com.emc.storageos.imageservercontroller.ImageServerController in project coprhd-controller by CoprHD.
the class HostService method osInstall.
/**
* Install operating system on the host.
*
* @param hostId
* host URI
* @param param
* OS install data
* @brief Install operating system on the host
* @return TaskResourceRep (asynchronous call)
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/os-install")
public TaskResourceRep osInstall(@PathParam("id") URI hostId, OsInstallParam param) {
// validate params
ArgValidator.checkFieldUriType(hostId, Host.class, "id");
ArgValidator.checkFieldNotNull(param.getComputeImage(), "compute_image");
// get data
ComputeImage img = queryObject(ComputeImage.class, param.getComputeImage(), true);
ArgValidator.checkEntity(img, param.getComputeImage(), isIdEmbeddedInURL(param.getComputeImage()));
if (!ComputeImageStatus.AVAILABLE.name().equals(img.getComputeImageStatus())) {
throw APIException.badRequests.invalidParameterComputeImageIsNotAvailable(img.getId());
}
ArgValidator.checkFieldNotEmpty(param.getHostIp(), "host_ip");
Host host = queryObject(Host.class, hostId, true);
ArgValidator.checkEntity(host, hostId, isIdEmbeddedInURL(hostId));
// COP-28718 Fixed by making sure that the host we are installing OS does not cause an IP conflict
// by throwing appropriate exception.
verifyHostForDuplicateIP(host, param);
// only support os install on hosts with compute elements
if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
throw APIException.badRequests.invalidParameterHostHasNoComputeElement();
}
if (!host.getType().equals(Host.HostType.No_OS.name()) && !param.getForceInstallation()) {
throw APIException.badRequests.invalidParameterHostAlreadyHasOs(host.getType());
}
if (!StringUtils.isNotBlank(param.getRootPassword())) {
throw APIException.badRequests.hostPasswordNotSet();
} else {
host.setPassword(param.getRootPassword());
host.setUsername("root");
}
// check that CS has os install network
ComputeElement ce = queryObject(ComputeElement.class, host.getComputeElement(), true);
ArgValidator.checkEntity(ce, host.getComputeElement(), isIdEmbeddedInURL(host.getComputeElement()));
if (ce.getUuid() == null) {
throw APIException.badRequests.computeElementHasNoUuid();
}
ComputeSystem cs = queryObject(ComputeSystem.class, ce.getComputeSystem(), true);
ArgValidator.checkEntity(cs, ce.getComputeSystem(), isIdEmbeddedInURL(ce.getComputeSystem()));
verifyImagePresentOnImageServer(cs, img);
if (!StringUtils.isNotBlank(cs.getOsInstallNetwork())) {
throw APIException.badRequests.osInstallNetworkNotSet();
}
if (!cs.getVlans().contains(cs.getOsInstallNetwork())) {
throw APIException.badRequests.osInstallNetworkNotValid(cs.getOsInstallNetwork());
}
// check that there is no os install in progress for this host
URIQueryResultList jobUriList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeImageJobsByHostConstraint(host.getId()), jobUriList);
Iterator<URI> iterator = jobUriList.iterator();
while (iterator.hasNext()) {
ComputeImageJob existingJob = _dbClient.queryObject(ComputeImageJob.class, iterator.next());
if (!existingJob.getInactive() && existingJob.getJobStatus().equals(ComputeImageJob.JobStatus.CREATED.name())) {
throw APIException.badRequests.osInstallAlreadyInProgress();
}
}
// openssl passwd -1 (MD5 encryption of password)
String passwordHash = Md5Crypt.md5Crypt(host.getPassword().getBytes());
// create session
ComputeImageJob job = new ComputeImageJob();
job.setId(URIUtil.createId(ComputeImageJob.class));
job.setComputeImageId(img.getId());
job.setHostId(host.getId());
job.setPasswordHash(passwordHash);
job.setHostName(param.getHostName());
job.setHostIp(param.getHostIp());
job.setNetmask(param.getNetmask());
job.setGateway(param.getGateway());
job.setNtpServer(param.getNtpServer());
job.setDnsServers(param.getDnsServers());
job.setManagementNetwork(param.getManagementNetwork());
job.setPxeBootIdentifier(ImageServerUtils.uuidFromString(host.getUuid()).toString());
job.setComputeImageServerId(cs.getComputeImageServer());
// volume id is optional
if (!NullColumnValueGetter.isNullURI(param.getVolume()) || !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
Volume vol = null;
if (!NullColumnValueGetter.isNullURI(param.getVolume())) {
vol = queryObject(Volume.class, param.getVolume(), true);
host.setBootVolumeId(vol.getId());
} else {
vol = queryObject(Volume.class, host.getBootVolumeId(), true);
}
job.setVolumeId(vol.getId());
StorageSystem st = queryObject(StorageSystem.class, vol.getStorageController(), true);
// XtremIO uses some other ID type (e.g. 514f0c5dc9600016)
if (st != null && DiscoveredDataObject.Type.xtremio.name().equals(st.getSystemType())) {
_log.info("xtremio volume id {}", vol.getNativeId());
job.setBootDevice(vol.getNativeId());
} else {
_log.info("volume id {}", vol.getWWN());
job.setBootDevice(ImageServerUtils.uuidFromString(vol.getWWN()).toString());
}
}
host.setProvisioningStatus(ProvisioningJobStatus.IN_PROGRESS.toString());
_dbClient.persistObject(host);
_dbClient.createObject(job);
// create task
String taskId = UUID.randomUUID().toString();
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM);
_dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, op);
ImageServerController controller = getController(ImageServerController.class, null);
AsyncTask task = new AsyncTask(Host.class, host.getId(), taskId);
try {
controller.installOperatingSystem(task, job.getId());
} catch (InternalException e) {
_log.error("Did not install OS due to controller error", e);
job.setJobStatus(ComputeImageJob.JobStatus.FAILED.name());
_dbClient.persistObject(job);
_dbClient.error(Host.class, host.getId(), taskId, e);
}
return toTask(host, taskId, op);
}
use of com.emc.storageos.imageservercontroller.ImageServerController in project coprhd-controller by CoprHD.
the class ComputeImageService method doRemoveImage.
/*
* Schedules the remove task.
*/
private TaskResourceRep doRemoveImage(ComputeImage ci) {
log.info("doRemoveImage");
ImageServerController controller = getController(ImageServerController.class, null);
AsyncTask task = new AsyncTask(ComputeImage.class, ci.getId(), UUID.randomUUID().toString());
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.REMOVE_IMAGE);
_dbClient.createTaskOpStatus(ComputeImage.class, ci.getId(), task._opId, op);
controller.deleteImage(task);
log.info("Removing image " + ci.getImageName());
return TaskMapper.toTask(ci, task._opId, op);
}
use of com.emc.storageos.imageservercontroller.ImageServerController in project coprhd-controller by CoprHD.
the class ComputeImageService method doImportImage.
/*
* Schedules the import task.
*/
private TaskResourceRep doImportImage(ComputeImage ci) {
log.info("doImportImage");
ImageServerController controller = getController(ImageServerController.class, null);
AsyncTask task = new AsyncTask(ComputeImage.class, ci.getId(), UUID.randomUUID().toString());
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.IMPORT_IMAGE);
_dbClient.createTaskOpStatus(ComputeImage.class, ci.getId(), task._opId, op);
controller.importImageToServers(task);
return TaskMapper.toTask(ci, task._opId, op);
}
Aggregations