This commit consists of:
1) Add session management to netconf
2) Modularize the rpc call
3) Improve the error handling
4) Small bug fixes

Change-Id: I023edb76e3743b633ac87be4967d656e09e2b970
diff --git a/netconf/nc_rpc/__init__.py b/netconf/nc_rpc/__init__.py
new file mode 100644
index 0000000..7398217
--- /dev/null
+++ b/netconf/nc_rpc/__init__.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-#
+#
+# December 23 2014, Christian Hopps <chopps@gmail.com>
+#
+# Copyright (c) 2015, Deutsche Telekom AG
+#
+# 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.
+#
+from __future__ import absolute_import, division, unicode_literals, print_function, nested_scopes
+from lxml.etree import register_namespace
+
+MAXSSHBUF = 16 * 1024
+NSMAP = { }
+
+
+def nsmap_add (prefix, namespace):
+    "Add a prefix namespace mapping to the modules mapping dictionary"
+    NSMAP[prefix] = namespace
+    register_namespace(prefix, namespace)
+
+
+def nsmap_update (nsdict):
+    "Add a dicitonary of prefx namespace mappings to the modules mapping dictionary"
+    NSMAP.update(nsdict)
+    for key, val in nsdict.items():
+        register_namespace(key, val)
+
+
+def qmap (key):
+    return "{" + NSMAP[key] + "}"
+
+
+# Add base spec namespace
+nsmap_add('nc', "urn:ietf:params:xml:ns:netconf:base:1.0")
diff --git a/netconf/nc_rpc/base/__init__.py b/netconf/nc_rpc/base/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/netconf/nc_rpc/base/__init__.py
diff --git a/netconf/nc_rpc/base/close_session.py b/netconf/nc_rpc/base/close_session.py
new file mode 100644
index 0000000..43babb8
--- /dev/null
+++ b/netconf/nc_rpc/base/close_session.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class CloseSession(Rpc):
+
+    def __init__(self, rpc_request, rpc_method, session):
+        super(CloseSession, self).__init__(rpc_request, rpc_method, session)
+        self._validate_parameters()
+
+    def execute(self):
+        log.info('close-session-request', session=self.session.session_id)
+        if self.rpc_response.is_error:
+            return self.rpc_response
+
+        self.rpc_response.node = etree.Element("ok")
+        return self.rpc_response
+
+
+    def _validate_parameters(self):
+        for child in self.rpc_method.getchildren():
+            # There cannot be parameters to a close session request
+            self.rpc_response.is_error = True
+            self.rpc_response.node = ncerror.BadMsg(self.rpc_request)
+            return
\ No newline at end of file
diff --git a/netconf/nc_rpc/base/commit.py b/netconf/nc_rpc/base/commit.py
new file mode 100644
index 0000000..61b7604
--- /dev/null
+++ b/netconf/nc_rpc/base/commit.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class Commit(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(Commit, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('commit-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/base/copy_config.py b/netconf/nc_rpc/base/copy_config.py
new file mode 100644
index 0000000..cf2fc82
--- /dev/null
+++ b/netconf/nc_rpc/base/copy_config.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class CopyConfig(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(CopyConfig, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('copy-config-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/base/delete_config.py b/netconf/nc_rpc/base/delete_config.py
new file mode 100644
index 0000000..7163ee6
--- /dev/null
+++ b/netconf/nc_rpc/base/delete_config.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class DeleteConfig(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(DeleteConfig, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('delete-config-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/base/discard_changes.py b/netconf/nc_rpc/base/discard_changes.py
new file mode 100644
index 0000000..c41d32e
--- /dev/null
+++ b/netconf/nc_rpc/base/discard_changes.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class DiscardChanges(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(DiscardChanges, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('discard-changes-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/base/edit_config.py b/netconf/nc_rpc/base/edit_config.py
new file mode 100644
index 0000000..5c7599a
--- /dev/null
+++ b/netconf/nc_rpc/base/edit_config.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class EditConfig(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(EditConfig, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('edit-config-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/base/get.py b/netconf/nc_rpc/base/get.py
new file mode 100644
index 0000000..c6cdfab
--- /dev/null
+++ b/netconf/nc_rpc/base/get.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+from netconf.constants import Constants as C
+from netconf.utils import filter_tag_match
+
+log = structlog.get_logger()
+
+class Get(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(Get, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('get-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
+		self.params = self.rpc_method.getchildren()
+		if len(self.params) > 1:
+			self.rpc_response.is_error = True
+			self.rpc_response.node = ncerror.BadMsg(self.rpc_request)
+			return
+
+		if self.params and not filter_tag_match(self.params[0], C.NC_FILTER):
+			self.rpc_response.is_error = True
+			self.rpc_response.node = ncerror.UnknownElement(
+				self.rpc_request, self.params[0])
+			return
+
+		if not self.params:
+			self.params = [None]
+
+
diff --git a/netconf/nc_rpc/base/get_config.py b/netconf/nc_rpc/base/get_config.py
new file mode 100644
index 0000000..dffe0d6
--- /dev/null
+++ b/netconf/nc_rpc/base/get_config.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+from netconf.constants import Constants as C
+from netconf.utils import elm
+from netconf import NSMAP
+
+log = structlog.get_logger()
+
+class GetConfig(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(GetConfig, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('get-config-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
+
+		self.params = self.rpc_method.getchildren()
+		paramslen = len(self.params)
+		# Verify that the source parameter is present
+		if paramslen > 2:
+			# TODO: need to specify all elements not known
+			self.rpc_response.is_error = True
+			self.rpc_response.node = ncerror.BadMsg(self.rpc_request)
+			return
+
+		self.source_param = self.rpc_method.find(C.NC_SOURCE, namespaces=NSMAP)
+		if self.source_param is None:
+			self.rpc_response.is_error = True
+			self.rpc_response.node = ncerror.MissingElement(
+				self.rpc_request, elm(C.NC_SOURCE))
+			return
+
+		self.filter_param = None
+		if paramslen == 2:
+			self.filter_param = self.rpc_method.find(C.NC_FILTER,
+												  namespaces=NSMAP)
+			if self.filter_param is None:
+				unknown_elm = self.params[0] if self.params[0] != \
+												self.source_param else \
+												self.params[1]
+				self.rpc_response.is_error = True
+				self.rpc_response.node = ncerror.UnknownElement(
+					self.rpc_request, unknown_elm)
+
+		self.params = [self.source_param, self.filter_param]
diff --git a/netconf/nc_rpc/base/kill_session.py b/netconf/nc_rpc/base/kill_session.py
new file mode 100644
index 0000000..08a2e7a
--- /dev/null
+++ b/netconf/nc_rpc/base/kill_session.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+
+class KillSession(Rpc):
+
+    def __init__(self, rpc_request, rpc_method, session):
+        super(KillSession, self).__init__(rpc_request, rpc_method, session)
+        self._validate_parameters()
+
+    def execute(self):
+        log.info('kill-session-request', session=self.session.session_id)
+        if self.rpc_response.error:
+            return self.rpc_response
+
+        self.rpc_response.node = etree.Element("ok")
+        return self.rpc_response
+
+    def _validate_parameters(self):
+        log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/base/lock.py b/netconf/nc_rpc/base/lock.py
new file mode 100644
index 0000000..fc74e83
--- /dev/null
+++ b/netconf/nc_rpc/base/lock.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class Lock(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(Lock, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('Lock-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/base/unlock.py b/netconf/nc_rpc/base/unlock.py
new file mode 100644
index 0000000..78c59f1
--- /dev/null
+++ b/netconf/nc_rpc/base/unlock.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class UnLock(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(UnLock, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('UnLock-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/base/validate.py b/netconf/nc_rpc/base/validate.py
new file mode 100644
index 0000000..1cb84af
--- /dev/null
+++ b/netconf/nc_rpc/base/validate.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# 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.
+#
+from lxml import etree
+import structlog
+from netconf.nc_rpc.rpc import Rpc
+import netconf.nc_common.error as ncerror
+
+log = structlog.get_logger()
+
+class Validate(Rpc):
+
+	def __init__(self, rpc_request, rpc_method, session):
+		super(Validate, self).__init__(rpc_request, rpc_method, session)
+		self._validate_parameters()
+
+	def execute(self):
+		log.info('Validate-request', session=self.session.session_id)
+		if self.rpc_response.is_error:
+			return self.rpc_response
+
+	def _validate_parameters(self):
+		log.info('validate-parameters', session=self.session.session_id)
diff --git a/netconf/nc_rpc/rpc.py b/netconf/nc_rpc/rpc.py
new file mode 100644
index 0000000..3dd2f17
--- /dev/null
+++ b/netconf/nc_rpc/rpc.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# Code adapted from https://github.com/choppsv1/netconf
+#
+# 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.
+#
+
+from  rpc_response import RpcResponse
+
+class Rpc(object):
+    def __init__(self,rpc_request, rpc_method, session):
+        self.rpc_request = rpc_request
+        self.rpc_method = rpc_method
+        self.rpc_response = RpcResponse()
+        self.session = session
+
+    def execute(self):
+        """ run the command - returns a OperationResponse """
+        pass
+
+    def set_rpc_response(self):
+        self.rpc_response = RpcResponse()
+
+    def _validate_parameters(self, rpc_request):
+        """Sets and validates the node as well"""
+        pass
diff --git a/netconf/nc_rpc/rpc_factory.py b/netconf/nc_rpc/rpc_factory.py
new file mode 100644
index 0000000..f3ec0cc
--- /dev/null
+++ b/netconf/nc_rpc/rpc_factory.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# Code adapted from https://github.com/choppsv1/netconf
+#
+# 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.
+#
+import structlog
+from base.commit import Commit
+from base.copy_config import CopyConfig
+from base.delete_config import DeleteConfig
+from base.discard_changes import DiscardChanges
+from base.edit_config import EditConfig
+from base.get import Get
+from base.get_config import GetConfig
+from base.lock import Lock
+from base.unlock import UnLock
+from base.close_session import CloseSession
+from base.kill_session import KillSession
+from netconf import NSMAP, qmap
+import netconf.nc_common.error as ncerror
+log = structlog.get_logger()
+
+class RpcFactory:
+
+	instance = None
+
+	def get_rpc_handler(self, rpc_node, msg, session):
+		try:
+			msg_id = rpc_node.get('message-id')
+			log.info("Received-rpc-message-id", msg_id=msg_id)
+
+		except (TypeError, ValueError):
+			raise ncerror.SessionError(msg,
+									   "No valid message-id attribute found")
+
+		# Get the first child of rpc as the method name
+		rpc_method = rpc_node.getchildren()
+		if len(rpc_method) != 1:
+			log.error("badly-formatted-rpc-method", msg_id=msg_id)
+			raise ncerror.BadMsg(rpc_node)
+
+		rpc_method = rpc_method[0]
+
+		rpc_name = rpc_method.tag.replace(qmap('nc'), "")
+
+		log.info("rpc-request", rpc=rpc_name)
+
+		class_handler = self.rpc_class_handlers.get(rpc_name, None)
+		if class_handler is not None:
+			return class_handler(rpc_node, rpc_method, session)
+
+		log.error("rpc-not-implemented", rpc=rpc_name)
+
+
+	rpc_class_handlers = {
+		'get-config': GetConfig,
+		'get': Get,
+		'edit-config': EditConfig,
+		'copy-config': CopyConfig,
+		'delete-config': DeleteConfig,
+		'commit': Commit,
+		'lock': Lock,
+		'unlock': UnLock,
+		'close-session': CloseSession,
+		'kill-session': KillSession
+	}
+
+
+def get_rpc_factory_instance():
+	if RpcFactory.instance == None:
+		RpcFactory.instance = RpcFactory()
+	return RpcFactory.instance
+
diff --git a/netconf/nc_rpc/rpc_response.py b/netconf/nc_rpc/rpc_response.py
new file mode 100644
index 0000000..cdbe167
--- /dev/null
+++ b/netconf/nc_rpc/rpc_response.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the original author or authors.
+#
+# Code adapted from https://github.com/choppsv1/netconf
+#
+# 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.
+#
+
+class RpcResponse():
+    def __init__(self):
+        self.is_error = False
+        # if there is an error then the reply_node will contains an Error
+        # object
+        self.reply_node = None
+        self.close_session = False
\ No newline at end of file