Search in sources :

Example 1 with NetworkCreateConfig

use of io.fabric8.maven.docker.access.NetworkCreateConfig in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method createNetwork.

@Override
public String createNetwork(NetworkCreateConfig networkConfig) throws DockerAccessException {
    String createJson = networkConfig.toJson();
    log.debug("Network create config: " + createJson);
    try {
        String url = urlBuilder.createNetwork();
        log.verbose(Logger.LogVerboseCategory.API, API_LOG_FORMAT_POST_WITH_REQUEST, url, createJson);
        String response = delegate.post(url, createJson, new ApacheHttpClientDelegate.BodyResponseHandler(), HTTP_CREATED);
        log.debug(response);
        JsonObject json = JsonFactory.newJsonObject(response);
        if (json.has("Warnings")) {
            logWarnings(json);
        }
        // only need first 12 to id a container
        return json.get("Id").getAsString().substring(0, 12);
    } catch (IOException e) {
        throw new DockerAccessException(e, "Unable to create network for [%s]", networkConfig.getName());
    }
}
Also used : DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Aggregations

JsonObject (com.google.gson.JsonObject)1 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 IOException (java.io.IOException)1