Example #1
0
def extend_get_node(rpc, node, filter=None, defaults=None, inactive=None):
    if filter is not None:
        node.append(util.build_filter(filter, rpc._assert))
    if defaults is not None:
        etree.SubElement(node, qualify("with-defaults",
                                       DEFAULTS_NS)).text = defaults
    if inactive is not None:
        etree.SubElement(node, qualify("with-inactive", INACTIVE_NS))
    return node
Example #2
0
 def invoke(self, mc, ns, path=None):
     replydata = self._invoke(mc, ns, path)
     if "noaaa" in ns.style:
         aaa = replydata.find(qualify("aaa", TAILF_AAA_NS))
         if aaa is not None:
             replydata.remove(aaa)
         nacm = replydata.find(qualify("nacm", IETF_NACM_NS))
         if nacm is not None:
             replydata.remove(nacm)
     return replydata
Example #3
0
 def invoke(self, mc, ns, stream=None):
     sub = etree.Element(qualify("create-subscription", NOTIFICATION_NS))
     if stream is not None:
         etree.SubElement(sub, qualify("stream",
                                       NOTIFICATION_NS)).text = stream
     if ns.xpath is not None:
         etree.SubElement(sub,
                          qualify("filter", NOTIFICATION_NS),
                          type="xpath",
                          select=ns.xpath)
     self.start_listener(mc)
     reply = mc.rpc(sub)
     return reply._root[0]
Example #4
0
 def test_iosxe_transform_edit_config(self):
     node = new_ele("edit-config")
     node.append(
         validated_element(CFG_BROKEN, ("config", qualify("config"))))
     node = self.obj.transform_edit_config(node)
     config_nodes = node.findall('./config')
     self.assertTrue(len(config_nodes) == 0)
Example #5
0
    def __init__(self, raw):
        self._raw = raw
        notif_xml = ncxml.to_ele(self._raw)

        # The notification xml contains a xsd:sequence of two elements
        #   - eventTime
        #   - Notification Content (anyxml)
        if len(notif_xml) != 2:
            raise errors.OperationError(
                "Invalid notification xml. " +
                "Found {} elements.".format(len(notif_xml)))

        if notif_xml[0].tag != ncxml.qualify("eventTime", NC_NOTIFICATION_NS):
            raise errors.OperationError("Element eventTime not found")

        self._event_time = util.parse_datetime(notif_xml[0].text)
        self._event_xml = notif_xml[1]
Example #6
0
    def request(self, source):
        """Validate the contents of the specified configuration.

        *source* is the name of the configuration datastore being
         validated or `config` element containing the configuration
         subtree to be validated

        :seealso: :ref:`srctarget_params`
        """
        node = new_ele("validate")
        if type(source) is str:
            src = util.datastore_or_url("source", source, self._assert)
        else:
            validated_element(source, ("config", qualify("config")))
            src = new_ele("source")
            src.append(source)
        node.append(src)
        return self._request(node)
Example #7
0
def request(self,
            config,
            format='xml',
            target='candidate',
            default_operation=None,
            test_option=None,
            error_option=None):
    """Loads all or part of the specified *config* to the *target* configuration datastore.
    *target* is the name of the configuration datastore being edited
    *config* is the configuration, which must be rooted in the `config` element. It can be specified either as a string or an :class:`~xml.etree.ElementTree.Element`.
    *default_operation* if specified must be one of { `"merge"`, `"replace"`, or `"none"` }
    *test_option* if specified must be one of { `"test_then_set"`, `"set"` }
    *error_option* if specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` }
    The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability.
    """
    node = new_ele("edit-config")
    # node.append(util.datastore_or_url("target", target, self._assert))
    node.append(
        operations.util.datastore_or_url("target", target, self._assert))
    if error_option is not None:
        if error_option == "rollback-on-error":
            self._assert(":rollback-on-error")
        sub_ele(node, "error-option").text = error_option
    if test_option is not None:
        self._assert(':validate')
        sub_ele(node, "test-option").text = test_option
    if default_operation is not None:
        # TODO: check if it is a valid default-operation
        sub_ele(node, "default-operation").text = default_operation
# <<<<<<< HEAD
#         node.append(validated_element(config, ("config", qualify("config"))))
# =======
    if format == 'xml':
        # node.append(validated_element(config, ("config", qualify("config"))))
        _append(node, validated_element(config, ("config", qualify("config"))))
    if format == 'text':
        config_text = sub_ele(node, "config-text")
        sub_ele(config_text, "configuration-text").text = config


