Пример #1
0
    def request(self, content='xml', filter=None, detail=False):
        """Get config from Alu router
        *content*   Content layer. cli or xml
        *filter*    specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
        *detail*    Show detailed config in CLI -layer"""

        node = new_ele('get-config')
        node.append(util.datastore_or_url('source', 'running', self._assert))

        if filter is not None:

            if content == 'xml':
                node.append(util.build_filter(('subtree', filter)))

            elif content == 'cli':
                rep = new_ele('filter')
                sub_filter = sub_ele(rep, 'config-format-cli-block')

                if filter is not None:
                    for item in filter:
                        if detail:
                            sub_ele(sub_filter, 'cli-info-detail').text = item
                        else:
                            sub_ele(sub_filter, 'cli-info').text = item
                else:
                    if detail:
                        sub_ele(sub_filter, 'cli-info-detail')
                    else:
                        sub_ele(sub_filter, 'cli-info')

                node.append(validated_element(rep))

        return self._request(node)
Пример #2
0
    def request(self, rpc_command, source=None, filter=None):
        """
        *rpc_command* specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)

        *source* name of the configuration datastore being queried

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`

        Examples of usage::

            dispatch('clear-arp-table')

        or dispatch element like ::

            xsd_fetch = new_ele('get-xnm-information')
            sub_ele(xsd_fetch, 'type').text="xml-schema"
            sub_ele(xsd_fetch, 'namespace').text="junos-configuration"
            dispatch(xsd_fetch)
        """

        if etree.iselement(rpc_command):
            node = rpc_command
        else:
            node = new_ele(rpc_command)
        if source is not None:
            node.append(util.datastore_or_url("source", source, self._assert))
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)
Пример #3
0
    def request(self, rpc_command, source=None, filter=None):
        """
        *rpc_command* specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)

        *source* name of the configuration datastore being queried

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`

        Examples of usage::

            dispatch('clear-arp-table')

        or dispatch element like ::

            xsd_fetch = new_ele('get-xnm-information')
            sub_ele(xsd_fetch, 'type').text="xml-schema"
            sub_ele(xsd_fetch, 'namespace').text="junos-configuration"
            dispatch(xsd_fetch)
        """


        if etree.iselement(rpc_command):
            node = rpc_command
        else:
            node = new_ele(rpc_command)
        if source is not None:
            node.append(util.datastore_or_url("source", source, self._assert))
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)
Пример #4
0
    def request(self, content='xml', filter=None, detail=False):
        """Get config from Alu router
        *content*   Content layer. cli or xml
        *filter*    specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
        *detail*    Show detailed config in CLI -layer"""

        node = new_ele('get-config')
        node.append(util.datastore_or_url('source', 'running', self._assert))

        if filter is not None:

            if content == 'xml':
                node.append(util.build_filter(('subtree', filter)))

            elif content == 'cli':
                rep = new_ele('filter')
                sub_filter = sub_ele(rep, 'config-format-cli-block')

                if filter is not None:
                    for item in filter:
                        if detail:
                            sub_ele(sub_filter, 'cli-info-detail').text = item
                        else:
                            sub_ele(sub_filter, 'cli-info').text = item
                else:
                    if detail:
                        sub_ele(sub_filter, 'cli-info-detail')
                    else:
                        sub_ele(sub_filter, 'cli-info')

                node.append(validated_element(rep))

        return self._request(node)
Пример #5
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
Пример #6
0
    def request(self, callback, errback, manager=None, retries=20, delay=1,
        stream=None, filter=None, start_time=None, stop_time=None):

        """Create a subscription to NETCONF server

        *callback* user-defined callback function to be invoked when a notfiication arrives

        *errback* user-defined function to be invoked when an error occurs

        *manager* Manager object returned when user connects to NETCONF server,
        used to store connection info so ncclient can reconnect using that information
        (by default ncclient will not handle reconnecting the the NETCONF server if user
        does not pass in a manager)

        *retries* specifies the number of times ncclient will attempt to reconnect to VTS
        if the connection is dropped

        *delay* specifies the time ncclient will wait between consecutive attempts to
        reconnect to VTS following a dropped connection

        *stream* specifies the stream user want to receive notifications from
        (by default NETCONF stream notifications)

        *filter* specifies the notifications user wants to receive
        based on xml subtree structure and content (by default all notifications arrive)

        *start_time* specifies the time user wants to start receiving notifications
        (by default start from present time)

        *stop_time* specifies time time user wants to stop receiving notifications

        :seealso: :ref:`filter_params`"""

        if callback is None:
            raise ValueError("Missing a callback function")

        if errback is None:
            raise ValueError("Missing a errback function")

        subscription_node = etree.Element(qualify("create-subscription", NETCONF_NOTIFICATION_NS))

        if stream is not None:
            streamTag = etree.Element(qualify("stream"))
            streamTag.text = stream
            subscription_node.append(streamTag)
        if filter is not None:
            subscription_node.append(util.build_filter(filter))
        if start_time is not None:
            subscription_node.append(self.datetime_to_rfc("startTime", start_time))
        if stop_time is not None:
            subscription_node.append(self.datetime_to_rfc("stopTime", stop_time))
        self.session.add_listener(NotificationListener(callback, errback,
            manager=manager, retries=retries, delay=delay,
            stream=stream, filter=filter, start_time=start_time, stop_time=stop_time))
        return self._request(subscription_node)
