Search in sources :

Example 21 with IpInterface

use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.

the class AbstractDiscoveryAdapter method getOrCreateInterfaceByIp.

/**
 * Finds a matching value in the list of IpInterfaces by ipAddress, or creates one if none is found. If a match is
 * found in
 * the list, it will be removed from the list before returning.
 *
 * @param models
 *            the list of IpInterface models.
 * @param ip
 *            the ip to match.
 * @return the matched value, or a new instance created with the specified ip.
 */
protected IpInterface getOrCreateInterfaceByIp(List<IpInterface> models, String ip) {
    IpInterface model = findInterfaceByIp(models, ip);
    if (model == null) {
        model = new IpInterface();
        model.setIsManualCreation(false);
        model.setIpAddress(ip);
        model.setLabel(ip);
    } else {
        models.remove(model);
    }
    return model;
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface)

Example 22 with IpInterface

use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.

the class HostService method verifyHostForDuplicateIP.

/**
 * Verifies the host being installed does not conflict with existing host IPs.
 * @param host {@link Host} host being newly provisioned.
 * @param param {@link OsInstallParam}
 *
 * @throws APIException
 */
private void verifyHostForDuplicateIP(Host host, OsInstallParam param) throws APIException {
    Collection<URI> ipInterfaceURIS = _dbClient.queryByType(IpInterface.class, true);
    Collection<IpInterface> ipInterfaces = _dbClient.queryObjectFields(IpInterface.class, Arrays.asList("ipAddress", "host"), ControllerUtils.getFullyImplementedCollection(ipInterfaceURIS));
    if (CollectionUtils.isNotEmpty(ipInterfaces) && StringUtils.isNotEmpty(param.getHostIp())) {
        _log.info("Validating host {} for duplicate IPs.", host.getLabel());
        for (IpInterface ipInterface : ipInterfaces) {
            if (ipInterface.getIpAddress() != null && ipInterface.getIpAddress().equals(param.getHostIp())) {
                if (!NullColumnValueGetter.isNullURI(ipInterface.getHost())) {
                    Host hostWithSameIp = _dbClient.queryObject(Host.class, ipInterface.getHost());
                    if (hostWithSameIp != null) {
                        _log.error("Found duplicate IP {} for existing host {}.  Host with same IP exists already.", param.getHostIp(), hostWithSameIp.getLabel());
                        throw APIException.badRequests.hostWithDuplicateIP(host.getLabel(), param.getHostIp(), hostWithSameIp.getLabel());
                    } else {
                        // If there is a valid IpInterface object, but the host inside it is no longer in the
                        // database, then we take this opportunity to clear out the object before it causes more
                        // issues.
                        _log.warn("Found duplicate IP {} for non-existent host URI {}.  Deleting IP Interface.", param.getHostIp(), ipInterface.getHost().toString());
                        _dbClient.markForDeletion(ipInterface);
                    }
                } else {
                    _log.error("Found duplicate IP {} for IpInterface {}.  IpInterface with same IP exists already.", param.getHostIp(), ipInterface.getId().toString());
                    throw APIException.badRequests.hostWithDuplicateIP(host.getLabel(), param.getHostIp(), ipInterface.getLabel());
                }
            }
        }
    }
}
Also used : IpInterface(com.emc.storageos.db.client.model.IpInterface) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 23 with IpInterface

use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.

the class IpInterfaceService method deregisterIpInterface.

