root / ncclient / operations / edit.py @ d6688264
History | View | Annotate | Download (3.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 |
from ncclient.capabilities import URI |
16 |
from ncclient.rpc import RPC |
17 |
|
18 |
import util |
19 |
|
20 |
class EditConfig(RPC): |
21 |
|
22 |
SPEC = { |
23 |
'tag': 'edit-config', |
24 |
'children': [
|
25 |
{ 'target': None } |
26 |
] |
27 |
} |
28 |
|
29 |
def request(self): |
30 |
pass
|
31 |
|
32 |
|
33 |
class DeleteConfig(RPC): # x |
34 |
|
35 |
SPEC = { |
36 |
'tag': 'delete-config', |
37 |
'children': [ { 'tag': 'target', 'children': None } ] |
38 |
} |
39 |
|
40 |
def request(self, target=None, target_url=None): |
41 |
spec = DeleteConfig.SPEC.copy() |
42 |
spec['children'][0]['children'] = util.store_or_url(target, target_url) |
43 |
return self._request(spec) |
44 |
|
45 |
|
46 |
class CopyConfig(RPC): # x |
47 |
|
48 |
SPEC = { |
49 |
'tag': 'copy-config', |
50 |
'children': [
|
51 |
{ 'tag': 'source', 'children': {'tag': None } }, |
52 |
{ 'tag': 'target', 'children': {'tag': None } } |
53 |
] |
54 |
} |
55 |
|
56 |
def request(self, source=None, source_url=None, target=None, target_url=None): |
57 |
spec = CopyConfig.SPEC.copy() |
58 |
spec['children'][0]['children'] = util.store_or_url(source, source_url) |
59 |
spec['children'][1]['children'] = util.store_or_url(target, target_url) |
60 |
return self._request(spec) |
61 |
|
62 |
|
63 |
class Validate(RPC): # xxxxx |
64 |
|
65 |
DEPENDS = [':validate']
|
66 |
|
67 |
SPEC = { |
68 |
'tag': 'validate', |
69 |
'children': []
|
70 |
} |
71 |
|
72 |
def request(self, source=None, config=None): |
73 |
#self.either_or(source, config)
|
74 |
#
|
75 |
#if source is None and config is None:
|
76 |
# raise OperationError('Insufficient parameters')
|
77 |
#if source is not None and config is not None:
|
78 |
# raise OperationError('Too many parameters')
|
79 |
#spec = Validate.SPEC.copy()
|
80 |
#
|
81 |
util.one_of(source, capability) |
82 |
if source is not None: |
83 |
spec['children'].append({
|
84 |
'tag': 'source', |
85 |
'children': {'tag': source} |
86 |
}) |
87 |
#
|
88 |
#else:
|
89 |
# if isinstance(config, dict):
|
90 |
# if config['tag'] != 'config':
|
91 |
# child['tag'] = 'config'
|
92 |
# child['children'] = config
|
93 |
# else:
|
94 |
# child = config
|
95 |
# elif isinstance(config, Element):
|
96 |
# pass
|
97 |
# else:
|
98 |
# from xml.etree import cElementTree as ET
|
99 |
# ele = ET.XML(unicode(config))
|
100 |
# if __(ele.tag) != 'config':
|
101 |
# pass
|
102 |
# else:
|
103 |
# pass
|
104 |
# spec['children'].append(child)
|
105 |
#
|
106 |
return self._request(spec) |
107 |
|
108 |
class Commit(RPC): # x |
109 |
|
110 |
DEPENDS = [':candidate']
|
111 |
|
112 |
SPEC = {'tag': 'commit', 'children': [] } |
113 |
|
114 |
def _parse_hook(self): |
115 |
pass
|
116 |
|
117 |
def request(self, confirmed=False, timeout=None): |
118 |
spec = SPEC.copy() |
119 |
if confirmed:
|
120 |
self._assert(':confirmed-commit') |
121 |
children = spec['children']
|
122 |
children.append({'tag': 'confirmed'}) |
123 |
if timeout is not None: |
124 |
children.append({ |
125 |
'tag': 'confirm-timeout', |
126 |
'text': timeout
|
127 |
}) |
128 |
return self._request(Commit.SPEC) |
129 |
|
130 |
|
131 |
class DiscardChanges(RPC): # x |
132 |
|
133 |
DEPENDS = [':candidate']
|
134 |
|
135 |
SPEC = {'tag': 'discard-changes'} |
136 |
|
137 |
def request(self): |
138 |
return self._request(DiscardChanges.SPEC) |