| 1 |
from ncclient.operations import OperationError |
| 2 |
from ncclient.xml_ import * |
| 3 |
|
| 4 |
from ncclient.operations.rpc import RPC |
| 5 |
|
| 6 |
def global_operations(node): |
| 7 |
"""Instantiate an SR OS global operation action element |
| 8 |
|
| 9 |
Args: |
| 10 |
node: A string representing the top-level action for a |
| 11 |
given global operation. |
| 12 |
Returns: |
| 13 |
A tuple of 'lxml.etree._Element' values. The first value |
| 14 |
represents the top-level YANG action element and the second |
| 15 |
represents the caller supplied initial node. |
| 16 |
""" |
| 17 |
parent, child = yang_action('global-operations', |
| 18 |
attrs={'xmlns': SROS_GLOBAL_OPS_NS}) |
| 19 |
ele = sub_ele(child, node) |
| 20 |
return (parent, ele) |
| 21 |
|
| 22 |
class MdCliRawCommand(RPC): |
| 23 |
def request(self, command=None): |
| 24 |
node, raw_cmd_node = global_operations('md-cli-raw-command') |
| 25 |
sub_ele(raw_cmd_node, 'md-cli-input-line').text = command |
| 26 |
self._huge_tree = True |
| 27 |
return self._request(node) |
| 28 |
|
| 29 |
|
| 30 |
class Commit(RPC): |
| 31 |
"`commit` RPC. Depends on the `:candidate` capability, and the `:confirmed-commit`." |
| 32 |
|
| 33 |
DEPENDS = [':candidate'] |
| 34 |
|
| 35 |
def request(self, confirmed=False, timeout=None, persist=None, persist_id=None, comment=None): |
| 36 |
"""Commit the candidate configuration as the device's new current configuration. Depends on the `:candidate` capability. |
| 37 |
|
| 38 |
A confirmed commit (i.e. if *confirmed* is `True`) is reverted if there is no followup commit within the *timeout* interval. If no timeout is specified the confirm timeout defaults to 600 seconds (10 minutes). A confirming commit may have the *confirmed* parameter but this is not required. Depends on the `:confirmed-commit` capability. |
| 39 |
|
| 40 |
*confirmed* whether this is a confirmed commit |
| 41 |
|
| 42 |
*timeout* specifies the confirm timeout in seconds |
| 43 |
|
| 44 |
*persist* make the confirmed commit survive a session termination, and set a token on the ongoing confirmed commit |
| 45 |
|
| 46 |
*persist_id* value must be equal to the value given in the <persist> parameter to the original <commit> operation. |
| 47 |
|
| 48 |
*comment* a descriptive text comment that will be associated with the commit action. This is useful for logging or audit purposes. |
| 49 |
""" |
| 50 |
|
| 51 |
node = new_ele("commit") |
| 52 |
if comment and comment.strip(): |
| 53 |
sub_ele(node, "comment", |
| 54 |
attrs={'xmlns': "urn:nokia.com:sros:ns:yang:sr:ietf-netconf-augments"}).text = comment |
| 55 |
|
| 56 |
if persist and persist_id: |
| 57 |
raise OperationError("Invalid operation as persist cannot be present with persist-id") |
| 58 |
if confirmed: |
| 59 |
self._assert(":confirmed-commit") |
| 60 |
sub_ele(node, "confirmed") |
| 61 |
if timeout is not None: |
| 62 |
sub_ele(node, "confirm-timeout").text = timeout |
| 63 |
if persist is not None: |
| 64 |
sub_ele(node, "persist").text = persist |
| 65 |
if persist_id: |
| 66 |
sub_ele(node, "persist-id").text = persist_id |
| 67 |
|
| 68 |
return self._request(node) |