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
|
|
@ -535,9 +535,9 @@ static const map_str2str namespace_map[] = {
|
|||
*/
|
||||
int
|
||||
example_upgrade(clicon_handle h,
|
||||
char *db,
|
||||
cxobj *xt,
|
||||
modstate_diff_t *msd)
|
||||
char *db,
|
||||
cxobj *xt,
|
||||
modstate_diff_t *msd)
|
||||
{
|
||||
int retval = -1;
|
||||
cvec *nsc = NULL; /* Canonical namespace */
|
||||
|
|
@ -616,16 +616,17 @@ example_upgrade(clicon_handle h,
|
|||
* @param[in] h Clicon handle
|
||||
* @param[in] xn XML tree to be updated
|
||||
* @param[in] ns Namespace of module (for info)
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
|
||||
* @param[in] from From revision on the form YYYYMMDD
|
||||
* @param[in] to To revision on the form YYYYMMDD (0 not in system)
|
||||
* @param[in] arg User argument given at rpc_callback_register()
|
||||
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
|
||||
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error.. if retval = 0
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid
|
||||
* @retval -1 Error
|
||||
* @see clicon_upgrade_cb
|
||||
* @see test_upgrade_interfaces.sh
|
||||
* @see upgrade_2016
|
||||
* @see upgrade_2014_to_2016
|
||||
* This example shows a two-step upgrade where the 2014 function does:
|
||||
* - Move /if:interfaces-state/if:interface/if:admin-status to
|
||||
* /if:interfaces/if:interface/
|
||||
|
|
@ -634,13 +635,14 @@ example_upgrade(clicon_handle h,
|
|||
* - Rename /interfaces/interface/description to descr
|
||||
*/
|
||||
static int
|
||||
upgrade_2016(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
void *arg,
|
||||
cbuf *cbret)
|
||||
upgrade_2014_to_2016(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
void *arg,
|
||||
cbuf *cbret)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yspec;
|
||||
|
|
@ -654,6 +656,7 @@ upgrade_2016(clicon_handle h,
|
|||
int i;
|
||||
char *name;
|
||||
|
||||
clicon_debug(1, "%s from:%d to:%d", __FUNCTION__, from, to);
|
||||
/* Get Yang module for this namespace. Note it may not exist (if obsolete) */
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((ym = yang_find_module_by_namespace(yspec, ns)) == NULL)
|
||||
|
|
@ -716,16 +719,17 @@ upgrade_2016(clicon_handle h,
|
|||
* @param[in] h Clicon handle
|
||||
* @param[in] xn XML tree to be updated
|
||||
* @param[in] ns Namespace of module (for info)
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
|
||||
* @param[in] from From revision on the form YYYYMMDD
|
||||
* @param[in] to To revision on the form YYYYMMDD (0 not in system)
|
||||
* @param[in] arg User argument given at rpc_callback_register()
|
||||
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error..
|
||||
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error.. if retval = 0
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid
|
||||
* @retval -1 Error
|
||||
* @see clicon_upgrade_cb
|
||||
* @see test_upgrade_interfaces.sh
|
||||
* @see upgrade_2016
|
||||
* @see upgrade_2016_to_2018
|
||||
* The 2016 function does:
|
||||
* - Delete /if:interfaces-state
|
||||
* - Wrap /interfaces/interface/descr to /interfaces/interface/docs/descr
|
||||
|
|
@ -733,13 +737,14 @@ upgrade_2016(clicon_handle h,
|
|||
* fraction-digits 3 and divide all values with 1000
|
||||
*/
|
||||
static int
|
||||
upgrade_2018(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
void *arg,
|
||||
cbuf *cbret)
|
||||
upgrade_2016_to_2018(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
void *arg,
|
||||
cbuf *cbret)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yspec;
|
||||
|
|
@ -752,6 +757,7 @@ upgrade_2018(clicon_handle h,
|
|||
size_t vlen;
|
||||
int i;
|
||||
|
||||
clicon_debug(1, "%s from:%d to:%d", __FUNCTION__, from, to);
|
||||
/* Get Yang module for this namespace. Note it may not exist (if obsolete) */
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
if ((ym = yang_find_module_by_namespace(yspec, ns)) == NULL)
|
||||
|
|
@ -800,6 +806,58 @@ upgrade_2018(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Testcase module-specific upgrade function moving interfaces-state to interfaces
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xn XML tree to be updated
|
||||
* @param[in] ns Namespace of module (for info)
|
||||
* @param[in] op One of XML_FLAG_ADD, _DEL, _CHANGE
|
||||
* @param[in] from From revision on the form YYYYMMDD
|
||||
* @param[in] to To revision on the form YYYYMMDD (0 not in system)
|
||||
* @param[in] arg User argument given at rpc_callback_register()
|
||||
* @param[out] cbret Return xml tree, eg <rpc-reply>..., <rpc-error.. if retval = 0
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid
|
||||
* @retval -1 Error
|
||||
* @see clicon_upgrade_cb
|
||||
* @see test_upgrade_interfaces.sh
|
||||
* @see upgrade_2014_to_2016
|
||||
* This example shows a two-step upgrade where the 2014 function does:
|
||||
* - Move /if:interfaces-state/if:interface/if:admin-status to
|
||||
* /if:interfaces/if:interface/
|
||||
* - Move /if:interfaces-state/if:interface/if:statistics to
|
||||
* /if:interfaces/if:interface/
|
||||
* - Rename /interfaces/interface/description to descr
|
||||
*/
|
||||
static int
|
||||
upgrade_interfaces(clicon_handle h,
|
||||
cxobj *xt,
|
||||
char *ns,
|
||||
uint16_t op,
|
||||
uint32_t from,
|
||||
uint32_t to,
|
||||
void *arg,
|
||||
cbuf *cbret)
|
||||
{
|
||||
int retval = -1;
|
||||
|
||||
if (from <= 20140508){
|
||||
if ((retval = upgrade_2014_to_2016(h, xt, ns, op, from, to, arg, cbret)) < 0)
|
||||
goto done;
|
||||
if (retval == 0)
|
||||
goto done;
|
||||
}
|
||||
if (from <= 20160101){
|
||||
if ((retval = upgrade_2016_to_2018(h, xt, ns, op, from, to, arg, cbret)) < 0)
|
||||
goto done;
|
||||
if (retval == 0)
|
||||
goto done;
|
||||
}
|
||||
// ok:
|
||||
retval = 1;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Plugin state reset. Add xml or set state in backend machine.
|
||||
* Called in each backend plugin. plugin_reset is called after all plugins
|
||||
* have been initialized. This give the application a chance to reset
|
||||
|
|
@ -1026,13 +1084,18 @@ clixon_plugin_init(clicon_handle h)
|
|||
* test interface example. Otherwise the auto-upgrade feature is enabled.
|
||||
*/
|
||||
if (_module_upgrade){
|
||||
if (upgrade_callback_register(h, upgrade_2016, "urn:example:interfaces", 20140508, 20160101, NULL) < 0)
|
||||
#if 1
|
||||
if (upgrade_callback_register(h, upgrade_interfaces, "urn:example:interfaces", NULL) < 0)
|
||||
goto done;
|
||||
if (upgrade_callback_register(h, upgrade_2018, "urn:example:interfaces", 20160101, 20180220, NULL) < 0)
|
||||
#else
|
||||
if (upgrade_callback_register(h, upgrade_2014_to_2016, "urn:example:interfaces", NULL) < 0)
|
||||
goto done;
|
||||
if (upgrade_callback_register(h, upgrade_2016_to_2018, "urn:example:interfaces", NULL) < 0)
|
||||
goto done;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
if (upgrade_callback_register(h, xml_changelog_upgrade, NULL, 0, 0, NULL) < 0)
|
||||
if (upgrade_callback_register(h, xml_changelog_upgrade, NULL, NULL) < 0)
|
||||
goto done;
|
||||
|
||||
/* Return plugin API */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue