def main(): data = yaml_ops.read_yaml("vlan_data.yaml") if not data['switchip']: data['switchip'] = input("Switch IP Address: ") if data['bypassproxy']: os.environ['no_proxy'] = data['switchip'] os.environ['NO_PROXY'] = data['switchip'] base_url = "https://{0}/rest/{1}/".format(data['switchip'], data['version']) try: session_dict = dict(s=session.login(base_url, data['username'], data['password']), url=base_url) vlan.create_vlan_and_svi(data['vlanid'], data['vlanname'], data['vlanportname'], data['vlaninterfacename'], data['vlandescription'], data['vlanip'], vlan_port_desc=data['vlanportdescription'], **session_dict) # Add DHCP helper IPv4 addresses for SVI dhcp.add_dhcp_relays(data['vlanportname'], "default", data['ipv4helperaddresses'], **session_dict) # Add a new entry to the Port table if it doesn't yet exist interface.add_l2_interface(data['physicalport'], **session_dict) # Update the Interface table entry with "user-config": {"admin": "up"} interface.enable_disable_interface(data['physicalport'], **session_dict) # Set the L2 port VLAN mode as 'access' vlan.port_set_vlan_mode(data['physicalport'], "access", **session_dict) # Set the access VLAN on the port vlan.port_set_untagged_vlan(data['physicalport'], data['vlanid'], **session_dict) except Exception as error: print('Ran into exception: {}. Logging out..'.format(error)) session.logout(**session_dict)
def _delete_lag_interface_v1(name, phys_ports, **kwargs): """ Perform a DELETE call to delete a LAG interface. Also, for each physical port, create the associated Port table entry, and remove the LAG ID from the Port and Interface entries by initializing them to default state. :param name: Alphanumeric name of LAG interface :param phys_ports: List of physical ports to aggregate (e.g. ["1/1/1", "1/1/2", "1/1/3"]) :param kwargs: keyword s: requests.session object with loaded cookie jar keyword url: URL in main() function :return: Nothing """ interface.delete_interface(name, **kwargs) # For each port, create a Port table entry, then initialize the Port and Interface entries to remove LAG for phys_port in phys_ports: interface.add_l2_interface(phys_port, **kwargs) port.initialize_port_entry(phys_port, **kwargs)
def main(): data = yaml_ops.read_yaml("loop_protect_data.yaml") if not data['switchip']: data['switchip'] = input("Switch IP Address: ") if data['bypassproxy']: os.environ['no_proxy'] = data['switchip'] os.environ['NO_PROXY'] = data['switchip'] base_url = "https://{0}/rest/{1}/".format(data['switchip'], data['version']) try: session_dict = dict(s=session.login(base_url, data['username'], data['password']), url=base_url) # Create VLANs and L2 LAG; assign VLANs as trunk VLANs on LAG for l2_lag_data in data['lags']: # Create VLANs for vlan_id in l2_lag_data['trunk_vlans']: vlan.create_vlan(vlan_id, "vlan%s" % vlan_id, **session_dict) # Create L2 LAG and assign VLANs as trunk VLANs on the LAG lag.create_l2_lag_interface( data['lags'][0]['name'], data['lags'][0]['interfaces'], vlan_ids_list=data['lags'][0]['trunk_vlans'], lacp_mode=data['lags'][0]['lacp_mode'], mc_lag=data['lags'][0]['mc_lag'], **session_dict) # Add a new entry to the Port table if it doesn't yet exist interface.add_l2_interface(data['interfacename'], **session_dict) vlan.port_add_vlan_trunks(data['interfacename'], data['lags'][0]['trunk_vlans'], **session_dict) # Update the Interface table entry with "user-config": {"admin": "up"} interface.enable_disable_interface(data['interfacename'], **session_dict) # Enable Loop-protect on Interface loop_protect.update_port_loop_protect(data['interfacename'], action=None, vlan_list=[], **session_dict) # Enable Loop-protect for specific VLANs on Interface loop_protect.update_port_loop_protect( data['interfacename'], action=None, vlan_list=data['lags'][0]['trunk_vlans'], **session_dict) # Enable Loop-protect on LAG loop_protect.update_port_loop_protect(data['lags'][0]['name'], action=None, vlan_list=[], **session_dict) # Enable Loop-protect for specific VLANs on LAG loop_protect.update_port_loop_protect( data['lags'][0]['name'], action=None, vlan_list=data['lags'][0]['trunk_vlans'], **session_dict) # Update Loop-protect Actions on Interface loop_protect.update_port_loop_protect(data['interfacename'], action=data['interfaceaction'], vlan_list=None, **session_dict) # Update Loop-protect Actions on LAG loop_protect.update_port_loop_protect(l2_lag_data.get('name'), action=data['lagaction'], vlan_list=[], **session_dict) except Exception as error: print('Ran into exception: {}. Logging out..'.format(error)) session.logout(**session_dict)
def main(): data = yaml_ops.read_yaml("qos_data.yaml") if not data['switchip']: data['switchip'] = input("Switch IP Address: ") if data['bypassproxy']: os.environ['no_proxy'] = data['switchip'] os.environ['NO_PROXY'] = data['switchip'] base_url = "https://{0}/rest/{1}/".format(data['switchip'], data['version']) try: session_dict = dict(s=session.login(base_url, data['username'], data['password']), url=base_url) system_info_dict = system.get_system_info(**session_dict) platform_name = system_info_dict['platform_name'] # Create empty queue profile qos.create_queue_profile(data['queueprofilename'], **session_dict) # Add entries to queue profile for i in range(0, 5): qos.create_queue_profile_entry(data['queueprofilename'], i, [i], **session_dict) for i in range(5, 7): qos.create_queue_profile_entry(data['queueprofilename'], i, [i + 1], **session_dict) qos.create_queue_profile_entry(data['queueprofilename'], 7, [5], desc="VOICE", **session_dict) # Create empty schedule profile qos.create_schedule_profile(data['scheduleprofilename'], **session_dict) # Add entries to schedule profile # Scheduling algorithms: 8400 uses WFQ; other platforms use DWRR if "8400" in platform_name: algorithm = "wfq" else: algorithm = "dwrr" for i in range(0, 7): qos.create_schedule_profile_entry(data['scheduleprofilename'], i, algorithm, weight=i + 1, **session_dict) qos.create_schedule_profile_entry(data['scheduleprofilename'], 7, "strict", **session_dict) # Apply profiles globally qos.apply_profiles_globally(data['queueprofilename'], data['scheduleprofilename'], **session_dict) # Set trust globally qos.set_trust_globally('dscp', **session_dict) # Remap DSCP code points' priorities qos.remap_dscp_entry(40, color='green', local_priority=6, desc='CS5', **session_dict) for i in range(41, 46): qos.remap_dscp_entry(i, color='green', local_priority=6, **session_dict) qos.remap_dscp_entry(47, color='green', local_priority=6, **session_dict) # Create empty traffic class qos.create_traffic_class(data['trafficclass']['name'], data['trafficclass']['type'], **session_dict) # Create traffic class entry qos.create_traffic_class_entry(data['trafficclass']['name'], data['trafficclass']['type'], "match", 10, **session_dict) # Version-up the traffic class to complete the change qos.update_traffic_class(data['trafficclass']['name'], data['trafficclass']['type'], **session_dict) # Create empty classifier policy qos.create_policy(data['policy']['name'], **session_dict) # Add entry to classifier policy qos.create_policy_entry(data['policy']['name'], data['trafficclass']['name'], data['trafficclass']['type'], 10, **session_dict) # Set action on the policy entry qos.create_policy_entry_action(data['policy']['name'], 10, dscp=0, pcp=0, **session_dict) # Version-up the policy to complete the change qos.update_policy(data['policy']['name'], **session_dict) # Create LAGs and set trust mode on the LAG interfaces for lag_data in data['lags']: lag.create_l2_lag_interface(lag_data['name'], lag_data['interfaces'], **session_dict) qos.set_trust_interface(lag_data['name'], lag_data['qostrust'], **session_dict) # Create L2 interface interface.add_l2_interface(data['portrateinterface'], **session_dict) if platform_name.startswith("6"): unknown_unicast_limit = None unknown_unicast_units = None else: unknown_unicast_limit = 30 unknown_unicast_units = 'pps' # Set rate limits on the L2 interface qos.update_port_rate_limits( data['portrateinterface'], broadcast_limit=50, broadcast_units='pps', multicast_limit=40, multicast_units='pps', unknown_unicast_limit=unknown_unicast_limit, unknown_unicast_units=unknown_unicast_units, **session_dict) # Create L2 interface interface.add_l2_interface(data['portpolicyinterface'], **session_dict) # Apply policy to L2 interface qos.update_port_policy(data['portpolicyinterface'], data['policy']['name'], **session_dict) except Exception as error: print('Ran into exception: {}. Logging out..'.format(error)) session.logout(**session_dict)
def main(): data = yaml_ops.read_yaml("vrf_vlan_data.yaml") if not data['switchip']: data['switchip'] = input("Switch IP Address: ") if data['bypassproxy']: os.environ['no_proxy'] = data['switchip'] os.environ['NO_PROXY'] = data['switchip'] base_url = "https://{0}/rest/{1}/".format(data['switchip'], data['version']) try: session_dict = dict(s=session.login(base_url, data['username'], data['password']), url=base_url) # Add new VRF with optional route distinguisher to VRF table vrf.add_vrf(data['vrfname'], data['vrfrd'], **session_dict) vlan.create_vlan_and_svi(data['vlan1id'], data['vlan1name'], data['vlan1portname'], data['vlan1interfacename'], data['vlan1description'], data['vlan1ip'], data['vrfname'], data['vlan1portdescription'], **session_dict) vlan.create_vlan_and_svi(data['vlan2id'], data['vlan2name'], data['vlan2portname'], data['vlan2interfacename'], data['vlan2description'], data['vlan2ip'], data['vrfname'], data['vlan2portdescription'], **session_dict) # Add DHCP helper IPv4 addresses for SVI dhcp.add_dhcp_relays(data['vlan1portname'], data['vrfname'], data['ipv4helperaddresses'], **session_dict) # Add a new entry to the Port table if it doesn't yet exist interface.add_l2_interface(data['systemportname'], **session_dict) # Update the Interface table entry with "user-config": {"admin": "up"} interface.enable_disable_interface(data['systeminterfacename'], **session_dict) # Set the L2 port VLAN mode as 'access' src.vlan.port_set_vlan_mode(data['systemportname'], "access", **session_dict) # Set the access VLAN on the port src.vlan.port_set_untagged_vlan(data['systemportname'], data['vlan1id'], **session_dict) # Print ARP entries of VRF arp_entries = arp.get_arp_entries(data['vrfname'], **session_dict) print("VRF '%s' ARP entries: %s" % (data['vrfname'], repr(arp_entries))) # Modify the created VLANs vlan.modify_vlan(data['vlan1id'], "New Name for VLAN %s" % data['vlan1id'], "New Description for VLAN %s" % data['vlan1id'], **session_dict) vlan.modify_vlan(data['vlan2id'], "New Name for VLAN %s" % data['vlan2id'], "New Description for VLAN %s" % data['vlan2id'], **session_dict) # Print modified VLANs' data vlan_data1 = vlan.get_vlan(data['vlan1id'], **session_dict) print("VLAN '%d' data: %s" % (data['vlan1id'], repr(vlan_data1))) vlan_data2 = vlan.get_vlan(data['vlan2id'], **session_dict) print("VLAN '%d' data: %s" % (data['vlan2id'], repr(vlan_data2))) except Exception as error: print('Ran into exception: {}. Logging out..'.format(error)) session.logout(**session_dict)
def main(): data = yaml_ops.read_yaml("acl_data.yaml") if not data['switchip']: data['switchip'] = input("Switch IP Address: ") if data['bypassproxy']: os.environ['no_proxy'] = data['switchip'] os.environ['NO_PROXY'] = data['switchip'] if not data['version']: data['version'] = "v10.04" base_url = "https://{0}/rest/{1}/".format(data['switchip'], data['version']) try: session_dict = dict(s=session.login(base_url, data['username'], data['password']), url=base_url) # Create empty IPv4 ACL acl.create_acl(data['ipv4aclname'], "ipv4", **session_dict) # Add entry 10 to IPv4 ACL acl.create_acl_entry(data['ipv4aclname'], "ipv4", 10, action="deny", count=data['hitcount'], ip_protocol=6, src_ip="10.1.2.1/255.255.255.0", **session_dict) # Add entry 20 to IPv4 ACL acl.create_acl_entry(data['ipv4aclname'], "ipv4", 20, action="deny", count=data['hitcount'], ip_protocol=17, dst_ip="10.33.12.3/255.255.255.255", dst_l4_port_min=80, dst_l4_port_max=80, **session_dict) # Add entry 30 to IPv4 ACL acl.create_acl_entry(data['ipv4aclname'], "ipv4", 30, action="permit", count=data['hitcount'], src_ip="10.2.4.2/255.255.255.255", dst_ip="10.33.25.34/255.255.255.0", **session_dict) # Add entry 40 to IPv4 ACL acl.create_acl_entry(data['ipv4aclname'], "ipv4", 40, action="deny", count=data['hitcount'], **session_dict) # Add entry 50 to IPv4 ACL acl.create_acl_entry(data['ipv4aclname'], "ipv4", 50, action="permit", count=data['hitcount'], **session_dict) # Version-up the IPv4 ACL to complete the change acl.update_acl(data['ipv4aclname'], "ipv4", **session_dict) # Create empty IPv6 ACL acl.create_acl(data['ipv6aclname'], "ipv6", **session_dict) # Add entry 10 to IPv6 ACL acl.create_acl_entry(data['ipv6aclname'], "ipv6", 10, action="deny", count=data['hitcount'], ip_protocol=6, dst_ip="22f4:23::1/ffff:ffff:ffff:ffff::", **session_dict) # Add entry 20 to IPv6 ACL acl.create_acl_entry(data['ipv6aclname'], "ipv6", 20, action="permit", count=data['hitcount'], ip_protocol=6, src_ip="3000:323:1221::88/ffff:ffff:ffff:ffff::", **session_dict) # Add entry 30 to IPv6 ACL acl.create_acl_entry( data['ipv6aclname'], "ipv6", 30, action="permit", count=data['hitcount'], ip_protocol=89, dst_ip= "3999:929:fa98:00f0::4/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00", **session_dict) # Add entry 40 to IPv6 ACL acl.create_acl_entry(data['ipv6aclname'], "ipv6", 40, action="deny", count=data['hitcount'], **session_dict) # Add entry 50 to IPv6 ACL acl.create_acl_entry(data['ipv6aclname'], "ipv6", 50, action="permit", count=data['hitcount'], **session_dict) # Version-up the IPv6 ACL to complete the change acl.update_acl(data['ipv6aclname'], "ipv6", **session_dict) # Create empty MAC ACL acl.create_acl(data['macaclname'], "mac", **session_dict) # Add entry 10 to MAC ACL acl.create_acl_entry(data['macaclname'], "mac", 10, action="permit", count=data['hitcount'], ethertype=2054, src_mac="ff33.244c.aabb/ffff.ffff.ffff", **session_dict) # Add entry 20 to MAC ACL acl.create_acl_entry(data['macaclname'], "mac", 20, action="permit", count=data['hitcount'], ethertype=34525, src_mac="1f33.cc4c.aaff/ffff.ffff.ffff", dst_mac="ff33.244c.aa11/ffff.ffff.ffff", **session_dict) # Add entry 30 to MAC ACL acl.create_acl_entry(data['macaclname'], "mac", 30, action="permit", count=data['hitcount'], ethertype=35020, src_mac="1f33.cc4c.aaff/ffff.ffff.ffff", dst_mac="ff33.244c.aa11/ffff.ffff.ffff", **session_dict) # Add entry 40 to MAC ACL acl.create_acl_entry(data['macaclname'], "mac", 40, action="permit", count=data['hitcount'], ethertype=32923, src_mac="1f33.cc4c.aaff/ffff.ffff.ffff", dst_mac="ff33.244c.aa11/ffff.ffff.ffff", **session_dict) # Add entry 50 to MAC ACL acl.create_acl_entry(data['macaclname'], "mac", 50, action="deny", count=data['hitcount'], **session_dict) # Version-up the ACL to complete the change acl.update_acl(data['macaclname'], "mac", **session_dict) # Create VLAN and L2 System interfaces interface.add_l2_interface(data['interfaceVLAN'], **session_dict) interface.enable_disable_interface(data['interfaceVLAN'], "up", **session_dict) interface.add_l2_interface(data['ipv4L2ingressinterface'], **session_dict) interface.enable_disable_interface(data['ipv4L2ingressinterface'], "up", **session_dict) vlan.port_set_vlan_mode(data['ipv4L2ingressinterface'], "native-tagged", **session_dict) vlan.port_add_vlan_trunks(data['ipv4L2ingressinterface'], **session_dict) interface.add_l2_interface(data['ipv6L2ingressinterface'], **session_dict) interface.enable_disable_interface(data['ipv6L2ingressinterface'], "up", **session_dict) vlan.port_set_vlan_mode(data['ipv6L2ingressinterface'], "native-tagged", **session_dict) vlan.port_add_vlan_trunks(data['ipv6L2ingressinterface'], **session_dict) # Create LAG Interfaces for LAGinterface in data['LAGinterfaces']: interface.add_l2_interface(LAGinterface, **session_dict) interface.enable_disable_interface(LAGinterface, "up", **session_dict) # Create L3 interface interface.add_l3_ipv4_interface(data['L3egressinterface'], **session_dict) interface.enable_disable_interface(data['L3egressinterface'], "up", **session_dict) # Create LAG interfaces lag.create_l2_lag_interface(data['LAGname'], data['LAGinterfaces'], **session_dict) # Create VLAN vlan.create_vlan(data['aclVLANid'], "vlan%d" % data['aclVLANid'], **session_dict) # Attach the ACL to VLAN vlan.attach_vlan_acl(data['aclVLANid'], data['ipv4aclname'], "ipv4", **session_dict) # Attach VLAN to interface vlan.port_set_vlan_mode(data['interfaceVLAN'], "native-tagged", **session_dict) vlan.port_add_vlan_trunks(data['interfaceVLAN'], [data['aclVLANid']], **session_dict) # Apply IPv4 ACL to L2 interface on ingress acl.update_port_acl_in(data['ipv4L2ingressinterface'], data['ipv4aclname'], 'ipv4', **session_dict) # Apply IPv6 ACL to L2 interface on ingress acl.update_port_acl_in(data['ipv6L2ingressinterface'], data['ipv6aclname'], 'ipv6', **session_dict) # Apply IPv4 ACL to L3 interface on egress acl.update_port_acl_out(data['L3egressinterface'], data['ipv4aclname'], **session_dict) # Apply IPv4 ACL to L2 LAG on ingress acl.update_port_acl_in(data['LAGname'], data['ipv4aclname'], 'ipv4', **session_dict) except Exception as error: print('Ran into exception: {}. Logging out..'.format(error)) session.logout(**session_dict)
def main(): data = yaml_ops.read_yaml("access_security_data.yaml") if not data['switchip']: data['switchip'] = input("Switch IP Address: ") if data['bypassproxy']: os.environ['no_proxy'] = data['switchip'] os.environ['NO_PROXY'] = data['switchip'] base_url = "https://{0}/rest/{1}/".format(data['switchip'], data['version']) try: session_dict = dict(s=session.login(base_url, data['username'], data['password']), url=base_url) system_info_dict = system.get_system_info(**session_dict) platform_name = system_info_dict['platform_name'] # Only execute workflow if the platform is in the 6xxx series if platform_name.startswith("6"): # Configure RADIUS server host access_security.create_radius_host_config( data['radius_server_host']['vrf'], data['radius_server_host']['hostname'], passkey=data['radius_server_host']['passkey'], **session_dict) # Enable 802.1x globally access_security.enable_disable_dot1x_globally(enable=True, **session_dict) # Create L2 interface interface.add_l2_interface(data['802.1x']['port'], **session_dict) # Configure 802.1x on the L2 interface access_security.configure_dot1x_interface( data['802.1x']['port'], auth_enable=data['802.1x']['auth_enable'], cached_reauth_enable=data['802.1x']['cached_reauth_enable'], cached_reauth_period=data['802.1x']['cached_reauth_period'], discovery_period=data['802.1x']['discovery_period'], eapol_timeout=data['802.1x']['eapol_timeout'], max_requests=data['802.1x']['max_requests'], max_retries=data['802.1x']['max_retries'], quiet_period=data['802.1x']['quiet_period'], reauth_enable=data['802.1x']['reauth_enable'], reauth_period=data['802.1x']['reauth_period'], **session_dict) # Enable MAC authentication globally access_security.enable_disable_mac_auth_globally(enable=True, **session_dict) # Create L2 interface interface.add_l2_interface(data['mac_auth']['port'], **session_dict) # Configure MAC authentication on the L2 interface access_security.configure_mac_auth_interface( data['mac_auth']['port'], auth_enable=data['mac_auth']['auth_enable'], cached_reauth_enable=data['mac_auth']['cached_reauth_enable'], cached_reauth_period=data['mac_auth']['cached_reauth_period'], quiet_period=data['mac_auth']['quiet_period'], reauth_enable=data['mac_auth']['reauth_enable'], reauth_period=data['mac_auth']['reauth_period'], **session_dict) # Enable port security globally access_security.enable_disable_port_security_globally( enable=True, **session_dict) # Create reserved VLAN for tunneled clients vlan.create_vlan(data['vlan']['id'], data['vlan']['name'], **session_dict) # Set reserved VLAN for tunneled clients access_security.set_ubt_client_vlan(data['vlan']['id'], **session_dict) # Create user-based-tunneling (UBT) zone access_security.create_ubt_zone( data['zone']['name'], data['zone']['vrf_name'], enable=data['zone']['enable'], pri_ctrlr_ip_addr=data['zone']['pri_ctrlr_ip_addr'], sac_heartbeat_interval=data['zone']['sac_heartbeat_interval'], uac_keepalive_interval=data['zone']['uac_keepalive_interval'], **session_dict) # Create port access role access_security.create_port_access_role( data['role']['name'], gateway_zone=data['role']['gateway_zone'], ubt_gateway_role=data['role']['ubt_gateway_role'], vlan_mode=data['role']['vlan_mode'], vlan_tag=data['role']['vlan_tag'], **session_dict) # Create L2 interface interface.add_l2_interface(data['client_port']['port'], **session_dict) # Enable MAC authentication on client port access_security.configure_mac_auth_interface( data['client_port']['port'], auth_enable=data['client_port']['auth_enable'], reauth_enable=data['client_port']['reauth_enable'], cached_reauth_enable=data['client_port'] ['cached_reauth_enable'], **session_dict) # Set maximum limit of allowable authorized clients on the client port access_security.set_port_access_clients_limit( data['client_port']['port'], data['client_port']['clients_limit'], **session_dict) # Set source IP address for UBT access_security.set_source_ip_ubt( data['ubt_source_ip']['vrf_name'], data['ubt_source_ip']['ip_addr'], **session_dict) else: print("This workflow only applies to access platforms!") except Exception as error: print('Ran into exception: {}. Logging out..'.format(error)) session.logout(**session_dict)