use of org.onosproject.k8snetworking.api.K8sIpam in project onos by opennetworkinglab.
the class K8sIpamCodecTest method testK8sIpamDecode.
/**
* Tests the kubernetes IPAM decoding.
*/
@Test
public void testK8sIpamDecode() throws IOException {
K8sIpam ipam = getK8sIpam("K8sIpam.json");
assertEquals("10.10.10.2", ipam.ipAddress().toString());
assertEquals("network-1", ipam.networkId());
}
use of org.onosproject.k8snetworking.api.K8sIpam 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.K8sIpam 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.K8sIpam in project onos by opennetworkinglab.
the class K8sIpamCodecTest method testK8sIpamEncode.
/**
* Tests the kubernetes IPAM encoding.
*/
@Test
public void testK8sIpamEncode() {
K8sIpam ipam = new DefaultK8sIpam("network-1-10.10.10.10", IpAddress.valueOf("10.10.10.10"), "network-1");
ObjectNode nodeJson = k8sIpamCodec.encode(ipam, context);
assertThat(nodeJson, matchesK8sIpam(ipam));
}
use of org.onosproject.k8snetworking.api.K8sIpam in project onos by opennetworkinglab.
the class K8sIpamCodecTest method getK8sIpam.
/**
* Reads in an kubernetes IPAM from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule
* @return decoded kubernetes node
* @throws IOException if processing the resource fails
*/
private K8sIpam getK8sIpam(String resourceName) throws IOException {
InputStream jsonStream = K8sIpamCodecTest.class.getResourceAsStream(resourceName);
JsonNode json = context.mapper().readTree(jsonStream);
MatcherAssert.assertThat(json, notNullValue());
K8sIpam node = k8sIpamCodec.decode((ObjectNode) json, context);
assertThat(node, notNullValue());
return node;
}
Aggregations