use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.
the class KubevirtListFloatingIpCommand method json.
private String json(List<KubevirtFloatingIp> fips) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (KubevirtFloatingIp fip : fips) {
result.add(jsonForEntity(fip, KubevirtFloatingIp.class));
}
return prettyJson(mapper, result.toString());
}
use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.
the class KubevirtFloatingIpCodec method decode.
@Override
public KubevirtFloatingIp decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String id = nullIsIllegal(json.get(ID).asText(), ID + MISSING_MESSAGE);
String routerName = nullIsIllegal(json.get(ROUTER_NAME).asText(), ROUTER_NAME + MISSING_MESSAGE);
String floatingIp = nullIsIllegal(json.get(FLOATING_IP).asText(), FLOATING_IP + MISSING_MESSAGE);
String networkName = nullIsIllegal(json.get(NETWORK_NAME).asText(), NETWORK_NAME + MISSING_MESSAGE);
KubevirtFloatingIp.Builder builder = DefaultKubevirtFloatingIp.builder().id(id).routerName(routerName).networkName(networkName).floatingIp(IpAddress.valueOf(floatingIp));
JsonNode podName = json.get(POD_NAME);
if (podName != null) {
builder.podName(podName.asText());
}
JsonNode vmName = json.get(VM_NAME);
if (vmName != null) {
builder.vmName(vmName.asText());
}
JsonNode fixedIp = json.get(FIXED_IP);
if (fixedIp != null) {
builder.fixedIp(IpAddress.valueOf(fixedIp.asText()));
}
return builder.build();
}
use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.
the class KubevirtFloatingIpCodecTest method testKubevirtFloatingIpDecode.
@Test
public void testKubevirtFloatingIpDecode() throws IOException {
KubevirtFloatingIp floatingIp = getKubevirtFloatingIp("KubevirtFloatingIp.json");
assertEquals("fip-1", floatingIp.id());
assertEquals("router-1", floatingIp.routerName());
assertEquals("flat-1", floatingIp.networkName());
assertEquals("10.10.10.10", floatingIp.floatingIp().toString());
assertEquals("pod-1", floatingIp.podName());
assertEquals("vm-1", floatingIp.vmName());
assertEquals("20.20.20.20", floatingIp.fixedIp().toString());
}
use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.
the class KubevirtFloatingIpCodecTest method testKubevirtFloatingIpEncode.
/**
* Tests the kubevirt floating IP encoding.
*/
@Test
public void testKubevirtFloatingIpEncode() {
KubevirtFloatingIp floatingIp = DefaultKubevirtFloatingIp.builder().id("fip-id").routerName("router-1").networkName("flat-1").floatingIp(IpAddress.valueOf("10.10.10.10")).podName("pod-1").vmName("vm-1").fixedIp(IpAddress.valueOf("20.20.20.20")).build();
ObjectNode floatingIpJson = kubevirtFloatingIpCodec.encode(floatingIp, context);
assertThat(floatingIpJson, matchesKubevirtFloatingIp(floatingIp));
}
use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.
the class KubevirtFloatingIpCodecTest method getKubevirtFloatingIp.
private KubevirtFloatingIp getKubevirtFloatingIp(String resourceName) throws IOException {
InputStream jsonStream = KubevirtFloatingIpCodecTest.class.getResourceAsStream(resourceName);
JsonNode json = context.mapper().readTree(jsonStream);
MatcherAssert.assertThat(json, notNullValue());
KubevirtFloatingIp fip = kubevirtFloatingIpCodec.decode((ObjectNode) json, context);
assertThat(fip, notNullValue());
return fip;
}
Aggregations