Khen Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
Khen Nursimulu | c9ef7c1 | 2017-01-04 20:40:53 -0500 | [diff] [blame] | 3 | # Copyright 2017 the original author or authors. |
Khen Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 4 | # |
| 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 Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 17 | import structlog |
| 18 | from netconf.nc_rpc.rpc import Rpc |
| 19 | import netconf.nc_common.error as ncerror |
| 20 | from netconf.constants import Constants as C |
Khen Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 21 | |
| 22 | log = structlog.get_logger() |
| 23 | |
| 24 | class GetConfig(Rpc): |
| 25 | |
Khen Nursimulu | c9ef7c1 | 2017-01-04 20:40:53 -0500 | [diff] [blame] | 26 | def __init__(self, request, request_xml, grpc_client, session, capabilities): |
| 27 | super(GetConfig, self).__init__(request, request_xml, grpc_client, session) |
Khen Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 28 | 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 Nursimulu | c9ef7c1 | 2017-01-04 20:40:53 -0500 | [diff] [blame] | 47 | 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 Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 53 | |
| 54 | self.filter_param = None |
| 55 | if paramslen == 2: |
| 56 | self.filter_param = self.rpc_method.find(C.NC_FILTER, |
Khen Nursimulu | c9ef7c1 | 2017-01-04 20:40:53 -0500 | [diff] [blame] | 57 | namespaces=C.NS_MAP) |
Khen Nursimulu | a7b842a | 2016-12-03 23:28:42 -0500 | [diff] [blame] | 58 | 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] |