use of org.onosproject.k8snetworking.api.DefaultK8sIpam in project onos by opennetworkinglab.
the class K8sIpamManager method reserveIp.
@Override
public void reserveIp(String networkId, IpAddress ipAddress) {
if (!allocatedIps(networkId).contains(ipAddress)) {
String ipamId = networkId + "-" + ipAddress.toString();
k8sIpamStore.removeAvailableIp(ipamId);
k8sIpamStore.createAllocatedIp(new DefaultK8sIpam(ipamId, ipAddress, networkId));
log.info("Reserved the IP {}", ipAddress.toString());
}
}
use of org.onosproject.k8snetworking.api.DefaultK8sIpam in project onos by opennetworkinglab.
the class K8sIpamWebResource method allocateIp.
/**
* Requests for allocating a unique IP address of the given network ID.
*
* @param netId network identifier
* @return 200 OK with the serialized IPAM JSON string
* @onos.rsModel K8sIpam
*/
@GET
@Path("{netId}")
@Produces(MediaType.APPLICATION_JSON)
public Response allocateIp(@PathParam("netId") String netId) {
log.trace("Received IP allocation request of network " + netId);
K8sNetwork network = nullIsNotFound(networkService.network(netId), NETWORK_ID_NOT_FOUND);
IpAddress ip = nullIsNotFound(ipamService.allocateIp(network.networkId()), IP_NOT_ALLOCATED);
ObjectNode root = mapper().createObjectNode();
String ipamId = network.networkId() + "-" + ip.toString();
K8sIpam ipam = new DefaultK8sIpam(ipamId, ip, network.networkId());
root.set(IPAM, codec(K8sIpam.class).encode(ipam, this));
return ok(root).build();
}
use of org.onosproject.k8snetworking.api.DefaultK8sIpam in project onos by opennetworkinglab.
the class K8sIpamManager method releaseIp.
@Override
public boolean releaseIp(String networkId, IpAddress ipAddress) {
IpAddress releasedIp = allocatedIps(networkId).stream().filter(ip -> ip.equals(ipAddress)).findFirst().orElse(null);
if (releasedIp != null) {
String ipamId = networkId + "-" + releasedIp.toString();
k8sIpamStore.removeAllocatedIp(ipamId);
k8sIpamStore.createAvailableIp(new DefaultK8sIpam(ipamId, releasedIp, networkId));
log.info("Release the IP {}", releasedIp.toString());
return true;
} else {
log.warn("Failed to find requested IP {} for releasing...", ipAddress.toString());
}
return false;
}
use of org.onosproject.k8snetworking.api.DefaultK8sIpam in project onos by opennetworkinglab.
the class K8sIpamManager method initializeIpPool.
@Override
public void initializeIpPool(String networkId, Set<IpAddress> ipAddresses) {
ipAddresses.forEach(ip -> {
String ipamId = networkId + "-" + ip;
K8sIpam ipam = new DefaultK8sIpam(ipamId, ip, networkId);
k8sIpamStore.createAvailableIp(ipam);
});
}
use of org.onosproject.k8snetworking.api.DefaultK8sIpam in project onos by opennetworkinglab.
the class K8sIpamManager method allocateIp.
@Override
public IpAddress allocateIp(String networkId) {
IpAddress availableIp = availableIps(networkId).stream().findFirst().orElse(null);
if (availableIp != null) {
String ipamId = networkId + "-" + availableIp.toString();
k8sIpamStore.removeAvailableIp(ipamId);
k8sIpamStore.createAllocatedIp(new DefaultK8sIpam(ipamId, availableIp, networkId));
log.info("Allocate a new IP {}", availableIp.toString());
return availableIp;
} else {
log.warn("No IPs are available for allocating.");
}
return null;
}
Aggregations