-static int docker_container_create(const char *image, manager_network_function_instance_t *instance);
-static int docker_container_start(manager_network_function_instance_t *instance);
-static int docker_container_inspect(manager_network_function_instance_t *instance);
-
-
-bool docker_container_init(void) {
- int rc;
-
- sr_log_stderr(SR_LL_NONE);
- log_message(1, "Entering container-init mode...\n");
-
- // connect to sysrepo
- rc = sr_connect(0, &session_connection);
- if(SR_ERR_OK != rc) {
- log_error("sr_connect failed");
- return false;
- }
-
- /* get context */
- session_context = (struct ly_ctx *)sr_get_context(session_connection);
- if(session_context == 0) {
- log_error("sr_get_context failed");
- return false;
- }
-
- /* install yang files */
- log_message(1, "Installing yang files...\n");
- struct installable_module *modules;
- int total_modules = get_installable_modules(&modules);
- log_message(1, "Found total modules: %d\n", total_modules);
-
- int old_failed_installations = 1;
- int failed_installations = 0;
- int install_round = 0;
- while(failed_installations != old_failed_installations) {
- old_failed_installations = failed_installations;
- failed_installations = 0;
- install_round++;
- for(int i = 0; i < total_modules; i++) {
- if(!modules[i].installed) {
- modules[i].submodule = context_yang_is_module(modules[i].fullpath);
- if(!modules[i].submodule) {
- if(!framework_is_docker_excluded_module(modules[i].name)) {
- log_message(1, "[round %d] trying to install module %s from %s... ", install_round, modules[i].name, modules[i].fullpath);
- if(!context_module_install(modules[i].name, modules[i].fullpath)) {
- failed_installations++;
- log_message(1, LOG_COLOR_BOLD_YELLOW"failed"LOG_COLOR_RESET"\n");
- }
- else {
- log_message(1, LOG_COLOR_BOLD_GREEN"done"LOG_COLOR_RESET"\n");
- modules[i].installed = true;
- }
- }
- else {
- log_message(1, "[round %d] not installing module %s as it's excluded in config.\n", install_round, modules[i].name);
- modules[i].installed = true;
- }
- }
- else {
- log_message(1, "[round %d] %s is a submodule... "LOG_COLOR_BOLD_YELLOW"skipping"LOG_COLOR_RESET"\n", install_round, modules[i].name);
- modules[i].installed = true;
- }
- }
- }
- }
-
- if(failed_installations != 0) {
- log_error("Failed to install all modules in %d rounds...", install_round);
- return false;
- }
- else {
- log_message(1, LOG_COLOR_BOLD_GREEN"successfully"LOG_COLOR_RESET" installed "LOG_COLOR_BOLD_GREEN"ALL"LOG_COLOR_RESET" modules in "LOG_COLOR_BOLD_YELLOW"%d"LOG_COLOR_RESET" rounds\n", (install_round - 1));
- }
-
- //set access for all installed modules
- log_message(1, "Setting access configuration for installed modules... ");
- for(int i = 0; i < total_modules; i++) {
- if((!framework_is_docker_excluded_module(modules[i].name)) && (!modules[i].submodule)) {
- if(!context_module_set_access(modules[i].name)) {
- log_error("Failed to set access to module %s...", modules[i].name);
- return false;
- }
- }
- }
- log_message(1, LOG_COLOR_BOLD_GREEN"done"LOG_COLOR_RESET"\n");
-
- //cleanup module-install used memory
- for(int i = 0; i < total_modules; i++) {
- free(modules[i].name);
- free(modules[i].fullpath);
- }
- free(modules);
-
- //get context
- session_context = (struct ly_ctx *)sr_get_context(session_connection);
- if(session_context == 0) {
- log_error("sr_get_context failed");
- return false;
- }
-
- //init context so we can see all the available modules, features, etc
- rc = context_init(session_context);
- if(rc != 0) {
- log_error("context_init() failed");
- return false;
- }
-
- /* enable features */
- log_message(1, "Enabling yang features...\n");
- char **available_features;
- int total_available_features;
- total_available_features = context_get_features(&available_features);
- log_message(1, "Found total features: %d\n", total_available_features);
- for(int i = 0; i < total_available_features; i++) {
- log_message(1, "feature %s: ", available_features[i]);
-
- if(!context_get_feature_enabled(available_features[i])) {
- if(!framework_is_docker_excluded_feature(available_features[i])) {
- if(context_feature_enable(available_features[i])) {
- log_message(1, "enabling... "LOG_COLOR_BOLD_GREEN"done"LOG_COLOR_RESET"\n");
- }
- else {
- log_error("enabling... failed\n");
- }
- }
- else {
- log_message(1, "excluded in config, skipping\n");
- }
- }
- else {
- log_message(1, "already "LOG_COLOR_BOLD_GREEN"enabled"LOG_COLOR_RESET", skipping.\n");
- }
- }
- for(int i = 0; i < total_available_features; i++) {
- free(available_features[i]);
- }
- free(available_features);