This commit consists of:
1) Ability for the netconf client to retrieve schemas metadata from
   the netconf server
2) Ability for the netconf server to retrieve specific yang schema from
   the netconf server
3) Netconf says Happy New Year 2017

Change-Id: I6552224707607ca6cc1397f2fbf193503bb116a3
diff --git a/netconf/nc_rpc/ext/get_schema.py b/netconf/nc_rpc/ext/get_schema.py
new file mode 100644
index 0000000..ec473d3
--- /dev/null
+++ b/netconf/nc_rpc/ext/get_schema.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 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.nc_common.utils import qmap, ns
+
+log = structlog.get_logger()
+
+class GetSchema(Rpc):
+    def __init__(self, request, request_xml, grpc_client, session, capabilities):
+        super(GetSchema, self).__init__(request, request_xml, grpc_client, session)
+        self.capabilities = capabilities
+        # specific schema parsing required
+        self.parse_schema_request(request_xml)
+        self._validate_parameters()
+
+    def execute(self):
+        if self.rpc_response.is_error:
+            return(self.rpc_response)
+
+        log.info('get-schema-request', session=self.session.session_id,
+                 request=self.request)
+
+        # Get the yang schema content
+        # TODO: Use version as well
+        content = self.capabilities.get_schema_content(self.request['identifier'])
+        if not content:
+            self.rpc_response.is_error = True
+            self.rpc_response.node = ncerror.BadMsg('Server Error')
+            return
+
+        self.rpc_response.node = self.create_xml_response(content)
+
+        self.rpc_response.is_error = False
+
+        return(self.rpc_response)
+
+    def _validate_parameters(self):
+        log.info('validate-parameters', session=self.session.session_id)
+        # Validate the GET command
+        if self.request:
+            try:
+                if self.request['command'] != 'get-schema' or \
+                        not self.request.has_key('identifier') or \
+                        not self.request.has_key('format') or \
+                        not self.request.has_key('version'):
+                    self.rpc_response.is_error = True
+                    self.rpc_response.node = ncerror.BadMsg('Improperly '
+                                                            'formatted get '
+                                                            'schemas request')
+                    return
+
+                if self.request.has_key('filter'):
+                    if not self.request.has_key('class'):
+                        self.rpc_response.is_error = True
+                        self.rpc_response.node = ncerror.BadMsg(
+                            'Missing filter sub-element')
+                        return
+
+                # Verify that the requested schema exists
+                if not self.capabilities.is_schema_supported(self.request[
+                                                             'identifier']) \
+                        or self.request['format'] != 'yang' :
+                    self.rpc_response.is_error = True
+                    self.rpc_response.node = ncerror.BadMsg(
+                        'Unsupported request')
+                    return
+
+            except Exception as e:
+                self.rpc_response.is_error = True
+                self.rpc_response.node = ncerror.BadMsg(self.request)
+                return
+
+    # Parse context-specific parameters
+    def parse_schema_request(self, node):
+        if not len(node):
+            return
+        schema_node = node.find(''.join([qmap(C.NCM), 'get-schema']))
+        if schema_node is not None:
+            for item in ['identifier', 'version', 'format']:
+                elem = schema_node.find(''.join([qmap(C.NCM), item]))
+                if elem is not None:
+                    self.request[item] = elem.text
+
+    def create_xml_response(self, content):
+        ns = {}
+        ns['xmlns'] = "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"
+
+        elem = etree.Element('data', attrib=ns)
+        elem.text = unicode(content, "utf-8")
+        return elem
diff --git a/netconf/nc_rpc/ext/get_schemas.py b/netconf/nc_rpc/ext/get_schemas.py
new file mode 100644
index 0000000..7ec4555
--- /dev/null
+++ b/netconf/nc_rpc/ext/get_schemas.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 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 GetSchemas(Rpc):
+    def __init__(self, request, request_xml, grpc_client, session, capabilities):
+        super(GetSchemas, self).__init__(request, request_xml, grpc_client, session)
+        self._validate_parameters()
+        self.capabilities = capabilities
+
+    def execute(self):
+        if self.rpc_response.is_error:
+            return(self.rpc_response)
+
+        log.info('get-schemas-request', session=self.session.session_id,
+                 request=self.request)
+
+        # Get the schema definitions
+        schema_defs = self.capabilities.get_yang_schemas_definitions()
+        log.info('schema-defs', definitions=schema_defs)
+
+        # format the schemas in xml
+        top = etree.Element('yang')
+        for dict in schema_defs:
+            schema = etree.SubElement(top, 'schema')
+            node = etree.SubElement(schema, 'identifier')
+            node.text = dict['id']
+            node = etree.SubElement(schema, 'version')
+            node.text = dict['version']
+            node = etree.SubElement(schema, 'format')
+            node.text = dict['format']
+            node = etree.SubElement(schema, 'namespace')
+            node.text = dict['namespace']
+            node = etree.SubElement(schema, 'location')
+            node.text = dict['location']
+
+        # Build the yang response
+        self.rpc_response.node = self.rpc_response.build_xml_response(
+            self.request, top)
+
+        self.rpc_response.is_error = False
+
+        return(self.rpc_response)
+
+
+    def _validate_parameters(self):
+        log.info('validate-parameters', session=self.session.session_id)
+        # Validate the GET command
+        if self.request:
+            try:
+                if self.request['command'] != 'get-schemas':
+                    self.rpc_response.is_error = True
+                    self.rpc_response.node = ncerror.BadMsg('Improperly '
+                                                            'formatted get '
+                                                            'schemas request')
+
+                if self.request.has_key('filter'):
+                    if not self.request.has_key('class'):
+                        self.rpc_response.is_error = True
+                        self.rpc_response.node = ncerror.BadMsg(
+                            'Missing filter sub-element')
+
+            except Exception as e:
+                self.rpc_response.is_error = True
+                self.rpc_response.node = ncerror.BadMsg(self.request)
+                return
+
diff --git a/netconf/nc_rpc/ext/get_voltha.py b/netconf/nc_rpc/ext/get_voltha.py
index 0c51e9a..5b004e7 100644
--- a/netconf/nc_rpc/ext/get_voltha.py
+++ b/netconf/nc_rpc/ext/get_voltha.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Copyright 2016 the original author or authors.
+# Copyright 2017 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.
@@ -18,20 +18,18 @@
 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
 from twisted.internet.defer import inlineCallbacks, returnValue
 import dicttoxml
-from simplejson import dumps, load
 
 log = structlog.get_logger()
 
 
 class GetVoltha(Rpc):
-    def __init__(self, request, grpc_client, session):
-        super(GetVoltha, self).__init__(request, grpc_client, session)
+    def __init__(self, request, request_xml, grpc_client, session, capabilities):
+        super(GetVoltha, self).__init__(request, request_xml, grpc_client, session)
         self._validate_parameters()
 
+
     @inlineCallbacks
     def execute(self):
         log.info('get-voltha-request', session=self.session.session_id,
@@ -64,11 +62,5 @@
             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]