/**
 * Allows the user to deregister a registered IP interface so that it is no
 * longer used by the system. This simply sets the registration_status of
 * the IP interface to UNREGISTERED.
 *
 * @param id the URN of a ViPR IP interface
 *
 * @brief Unregister IP interface
 * @return Status response indicating success or failure
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.TENANT_ADMIN })
public IpInterfaceRestRep deregisterIpInterface(@PathParam("id") URI id) {
    IpInterface ipInterface = queryResource(id);
    ArgValidator.checkEntity(ipInterface, id, isIdEmbeddedInURL(id));
    if (ComputeSystemHelper.isHostIpInterfacesInUse(_dbClient, Collections.singletonList(ipInterface.getIpAddress()), ipInterface.getHost())) {
        throw APIException.badRequests.resourceHasActiveReferencesWithType(IpInterface.class.getSimpleName(), ipInterface.getId(), FileExport.class.getSimpleName());
    }
    if (RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(ipInterface.getRegistrationStatus())) {
        ipInterface.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        _dbClient.persistObject(ipInterface);
        auditOp(OperationTypeEnum.DEREGISTER_HOST_IPINTERFACE, true, null, ipInterface.getLabel(), ipInterface.getId().toString());
    }
    return map(ipInterface);
}
Also used : MapIpInterface(com.emc.storageos.api.mapper.functions.MapIpInterface) IpInterface(com.emc.storageos.db.client.model.IpInterface) FileExport(com.emc.storageos.db.client.model.FileExport) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 24 with IpInterface

use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.

the class IpInterfaceService method registerIpInterface.

/**
 * Manually register the IP interface with the passed id.
 *
 * @param id the URN of a ViPR IP interface
 *
 * @brief Register IP interface
 * @return A reference to an IpInterfaceRestRep specifying the data for the
 *         IP interface.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/register")
public IpInterfaceRestRep registerIpInterface(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, IpInterface.class, "id");
    IpInterface ipInterface = _dbClient.queryObject(IpInterface.class, id);
    ArgValidator.checkEntity(ipInterface, id, isIdEmbeddedInURL(id));
    if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(ipInterface.getRegistrationStatus())) {
        ipInterface.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
        _dbClient.persistObject(ipInterface);
        auditOp(OperationTypeEnum.REGISTER_HOST_IPINTERFACE, true, null, ipInterface.getId().toString());
    }
    return map(ipInterface);
}
Also used : MapIpInterface(com.emc.storageos.api.mapper.functions.MapIpInterface) IpInterface(com.emc.storageos.db.client.model.IpInterface) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 25 with IpInterface

use of com.emc.storageos.db.client.model.IpInterface in project coprhd-controller by CoprHD.

the class IpInterfaceService method getIpInterface.

/**
 * Shows the data for an IP interface
 *
 * @param id the URN of a ViPR IP interface
 *
 * @prereq none
 * @brief Show IP interface
 * @return A IpInterfaceRestRep reference specifying the data for the
 *         IP interface with the passed id.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.SYSTEM_ADMIN, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public IpInterfaceRestRep getIpInterface(@PathParam("id") URI id) {
    IpInterface ipInterface = queryResource(id);
    // verify permissions
    verifyUserPermisions(ipInterface);
    return HostMapper.map(ipInterface);
}
Also used : MapIpInterface(com.emc.storageos.api.mapper.functions.MapIpInterface) IpInterface(com.emc.storageos.db.client.model.IpInterface) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

IpInterface (com.emc.storageos.db.client.model.IpInterface)27 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7 URI (java.net.URI)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 MapIpInterface (com.emc.storageos.api.mapper.functions.MapIpInterface)6 Host (com.emc.storageos.db.client.model.Host)6 POST (javax.ws.rs.POST)4 Initiator (com.emc.storageos.db.client.model.Initiator)3 IPInterface (com.iwave.ext.linux.model.IPInterface)3 ArrayList (java.util.ArrayList)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 FileExport (com.emc.storageos.db.client.model.FileExport)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 AixSystem (com.emc.aix.AixSystem)1 HpuxSystem (com.emc.hpux.HpuxSystem)1 MapNetwork (com.emc.storageos.api.mapper.functions.MapNetwork)1 ComputeSystemController (com.emc.storageos.computesystemcontroller.ComputeSystemController)1 DbClient (com.emc.storageos.db.client.DbClient)1