def get_pon_port_state_results(): from ncclient.operations.retrieve import GetReply raw = """ <?xml version="1.0" encoding="UTF-8"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:59e71979-01bb-462f-b17a-b3a45e1889ac"> <data> <interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> <interface><name>XPON 0/1</name></interface> <interface><name>XPON 0/2</name></interface> <interface><name>XPON 0/3</name></interface> <interface><name>XPON 0/4</name></interface> <interface><name>XPON 0/5</name></interface> <interface><name>XPON 0/6</name></interface> <interface><name>XPON 0/7</name></interface> <interface><name>XPON 0/8</name></interface> <interface><name>XPON 0/9</name></interface> <interface><name>XPON 0/10</name></interface> <interface><name>XPON 0/11</name></interface> <interface><name>XPON 0/12</name></interface> <interface><name>XPON 0/13</name></interface> <interface><name>XPON 0/14</name></interface> <interface><name>XPON 0/15</name></interface> <interface><name>XPON 0/16</name></interface> </interfaces-state> </data> </rpc-reply> """ return GetReply(raw)
def get(self, payload): """ Get the requested data from the server :param payload: Payload/filter :return: (deferred) for GetReply """ yield asleep(random.uniform(0.01, 0.03)) # Simulate NETCONF request delay # TODO: Customize if needed... xml = _dummy_xml returnValue(GetReply(xml))
def get_config(self, source='running'): """ Get the configuration from the specified source :param source: (string) Configuration source, 'running', 'candidate', ... :return: (deferred) Deferred request that wraps the GetReply class """ yield asleep(random.uniform(0.01, 0.04)) # Simulate NETCONF request delay # TODO: Customize if needed... xml = _dummy_xml returnValue(GetReply(xml))
def get_nni_port_state_results(): from ncclient.operations.retrieve import GetReply raw = """ <?xml version="1.0" encoding="UTF-8"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:59e71979-01bb-462f-b17a-b3a45e1889ac"> <data> <interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> <interface><name>hundred-gigabit-ethernet 0/1</name></interface> </interfaces-state> </data> </rpc-reply> """ return GetReply(raw)
def recv_data(self): """Retrieve data from process pipe.""" if not self.proc: logger.info('Not connected.') else: buf = '' while True: # TODO: Could be better...1 byte at a time... # but, too much buffer and it deadlocks!! data = self.proc.stdout.read(1) if not data: return GetReply(self.rpc_pipe_err) buf += data if buf.endswith('\n##'): buf = buf[:-3] break logger.info(buf) buf = buf[buf.find('<'):] reply = re.sub(self.chunk, '', buf) return GetReply(reply)
def test_rawrpc(self): from ncclient.operations.retrieve import GetReply h = DefaultDeviceHandler() self.rawrpc = yang.connector.netconf.RawRPC( session=transport.SSHSession(h), device_handler=h) self.rawrpc._event = MyEvent() self.rawrpc._session = MySSHSession() reply_raw = ''' <rpc-reply message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" > <data> <native xmlns="http://cisco.com/ns/yang/ned/ios"> <version>16.3</version> </native> </data> </rpc-reply> ''' self.rawrpc._reply = GetReply(reply_raw) r = ''' <rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <get> <filter> <native xmlns="http://cisco.com/ns/yang/ned/ios"> <version> </version> </native> </filter> </get> </rpc> ''' generated_value = self.rawrpc._request(r).xml expected_value = ''' <rpc-reply message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" > <data> <native xmlns="http://cisco.com/ns/yang/ned/ios"> <version>16.3</version> </native> </data> </rpc-reply> ''' self.assertEqual(generated_value, expected_value)
def read_get_reply_xml(self, filename): return GetReply(self.read_xml('get_reply', filename))