aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-07-24 14:13:22 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-24 14:13:22 +0000
commit6a949fae1d76bd133a198c54c5a616c9835527b5 (patch)
treee9bd44047a55cdd54a73ef42763c4cd86298b314 /components
parent5e6fbc2ee27fc9514d026d17093ba7530184b55f (diff)
parenta0140dea9c608d745767574ac621ca0060a2bddc (diff)
Merge "Refactor Netconf script component parent."
Diffstat (limited to 'components')
-rw-r--r--components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/NetconfRpcExample.py70
-rw-r--r--components/scripts/python/ccsdk_netconf/common.py19
-rw-r--r--components/scripts/python/ccsdk_netconf/netconfclient.py114
3 files changed, 100 insertions, 103 deletions
diff --git a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/NetconfRpcExample.py b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/NetconfRpcExample.py
index f146e8123..2fd6c6659 100644
--- a/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/NetconfRpcExample.py
+++ b/components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/NetconfRpcExample.py
@@ -16,39 +16,37 @@ import netconf_constant
from common import ResolutionHelper
from java.lang import Exception as JavaException
from netconfclient import NetconfClient
-from org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor import \
- NetconfComponentFunction
-
-
-class NetconfRpcExample(NetconfComponentFunction):
-
- def process(self, execution_request):
- try:
- log = globals()[netconf_constant.SERVICE_LOG]
- print(globals())
- nc = NetconfClient(log, self, "netconf-connection")
- rr = ResolutionHelper(self)
-
- payload = rr.resolve_and_generate_message_from_template_prefix("hostname")
-
- nc.connect()
- response = nc.lock()
- if not response.isSuccess():
- log.error(response.errorMessage)
-
- nc.edit_config(message_content=payload, edit_default_peration="none")
- nc.validate()
- nc.discard_change()
- nc.validate()
- nc.commit()
- nc.unlock()
- nc.disconnect()
-
- except JavaException, err:
- log.error("Java Exception in the script {}", err)
- except Exception, err:
- log.error("Python Exception in the script {}", err)
-
- def recover(self, runtime_exception, execution_request):
- print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH
- return None
+from org.onap.ccsdk.cds.blueprintsprocessor.services.execution import AbstractScriptComponentFunction
+
+class NetconfRpcExample(AbstractScriptComponentFunction):
+
+ def process(self, execution_request):
+ try:
+ log = globals()[netconf_constant.SERVICE_LOG]
+ print(globals())
+ nc = NetconfClient(log, self, "netconf-connection")
+ rr = ResolutionHelper(self)
+
+ payload = rr.resolve_and_generate_message_from_template_prefix("hostname")
+
+ nc.connect()
+ response = nc.lock()
+ if not response.isSuccess():
+ log.error(response.errorMessage)
+
+ nc.edit_config(message_content=payload, edit_default_peration="none")
+ nc.validate()
+ nc.discard_change()
+ nc.validate()
+ nc.commit()
+ nc.unlock()
+ nc.disconnect()
+
+ except JavaException, err:
+ log.error("Java Exception in the script {}", err)
+ except Exception, err:
+ log.error("Python Exception in the script {}", err)
+
+ def recover(self, runtime_exception, execution_request):
+ print "Recovering calling.." + PROPERTY_BLUEPRINT_BASE_PATH
+ return None
diff --git a/components/scripts/python/ccsdk_netconf/common.py b/components/scripts/python/ccsdk_netconf/common.py
index 896fb9128..f7ac1ac35 100644
--- a/components/scripts/python/ccsdk_netconf/common.py
+++ b/components/scripts/python/ccsdk_netconf/common.py
@@ -12,18 +12,17 @@
# 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.
+from org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution import ResourceResolutionExtensionsKt
-class ResolutionHelper:
- def __init__(self, component_function):
- self.component_function = component_function
+class ResolutionHelper:
- def resolve_and_generate_message_from_template_prefix(self, artifact_prefix):
- return self.component_function.contentFromResolvedArtifact(artifact_prefix)
+ def __init__(self, component_function):
+ self.component_function = component_function
- def resolve_and_generate_message(self, artifact_mapping, artifact_template):
- return self.component_function.resolveAndGenerateMessage(artifact_mapping,
- artifact_template)
+ def resolve_and_generate_message_from_template_prefix(self, artifact_prefix):
+ return ResourceResolutionExtensionsKt.contentFromResolvedArtifact(self.component_function, artifact_prefix)
- def retrieve_resolved_template_from_database(self, key, artifact_template):
- return self.component_function.storedContentFromResolvedArtifact(key, artifact_template)
+ def retrieve_resolved_template_from_database(self, key, artifact_template):
+ return ResourceResolutionExtensionsKt.storedContentFromResolvedArtifact(self.component_function, key,
+ artifact_template)
diff --git a/components/scripts/python/ccsdk_netconf/netconfclient.py b/components/scripts/python/ccsdk_netconf/netconfclient.py
index e263ba8f7..a942845b9 100644
--- a/components/scripts/python/ccsdk_netconf/netconfclient.py
+++ b/components/scripts/python/ccsdk_netconf/netconfclient.py
@@ -1,62 +1,62 @@
from netconf_constant import CONFIG_TARGET_RUNNING, CONFIG_TARGET_CANDIDATE, \
- CONFIG_DEFAULT_OPERATION_REPLACE
+ CONFIG_DEFAULT_OPERATION_REPLACE
+from org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor import NetconfExecutorExtensionsKt
class NetconfClient:
- def __init__(self, log, component_function, requirement_name):
- self.log = log
- self.component_function = component_function
- netconf_device = self.component_function.initializeNetconfConnection(
- requirement_name)
- self.netconf_rpc_client = netconf_device.netconfRpcService
- self.netconf_session = netconf_device.netconfSession
-
- def disconnect(self):
- self.netconf_session.disconnect()
- return
-
- def connect(self):
- self.netconf_session.connect()
- return
-
- def lock(self, config_target=CONFIG_TARGET_CANDIDATE):
- device_response = self.netconf_rpc_client.lock(config_target)
- return device_response
-
- def get_config(self, filter="", config_target=CONFIG_TARGET_RUNNING):
- device_response = self.netconf_rpc_client.getConfig(filter, config_target)
- return device_response
-
- def edit_config(self, message_content, config_target=CONFIG_TARGET_CANDIDATE,
- edit_default_peration=CONFIG_DEFAULT_OPERATION_REPLACE):
- device_response = self.netconf_rpc_client.editConfig(message_content,
- config_target,
- edit_default_peration)
- return device_response
-
- def commit(self, confirmed=False, confirm_timeout=60, persist="",
- persist_id=""):
- device_response = self.netconf_rpc_client.commit(confirmed, confirm_timeout,
- persist, persist_id)
- return device_response
-
- def invoke_rpc(self, rpc):
- device_response = self.netconf_rpc_client.invokeRpc(rpc)
- return device_response
-
- def cancel_commit(self, persist_id=""):
- device_response = self.netconf_rpc_client.cancelCommit(persist_id)
- return device_response
-
- def unlock(self, config_target=CONFIG_TARGET_CANDIDATE):
- device_response = self.netconf_rpc_client.unLock(config_target)
- return device_response
-
- def validate(self, config_target=CONFIG_TARGET_CANDIDATE):
- device_response = self.netconf_rpc_client.validate(config_target)
- return device_response
-
- def discard_change(self):
- device_response = self.netconf_rpc_client.discardConfig()
- return device_response
+ def __init__(self, log, component_function, requirement_name):
+ self.log = log
+ self.component_function = component_function
+ netconf_device = NetconfExecutorExtensionsKt.netconfDevice(component_function, requirement_name)
+ self.netconf_rpc_client = netconf_device.netconfRpcService
+ self.netconf_session = netconf_device.netconfSession
+
+ def disconnect(self):
+ self.netconf_session.disconnect()
+ return
+
+ def connect(self):
+ self.netconf_session.connect()
+ return
+
+ def lock(self, config_target=CONFIG_TARGET_CANDIDATE):
+ device_response = self.netconf_rpc_client.lock(config_target)
+ return device_response
+
+ def get_config(self, filter="", config_target=CONFIG_TARGET_RUNNING):
+ device_response = self.netconf_rpc_client.getConfig(filter, config_target)
+ return device_response
+
+ def edit_config(self, message_content, config_target=CONFIG_TARGET_CANDIDATE,
+ edit_default_peration=CONFIG_DEFAULT_OPERATION_REPLACE):
+ device_response = self.netconf_rpc_client.editConfig(message_content,
+ config_target,
+ edit_default_peration)
+ return device_response
+
+ def commit(self, confirmed=False, confirm_timeout=60, persist="",
+ persist_id=""):
+ device_response = self.netconf_rpc_client.commit(confirmed, confirm_timeout,
+ persist, persist_id)
+ return device_response
+
+ def invoke_rpc(self, rpc):
+ device_response = self.netconf_rpc_client.invokeRpc(rpc)
+ return device_response
+
+ def cancel_commit(self, persist_id=""):
+ device_response = self.netconf_rpc_client.cancelCommit(persist_id)
+ return device_response
+
+ def unlock(self, config_target=CONFIG_TARGET_CANDIDATE):
+ device_response = self.netconf_rpc_client.unLock(config_target)
+ return device_response
+
+ def validate(self, config_target=CONFIG_TARGET_CANDIDATE):
+ device_response = self.netconf_rpc_client.validate(config_target)
+ return device_response
+
+ def discard_change(self):
+ device_response = self.netconf_rpc_client.discardConfig()
+ return device_response