Search in sources :

Example 1 with KubevirtApiConfig

use of org.onosproject.kubevirtnode.api.KubevirtApiConfig in project onos by opennetworkinglab.

the class KubevirtNetworkingUtil method k8sClient.

/**
 * Obtains workable kubernetes client.
 *
 * @param service kubernetes API service
 * @return kubernetes client
 */
public static KubernetesClient k8sClient(KubevirtApiConfigService service) {
    KubevirtApiConfig config = service.apiConfig();
    if (config == null) {
        log.error("Failed to find valid kubernetes API configuration.");
        return null;
    }
    KubernetesClient client = k8sClient(config);
    if (client == null) {
        log.error("Failed to connect to kubernetes API server.");
        return null;
    }
    return client;
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig)

Example 2 with KubevirtApiConfig

use of org.onosproject.kubevirtnode.api.KubevirtApiConfig in project onos by opennetworkinglab.

the class KubevirtApiConfigWebResource method createApiConfigs.

/**
 * Creates a set of KubeVirt API config from the JSON input stream.
 *
 * @param input KubeVirt API configs JSON input stream
 * @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
 * is malformed
 * @onos.rsModel KubevirtApiConfig
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createApiConfigs(InputStream input) {
    log.trace(String.format(MESSAGE_CONFIG, CREATE));
    KubevirtApiConfig config = readApiConfig(input);
    KubevirtApiConfigAdminService service = get(KubevirtApiConfigAdminService.class);
    if (config != null) {
        service.createApiConfig(config);
    }
    UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(API_CONFIG);
    return created(locationBuilder.build()).build();
}
Also used : KubevirtApiConfigAdminService(org.onosproject.kubevirtnode.api.KubevirtApiConfigAdminService) UriBuilder(javax.ws.rs.core.UriBuilder) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with KubevirtApiConfig

use of org.onosproject.kubevirtnode.api.KubevirtApiConfig in project onos by opennetworkinglab.

the class KubevirtApiConfigCodec method decode.

@Override
public KubevirtApiConfig decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    KubevirtApiConfig.Scheme scheme = KubevirtApiConfig.Scheme.valueOf(nullIsIllegal(json.get(SCHEME).asText(), SCHEME + MISSING_MESSAGE));
    IpAddress ipAddress = IpAddress.valueOf(nullIsIllegal(json.get(IP_ADDRESS).asText(), IP_ADDRESS + MISSING_MESSAGE));
    int port = json.get(PORT).asInt();
    KubevirtApiConfig.Builder builder = DefaultKubevirtApiConfig.builder().scheme(scheme).ipAddress(ipAddress).port(port).state(DISCONNECTED);
    JsonNode tokenJson = json.get(TOKEN);
    JsonNode caCertDataJson = json.get(CA_CERT_DATA);
    JsonNode clientCertDataJson = json.get(CLIENT_CERT_DATA);
    JsonNode clientKeyDataJson = json.get(CLIENT_KEY_DATA);
    JsonNode serviceFqdn = json.get(SERVICE_FQDN);
    JsonNode apiServerFqdn = json.get(API_SERVER_FQDN);
    JsonNode controllerIp = json.get(CONTROLLER_IP);
    String token = "";
    String caCertData = "";
    String clientCertData = "";
    String clientKeyData = "";
    if (scheme == HTTPS) {
        caCertData = nullIsIllegal(caCertDataJson.asText(), CA_CERT_DATA + MISSING_MESSAGE);
        clientCertData = nullIsIllegal(clientCertDataJson.asText(), CLIENT_CERT_DATA + MISSING_MESSAGE);
        clientKeyData = nullIsIllegal(clientKeyDataJson.asText(), CLIENT_KEY_DATA + MISSING_MESSAGE);
        if (tokenJson != null) {
            token = tokenJson.asText();
        }
    } else {
        if (tokenJson != null) {
            token = tokenJson.asText();
        }
        if (caCertDataJson != null) {
            caCertData = caCertDataJson.asText();
        }
        if (clientCertDataJson != null) {
            clientCertData = clientCertDataJson.asText();
        }
        if (clientKeyDataJson != null) {
            clientKeyData = clientKeyDataJson.asText();
        }
    }
    if (StringUtils.isNotEmpty(token)) {
        builder.token(token);
    }
    if (StringUtils.isNotEmpty(caCertData)) {
        builder.caCertData(caCertData);
    }
    if (StringUtils.isNotEmpty(clientCertData)) {
        builder.clientCertData(clientCertData);
    }
    if (StringUtils.isNotEmpty(clientKeyData)) {
        builder.clientKeyData(clientKeyData);
    }
    if (serviceFqdn != null) {
        builder.serviceFqdn(serviceFqdn.asText());
    }
    if (apiServerFqdn != null) {
        builder.apiServerFqdn(apiServerFqdn.asText());
    }
    if (controllerIp != null) {
        builder.controllerIp(IpAddress.valueOf(controllerIp.asText()));
    }
    return builder.build();
}
Also used : IpAddress(org.onlab.packet.IpAddress) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultKubevirtApiConfig(org.onosproject.kubevirtnode.api.DefaultKubevirtApiConfig) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig)

Example 4 with KubevirtApiConfig

use of org.onosproject.kubevirtnode.api.KubevirtApiConfig in project onos by opennetworkinglab.

the class KubevirtApiConfigManager method createApiConfig.

@Override
public void createApiConfig(KubevirtApiConfig config) {
    checkNotNull(config, ERR_NULL_CONFIG);
    checkArgument(configStore.apiConfigs().size() == 0, ERR_UNIQUE_CONFIG);
    KubevirtApiConfig newConfig = config;
    if (config.apiServerFqdn() != null) {
        IpAddress apiServerIp = resolveHostname(config.apiServerFqdn());
        if (apiServerIp != null) {
            newConfig = config.updateIpAddress(apiServerIp);
            newConfig = newConfig.updatePort(API_SERVER_PORT);
        } else {
            log.warn("API server IP is not resolved for host {}", config.apiServerFqdn());
        }
    }
    configStore.createApiConfig(newConfig);
    log.info(String.format(MSG_CONFIG, endpoint(newConfig), MSG_CREATED));
}
Also used : IpAddress(org.onlab.packet.IpAddress) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig)

Example 5 with KubevirtApiConfig

use of org.onosproject.kubevirtnode.api.KubevirtApiConfig in project onos by opennetworkinglab.

the class KubevirtApiConfigCodecTest method testKubevirtApiConfigDecode.

/**
 * Tests the KubeVirt API config decoding.
 *
 * @throws IOException IO exception
 */
