Search in sources :

Example 11 with Host

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());
    }
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) AuditLogManager(com.emc.storageos.security.audit.AuditLogManager) Host(com.emc.storageos.db.client.model.Host) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 12 with Host

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());
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Cluster(com.emc.storageos.db.client.model.Cluster) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) Host(com.emc.storageos.db.client.model.Host) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 13 with Host

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());
}
Also used : Host(com.emc.storageos.db.client.model.Host)

Example 14 with Host

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();
}
Also used : MapIpInterface(com.emc.storageos.api.mapper.functions.MapIpInterface) IpInterface(com.emc.storageos.db.client.model.IpInterface) Host(com.emc.storageos.db.client.model.Host)

Example 15 with Host

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;
}
Also used : Host(com.emc.storageos.db.client.model.Host) InitiatorList(com.emc.storageos.model.host.InitiatorList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16