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;
}
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());
}
}
}
}
}
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);
}
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);
}
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);
}
Aggregations