diff options
author | tragait <rahul.tyagi@est.tech> | 2019-11-06 11:44:11 +0000 |
---|---|---|
committer | tragait <rahul.tyagi@est.tech> | 2019-11-13 14:51:40 +0000 |
commit | 6f7a427e53f4e129d84198f4c94036b4fe6b3898 (patch) | |
tree | 87238feaa6262bd4c96a910cc0b3df38f0a7905d /components/model-catalog/blueprint-model/uat-blueprints/pnf_config_aai/Scripts | |
parent | 54eb2f2680d4f2447a4d48b612b2b83e37d90754 (diff) |
CCSDK-1603:Changes in 'Config via netconf' BP to pull data from AAI
This commit includes changes in blueprint for "Configuration over
netconf", So that CDS can fetch data from AAI.
It has enhancement in UAT test yaml file, so this blueprint
can be tested.
An enhancement is also included to introduce request headers
in the source-rest.
Change-Id: I4ff973538249925239b89da4c5720ec63ffe8037
Issue-ID: CCSDK-1603
Signed-off-by: tragait <rahul.tyagi@est.tech>
Diffstat (limited to 'components/model-catalog/blueprint-model/uat-blueprints/pnf_config_aai/Scripts')
-rw-r--r-- | components/model-catalog/blueprint-model/uat-blueprints/pnf_config_aai/Scripts/python/RestconfConfigDeploy.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/components/model-catalog/blueprint-model/uat-blueprints/pnf_config_aai/Scripts/python/RestconfConfigDeploy.py b/components/model-catalog/blueprint-model/uat-blueprints/pnf_config_aai/Scripts/python/RestconfConfigDeploy.py new file mode 100644 index 000000000..af0b7e129 --- /dev/null +++ b/components/model-catalog/blueprint-model/uat-blueprints/pnf_config_aai/Scripts/python/RestconfConfigDeploy.py @@ -0,0 +1,78 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2019 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= + +from java.lang import Exception as JavaException + +from restconf_client import RestconfClient +from org.onap.ccsdk.cds.blueprintsprocessor.services.execution import AbstractScriptComponentFunction + + +class RestconfConfigDeploy(AbstractScriptComponentFunction): + log = globals()["log"] + configlet_template_name = "config-assign" + configlet_resource_path = "/yang-ext:mount/mynetconf:netconflist" + restconf_server_identifier = "sdnc" + + def process(self, execution_request): + + self.log.info("Started execution of process method") + try: + restconf_client = RestconfClient(self.log, self) + pnf_id, resolution_key = self.retrieve_parameters(execution_request) + web_client_service = restconf_client.web_client_service(self.restconf_server_identifier) + + try: + # mount the device + mount_payload = restconf_client.resolve_and_generate_message_from_template_prefix("config-deploy") + restconf_client.mount_device(web_client_service, pnf_id, mount_payload, "application/json") + + # log the current configuration subtree + current_configuration = restconf_client.retrieve_device_configuration_subtree( + web_client_service, pnf_id, self.configlet_resource_path) + self.log.info("Current configuration subtree: {}", current_configuration) + + # apply configuration + configlet = restconf_client.retrieve_resolved_template_from_database(resolution_key, self.configlet_template_name) + restconf_client.configure_device_json_patch( + web_client_service, pnf_id, self.configlet_resource_path, configlet) + except Exception, err: + self.log.error("an error occurred while configuring device {}", err) + raise err + finally: + restconf_client.unmount_device(web_client_service, pnf_id) + + except JavaException, err: + self.log.error("Java Exception in the script", err) + raise err + except Exception, err: + self.log.error("Python Exception in the script:" + str(err), err) + raise err + self.log.info("Ended execution of process method") + + def retrieve_parameters(self, execution_request): + resolution_key = self.getDynamicProperties("resolution-key").asText() + self.log.info("resolution_key: {}", resolution_key) + pnf_id = execution_request.payload.get("config-deploy-request").get("config-deploy-properties").get("pnf-id") + pnf_id = str(pnf_id).strip('\"') + self.log.info("pnf-id: {}", pnf_id) + return pnf_id, resolution_key + + def recover(self, runtime_exception, execution_request): + self.log.info("Recover function called!") + self.log.info("Execution request", execution_request) + self.log.error("Exception", runtime_exception) + print self.bluePrintRuntimeService.getBluePrintError().addError(runtime_exception.getMessage()) + return None |