@Test
public void testKubevirtApiConfigDecode() throws IOException {
    KubevirtApiConfig config = getKubevirtApiConfig("KubevirtApiConfig.json");
    assertEquals("HTTPS", config.scheme().name());
    assertEquals("10.134.34.223", config.ipAddress().toString());
    assertEquals(6443, config.port());
    assertEquals("token", config.token());
    assertEquals("caCertData", config.caCertData());
    assertEquals("clientCertData", config.clientCertData());
    assertEquals("clientKeyData", config.clientKeyData());
    assertEquals("kubevirt.edgestack.svc.cluster.local", config.serviceFqdn());
    assertEquals("kubernetes.default.svc.cluster.local", config.apiServerFqdn());
    assertEquals("127.0.0.1", config.controllerIp().toString());
}
Also used : KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig) DefaultKubevirtApiConfig(org.onosproject.kubevirtnode.api.DefaultKubevirtApiConfig) KubevirtApiConfigJsonMatcher.matchesKubevirtApiConfig(org.onosproject.kubevirtnode.codec.KubevirtApiConfigJsonMatcher.matchesKubevirtApiConfig) Test(org.junit.Test)

Aggregations

KubevirtApiConfig (org.onosproject.kubevirtnode.api.KubevirtApiConfig)14 DefaultKubevirtApiConfig (org.onosproject.kubevirtnode.api.DefaultKubevirtApiConfig)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Produces (javax.ws.rs.Produces)3 KubevirtApiConfigService (org.onosproject.kubevirtnode.api.KubevirtApiConfigService)3 KubevirtApiConfigJsonMatcher.matchesKubevirtApiConfig (org.onosproject.kubevirtnode.codec.KubevirtApiConfigJsonMatcher.matchesKubevirtApiConfig)3 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Test (org.junit.Test)2 IpAddress (org.onlab.packet.IpAddress)2 KubevirtApiConfigAdminService (org.onosproject.kubevirtnode.api.KubevirtApiConfigAdminService)2 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 InputStream (java.io.InputStream)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)1