# >>>>>>> juniper
    return self._request(node)
Example #8
0
    def callback(self, root, raw):
        """Handles the notification netconf message and invokes the registered
        notification callback if any

        Arguments:
            root - contains a tuple a top level tag and its attributes of the
                   received message
            raw  - XML raw string received from the Netconf server
        """
        tag, attrs = root
        if tag != ncxml.qualify("notification", NC_NOTIFICATION_NS):
            return

        logger.info('Notification received %s', raw)
        try:
            if self._session.notification_callback is not None:
                notification_event = Notification(raw)
                self._session.notification_callback(notification_event)
        except errors.OperationError as exp:
            logger.error('Invalid Notification Received: %s %s', exp, raw)
Example #9
0
 def _mock_manager_3foobar_warnings(self, *args, **kwargs):
     cmd = """
     <load-configuration action="set" format="text">
         <configuration-set>
             delete interfaces ge-0/0/0
             delete protocols ospf
             delete policy-options prefix-list foo
         </configuration-set>
     </load-configuration>
     """
     rsp_string = """
     <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/16.1R4/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:1f3dfa00-3434-414a-8aa8-0073590c5812">
         <load-configuration-results>
             <rpc-error>
                 <error-severity>warning</error-severity>
                 <error-message>
                     foo boom
                 </error-message>
             </rpc-error>
             <rpc-error>
                 <error-severity>warning</error-severity>
                 <error-message>
                     boom bar
                 </error-message>
             </rpc-error>
             <rpc-error>
                 <error-severity>warning</error-severity>
                 <error-message>
                     foo bar
                 </error-message>
             </rpc-error>
             <ok/>
         </load-configuration-results>
     </rpc-reply>
     """
     rsp = XML(rsp_string)
     errors = []
     for err in rsp.findall('.//' + qualify('rpc-error')):
         errors.append(RPCError(err))
     raise RPCError(rsp, errs=errors)
Example #10
0
 def _mock_manager_3foobar_warnings(self, *args, **kwargs):
     cmd = """
     <load-configuration action="set" format="text">
         <configuration-set>
             delete interfaces ge-0/0/0
             delete protocols ospf
             delete policy-options prefix-list foo
         </configuration-set>
     </load-configuration>
     """
     rsp_string = """
     <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/16.1R4/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:1f3dfa00-3434-414a-8aa8-0073590c5812">
         <load-configuration-results>
             <rpc-error>
                 <error-severity>warning</error-severity>
                 <error-message>
                     foo boom
                 </error-message>
             </rpc-error>
             <rpc-error>
                 <error-severity>warning</error-severity>
                 <error-message>
                     boom bar
                 </error-message>
             </rpc-error>
             <rpc-error>
                 <error-severity>warning</error-severity>
                 <error-message>
                     foo bar
                 </error-message>
             </rpc-error>
             <ok/>
         </load-configuration-results>
     </rpc-reply>
     """
     rsp = XML(rsp_string)
     errors = []
     for err in rsp.findall('.//'+qualify('rpc-error')):
         errors.append(RPCError(err))
     raise RPCError(rsp, errs=errors)
Example #11
0
 def _mock_manager_1snf_warning_1err(self, *args, **kwargs):
     cmd = """
     <load-configuration action="set" format="text">
         <configuration-set>
             delete interfaces ge-0/0/0
             delete protcols ospf
             delete policy-options prefix-list foo
         </configuration-set>
     </load-configuration>
     """
     rsp_string = """
     <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/16.1R4/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:1f3dfa00-3434-414a-8aa8-0073590c5812">
         <load-configuration-results>
             <rpc-error>
                 <error-severity>warning</error-severity>
                 <error-message>
                 statement not found
                 </error-message>
             </rpc-error>
             <rpc-error>
                 <error-type>protocol</error-type>
                 <error-tag>operation-failed</error-tag>
                 <error-severity>error</error-severity>
                 <error-message>syntax error</error-message>
                 <error-info>
                 <bad-element>protcols</bad-element>
                 </error-info>
             </rpc-error>
             <ok/>
         </load-configuration-results>
     </rpc-reply>
     """
     rsp = XML(rsp_string)
     errors = []
     for err in rsp.findall(".//" + qualify("rpc-error")):
         errors.append(RPCError(err))
     raise RPCError(rsp, errs=errors)
Example #12
0
 def callback(self, root, raw):
     tag, attrs = root
     if tag != qualify("notification", NOTIFICATION_NS):
         return
     print(raw)