@@ -0,0 +1,1746 @@
+from jnpr.junos import Device%0Afrom jnpr.junos.utils.config import Config%0Afrom lxml import etree%0Aimport string%0Aimport argparse%0A%0Aarguments = %7B'hashtag': 'Configuration element hash tag'%7D%0A%0Adef build_xml_filter( root, element):%0A    path = %5B%5D%0A    s = ''%0A    %0A    while element!= root:%0A        name = element.find( 'name')%0A        if name!=None:%0A            s = '%3Cname%3E'+name.text+'%3C/name%3E'+s            %0A        s = '%3C'+element.tag + '%3E'+s+'%3C/'+element.tag+'%3E'%0A        element = element.getparent()%0A    return s%0A    %0Adef main():%0A%0A    parser = argparse.ArgumentParser(description='Displays configuration elements with select hashtag. Hashtags are configured at any level using %22set apply-macro ht %3Chashtag-name%3E%22 command.')%0A    %0A    for key in arguments:%0A        parser.add_argument(('-' + key), required=True, help=arguments%5Bkey%5D)%0A    args = parser.parse_args()%0A%0A    dev = Device()%0A    dev.open()%0A    dev.timeout = 300%0A    xml_config = dev.rpc.get_config(options=%7B'database':'committed','inherit':'inherit'%7D)    %0A    paths = %5B%5D%0A    #select all elements matching pattern%0A    for ht_element in xml_config.findall( './/apply-macro/data/%5Bname=%5C'%7B%7D%5C'%5D/../'.format( args.hashtag)):%0A        #filter by node id just in case        %0A        if ht_element.text == 'ht':%0A            s = build_xml_filter( xml_config, ht_element.getparent().getparent())%0A            paths.append( s)%0A    if paths:%0A        path = '%3Cconfiguration%3E'+%22%22.join( paths)+'%3C/configuration%3E'    %0A        xml_config = dev.rpc.get_config( filter_xml=path,options=%7B'database':'committed','inherit':'inherit', 'format':'text'%7D)%0A        print xml_config.text%0A    else:%0A        print 'hashtag %5C'%7B%7D%5C' is not found'.format( args.hashtag)%0A    dev.close()%0A%0A    %0Aif __name__ == %22__main__%22:%0A    main()%0A

Create hashtag.py