cJSON_AddItemToObject(postDataJson, "Env", env_variables_array);
- char environment_var[50];
+ char environment_var[100];
sprintf(environment_var, "NTS_IP=%s", getenv("NTS_IP"));
cJSON *env_var_obj = cJSON_CreateString(environment_var);
}
cJSON_AddItemToArray(env_variables_array, env_var_obj);
+ char *external_nts_ip = getenv("EXTERNAL_NTS_IP");
+ if (external_nts_ip == NULL)
+ {
+ sprintf(environment_var, "EXTERNAL_NTS_IP=%s", getenv("NTS_IP"));
+ }
+ else
+ {
+ sprintf(environment_var, "EXTERNAL_NTS_IP=%s", external_nts_ip);
+ }
+
+ cJSON *env_var_obj_0 = cJSON_CreateString(environment_var);
+ if (env_var_obj_0 == NULL)
+ {
+ printf("Could not create JSON object: Env array object EXTERNAL_NTS_IP\n");
+ return NULL;
+ }
+ cJSON_AddItemToArray(env_variables_array, env_var_obj_0);
+
sprintf(environment_var, "NETCONF_BASE=%d", base_netconf_port);
cJSON *env_var_obj_2 = cJSON_CreateString(environment_var);
if (env_var_obj_2 == NULL)
"<max-connection-attempts xmlns=\"urn:opendaylight:netconf-node-topology\">100</max-connection-attempts>"
"<between-attempts-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">2000</between-attempts-timeout-millis>"
"</node>",
- device_name, device_port, getenv("NTS_IP"), device_port, "netconf", "netconf");
+ device_name, device_port, (getenv("EXTERNAL_NTS_IP") == NULL) ? getenv("NTS_IP") : getenv("EXTERNAL_NTS_IP"),
+ device_port, "netconf", "netconf");
printf("Post data:\n%s\n", post_data_xml);
"<max-connection-attempts xmlns=\"urn:opendaylight:netconf-node-topology\">100</max-connection-attempts>"
"<between-attempts-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">2000</between-attempts-timeout-millis>"
"</node>",
- device_name, device_port, getenv("NTS_IP"), "netconf", device_port);
+ device_name, device_port, (getenv("EXTERNAL_NTS_IP") == NULL) ? getenv("NTS_IP") : getenv("EXTERNAL_NTS_IP"), "netconf", device_port);
printf("Post data:\n%s\n", post_data_xml);
bool is_mounted = true;
int port = 0;
- char device_name[100];
+ char device_name[200];
sprintf(device_name, "%s-%d", getenv("CONTAINER_NAME"), current_device->device_number);
//This is where we hardcoded: 7 devices will have SSH connections and 3 devices will have TLS connections
int ves_ip_changed(char *new_ip)
{
- char *stringConfiguration = readConfigFileInString();
+ char *stringConfiguration = readConfigFileInString();
- if (stringConfiguration == NULL)
- {
- printf("Could not read configuration file!\n");
- return SR_ERR_OPERATION_FAILED;
- }
+ if (stringConfiguration == NULL)
+ {
+ printf("Could not read configuration file!\n");
+ return SR_ERR_OPERATION_FAILED;
+ }
- cJSON *jsonConfig = cJSON_Parse(stringConfiguration);
- if (jsonConfig == NULL)
- {
- free(stringConfiguration);
- const char *error_ptr = cJSON_GetErrorPtr();
- if (error_ptr != NULL)
- {
- fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
- }
- return SR_ERR_OPERATION_FAILED;
- }
- //we don't need the string anymore
- free(stringConfiguration);
- stringConfiguration = NULL;
+ cJSON *jsonConfig = cJSON_Parse(stringConfiguration);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfiguration);
+ const char *error_ptr = cJSON_GetErrorPtr();
+ if (error_ptr != NULL)
+ {
+ fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
+ }
+ return SR_ERR_OPERATION_FAILED;
+ }
+ //we don't need the string anymore
+ free(stringConfiguration);
+ stringConfiguration = NULL;
- cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
- if (!cJSON_IsObject(vesDetails))
- {
- printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
- cJSON_Delete(jsonConfig);
- return SR_ERR_OPERATION_FAILED;
- }
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
- cJSON *vesIp = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-ip");
- if (!cJSON_IsString(vesIp))
- {
- printf("Configuration JSON is not as expected: ves-endpoint-ip is not a string");
- cJSON_Delete(jsonConfig);
- return SR_ERR_OPERATION_FAILED;
- }
+ cJSON *vesIp = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-ip");
+ if (!cJSON_IsString(vesIp))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-ip is not a string");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
- //we set the value of the fault-notification-delay-period object
- cJSON_ReplaceItemInObject(vesDetails, "ves-endpoint-ip", cJSON_CreateString(new_ip));
+ //we set the value of the fault-notification-delay-period object
+ cJSON_ReplaceItemInObject(vesDetails, "ves-endpoint-ip", cJSON_CreateString(new_ip));
- //writing the new JSON to the configuration file
- stringConfiguration = cJSON_Print(jsonConfig);
- writeConfigFile(stringConfiguration);
+ //writing the new JSON to the configuration file
+ stringConfiguration = cJSON_Print(jsonConfig);
+ writeConfigFile(stringConfiguration);
if (stringConfiguration != NULL)
{
stringConfiguration = NULL;
}
- cJSON_Delete(jsonConfig);
+ cJSON_Delete(jsonConfig);
- return SR_ERR_OK;
+ return SR_ERR_OK;
}
int ves_port_changed(int new_port)
return SR_ERR_OK;
}
+int ves_username_changed(char *new_username)
+{
+ char *stringConfiguration = readConfigFileInString();
+
+ if (stringConfiguration == NULL)
+ {
+ printf("Could not read configuration file!\n");
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *jsonConfig = cJSON_Parse(stringConfiguration);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfiguration);
+ const char *error_ptr = cJSON_GetErrorPtr();
+ if (error_ptr != NULL)
+ {
+ fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
+ }
+ return SR_ERR_OPERATION_FAILED;
+ }
+ //we don't need the string anymore
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *vesUsername = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-username");
+ if (!cJSON_IsString(vesUsername))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-username is not a string");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ //we set the value of the fault-notification-delay-period object
+ cJSON_ReplaceItemInObject(vesDetails, "ves-endpoint-username", cJSON_CreateString(new_username));
+
+ //writing the new JSON to the configuration file
+ stringConfiguration = cJSON_Print(jsonConfig);
+ writeConfigFile(stringConfiguration);
+
+ if (stringConfiguration != NULL)
+ {
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+ }
+
+ cJSON_Delete(jsonConfig);
+
+ return SR_ERR_OK;
+}
+
+int ves_password_changed(char *new_password)
+{
+ char *stringConfiguration = readConfigFileInString();
+
+ if (stringConfiguration == NULL)
+ {
+ printf("Could not read configuration file!\n");
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *jsonConfig = cJSON_Parse(stringConfiguration);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfiguration);
+ const char *error_ptr = cJSON_GetErrorPtr();
+ if (error_ptr != NULL)
+ {
+ fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
+ }
+ return SR_ERR_OPERATION_FAILED;
+ }
+ //we don't need the string anymore
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *vesPassword = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-password");
+ if (!cJSON_IsString(vesPassword))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-password is not a string");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ //we set the value of the fault-notification-delay-period object
+ cJSON_ReplaceItemInObject(vesDetails, "ves-endpoint-password", cJSON_CreateString(new_password));
+
+ //writing the new JSON to the configuration file
+ stringConfiguration = cJSON_Print(jsonConfig);
+ writeConfigFile(stringConfiguration);
+
+ if (stringConfiguration != NULL)
+ {
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+ }
+
+ cJSON_Delete(jsonConfig);
+
+ return SR_ERR_OK;
+}
+
+int ves_auth_method_changed(char *new_auth_method)
+{
+ char *stringConfiguration = readConfigFileInString();
+
+ if (stringConfiguration == NULL)
+ {
+ printf("Could not read configuration file!\n");
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *jsonConfig = cJSON_Parse(stringConfiguration);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfiguration);
+ const char *error_ptr = cJSON_GetErrorPtr();
+ if (error_ptr != NULL)
+ {
+ fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
+ }
+ return SR_ERR_OPERATION_FAILED;
+ }
+ //we don't need the string anymore
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *vesAuthMethod = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-auth-method");
+ if (!cJSON_IsString(vesAuthMethod))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-auth-method is not a string");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ //we set the value of the fault-notification-delay-period object
+ cJSON_ReplaceItemInObject(vesDetails, "ves-endpoint-auth-method", cJSON_CreateString(new_auth_method));
+
+ //writing the new JSON to the configuration file
+ stringConfiguration = cJSON_Print(jsonConfig);
+ writeConfigFile(stringConfiguration);
+
+ if (stringConfiguration != NULL)
+ {
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+ }
+
+ cJSON_Delete(jsonConfig);
+
+ return SR_ERR_OK;
+}
+
int ves_registration_changed(cJSON_bool new_bool)
{
char *stringConfiguration = readConfigFileInString();
curl_easy_reset(curl);
set_curl_common_info();
- char url[100];
+ char url[500];
sprintf(url, "http:/v%s/exec/%s/start", getenv("DOCKER_ENGINE_VERSION"), exec_id);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_reset(curl);
set_curl_common_info();
- char url[100];
+ char url[500];
sprintf(url, "http:/v%s/exec/%s/json", getenv("DOCKER_ENGINE_VERSION"), exec_id);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_reset(curl);
set_curl_common_info();
- char url[100];
+ char url[300];
sprintf(url, "http:/v%s/containers/%s/exec", getenv("DOCKER_ENGINE_VERSION"), device_id);
curl_easy_setopt(curl, CURLOPT_URL, url);
cJSON *cmd_string_2 = cJSON_CreateString("-c");
cJSON_AddItemToArray(cmd_array, cmd_string_2);
- char string_command[500];
+ //some notifications require a really long notification object
+ char string_command[1000000];
sprintf(string_command, "/usr/local/bin/generic-notifications %s '%s'", module_name, notification_string);
cJSON *cmd_string_3 = cJSON_CreateString(string_command);
curl_easy_reset(curl);
set_curl_common_info();
- char url[100];
+ char url[300];
sprintf(url, "http:/v%s/images/create?fromImage=%s", getenv("DOCKER_ENGINE_VERSION"), getenv("MODELS_IMAGE"));
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&curl_response_mem);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 300L);
+
res = curl_easy_perform(curl);
if (res != CURLE_OK)