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;
}
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();
}
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();
}
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));
}
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());
}
Aggregations