Changed module-specific upgrade API, not backward compatible. The API has been simplified which means more has to be done by the programmer.
* In summary, a user registers an upgrade callback per module. The callback is called at startup if the module is added, has been removed or if the revision on file is different from the one in the system. * The register function has removed `from` and `rev` parameters: `upgrade_callback_register(h, cb, namespace, arg)` * The callback function has a new `op` parameter with possible values: `XML_FLAG_ADD`, `XML_FLAG_CHANGE` or `XML_FLAG_CHANGE`: `clicon_upgrade_cb(h, xn, ns, op, from, to, arg, cbret)`
This commit is contained in:
parent
e2b3cdb3f6
commit
8f1de15ad3
10 changed files with 257 additions and 185 deletions
|
|
@ -793,9 +793,6 @@ typedef struct {
|
|||
const char *uc_fnstr; /* Stringified fn name for debug */
|
||||
void *uc_arg; /* Application specific argument to cb */
|
||||
char *uc_namespace; /* Module namespace */
|
||||
uint32_t uc_rev; /* Module revision (to) in YYYYMMDD format or 0 */
|
||||
uint32_t uc_from; /* Module revision (from) or 0 in YYYYMMDD format */
|
||||
|
||||
} upgrade_callback_t;
|
||||
|
||||
/* List of rpc callback entries XXX hang on handle */
|
||||
|
|
@ -808,8 +805,6 @@ static upgrade_callback_t *upgrade_cb_list = NULL;
|
|||
* @param[in] fnstr Stringified function for debug
|
||||
* @param[in] arg Domain-specific argument to send to callback
|
||||
* @param[in] namespace Module namespace (if NULL all modules)
|
||||
* @param[in] from From module revision (0 from any revision)
|
||||
* @param[in] revision To module revision (0 means module obsoleted)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @see upgrade_callback_call which makes the actual callback
|
||||
|
|
@ -819,8 +814,6 @@ upgrade_callback_reg_fn(clicon_handle h,
|
|||
clicon_upgrade_cb cb,
|
||||
const char *fnstr,
|
||||
char *namespace,
|
||||
uint32_t from,
|
||||
uint32_t revision,
|
||||
void *arg)
|
||||
{
|
||||
upgrade_callback_t *uc;
|
||||
|
|
@ -835,8 +828,6 @@ upgrade_callback_reg_fn(clicon_handle h,
|
|||
uc->uc_arg = arg;
|
||||
if (namespace)
|
||||
uc->uc_namespace = strdup(namespace);
|
||||
uc->uc_rev = revision;
|
||||
uc->uc_from = from;
|
||||
ADDQ(uc, upgrade_cb_list);
|
||||
return 0;
|
||||
done:
|
||||
|
|
@ -864,14 +855,14 @@ upgrade_callback_delete_all(clicon_handle h)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*! Search Upgrade callbacks and invoke if module match
|
||||
/*! Upgrade specific module identified by namespace, search matching callbacks
|
||||
*
|
||||
* @param[in] h clicon handle
|
||||
* @param[in] xt Top-level XML tree to be updated (includes other ns as well)
|
||||
* @param[in] modname Name of module
|
||||
* @param[in] modns Namespace of module (for info)
|
||||
* @param[in] from From revision on the form YYYYMMDD
|
||||
* @param[in] to To revision on the form YYYYMMDD (0 not in system)
|
||||
* @param[in] ns Namespace of module
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL or _CHANGE
|
||||
* @param[in] from From revision on the form YYYYMMDD (if DEL or CHANGE)
|
||||
* @param[in] to To revision on the form YYYYMMDD (if ADD or CHANGE)
|
||||
* @param[out] cbret Return XML (as string in CLIgen buffer), on invalid
|
||||
* @retval -1 Error
|
||||
* @retval 0 Invalid - cbret contains reason as netconf
|
||||
|
|
@ -881,7 +872,8 @@ upgrade_callback_delete_all(clicon_handle h)
|
|||
int
|
||||
upgrade_callback_call(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *namespace,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
cbuf *cbret)
|
||||
|
|
@ -903,23 +895,21 @@ upgrade_callback_call(clicon_handle h,
|
|||
* - Registered from revision >= from AND
|
||||
* - Registered to revision <= to (which includes case both 0)
|
||||
*/
|
||||
if (uc->uc_namespace == NULL || strcmp(uc->uc_namespace, namespace)==0)
|
||||
if ((uc->uc_from == 0) ||
|
||||
(uc->uc_from >= from && uc->uc_rev <= to)){
|
||||
if ((ret = uc->uc_callback(h, xt, namespace, from, to, uc->uc_arg, cbret)) < 0){
|
||||
clicon_debug(1, "%s Error in: %s", __FUNCTION__, uc->uc_namespace);
|
||||
if (uc->uc_namespace == NULL || strcmp(uc->uc_namespace, ns)==0){
|
||||
if ((ret = uc->uc_callback(h, xt, ns, op, from, to, uc->uc_arg, cbret)) < 0){
|
||||
clicon_debug(1, "%s Error in: %s", __FUNCTION__, uc->uc_namespace);
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
if (cbuf_len(cbret)==0){
|
||||
clicon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set",
|
||||
uc->uc_fnstr, ns);
|
||||
goto done;
|
||||
}
|
||||
if (ret == 0){
|
||||
if (cbuf_len(cbret)==0){
|
||||
clicon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set",
|
||||
uc->uc_fnstr, namespace);
|
||||
goto done;
|
||||
}
|
||||
goto fail;
|
||||
}
|
||||
nr++;
|
||||
goto fail;
|
||||
}
|
||||
nr++;
|
||||
}
|
||||
uc = NEXTQ(upgrade_callback_t *, uc);
|
||||
} while (uc != upgrade_cb_list);
|
||||
retval = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue