- //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);
-
- sr_disconnect(session_connection);
- context_free();
-
- log_message(1, LOG_COLOR_BOLD_GREEN"ntsim successfully initialized Docker container"LOG_COLOR_RESET"\n");
- return true;
-}
-
-static int get_installable_modules(struct installable_module **modules) {
- int total = 0;
- *modules = 0;
- list_yangs("/opt/dev/deploy/yang", modules, &total);
- return total;
-}
-
-static void list_yangs(const char *path, struct installable_module **modules, int *total) {
- DIR *d;
- struct dirent *dir;
- d = opendir(path);
- if(d) {
- while((dir = readdir(d)) != NULL) {
- if(dir->d_type == DT_DIR) {
- if(strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0)
- {
- char new_path[1024];
- snprintf(new_path, sizeof(new_path), "%s/%s", path, dir->d_name);
- list_yangs(new_path, modules, total);
- }
- } else {
- if(strstr(dir->d_name, ".yang") != 0) {
- *modules = (struct installable_module *)realloc(*modules, sizeof(struct installable_module) * (*total + 1));
- if(!*modules) {
- log_error("could not realloc");
- return;
- }
-
- (*modules)[*total].name = (char*)malloc(sizeof(char) * (strlen(dir->d_name) + 1));
- if(!(*modules)[*total].name) {
- log_error("could not alloc");
- return;
- }
- strcpy((*modules)[*total].name, dir->d_name);
- (*modules)[*total].name[strlen(dir->d_name) - 5] = 0; //extract ".yang"
- char *rev = strstr((*modules)[*total].name, "@");
- if(rev) { //extract revision, if exists
- *rev = 0;
- }
-
- (*modules)[*total].fullpath = (char*)malloc(sizeof(char) * (strlen(path) + 1 + strlen(dir->d_name) + 1));
- if(!(*modules)[*total].fullpath) {
- log_error("could not alloc");
- return;
- }
- sprintf((*modules)[*total].fullpath, "%s/%s", path, dir->d_name);
-
- (*modules)[*total].installed = false;
- (*modules)[*total].submodule = false;
-
- (*total)++;
- }
- }
- }
- closedir(d);
- }
-}
-
-int docker_device_init(void) {