blob: e7ade72ff2378c500eaea3531c69a05262a88cd6 [file] [log] [blame]
Khen Nursimulua7b842a2016-12-03 23:28:42 -05001#!/usr/bin/env python
2#
Khen Nursimuluc9ef7c12017-01-04 20:40:53 -05003# Copyright 2017 the original author or authors.
Khen Nursimulua7b842a2016-12-03 23:28:42 -05004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
Khen Nursimulua7b842a2016-12-03 23:28:42 -050017import structlog
18from netconf.nc_rpc.rpc import Rpc
19import netconf.nc_common.error as ncerror
20from netconf.constants import Constants as C
Khen Nursimulua7b842a2016-12-03 23:28:42 -050021
22log = structlog.get_logger()
23
24class GetConfig(Rpc):
25
Khen Nursimuluc9ef7c12017-01-04 20:40:53 -050026 def __init__(self, request, request_xml, grpc_client, session, capabilities):
27 super(GetConfig, self).__init__(request, request_xml, grpc_client, session)
Khen Nursimulua7b842a2016-12-03 23:28:42 -050028 self._validate_parameters()
29
30 def execute(self):
31 log.info('get-config-request', session=self.session.session_id)
32 if self.rpc_response.is_error:
33 return self.rpc_response
34
35 def _validate_parameters(self):
36 log.info('validate-parameters', session=self.session.session_id)
37
38 self.params = self.rpc_method.getchildren()
39 paramslen = len(self.params)
40 # Verify that the source parameter is present
41 if paramslen > 2:
42 # TODO: need to specify all elements not known
43 self.rpc_response.is_error = True
44 self.rpc_response.node = ncerror.BadMsg(self.rpc_request)
45 return
46
Khen Nursimuluc9ef7c12017-01-04 20:40:53 -050047 self.source_param = self.rpc_method.find(C.NC_SOURCE, namespaces=C.NS_MAP)
48 # if self.source_param is None:
49 # self.rpc_response.is_error = True
50 # self.rpc_response.node = ncerror.MissingElement(
51 # self.rpc_request, elm(C.NC_SOURCE))
52 # return
Khen Nursimulua7b842a2016-12-03 23:28:42 -050053
54 self.filter_param = None
55 if paramslen == 2:
56 self.filter_param = self.rpc_method.find(C.NC_FILTER,
Khen Nursimuluc9ef7c12017-01-04 20:40:53 -050057 namespaces=C.NS_MAP)
Khen Nursimulua7b842a2016-12-03 23:28:42 -050058 if self.filter_param is None:
59 unknown_elm = self.params[0] if self.params[0] != \
60 self.source_param else \
61 self.params[1]
62 self.rpc_response.is_error = True
63 self.rpc_response.node = ncerror.UnknownElement(
64 self.rpc_request, unknown_elm)
65
66 self.params = [self.source_param, self.filter_param]