cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
571
Views
5
Helpful
1
Replies

NSO python rollback with commit queue

yann.gayral
Level 1
Level 1

update : just fixed a syntax error in the code snippet below. get_rollback_id seems to works also in a commit queue context !

Hello,

We'd like to facilitate rollback action for persons operating action on the network handled by NSO. They may not have direct access to NSO to manually find a rollback file so we need to programmatically get the rollback ID.

We saw that this would be possible since NSO 5.4 so we've waited for it until we recently upgrade from NSO 5.2.8 to 5.7.4. It works as expected for basic transaction but we encounter an error when we try to use it along commit queue :

 

 

 

with ncs.maapi.Maapi() as m:
    with ncs.maapi.Session(m, uinfo.username, 'system'):
        with m.start_write_trans() as t:
            root = ncs.maagic.get_root(t)
            root.devices.device['DEVICE1'].config.port['4/2/5'].description = "test"
            commit_params = ncs.maapi.CommitParams()
            commit_params.no_overwrite()
            commit_params.commit_queue_sync()
            commit_params.commit_queue_atomic()
            commit_params.commit_queue_error_option("rollback-on-error")
            result = t.apply_params(params=commit_params)
            try:
                cq_id = result["id"]
            except KeyError:
                cq_id = None
                self.log.info("Pas de commit queue ID")
            else:
                status = result["status"]
                if status != 'completed':
                    self.log.info("Error sending conf")
                else:
                    rollbackID = _ncs.maapi.get_rollback_id(t.maapi.msock,t.th)
                    output.result = "configuration OK, rollback ID : " + str(rollbackID)

 

 

 

Error: Python cb_action error. Bad protocol usage or unexpected retval (21): not allowed for attached transaction

I've tried to tune cq-params (remove no-overwrite, cq-atomic, error-option) and set cq-async but same result yet. I didn't found a lot of documentation on top of the maapi spec : https://developer.cisco.com/docs/nso/api/#!_ncs-maapi/module-_ncs-maapi

Does anyone know if there is a way to use the get_rollback_id maapi function with commit queue ?

Thanks,

Regards,

Yann Gayral
Orange (fr)

1 Accepted Solution

Accepted Solutions

yann.gayral
Level 1
Level 1

just fixed a syntax error in the code snippet below. get_rollback_id seems to works also in a commit queue context !

View solution in original post

1 Reply 1

yann.gayral
Level 1
Level 1

just fixed a syntax error in the code snippet below. get_rollback_id seems to works also in a commit queue context !

Getting Started

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: