| 1 |
# Copyright 2009 Shikhar Bhushan |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
|
| 16 |
from ncclient.operations.rpc import RPC |
| 17 |
|
| 18 |
from ncclient.xml_ import * |
| 19 |
|
| 20 |
from ncclient.operations import util |
| 21 |
|
| 22 |
class CreateSubscription(RPC): |
| 23 |
"`create-subscription` RPC. Depends on the `:notification` capability." |
| 24 |
|
| 25 |
DEPENDS = [':notification'] |
| 26 |
|
| 27 |
def request(self, filter=None, stream_name=None, start_time=None, stop_time=None): |
| 28 |
"""Creates a subscription for notifications from the server. |
| 29 |
|
| 30 |
*filter* specifies the subset of notifications to receive (by |
| 31 |
default all notificaitons are received) |
| 32 |
|
| 33 |
:seealso: :ref:`filter_params` |
| 34 |
|
| 35 |
*stream_name* specifies the notification stream name. The |
| 36 |
default is None meaning all streams. |
| 37 |
|
| 38 |
*start_time* triggers the notification replay feature to |
| 39 |
replay notifications from the given time. The default is None, |
| 40 |
meaning that this is not a replay subscription. The format is |
| 41 |
an RFC 3339/ISO 8601 date and time. |
| 42 |
|
| 43 |
*stop_time* indicates the end of the notifications of |
| 44 |
interest. This parameter must be used with *start_time*. The |
| 45 |
default is None, meaning that (if *start_time* is present) the |
| 46 |
notifications will continue until the subscription is |
| 47 |
terminated. The format is an RFC 3339/ISO 8601 date and time. |
| 48 |
|
| 49 |
""" |
| 50 |
node = new_ele_ns("create-subscription", NETCONF_NOTIFICATION_NS) |
| 51 |
if filter is not None: |
| 52 |
node.append(util.build_filter(filter)) |
| 53 |
if stream_name is not None: |
| 54 |
sub_ele_ns(node, "stream", NETCONF_NOTIFICATION_NS).text = stream_name |
| 55 |
|
| 56 |
if start_time is not None: |
| 57 |
sub_ele_ns(node, "startTime", NETCONF_NOTIFICATION_NS).text = start_time |
| 58 |
|
| 59 |
if stop_time is not None: |
| 60 |
if start_time is None: |
| 61 |
raise ValueError("You must provide start_time if you provide stop_time") |
| 62 |
sub_ele_ns(node, "stopTime", NETCONF_NOTIFICATION_NS).text = stop_time |
| 63 |
|
| 64 |
return self._request(node) |