+
+ int ssh_connections_changed(int number)
+ {
+ 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 *sshConnections = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ssh-connections");
+ if (!cJSON_IsNumber(sshConnections))
+ {
+ printf("Configuration JSON is not as expected: ssh-connections is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ //we set the value of the ssh-connections object
+ cJSON_SetNumberValue(sshConnections, number);
+
+ //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 tls_connections_changed(int number)
+ {
+ 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 *tlsConnections = cJSON_GetObjectItemCaseSensitive(jsonConfig, "tls-connections");
+ if (!cJSON_IsNumber(tlsConnections))
+ {
+ printf("Configuration JSON is not as expected: tls-connections is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ //we set the value of the tls-connections object
+ cJSON_SetNumberValue(tlsConnections, number);
+
+ //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;
+}
+
+/*
+curl -X POST -H 'Content-Type: application/json' -i http://localhost:5000/extend-ports --data '{"number-of-ports":12}'
+*/
+int send_k8s_extend_port(void)
+{
+ int num_of_ports = getSshConnectionsFromConfigJson() + getTlsConnectionsFromConfigJson();
+
+ CURLcode res;
+
+ curl_easy_reset(curl_k8s);
+ set_curl_common_info_k8s();
+
+ char url_for_curl[100];
+ sprintf(url_for_curl, "http://localhost:5000/extend-ports");
+
+ curl_easy_setopt(curl_k8s, CURLOPT_URL, url_for_curl);
+
+ char post_data_json[1500];
+
+ sprintf(post_data_json,
+ "{\"number-of-ports\":%d}",
+ num_of_ports);
+
+ printf("Post data:\n%s\n", post_data_json);
+
+ curl_easy_setopt(curl_k8s, CURLOPT_POSTFIELDS, post_data_json);
+ curl_easy_setopt(curl_k8s, CURLOPT_CUSTOMREQUEST, "POST");
+
+ res = curl_easy_perform(curl_k8s);
+ if (res != CURLE_OK)
+ {
+ printf("cURL failed to url=%s\n", url_for_curl);
+ }
+
+ long http_response_code = 0;
+ curl_easy_getinfo (curl_k8s, CURLINFO_RESPONSE_CODE, &http_response_code);
+ if (http_response_code >= 200 && http_response_code <= 226 && http_response_code != CURLE_ABORTED_BY_CALLBACK)
+ {
+ printf("cURL succeeded to url=%s\n", url_for_curl);
+ }
+ else
+ {
+ printf("cURL to url=%s failed with code=%ld\n", url_for_curl, http_response_code);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ return SR_ERR_OK;
+}
+
+/*
+curl -X POST -H 'Content-Type: application/json' -i http://localhost:5000/scale --data '{"simulatedDevices":2}'
+*/
+int send_k8s_scale(int number_of_devices)
+{
+ CURLcode res;
+
+ curl_easy_reset(curl_k8s);
+ set_curl_common_info_k8s();
+
+ char url_for_curl[100];
+ sprintf(url_for_curl, "http://localhost:5000/scale");
+
+ curl_easy_setopt(curl_k8s, CURLOPT_URL, url_for_curl);
+
+ char post_data_json[1500];
+
+ sprintf(post_data_json,
+ "{\"simulatedDevices\":%d}",
+ number_of_devices);
+
+ printf("Post data:\n%s\n", post_data_json);
+
+ curl_easy_setopt(curl_k8s, CURLOPT_POSTFIELDS, post_data_json);
+ curl_easy_setopt(curl_k8s, CURLOPT_CUSTOMREQUEST, "POST");
+
+ res = curl_easy_perform(curl_k8s);
+ if (res != CURLE_OK)
+ {
+ printf("cURL failed to url=%s\n", url_for_curl);
+ }
+
+ long http_response_code = 0;
+ curl_easy_getinfo (curl_k8s, CURLINFO_RESPONSE_CODE, &http_response_code);
+ if (http_response_code >= 200 && http_response_code <= 226 && http_response_code != CURLE_ABORTED_BY_CALLBACK)
+ {
+ printf("cURL succeeded to url=%s\n", url_for_curl);
+ }
+ else
+ {
+ printf("cURL to url=%s failed with code=%ld\n", url_for_curl, http_response_code);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ return SR_ERR_OK;
+}
\ No newline at end of file