Search in sources :

Example 1 with DefaultK8sIpam

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());
    }
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam)

Example 2 with DefaultK8sIpam

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();
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sIpam(org.onosproject.k8snetworking.api.K8sIpam) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) IpAddress(org.onlab.packet.IpAddress) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with DefaultK8sIpam

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;
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) IpAddress(org.onlab.packet.IpAddress)

Example 4 with DefaultK8sIpam

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);
    });
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) K8sIpam(org.onosproject.k8snetworking.api.K8sIpam) DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam)

Example 5 with DefaultK8sIpam

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;
}
Also used : DefaultK8sIpam(org.onosproject.k8snetworking.api.DefaultK8sIpam) IpAddress(org.onlab.packet.IpAddress)

Aggregations

DefaultK8sIpam (org.onosproject.k8snetworking.api.DefaultK8sIpam)6 IpAddress (org.onlab.packet.IpAddress)3 K8sIpam (org.onosproject.k8snetworking.api.K8sIpam)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Test (org.junit.Test)1 K8sNetwork (org.onosproject.k8snetworking.api.K8sNetwork)1 K8sIpamJsonMatcher.matchesK8sIpam (org.onosproject.k8snetworking.codec.K8sIpamJsonMatcher.matchesK8sIpam)1