use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class OsInstallCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
log.info("OsInstallCompleter.complete {} {}", status.name(), coded);
Host host = dbClient.queryObject(Host.class, getId());
ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, jobId);
AuditLogManager auditMgr = AuditLogManagerFactory.getAuditLogManager();
if (status == Status.ready && job.getJobStatus().equals(JobStatus.SUCCESS.name())) {
// set host type based on image type
ComputeImage image = dbClient.queryObject(ComputeImage.class, job.getComputeImageId());
if (image.getImageType().equals(ComputeImage.ImageType.esx.name())) {
host.setType(Host.HostType.Esx.name());
host.setOsVersion(image.getOsVersion());
} else if (image.getImageType().equals(ComputeImage.ImageType.linux.name())) {
host.setType(Host.HostType.Linux.name());
host.setOsVersion(String.format("%s %s", image.getOsName(), image.getOsVersion()));
}
/*
* Create the IpInterface that represents the IpAddress that's
* supposed to come on the ESX Management Network (for ESX
* installations)
*/
IpInterface ipInterface = new IpInterface();
ipInterface.setHost(host.getId());
ipInterface.setId(URIUtil.createId(IpInterface.class));
ipInterface.setIpAddress(job.getHostIp());
ipInterface.setLabel(job.getHostName());
ipInterface.setNetmask(job.getNetmask());
ipInterface.setProtocol(HostInterface.Protocol.IPV4.toString());
ipInterface.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.toString());
dbClient.createObject(ipInterface);
/*
* End create IpInterface. Consider making this a seperate method.
*/
host.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
host.setProvisioningStatus(ProvisioningJobStatus.COMPLETE.toString());
dbClient.persistObject(host);
dbClient.ready(Host.class, getId(), getOpId());
auditMgr.recordAuditLog(null, null, serviceType, OperationTypeEnum.INSTALL_COMPUTE_IMAGE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, host.getId(), job.getId());
} else {
host.setProvisioningStatus(ProvisioningJobStatus.ERROR.toString());
dbClient.persistObject(host);
job.setJobStatus(JobStatus.FAILED.name());
dbClient.persistObject(job);
dbClient.error(Host.class, getId(), getOpId(), coded);
auditMgr.recordAuditLog(null, null, serviceType, OperationTypeEnum.INSTALL_COMPUTE_IMAGE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, host.getId(), job.getId());
}
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class HostService method provisionBareMetalHosts.
/**
* Provision bare metal hosts by taking compute elements from the compute
* virtual pool.
*
* @param param
* parameter for multiple host creation
* @brief Provision bare metal hosts
* @return TaskResourceRep (asynchronous call)
* @throws DatabaseException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/provision-bare-metal")
public TaskList provisionBareMetalHosts(ProvisionBareMetalHostsParam param) throws DatabaseException {
ComputeVirtualPool cvp = _dbClient.queryObject(ComputeVirtualPool.class, param.getComputeVpool());
ArgValidator.checkEntity(cvp, param.getComputeVpool(), false);
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, param.getVarray());
ArgValidator.checkEntity(varray, param.getVarray(), false);
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, param.getTenant());
ArgValidator.checkEntity(tenant, param.getTenant(), false);
if (!NullColumnValueGetter.isNullURI(param.getCluster())) {
Cluster cluster = _dbClient.queryObject(Cluster.class, param.getCluster());
ArgValidator.checkEntity(cluster, param.getCluster(), false);
}
_log.debug("checking if CVP is accessible");
_permissionsHelper.checkTenantHasAccessToComputeVirtualPool(tenant.getId(), cvp);
validateHostNames(param);
InterProcessLock lock = lockBladeReservation();
List<String> ceList = null;
try {
ceList = takeComputeElementsFromPool(cvp, param.getHostNames().size(), varray, param.getCluster());
} catch (Exception e) {
_log.error("unable to takeComputeElementsFromPool", e);
throw e;
} finally {
unlockBladeReservation(lock);
}
Set<Host> hosts = new HashSet<Host>();
for (int i = 0; i < param.getHostNames().size(); i++) {
Host host = populateHost(tenant, param.getHostNames().get(i), ceList.get(i), param.getCluster(), cvp.getId());
hosts.add(host);
_dbClient.createObject(host);
}
return createHostTasks(hosts, param.getComputeVpool(), param.getVarray());
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class IpInterfaceService method verifyUserPermisions.
/**
* Verify the user has read permission to the IP interface
*
* @param ipInterface the IP interface to be verified
*/
private void verifyUserPermisions(IpInterface ipInterface) {
// check the user permissions for the tenant org
Host host = queryObject(Host.class, ipInterface.getHost(), false);
verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class IpInterfaceService method getTenantOwner.
@Override
protected URI getTenantOwner(URI id) {
IpInterface ipInterface = queryObject(IpInterface.class, id, false);
Host host = queryObject(Host.class, ipInterface.getHost(), false);
return host.getTenant();
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class HostService method getInitiators.
/**
* Gets the id and name for all the host initiators of a host.
*
* @param id
* the URN of a ViPR Host
* @brief List host initiators
* @return a list of initiators that belong to the host
* @throws DatabaseException
* when a DB error occurs
*/
@GET
@Path("/{id}/initiators")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public InitiatorList getInitiators(@PathParam("id") URI id) throws DatabaseException {
Host host = queryObject(Host.class, id, false);
// check the user permissions
verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
// get the initiators
InitiatorList list = new InitiatorList();
List<NamedElementQueryResultList.NamedElement> dataObjects = listChildren(id, Initiator.class, "iniport", "host");
for (NamedElementQueryResultList.NamedElement dataObject : dataObjects) {
list.getInitiators().add(toNamedRelatedResource(ResourceTypeEnum.INITIATOR, dataObject.getId(), dataObject.getName()));
}
return list;
}
Aggregations