Add support to invoke device specific RPC 96/81996/2
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Tue, 12 Mar 2019 02:22:30 +0000 (22:22 -0400)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Tue, 12 Mar 2019 02:34:11 +0000 (22:34 -0400)
Change-Id: Ia003ed669cc88a4c24a495e79db620b5034bc3ca
Issue-ID: CCSDK-790
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
components/scripts/python/ccsdk_netconf/netconfclient.py
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt

index d898ec0..e263ba8 100644 (file)
@@ -41,6 +41,10 @@ class NetconfClient:
                                                      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
index 5508521..02c0a34 100644 (file)
@@ -56,6 +56,24 @@ interface NetconfRpcService {
     fun editConfig(messageContent: String, configTarget: String = NetconfDatastore.CANDIDATE.datastore,
                    editDefaultOperation: String = ModifyAction.NONE.action): DeviceResponse
 
+    /**
+     * Invoke custom RPC as provided as input.
+     *
+     * Some use cases might required one to directly invoke a device
+     * specific RPC. The RPC must be correctly formatted.
+     *
+     * Ex: in order to rollback last submitted configuration
+     * for JUNOS devices, such RPC can be use:
+     * <code>
+     *  &lt;rpc>
+     *      &lt;load-configuration rollback="1"/>
+     *  &lt;/rpc>
+     * </code>
+     *
+     * @param rpc the rpc content.
+     */
+    fun invokeRpc(rpc: String): DeviceResponse
+
     /**
      * Validate
      *
index 8d8e0ea..15fb312 100644 (file)
@@ -41,6 +41,19 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ
         this.netconfSession = netconfSession
     }
 
+    override fun invokeRpc(rpc: String): DeviceResponse {
+        var output = DeviceResponse()
+        val messageId = messageIdInteger.getAndIncrement().toString()
+        log.info("$deviceInfo: invokeRpc: messageId($messageId)")
+        try {
+            output = asyncRpc(rpc, messageId)
+        } catch (e: Exception) {
+            output.status = RpcStatus.FAILURE
+            output.errorMessage = "$deviceInfo: failed in invokeRpc command $e.message"
+        }
+        return output
+    }
+
     override fun getConfig(filter: String, configTarget: String): DeviceResponse {
         var output = DeviceResponse()
         val messageId = messageIdInteger.getAndIncrement().toString()