Пример #7
0
    def request(self, filter=None):
        """Retrieve running configuration and device state information.

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`
        """
        node = new_ele("get-bulk")
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)
Пример #8
0
    def request(self, filter=None):
        """Retrieve running configuration and device state information.

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`
        """
        node = new_ele("get")
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)
Пример #9
0
    def request(self, source, filter=None):
        """Retrieve all or part of a specified configuration.

        *source* name of the configuration datastore being queried

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`"""
        node = new_ele("get-bulk-config")
        node.append(util.datastore_or_url("source", source, self._assert))
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)
Пример #10
0
    def request(self, source, filter=None):
        """Retrieve all or part of a specified configuration.

        *source* name of the configuration datastore being queried

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`"""
        node = new_ele("get-config")
        node.append(util.datastore_or_url("source", source, self._assert))
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)
Пример #11
0
    def request(self, filter=None, with_defaults=None):
        """Retrieve running configuration and device state information.

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        *with_defaults* defines an explicit method of retrieving default values from the configuration (see RFC 6243)

        :seealso: :ref:`filter_params`
        """
        node = new_ele("get")
        if filter is not None:
            node.append(util.build_filter(filter))
        if with_defaults is not None:
            self._assert(":with-defaults")
            _append_with_defaults(node, with_defaults)
        return self._request(node)
Пример #12
0
    def request(self,
                rpc_command,
                source=None,
                filter=None,
                config=None,
                target=None,
                format=None):
        """
        *rpc_command* specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)

        *target* name of the configuration datastore being edited

        *source* name of the configuration datastore being queried

        *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`.

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`

        Examples of usage::

            m.rpc('rpc_command')

        or dispatch element like ::

            rpc_command = new_ele('get-xnm-information')
            sub_ele(rpc_command, 'type').text = "xml-schema"
            m.rpc(rpc_command)
        """

        if etree.iselement(rpc_command):
            node = rpc_command
        else:
            node = new_ele(rpc_command)
        if target is not None:
            node.append(util.datastore_or_url("target", target, self._assert))
        if source is not None:
            node.append(util.datastore_or_url("source", source, self._assert))
        if filter is not None:
            node.append(util.build_filter(filter))
        if config is not None:
            node.append(
                validated_element(config, ("config", qualify("config"))))

        return self._request(node)
Пример #13
0
    def request(self, callback, errback, notifListening=False, filter=None):

        node = new_ele("get")
        if filter is not None:
            node.append(util.build_filter(filter))
        if notifListening is False:
            self.session.add_listener(
                YangPushNotificationListener(callback, errback))

        print("\n")
        print("get subscription rpc:")
        print(to_xml(node, pretty_print=True))

        reply = self._request(node)

        print(reply)
        return reply
Пример #14
0
    def request(self,
                filter=None,
                stream_name=None,
                start_time=None,
                stop_time=None):
        """Creates a subscription for notifications from the server.

        *filter* specifies the subset of notifications to receive (by
        default all notificaitons are received)

        :seealso: :ref:`filter_params`

        *stream_name* specifies the notification stream name. The
        default is None meaning all streams.

        *start_time* triggers the notification replay feature to
        replay notifications from the given time. The default is None,
        meaning that this is not a replay subscription. The format is
        an RFC 3339/ISO 8601 date and time.

        *stop_time* indicates the end of the notifications of
        interest. This parameter must be used with *start_time*. The
        default is None, meaning that (if *start_time* is present) the
        notifications will continue until the subscription is
        terminated. The format is an RFC 3339/ISO 8601 date and time.

        """
        node = new_ele_ns("create-subscription", NETCONF_NOTIFICATION_NS)
        if filter is not None:
            node.append(util.build_filter(filter))
        if stream_name is not None:
            sub_ele_ns(node, "stream",
                       NETCONF_NOTIFICATION_NS).text = stream_name

        if start_time is not None:
            sub_ele_ns(node, "startTime",
                       NETCONF_NOTIFICATION_NS).text = start_time

        if stop_time is not None:
            if start_time is None:
                raise ValueError(
                    "You must provide start_time if you provide stop_time")
            sub_ele_ns(node, "stopTime",
                       NETCONF_NOTIFICATION_NS).text = stop_time

        return self._request(node)
Пример #15
0
    def request(self, source, filter=None, with_defaults=None):
        """Retrieve all or part of a specified configuration.

        *source* name of the configuration datastore being queried

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        *with_defaults* defines an explicit method of retrieving default values from the configuration (see RFC 6243)

        :seealso: :ref:`filter_params`"""
        node = new_ele("get-config")
        node.append(util.datastore_or_url("source", source, self._assert))
        if filter is not None:
            node.append(util.build_filter(filter))
        if with_defaults is not None:
            self._assert(":with-defaults")
            _append_with_defaults(node, with_defaults)
        return self._request(node)
