예제 #1
0
def main():
    parser = Parser(__file__)
    args = parser.parse_args()

    session = NetconfSSHSession(args.host, args.port, args.user, args.password)

    es_nsmap = {'yp': 'urn:ietf:params:xml:ns:yang:ietf-yang-push'}
    root = lxml.etree.Element(
        'establish-subscription',
        nsmap=es_nsmap,
        attrib={
            'xmlns':
            'urn:ietf:params:xml:ns:yang:ietf-subscribed-notifications'
        })

    datastore = util.leaf_elm('yp:datastore', 'ds:operational')
    root.append(datastore)

    datastore_xpath_filter = util.leaf_elm('yp:datastore-xpath-filter',
                                           args.xpath)

    root.append(datastore_xpath_filter)

    periodic = util.subelm(root, 'yp:periodic')
    period = util.leaf_elm("yp:period", args.period)
    periodic.append(period)

    res = session.send_rpc(root)

    while True:
        tree, notif, msg = session.get_notification()
        print(etree.tounicode(notif, pretty_print=True), end="\n\n")
예제 #2
0
 def receive_notifications(self, session: NetconfSSHSession, subscription_id: int):
     while True:
         try:
             notif = session.get_notification(subscription_id)
             for handler in self.handlers:
                 handler(notif, subscription_id, "/")
         except:
             traceback.print_exc()
             break