def DeployConfig_jcs(local_int, ckn, cak, conn_name=None): logger.debug('====> In DeployConfig_jcs') try: if conn_name is None: conn_name = id_generator() script = "system-check.py" change_xml = """<security> <macsec> <connectivity-association> <name>{0}</name> <security-mode>static-cak</security-mode> <pre-shared-key> <ckn>{1}</ckn> <cak>{2}</cak> </pre-shared-key> </connectivity-association> <interfaces> <name>{3}</name> <connectivity-association>{0}</connectivity-association> </interfaces> </macsec> </security>""".format(conn_name, ckn, cak, local_int) jcs.emit_change(change_xml, "change", "xml") except Exception as e: jcs.emit_warning( 'Cannot deploy pre-shared key, skip automatically MACsec deployment' ) jcs.emit_warning('Please see debug logs for detail.') quit() logger.debug('<==== Out DeployConfig_jcs')
def main(): # Get the configuration root object root = Junos_Configuration # Check for apply-macro configuration existence apply_macro_config = root.find("./routing-options/apply-macro[name='both-ribs']") if apply_macro_config: # Create configuration xml chunk transient_change_xml = """<routing-options><interface-routes> <rib-group><inet>{0}</inet></rib-group></interface-routes> <rib-groups><name>{1}</name><import-rib>{2}</import-rib> <import-rib>{3}</import-rib></rib-groups></routing-options> """.format("both-ribs", "both-ribs", "inet.0", "inet.2") # Committing 'transient' changes jcs.emit_change(transient_change_xml, "transient-change", "xml")
def main(): asumber = 0 vlan = 0 side = "" root = Junos_Configuration l2vpn = root.find("./{http://yang.juniper.net/customyang/l2vpn}l2vpn") l2vpn_lines = root.find( ".//{http://yang.juniper.net/customyang/l2vpn}lines") if l2vpn: for elem in l2vpn.iter(): if str(elem.tag).rstrip( '\n' ) == "{http://yang.juniper.net/customyang/l2vpn}as-number": asnumber = elem.text if str(elem.tag).rstrip( '\n') == "{http://yang.juniper.net/customyang/l2vpn}side": side = elem.text if l2vpn_lines: for line in l2vpn_lines.iter(): if str(line.tag).rstrip( '\n') == "{http://yang.juniper.net/customyang/l2vpn}vlan": vlan = line.text.rstrip('\n') if str(line.tag).rstrip( '\n' ) == "{http://yang.juniper.net/customyang/l2vpn}interface": interface = line.text change = "<interfaces><interface><name>{}</name><flexible-vlan-tagging/>\ <encapsulation>flexible-ethernet-services</encapsulation>\ <description>l2vpn {}</description>\ <unit><name>{}</name><vlan-id>{}</vlan-id>\ <encapsulation>vlan-ccc</encapsulation>\ <family><ccc/></family></unit>\ </interface></interfaces>".format( str(interface), str(asnumber), int(vlan), int(vlan)) jcs.emit_change(change, "transient-change", "xml")
E('routing-options', E.static(operation='delete')))) else: static_route = E.static() for route in routes.xpath('vpn:route', **ns_dict): dest = route.find('vpn:name', **ns_dict) nh = route.find('vpn:next-hop', **ns_dict) discard = route.find('vpn:discard', **ns_dict) if dest.get('operation') == 'delete': static_route.append( E.route(E.name(dest.text), operation='delete')) elif nh is not None and nh.get('operation') == 'delete': static_route.append( E.route(E.name(dest.text), E('next-hop', operation='delete'))) elif discard is not None and discard.get( 'operation') == 'delete': static_route.append( E.route(E.name(dest.text), E('discard', operation='delete'))) instances.append( E.instance(E.name(name.text), E('routing-options', static_route))) # logger.info('\n' + etree.tostring(interfaces, pretty_print=True)) # logger.info('\n' + etree.tostring(instances, pretty_print=True)) # jcs.emit_change('<interfaces operation="delete"/><routing-instances operation="delete"/>', 'transient-change', 'xml') ### Commit the junos config changes ### jcs.emit_change(etree.tostring(interfaces), 'transient-change', 'xml') jcs.emit_change(etree.tostring(instances), 'transient-change', 'xml')
#!/usr/bin/python # Script to commit permanent changes. # Author: Satya ([email protected]) import jcs count = 0 trace = "trace" size = "100m" files = "10" flag = "all" while (count < 5): change_xml = """<system><scripts><commit> <traceoptions><file><filename>{0}</filename><size>{1}</size><files>{2}</files></file><flag>{3}</flag> </traceoptions></commit> </scripts></system>""".format(trace + str(count), size, files, flag) # Commit permanent changes jcs.emit_change(change_xml, "change", "xml") count = count + 1
#!/usr/bin/python # # Copyright (c) 1999-2018, Juniper Networks Inc. # # All rights reserved. # # Script to commit transient changes. import jcs count = 0 trace = "trace" size = "100m" files = "10" flag = "all" while (count < 5): transient_change_xml = """<system><scripts><commit> <traceoptions><file><filename>{0}</filename><size>{1}</size><files>{2}</files></file><flag>{3}</flag> </traceoptions></commit> </scripts></system>""".format(trace + str(count), size, files, flag) # Commit transient changes jcs.emit_change(transient_change_xml, "transient-change", "xml") count = count + 1
from junos import Junos_Configuration as root import jcs if __name__ == "__main__": for unit in root.xpath( "interfaces/interface/unit[apply-macro[name='FAMILIES']]"): unit_name = unit.findtext("name") interface_name = unit.findtext("../name") conf = """<interfaces> <interface> <name>{0}</name> <unit> <name>{1}</name> <family> <mpls/> <iso/> </family> </unit> </interface> </interfaces>""".format(interface_name, unit_name) jcs.emit_change(conf, "transient-change", "xml")