Пример #16
0
    def request(self,
                stream=None,
                filter=None,
                start_time=None,
                stop_time=None):
        """Create a subscription to receive notifications on the session

        Arguments:
            stream - Optional string that specifies the stream of interest
            filter - XML subtree or XPath that indicates which subset of all
                     posible events is of interest
            start_time - Used to trigger the replay feature and indicates when
                         the replay should start. Type: datetime
            stop_time  - Indicates the newest notifications of interest. Used
                         with the replay feature and is a datetime type.
        """
        node = etree.Element("{%s}create-subscription" % NC_NOTIFICATION_NS)

        if stream is not None:
            stream_ele = etree.SubElement(node,
                                          "{%s}stream" % NC_NOTIFICATION_NS)
            stream_ele.text = stream

        if filter is not None:
            node.append(util.build_filter(filter))

        if start_time is not None:
            st_ele = etree.SubElement(node,
                                      "{%s}startTime" % NC_NOTIFICATION_NS)
            start_time = util.datetime_to_string(start_time)
            st_ele.text = start_time

        if stop_time is not None:
            st_ele = etree.SubElement(node, "{%s}endTime" % NC_NOTIFICATION_NS)
            stop_time = util.datetime_to_string(stop_time)
            st_ele.text = stop_time

        notify_listener = NotificationListener(self._session,
                                               self._device_handler)

        return self._request(node)
Пример #17
0
    def request(self, filter=None, stream_name=None, start_time=None, stop_time=None):
        """Creates a subscription for notifications from the server.

        *filter* specifies the subset of notifications to receive (by
        default all notificaitons are received)

        :seealso: :ref:`filter_params`

        *stream_name* specifies the notification stream name. The
        default is None meaning all streams.

        *start_time* triggers the notification replay feature to
        replay notifications from the given time. The default is None,
        meaning that this is not a replay subscription. The format is
        an RFC 3339/ISO 8601 date and time.

        *stop_time* indicates the end of the notifications of
        interest. This parameter must be used with *start_time*. The
        default is None, meaning that (if *start_time* is present) the
        notifications will continue until the subscription is
        terminated. The format is an RFC 3339/ISO 8601 date and time.

        """
        node = new_ele_ns("create-subscription", NETCONF_NOTIFICATION_NS)
        if filter is not None:
            node.append(util.build_filter(filter))
        if stream_name is not None:
            sub_ele(node, "stream").text = stream_name

        if start_time is not None:
            sub_ele(node, "startTime").text = start_time

        if stop_time is not None:
            if start_time is None:
                raise ValueError("You must provide start_time if you provide stop_time")
            sub_ele(node, "stopTime").text = stop_time

        return self._request(node)
Пример #18
0
    def request(self,
                stream=None,
                encoding=None,
                filter=None,
                subtree_filter=None,
                xpath_filter=None,
                period=None,
                no_synch_on_start=False,
                dampening_period=None):
        """Creates a subscription for notifications from the server.

        *filter* specifies the subset of notifications to receive (by
        default all notificaitons are received)

        :seealso: :ref:`filter_params`

        *stream_name* specifies the notification stream name. The
        default is None meaning all streams.

        *start_time* triggers the notification replay feature to
        replay notifications from the given time. The default is None,
        meaning that this is not a replay subscription. The format is
        an RFC 3339/ISO 8601 date and time.

        *stop_time* indicates the end of the notifications of
        interest. This parameter must be used with *start_time*. The
        default is None, meaning that (if *start_time* is present) the
        notifications will continue until the subscription is
        terminated. The format is an RFC 3339/ISO 8601 date and time.

        """
        ns = {
            None: IETF_NOTIFICATION_NS,
            'yp': IETF_PUSH_NS,
        }
        node = new_ele_ns("establish-subscription",
                          IETF_NOTIFICATION_NS,
                          nsmap=ns)

        if stream is not None:
            sub_ele_ns(node, "stream", IETF_NOTIFICATION_NS).text = stream

        if encoding is not None:
            sub_ele_ns(node, "encoding", IETF_NOTIFICATION_NS).text = encoding

        if filter is not None:
            # node.append(util.build_filter(filter))
            node.append(filter)

        if subtree_filter is not None:
            node.append(util.build_filter(subtree_filter))

        if xpath_filter is not None:
            sub_ele_ns(node, "xpath-filter", IETF_PUSH_NS).text = xpath_filter

        if period is not None:
            sub_ele_ns(node, "period", IETF_PUSH_NS).text = str(period)

        if no_synch_on_start:
            sub_ele_ns(node, "no-synch-on-start", IETF_PUSH_NS)

        if dampening_period is not None:
            sub_ele_ns(node, "dampening-period",
                       IETF_PUSH_NS).text = str(dampening_period)

        return self._request(node)