08-31-2020 02:26 AM
I want to configure a service using an action with code written in Python.
To be able to rollback that configuration would like to get the commit ID to be passed as result (output) of the action. Then, using that ID, I want to rollback that specific commit using in another action.
So what I need is somethiong like that
Configuring Action
with ncs.maapi.Maapi() as m:
with ncs.maapi.Session(m, uinfo.username, uinfo.context):
with m.start_write_trans() as t:
root = ncs.maagic.get_root(t)
Some code
t.apply()
output.commitID = ?????
Rollbacl Action
with ncs.maapi.Maapi() as m:
with ncs.maapi.Session(m, uinfo.username, uinfo.context):
with m.start_write_trans() as t:
Somecommand(input.commitID)
Solved! Go to Solution.
09-02-2020 04:55 AM
07-05-2021 10:02 PM
Adding rollback example using commit label:
def _rollback(username, commit_label): success = False rollback_num = __get_rollback_num(username, commit_label) print('Rollback Number:', rollback_num) try: with ncs.maapi.single_write_trans(username, 'system') as write_trans: # perform rollback _ncs.maapi.load_rollback_fixed(write_trans.maapi.msock, write_trans.th, rollback_num) write_trans.apply() print(f'Rollback {rollback_num} success') success = True except Exception as e: print(str(e)) return success def __get_rollback_num(username, commit_label): with ncs.maapi.single_read_trans(username, 'system') as read_trans: rollbacks = _ncs.maapi.list_rollbacks(read_trans.maapi.msock, 10) for rollback in rollbacks: if rollback.label == commit_label: return rollback.fixed_nr return -1
09-01-2020 05:17 AM
Hi,
In NSO5.4, we added support for receiving the rollback id in the commit:
- ncs: Add support for retrieving id of the rollback file created during a
transaction commit. The id returned can later be used to do selective
rollback. See API documentation for details. C, Python, Java, and Erlang
MAAPI interfaces supported. CLI, RESTCONF, NETCONF, and JSON-RPC
supported.
I believe the new python method is:
_ncs.maapi.get_rollback_id(sock, thandle) -> int
Get rollback id from a committed transaction. Returns int with fixed id,
where -1 indicates an error or no rollback id available.
Keyword arguments:
sock -- a python socket instance
thandle -- transaction handle
09-02-2020 12:32 AM
Thanks for the information.
I undestand that with the release 4.6.5 that I'm using there is non possibility to accomplish that task.
As a work-around is it possible to set a label an later have an action that rollback selective that commit?
09-02-2020 04:55 AM
07-05-2021 10:02 PM
Adding rollback example using commit label:
def _rollback(username, commit_label): success = False rollback_num = __get_rollback_num(username, commit_label) print('Rollback Number:', rollback_num) try: with ncs.maapi.single_write_trans(username, 'system') as write_trans: # perform rollback _ncs.maapi.load_rollback_fixed(write_trans.maapi.msock, write_trans.th, rollback_num) write_trans.apply() print(f'Rollback {rollback_num} success') success = True except Exception as e: print(str(e)) return success def __get_rollback_num(username, commit_label): with ncs.maapi.single_read_trans(username, 'system') as read_trans: rollbacks = _ncs.maapi.list_rollbacks(read_trans.maapi.msock, 10) for rollback in rollbacks: if rollback.label == commit_label: return rollback.fixed_nr return -1
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: