<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic NSO python rollback with commit queue in NSO Developer Hub Discussions</title>
    <link>https://community.cisco.com/t5/nso-developer-hub-discussions/nso-python-rollback-with-commit-queue/m-p/4720796#M7516</link>
    <description>&lt;P&gt;update : just fixed a syntax error in the code snippet below. get_rollback_id seems to works also in a commit queue context !&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;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 :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Error: Python cb_action error. Bad protocol usage or unexpected retval (21): &lt;STRONG&gt;not allowed for attached transaction&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;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 : &lt;A href="https://developer.cisco.com/docs/nso/api/#!_ncs-maapi/module-_ncs-maapi" target="_blank" rel="noopener"&gt;https://developer.cisco.com/docs/nso/api/#!_ncs-maapi/module-_ncs-maapi&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Does anyone know if there is a way to use the get_rollback_id maapi function with commit queue ?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Yann Gayral&lt;BR /&gt;Orange (fr)&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2022 10:07:24 GMT</pubDate>
    <dc:creator>yann.gayral</dc:creator>
    <dc:date>2022-11-14T10:07:24Z</dc:date>
    <item>
      <title>NSO python rollback with commit queue</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/nso-python-rollback-with-commit-queue/m-p/4720796#M7516</link>
      <description>&lt;P&gt;update : just fixed a syntax error in the code snippet below. get_rollback_id seems to works also in a commit queue context !&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;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 :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Error: Python cb_action error. Bad protocol usage or unexpected retval (21): &lt;STRONG&gt;not allowed for attached transaction&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;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 : &lt;A href="https://developer.cisco.com/docs/nso/api/#!_ncs-maapi/module-_ncs-maapi" target="_blank" rel="noopener"&gt;https://developer.cisco.com/docs/nso/api/#!_ncs-maapi/module-_ncs-maapi&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Does anyone know if there is a way to use the get_rollback_id maapi function with commit queue ?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Yann Gayral&lt;BR /&gt;Orange (fr)&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 10:07:24 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/nso-python-rollback-with-commit-queue/m-p/4720796#M7516</guid>
      <dc:creator>yann.gayral</dc:creator>
      <dc:date>2022-11-14T10:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: NSO python rollback with commit queue</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/nso-python-rollback-with-commit-queue/m-p/4720809#M7517</link>
      <description>&lt;P&gt;just fixed a syntax error in the code snippet below. get_rollback_id seems to works also in a commit queue context !&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 10:08:31 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/nso-python-rollback-with-commit-queue/m-p/4720809#M7517</guid>
      <dc:creator>yann.gayral</dc:creator>
      <dc:date>2022-11-14T10:08:31Z</dc:date>
    </item>
  </channel>
</rss>

