static PyObject *ncDatastoreAddAugment(PyObject *self, PyObject *args, PyObject *keywords) { const char *path, *transapi = NULL; char *name = NULL; PyObject *PyFeatures = NULL; char *kwlist[] = {"model", "transapi", "features", NULL}; /* Get input parameters */ if (! PyArg_ParseTupleAndKeywords(args, keywords, "s|zO!", kwlist, &path, &transapi, &PyList_Type, &PyFeatures)) { return (NULL); } /* get name of the datastore for further referencing */ if (ncds_model_info(path, &name, NULL, NULL, NULL, NULL, NULL) != EXIT_SUCCESS) { return (NULL); } /* create datastore */ if (transapi) { if (ncds_add_augment_transapi(path, transapi) == EXIT_FAILURE) { free(name); return (NULL); } } else { if (ncds_add_model(path) == EXIT_FAILURE) { free(name); return (NULL); } } set_features(name, PyFeatures); free(name); if (ncds_consolidate() != EXIT_SUCCESS) { return (NULL); } Py_RETURN_NONE; }
/* * if repo_type is -1, then we are working with augment models specifications */ static int parse_model_cfg(struct np_module* module, xmlNodePtr node, NCDS_TYPE repo_type) { char *transapi_path = NULL, *model_path = NULL, *feature, *name, *aux; struct transapi *st = NULL; xmlNodePtr aux_node; if (strcmp(module->name, NETOPEER_MODULE_NAME) == 0) { st = &netopeer_transapi; } else if (strcmp(module->name, NCSERVER_MODULE_NAME) == 0) { st = &server_transapi; } for (aux_node = node->children; aux_node != NULL; aux_node = aux_node->next) { if (xmlStrcmp(aux_node->name, BAD_CAST "path") == 0) { model_path = (char*)xmlNodeGetContent(aux_node); } if (xmlStrcmp(aux_node->name, BAD_CAST "transapi") == 0) { transapi_path = (char*)xmlNodeGetContent(aux_node); } if (model_path && transapi_path) { break; } } /* Netopeer module is something extra */ if (st != NULL && model_path) { /* internal static server (Netopeer) module */ if (repo_type == -1 && transapi_path) { /* augment transapi module */ nc_verb_verbose("Adding augment transapi \"%s\"", model_path); ncds_add_augment_transapi(model_path, transapi_path); } else if (repo_type == -1) { /* augment model */ nc_verb_verbose("Adding augment model \"%s\"", model_path); ncds_add_model(model_path); } else { nc_verb_verbose("Adding static transapi \"%s\"", model_path); if ((module->ds = ncds_new_transapi_static(repo_type, model_path, st)) == NULL) { free(model_path); free(transapi_path); return (EXIT_FAILURE); } } } else if (model_path && transapi_path) { if (repo_type == -1) { /* augment transapi module */ nc_verb_verbose("Adding augment transapi \"%s\"", model_path); ncds_add_augment_transapi(model_path, transapi_path); } else { /* base transapi module for datastore */ nc_verb_verbose("Adding transapi \"%s\"", model_path); if ((module->ds = ncds_new_transapi(repo_type, model_path, transapi_path)) == NULL) { free(model_path); free(transapi_path); return (EXIT_FAILURE); } } } else if (model_path) { if (repo_type == -1) { /* augment model */ nc_verb_verbose("Adding augment model \"%s\"", model_path); ncds_add_model(model_path); } else { /* base model for datastore */ nc_verb_verbose("Adding base model \"%s\"", model_path); if ((module->ds = ncds_new2(repo_type, model_path, NULL)) == NULL) { free(model_path); return (EXIT_FAILURE); } } } else { nc_verb_error("Configuration mismatch: missing model path in %s config.", module->name); } name = strdup(basename(model_path)); /* cut off the .yin suffix */ aux = strrchr(name, '.'); if (aux) { *aux = '\0';} free(model_path); free(transapi_path); /* set features */ for (aux_node = node->children; aux_node != NULL; aux_node = aux_node->next) { if (xmlStrcmp(aux_node->name, BAD_CAST "feature") == 0) { feature = (char*)xmlNodeGetContent(aux_node); if (strcmp(feature, "*") == 0) { ncds_features_enableall(name); } else { ncds_feature_enable(name, feature); } free(feature); } } free(name); return (EXIT_SUCCESS); }