def netconf_node_unmount(self, node_id): result = Result() path = ("config/network-topology:network-topology/" "topology/topology-netconf/node/controller-config/" "yang-ext:mount/config:modules/" "module/odl-sal-netconf-connector-cfg:" "sal-netconf-connector/{}").format(node_id) response = self._restconf_delete(path) if(response is None): result.status = http.SERVICE_UNAVAILABLE result.brief = "Connection error." msg = ("Connection to the '%s:%s' server has failed." % (self._ip_addr, self._http_port)) result.details = msg elif(response.status_code == http.OK or response.status_code == http.NO_CONTENT): result.status = http.OK result.brief = "Success." else: result.status = response.status_code result.brief = http.responses[response.status_code] result.details = response.content return result
def netconf_node_mount(self, node): result = Result() assert(isinstance(node, NETCONFDevice)) mr = NETCONFMountRequest(node.node_id, node.ip_addr, node.port, node.admin_name, node.admin_password) path = mr.path payload = mr.payload headers = {'content-type': 'application/yang.data+json'} response = self._restconf_post(path, payload, headers) if(response is None): result.status = http.SERVICE_UNAVAILABLE result.brief = "Connection error." msg = ("Connection to the '%s:%s' server has failed." % (self._ip_addr, self._http_port)) result.details = msg elif(response.status_code == http.OK or response.status_code == http.NO_CONTENT): result.status = http.OK result.brief = "Success." else: result.status = response.status_code result.brief = http.responses[response.status_code] result.details = response.content return result
def netconf_node_topo_info(self, node_id): result = Result() path = ("operational/network-topology:network-topology/" "topology/topology-netconf/node/{}").format(node_id) headers = {'accept': 'application/yang.data+json'} response = self._restconf_get(path, headers) if(response is None): result.status = http.SERVICE_UNAVAILABLE result.brief = "Connection error." msg = ("Connection to the '%s:%s' server has failed." % (self._ip_addr, self._http_port)) result.details = msg elif(response.status_code == http.OK): try: if(response.headers.get('content-type') != 'application/yang.data+json'): raise ValueError("unexpected response content encoding") # Deserialize response JSON content to Python object d = json.loads(response.content) node = d['node'][0] data = NETCONFNodeTopoInfo(**node) result.data = data result.status = http.OK except(Exception) as e: if(self._verbose): print("!!!Error: '%s'" % repr(e)) result.status = http.INTERNAL_SERVER_ERROR result.brief = "Failed to parse HTTP response." result.details = repr(e) else: result.status = response.status_code result.brief = http.responses[response.status_code] result.details = response.content return result
def netconf_nodes_ids(self): result = Result() path = ("operational/network-topology:network-topology/" "topology/topology-netconf") headers = {'accept': 'application/yang.data+json'} response = self._restconf_get(path, headers) if(response is None): result.status = http.SERVICE_UNAVAILABLE result.brief = "Connection error." msg = ("Connection to the '%s:%s' server has failed." % (self._ip_addr, self._http_port)) result.details = msg elif(response.status_code == http.OK): try: if(response.headers.get('content-type') != 'application/yang.data+json'): raise ValueError("unexpected response content encoding") # Deserialize response JSON content to Python object d = json.loads(response.content) # Extract the data nodes_list = d['topology'][0]['node'] data = [] for item in nodes_list: node_id = item.get('node-id') if(node_id is not None): data.append(node_id) result.data = data result.status = http.OK except(Exception) as e: if(self._verbose): print("!!!Error: '%s'" % repr(e)) result.status = http.INTERNAL_SERVER_ERROR result.brief = "Failed to parse HTTP response." result.details = repr(e) else: result.status = response.status_code result.brief = http.responses[response.status_code] result.details = response.content return result
def schema_info(self, node_id, shema_id, schema_version): """Fetch content of the YANG data model schema from the given NETCONF node. :param identifier: NETCONF node identifier :param identifier: unique identifier of the schema (name of the YANG module or submodule) :param str version: version of the schema (value of the revision statement in the YANG module or submodule) """ result = Result() path = ("operations/opendaylight-inventory:nodes/" "node/{}/yang-ext:mount/" "ietf-netconf-monitoring:get-schema").format(node_id) headers = {'content-type': 'application/yang.data+json', 'accept': 'application/xml'} payload = {'input': {'identifier': shema_id, 'version': schema_version, 'format': 'yang'}} response = self._restconf_post(path, json.dumps(payload), headers) if(response is None): result.status = http.SERVICE_UNAVAILABLE result.brief = "Connection error." msg = ("Connection to the '%s:%s' server has failed." % (self._ip_addr, self._http_port)) result.details = msg elif(response.status_code == http.OK): try: if(response.headers.get('content-type') != 'application/xml'): raise ValueError("unexpected response content encoding") root = xml.fromstring(response.content) result.data = "".join(root.itertext()) result.status = http.OK except(Exception) as e: if(self._verbose): print("!!!Error: '%s'" % repr(e)) result.status = http.INTERNAL_SERVER_ERROR result.brief = "Failed to parse HTTP response." result.details = repr(e) else: result.status = response.status_code result.brief = http.responses[response.status_code] result.details = response.content return result
def schemas_list(self, node_id): """Return list of all YANG data model schemas supported by the given NETCONF node. :param identifier: NETCONF node identifier """ result = Result() path = ("operational/opendaylight-inventory:nodes/" "node/{}/yang-ext:mount/" "ietf-netconf-monitoring:netconf-state/" "schemas").format(node_id) headers = {'accept': 'application/yang.data+json'} response = self._restconf_get(path, headers) if(response is None): result.status = http.SERVICE_UNAVAILABLE result.brief = "Connection error." msg = ("Connection to the '%s:%s' server has failed." % (self._ip_addr, self._http_port)) result.details = msg elif(response.status_code == http.OK): try: if(response.headers.get('content-type') != 'application/yang.data+json'): raise ValueError("unexpected response content encoding") # Deserialize response JSON content to Python object d = json.loads(response.content) # Extract the data data = d['schemas']['schema'] result.data = data result.status = http.OK except(Exception) as e: if(self._verbose): print("!!!Error: '%s'" % repr(e)) result.status = http.INTERNAL_SERVER_ERROR result.brief = "Failed to parse HTTP response." result.details = repr(e) else: result.status = response.status_code result.brief = http.responses[response.status_code] result.details = response.content return result