root / ncclient / capabilities.py @ 6bd810f9
History | View | Annotate | Download (2.8 kB)
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 |
class Capabilities: |
17 |
|
18 |
"""Represent the capabilities of client or server. Also facilitates using
|
19 |
abbreviated capability names in addition to complete URI.
|
20 |
"""
|
21 |
|
22 |
def __init__(self, capabilities=None): |
23 |
"TODO: docstring"
|
24 |
self._dict = {}
|
25 |
if isinstance(capabilities, dict): |
26 |
self._dict = capabilities
|
27 |
elif isinstance(capabilities, list): |
28 |
for uri in capabilities: |
29 |
self._dict[uri] = Capabilities.guess_shorthand(uri)
|
30 |
|
31 |
def __contains__(self, key): |
32 |
"TODO: docstring"
|
33 |
return ( key in self._dict ) or ( key in self._dict.values() ) |
34 |
|
35 |
def __iter__(self): |
36 |
"TODO: docstring"
|
37 |
return self._dict.keys().__iter__() |
38 |
|
39 |
def __repr__(self): |
40 |
"TODO: docstring"
|
41 |
return repr(self._dict.keys()) |
42 |
|
43 |
def add(self, uri, shorthand=None): |
44 |
"TODO: docstring"
|
45 |
if shorthand is None: |
46 |
shorthand = Capabilities.guess_shorthand(uri) |
47 |
self._dict[uri] = shorthand
|
48 |
|
49 |
set = add |
50 |
|
51 |
def remove(self, key): |
52 |
"TODO: docstring"
|
53 |
if key in self._dict: |
54 |
del self._dict[key] |
55 |
else:
|
56 |
for uri in self._dict: |
57 |
if self._dict[uri] == key: |
58 |
del self._dict[uri] |
59 |
break
|
60 |
|
61 |
@staticmethod
|
62 |
def guess_shorthand(uri): |
63 |
"TODO: docstring"
|
64 |
if uri.startswith('urn:ietf:params:netconf:capability:'): |
65 |
return (':' + uri.split(':')[5]) |
66 |
|
67 |
|
68 |
CAPABILITIES = Capabilities([ |
69 |
'urn:ietf:params:netconf:base:1.0', # TODO |
70 |
'urn:ietf:params:netconf:capability:writable-running:1.0', # TODO |
71 |
'urn:ietf:params:netconf:capability:candidate:1.0', # TODO |
72 |
'urn:ietf:params:netconf:capability:confirmed-commit:1.0', # TODO |
73 |
'urn:ietf:params:netconf:capability:rollback-on-error:1.0', # TODO |
74 |
'urn:ietf:params:netconf:capability:startup:1.0', # TODO |
75 |
'urn:ietf:params:netconf:capability:url:1.0', # TODO |
76 |
'urn:ietf:params:netconf:capability:validate:1.0', # TODO |
77 |
'urn:ietf:params:netconf:capability:xpath:1.0', # TODO |
78 |
'urn:ietf:params:netconf:capability:notification:1.0', # TODO |
79 |
'urn:ietf:params:netconf:capability:interleave:1.0' # TODO |
80 |
]) |