use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtListPortCommand method json.
private String json(List<KubevirtPort> ports) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (KubevirtPort port : ports) {
result.add(jsonForEntity(port, KubevirtPort.class));
}
return prettyJson(mapper, result.toString());
}
use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtPortCodecTest method testKubevirtPortEncode.
/**
* Tests the kubevirt port encoding.
*/
@Test
public void testKubevirtPortEncode() {
KubevirtPort port = DefaultKubevirtPort.builder().vmName("test-vm-1").networkId("net-1").macAddress(MacAddress.valueOf("11:22:33:44:55:66")).ipAddress(IpAddress.valueOf("10.10.10.100")).deviceId(DeviceId.deviceId("of:foo")).portNumber(PortNumber.portNumber("1")).build();
ObjectNode portJson = kubevirtPortCodec.encode(port, context);
assertThat(portJson, matchesKubevirtPort(port));
}
use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtLbHandler method setBucketsToGroup.
private void setBucketsToGroup(KubevirtLoadBalancer loadBalancer, KubevirtNode gateway, boolean install) {
int groupId = loadBalancer.hashCode();
KubevirtNetwork network = networkService.network(loadBalancer.networkId());
Set<KubevirtPort> ports = portService.ports(loadBalancer.networkId());
List<GroupBucket> bkts = Lists.newArrayList();
loadBalancer.members().forEach(ip -> {
ports.stream().filter(port -> port.ipAddress().equals(ip) && port.macAddress() != null).findAny().ifPresent(port -> bkts.add(buildGroupBucket(port)));
});
groupRuleService.setBuckets(appId, gateway.intgBridge(), groupId, bkts, install);
}
use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtListPortCommand method doExecute.
@Override
protected void doExecute() throws Exception {
KubevirtPortService service = get(KubevirtPortService.class);
List<KubevirtPort> ports = Lists.newArrayList(service.ports());
ports.sort(Comparator.comparing(KubevirtPort::networkId));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_NAME_LENGTH, CLI_MAC_ADDRESS_LENGTH, CLI_IP_ADDRESSES_LENGTH));
if (!Strings.isNullOrEmpty(networkId)) {
ports.removeIf(port -> !port.networkId().equals(networkId));
}
if (outputJson()) {
print("%s", json(ports));
} else {
print(format, "VM Name", "Network", "MAC Address", "Fixed IPs");
for (KubevirtPort port : ports) {
print(format, StringUtils.substring(port.vmName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(port.networkId(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(port.macAddress().toString(), 0, CLI_MAC_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), port.ipAddress() == null ? "" : port.ipAddress());
}
}
}
Aggregations