container->docker_ip = 0;
container->docker_netconf_ssh_port = STANDARD_NETCONF_PORT;
container->docker_netconf_tls_port = container->docker_netconf_ssh_port + framework_environment.settings.ssh_connections;
+ if(framework_environment.settings.ssh_connections == 0) {
+ container->docker_netconf_ssh_port = 0;
+ }
+ if(framework_environment.settings.tls_connections == 0) {
+ container->docker_netconf_tls_port = 0;
+ }
container->docker_ftp_port= STANDARD_FTP_PORT;
container->docker_sftp_port= STANDARD_SFTP_PORT;
return NTS_ERR_OK;
}
+int docker_pull(const char *repo, const char *image, const char *tag) {
+ assert(repo);
+ assert(image);
+ assert(tag);
+
+ char image_full[256];
+ if(tag && (tag[0] != 0)) {
+ sprintf(image_full, "%s/%s:%s", repo, image, tag);
+ }
+ else {
+ sprintf(image_full, "%s/%s:latest", repo, image);
+ }
+
+ char url[512];
+ sprintf(url, "http:/v%s/images/create?fromImage=%s", framework_environment.settings.docker_engine_version, image_full);
+
+ char *response = 0;
+ int response_code = 0;
+ int rc = http_socket_request(url, DOCKER_SOCK_FNAME, "POST", 0, &response_code, &response);
+
+ if(rc != NTS_ERR_OK) {
+ log_error("http_socket_request failed\n");
+ return NTS_ERR_FAILED;
+ }
+
+ if(response_code != 200) {
+ char *message = docker_parse_json_message(response);
+ log_error("docker_pull failed (%d): %s\n", response_code, message);
+ free(message);
+ free(response);
+ return NTS_ERR_FAILED;
+ }
+
+ return NTS_ERR_OK;
+}
+
static char *docker_parse_json_message(const char *json_string) {
assert(json_string);
return NTS_ERR_FAILED;
}
- if(cJSON_AddStringToObject(hostPort, "HostIp", "0.0.0.0") == 0) { //or, future, bind to container->host_ip
- log_error("could not create JSON object: HostIpString\n");
- cJSON_Delete(hostPort);
- return NTS_ERR_FAILED;
- }
-
if(cJSON_AddItemToArray(port, hostPort) == 0) {
log_error("cJSON_AddItemToArray failed\n");
cJSON_Delete(hostPort);
return NTS_ERR_FAILED;
}
+ cJSON *capAdd = cJSON_CreateArray();
+ if(capAdd == 0) {
+ log_error("could not create JSON array: CapAdd\n");
+ cJSON_Delete(postDataJson);
+ return NTS_ERR_FAILED;
+ }
+ if(cJSON_AddItemToObject(hostConfig, "CapAdd", capAdd) == 0) {
+ log_error("cJSON_AddItemToObject failed\n");
+ cJSON_Delete(postDataJson);
+ return NTS_ERR_FAILED;
+ }
+ cJSON *net_admin = cJSON_CreateString("NET_ADMIN");
+ if(net_admin == 0) {
+ log_error("could not create JSON string\n");
+ cJSON_Delete(postDataJson);
+ return NTS_ERR_FAILED;
+ }
+ if(cJSON_AddItemToArray(capAdd, net_admin) == 0) {
+ log_error("cJSON_AddItemToArray failed\n");
+ cJSON_Delete(postDataJson);
+ return NTS_ERR_FAILED;
+ }
+
+
cJSON *portBindings = cJSON_CreateObject();
if(portBindings == 0) {
- printf("could not create JSON object: PortBindings");
+ log_error("could not create JSON object: PortBindings\n");
cJSON_Delete(postDataJson);
return NTS_ERR_FAILED;
}