use of com.emc.storageos.db.client.model.ComputeSystem 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.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class VirtualArrayService method getServiceProfileTemplatesForComputeSystem.
private List<NamedRelatedResourceRep> getServiceProfileTemplatesForComputeSystem(URI computeSystemId, URI varrayId) {
List<NamedRelatedResourceRep> templates = new ArrayList<NamedRelatedResourceRep>();
ComputeSystem computeSystem = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayId);
_log.debug("Finding SPTs from Compute System:" + computeSystem.getLabel() + " valid for varray:" + varray.getLabel());
List<NamedRelatedResourceRep> spts = computeSystemService.getServiceProfileTemplatesForComputeSystem(computeSystem, _dbClient);
StringSet varrays = new StringSet();
varrays.add(varrayId.toString());
// Filter SPTs that are not valid for the varrays for the UCS in this vcp
for (NamedRelatedResourceRep spt : spts) {
if (computeSystemService.isServiceProfileTemplateValidForVarrays(varrays, spt.getId())) {
templates.add(spt);
_log.debug("SPT " + spt.getName() + " is valid for the varray:" + varray.getLabel());
} else {
_log.debug("SPT " + spt.getName() + " is not valid for the varray:" + varray.getLabel());
}
}
return templates;
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class VirtualArrayService method getComputeSystems.
/**
* Fetches all Compute Systems that are visible in the vArray
*
* First determine physical connectivity to any switches in the vArrray.
* 1. From the vArray, determine the networks. (Call this Network Set)
* 2. From the networks, get the physical switches that are attached.
* 3. For each physical switch, iterate through the networks and get the FC endpoints.
* 4. Look for any of the FIC ports in any of the FC endpoints on any of the
* networks on the physical switch. When a FIC port matches, call this FIC
* Port.
* 5. If found, then there is physical connectivity.
*
* With physical connectivity Established:
* 1. Given the FIC Port from step (4), pull the VSAN or VSANs assigned to
* it on UCS.
* 2. If the set contains one of the networks from the Network
* Set in (1), we have connectivity to that vArray.
*
* @param id
* the URN of a ViPR VirtualArray.
* @brief List all Compute Systems that are visible in the vArray
* @return List of Compute Systems
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/compute-systems")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public ComputeSystemBulkRep getComputeSystems(@PathParam("id") URI id) {
_log.info("get connected CS for vArray: {}", id);
// Get and validate the varray with the passed id.
ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
ArgValidator.checkEntityNotNull(varray, id, isIdEmbeddedInURL(id));
BulkIdParam matchingCsIds = new BulkIdParam();
// get varray networks
List<Network> networks = CustomQueryUtility.queryActiveResourcesByRelation(_dbClient, id, Network.class, "connectedVirtualArrays");
// collect network vsanIds and switch ids
Set<String> networkVsanIds = new HashSet<>();
Set<String> nsIds = new HashSet<>();
for (Network network : networks) {
if (StorageProtocol.Transport.FC.name().equalsIgnoreCase(network.getTransportType()) && DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(network.getRegistrationStatus())) {
networkVsanIds.add(network.getNativeId());
if (network.getNetworkSystems() != null) {
nsIds.addAll(network.getNetworkSystems());
}
}
}
_log.info("vArray has these networks: {}", networkVsanIds);
// use only registered network systems
Set<URI> nsUris = new HashSet<>();
for (String nsUri : nsIds) {
nsUris.add(URI.create(nsUri));
}
List<NetworkSystem> nsList = _dbClient.queryObject(NetworkSystem.class, nsUris);
for (NetworkSystem ns : nsList) {
if (!DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(ns.getRegistrationStatus())) {
nsIds.remove(ns.getId().toString());
}
}
_log.info("the networks run on these network systems: {}", nsIds);
if (networkVsanIds.isEmpty() || nsIds.isEmpty()) {
// no networks in the array - exit early
return new ComputeSystemBulkRep();
}
// for every switch get FCEndpoint.remotePortName(s)
Set<String> connectedEndpoints = new HashSet<String>();
for (String nsId : nsIds) {
URIQueryResultList uriList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(URI.create(nsId)), uriList);
List<URI> epIds = new ArrayList<URI>();
Iterator<URI> iter = uriList.iterator();
while (iter.hasNext()) {
epIds.add(iter.next());
}
List<FCEndpoint> eps = _dbClient.queryObjectField(FCEndpoint.class, "remotePortName", epIds);
for (FCEndpoint ep : eps) {
connectedEndpoints.add(ep.getRemotePortName());
}
}
_log.debug("all connected endpoints: {}", connectedEndpoints);
// get all CS
List<URI> csIds = _dbClient.queryByType(ComputeSystem.class, true);
List<ComputeSystem> csList = _dbClient.queryObject(ComputeSystem.class, csIds);
for (ComputeSystem cs : csList) {
if (!DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(cs.getRegistrationStatus())) {
// skip not registered CS
continue;
}
boolean connected = false;
_log.info("evaluating uplinks of cs: {}", cs.getLabel());
// loop thru UplinkPorts to find matches
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeFabricUplinkPortConstraint(cs.getId()), uris);
List<ComputeFabricUplinkPort> uplinkPorts = _dbClient.queryObject(ComputeFabricUplinkPort.class, uris, true);
for (ComputeFabricUplinkPort port : uplinkPorts) {
if (connectedEndpoints.contains(port.getWwpn())) {
_log.info("found matching endpoint: {}", port.getWwpn());
if (!Collections.disjoint(port.getVsans(), networkVsanIds)) {
_log.info("and networks overlap: {}", port.getVsans());
matchingCsIds.getIds().add(cs.getId());
connected = true;
break;
}
}
}
if (connected) {
// skip uplink port channel matching as we are already connected
continue;
}
// now loop thru UplinkPortChannels to find matches
uris = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeUplinkPortChannelConstraint(cs.getId()), uris);
List<ComputeFabricUplinkPortChannel> uplinkPortChannels = _dbClient.queryObject(ComputeFabricUplinkPortChannel.class, uris, true);
for (ComputeFabricUplinkPortChannel port : uplinkPortChannels) {
if (connectedEndpoints.contains(port.getWwpn())) {
_log.info("found matching endpoint: {}", port.getWwpn());
if (!Collections.disjoint(port.getVsans(), networkVsanIds)) {
_log.info("and networks overlap: {}", port.getVsans());
matchingCsIds.getIds().add(cs.getId());
connected = true;
break;
}
}
}
}
_log.info("these CS are connected to the vArray: {}", matchingCsIds.getIds());
if (matchingCsIds.getIds().isEmpty()) {
return new ComputeSystemBulkRep();
}
ComputeSystemBulkRep computeSystemReps = computeSystemService.getBulkResources(matchingCsIds);
return mapValidServiceProfileTemplatesToComputeSystem(computeSystemReps, varray.getId());
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class ComputeSystemUtils method queryRegisteredSystem.
/**
* Gets the compute system with the passed id from the database.
*
* @param id
* the URN of a ViPR compute system
*
* @return A detailed representation of the registered ComputeSystem.
*
* @throws BadRequestException
* When the compute system is not registered.
*/
public static ComputeSystem queryRegisteredSystem(URI id, DbClient _dbClient, boolean isIdEmbeddedInURL) {
ArgValidator.checkUri(id);
ComputeSystem system = _dbClient.queryObject(ComputeSystem.class, id);
ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL);
if (!RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(system.getRegistrationStatus())) {
throw APIException.badRequests.resourceNotRegistered(ComputeSystem.class.getSimpleName(), id);
}
return system;
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class ComputeImageServerService method removeImageServerFromComputeSystem.
/**
* Removes the given imageServerId from each ComputeSystem present,
* if the computeSystem has the given imageServerId as it association or relation.
* Disassociate's the imageServer from the computeSystem.
* @param imageServerID {@link URI} computeImageServer id
*/
private void removeImageServerFromComputeSystem(URI imageServerID) {
// Remove the association with the ComputeSystem and then delete
// the imageServer
List<URI> computeSystemURIList = _dbClient.queryByType(ComputeSystem.class, true);
if (computeSystemURIList != null && computeSystemURIList.iterator().hasNext()) {
List<ComputeSystem> computeSystems = _dbClient.queryObject(ComputeSystem.class, computeSystemURIList);
if (!CollectionUtils.isEmpty(computeSystems)) {
for (ComputeSystem computeSystem : computeSystems) {
if (computeSystem.getComputeImageServer() != null && computeSystem.getComputeImageServer().equals(imageServerID)) {
computeSystem.setComputeImageServer(NullColumnValueGetter.getNullURI());
_dbClient.updateObject(computeSystem);
log.info("Disassociating imageServer {} from ComputeSystem id {} ", imageServerID, computeSystem.getId());
}
}
}
}
}
Aggregations