Search in sources :

Example 6 with KubevirtPort

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());
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with KubevirtPort

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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) KubevirtPortJsonMatcher.matchesKubevirtPort(org.onosproject.kubevirtnetworking.codec.KubevirtPortJsonMatcher.matchesKubevirtPort) DefaultKubevirtPort(org.onosproject.kubevirtnetworking.api.DefaultKubevirtPort) Test(org.junit.Test)

Example 8 with KubevirtPort

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);
}
Also used : KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkingUtil.getRouterForKubevirtNetwork(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort)

Example 9 with KubevirtPort

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());
        }
    }
}
Also used : KubevirtPortService(org.onosproject.kubevirtnetworking.api.KubevirtPortService) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Aggregations

KubevirtPort (org.onosproject.kubevirtnetworking.api.KubevirtPort)9 KubevirtNetwork (org.onosproject.kubevirtnetworking.api.KubevirtNetwork)4 DefaultKubevirtPort (org.onosproject.kubevirtnetworking.api.DefaultKubevirtPort)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 KubevirtNetworkingUtil.getRouterForKubevirtNetwork (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork)2 PortNumber (org.onosproject.net.PortNumber)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Ethernet (org.onlab.packet.Ethernet)1 IpAddress (org.onlab.packet.IpAddress)1 KubevirtPortService (org.onosproject.kubevirtnetworking.api.KubevirtPortService)1 KubevirtPortJsonMatcher.matchesKubevirtPort (org.onosproject.kubevirtnetworking.codec.KubevirtPortJsonMatcher.matchesKubevirtPort)1 KubevirtNetworkingUtil.genFormatString (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)1 KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)1