コード例 #1
0
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)

        # Delete all DHCP relays for interface
        dhcp.delete_dhcp_relays(data['vlanportname'], "default",
                                **session_dict)

        # Delete VLAN and SVI
        vlan.delete_vlan_and_svi(data['vlanid'], data['vlanportname'],
                                 **session_dict)

        # Initialize L2 interface
        interface.initialize_interface(data['physicalport'], **session_dict)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))
    session.logout(**session_dict)
コード例 #2
0
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)

        system_info_dict = system.get_system_info(
            params={"selector": "configuration"}, **session_dict)

        # Clear Loop-protect settings on Interface
        loop_protect.clear_port_loop_protect(data['interfacename'],
                                             **session_dict)

        # Initialize L2 Interface
        interface.initialize_interface(data['interfacename'], **session_dict)

        # Delete L2 LAGs:
        for l2_lag_data in data['lags']:
            # Delete VLANs
            for vlan_id in l2_lag_data['trunk_vlans']:
                vlan.delete_vlan(vlan_id, **session_dict)

            # Clear Loop-protect settings on LAG
            loop_protect.clear_port_loop_protect(l2_lag_data.get('name'),
                                                 **session_dict)

            # Delete LAG
            lag.delete_lag_interface(l2_lag_data['name'],
                                     l2_lag_data.get('interfaces'),
                                     **session_dict)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))
    session.logout(**session_dict)
コード例 #3
0
def main():
    data = yaml_ops.read_yaml("ospf_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'] = "v1"

    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)

        # Initialize L3 interfaces
        interface.initialize_interface(data['l3interfacev3'], **session_dict)
        interface.initialize_interface(data['l3interfacev2'], **session_dict)

        # Remove an OSPFv3 Area for OSPF ID
        ospf.delete_ospfv3_area(data['ospfv3vrf'], data['ospfv3id'], data['ospfv3area'], **session_dict)

        # Remove an OSPFv2 Area for OSPF ID
        ospf.delete_ospf_area(data['ospfv2vrf'], data['ospfv2id'], data['ospfv2area'], **session_dict)

        # Remove OSPFv3 ID
        ospf.delete_ospfv3_id(data['ospfv3vrf'], data['ospfv3id'], **session_dict)

        # Remove OSPFv2 ID
        ospf.delete_ospf_id(data['ospfv2vrf'], data['ospfv2id'], **session_dict)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))

    session.logout(**session_dict)
コード例 #4
0
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)
        session_dict['platform_name'] = system.get_system_info(
            **session_dict).get('platform_name')

        # Clear Egress ACLs from L3 interface
        acl.clear_interface_acl(data['L3egressinterface'],
                                acl_type="aclv4_out",
                                **session_dict)

        # Clear Ingress ACLs from L2 interface
        acl.clear_interface_acl(data['ipv4L2ingressinterface'],
                                acl_type="aclv4_in",
                                **session_dict)
        acl.clear_interface_acl(data['ipv6L2ingressinterface'],
                                acl_type="aclv6_in",
                                **session_dict)

        # Clear Ingress ACLs from LAG interface
        acl.clear_interface_acl(data['LAGname'],
                                acl_type="aclv4_in",
                                **session_dict)

        # Detach ACL from VLAN
        vlan.detach_vlan_acl(data['aclVLANid'], "ipv4", **session_dict)

        # Remove and initialize L2 and L3 interfaces
        interface.initialize_interface(data['L3egressinterface'],
                                       **session_dict)
        interface.initialize_interface(data['ipv4L2ingressinterface'],
                                       **session_dict)
        interface.initialize_interface(data['ipv6L2ingressinterface'],
                                       **session_dict)
        interface.initialize_interface(data['interfaceVLAN'], **session_dict)

        # Remove LAG and initialize associated L2 interfaces
        lag.delete_lag_interface(data['LAGname'], data['LAGinterfaces'],
                                 **session_dict)
        for LAGinterface in data['LAGinterfaces']:
            interface.initialize_interface(LAGinterface, **session_dict)

        # Delete VLAN
        vlan.delete_vlan(data['aclVLANid'], **session_dict)

        # For each ACL that was configured
        for pair_dict in [{
                "name": data['ipv4aclname'],
                "type": "ipv4"
        }, {
                "name": data['ipv6aclname'],
                "type": "ipv6"
        }, {
                "name": data['macaclname'],
                "type": "mac"
        }]:

            # Delete ACL entries
            for i in range(10, 60, 10):
                acl.delete_acl_entry(pair_dict["name"], pair_dict["type"], i,
                                     **session_dict)

            # Delete the ACL
            acl.delete_acl(pair_dict["name"], pair_dict["type"],
                           **session_dict)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))

    session.logout(**session_dict)
コード例 #5
0
def main():
    data = yaml_ops.read_yaml("evpn_vxlan_data.yaml")

    if not data['version']:
        data['version'] = "v10.04"

    # Cleanup Border Leaf
    print("Cleaning up Border Leaf configuration...")
    border_data = data['borderleaf'][0]
    if data['bypassproxy']:
        os.environ['no_proxy'] = border_data['mgmtip']
        os.environ['NO_PROXY'] = border_data['mgmtip']
    base_url = "https://{0}/rest/{1}/".format(border_data['mgmtip'],
                                              data['version'])
    try:
        session_dict = dict(s=session.login(base_url, border_data['username'],
                                            border_data['password']),
                            url=base_url)
        # Delete external facing Interface settings
        for border_vlan in border_data['interfacevlans']:
            vlan.delete_vlan_and_svi(border_vlan['vlanid'],
                                     "vlan%d" % border_vlan['vlanid'],
                                     **session_dict)

        # Delete Tenant VRFs
        for tenants in border_data['tenantvrfs']:
            bgp.delete_bgp_asn(tenants['name'], border_data['bgpasn'],
                               **session_dict)
            vrf.delete_vrf(tenants['name'], **session_dict)

        # Remove Interface Settings to Core
        interface.initialize_interface(border_data['interfacetocore'],
                                       **session_dict)

        # Delete Router BGP Settings
        bgp.delete_bgp_asn(border_data['vrftocore'],
                           border_data['neighbortocoreasn'], **session_dict)

        # Delete VRF to Core
        vrf.delete_vrf(border_data['vrftocore'], **session_dict)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))

    session.logout(**session_dict)

    # Cleaning up Leafs for Fabric Infrastructure
    print("Cleaning up Leafs for Fabric Infrastructure...")
    for leaf_data in data['leafs']:
        if data['bypassproxy']:
            os.environ['no_proxy'] = leaf_data['mgmtip']
            os.environ['NO_PROXY'] = leaf_data['mgmtip']
        base_url = "https://{0}/rest/{1}/".format(leaf_data['mgmtip'],
                                                  data['version'])
        try:
            print("Cleaning up Leaf at %s" % leaf_data['mgmtip'])
            session_dict = dict(s=session.login(base_url,
                                                leaf_data['username'],
                                                leaf_data['password']),
                                url=base_url)
            # Remove BGP info
            # Delete EVPN instance
            evpn.delete_evpn_instance(**session_dict)

            # Delete VNI to VLAN
            for vni_list in leaf_data['vnivlans']:
                vxlan.delete_vni_mapping(vni_list, **session_dict)

            # Delete VXLAN
            interface.delete_interface(leaf_data['vxlanname'], **session_dict)

            # Delete LAGs to Downstream Servers
            for lag_data in leaf_data['lagtoserver']:
                lag.delete_lag_interface(lag_data['name'],
                                         lag_data['interfaces'],
                                         **session_dict)

            # Delete VLANs
            for vlan_id in leaf_data['vnivlans']:
                vlan.delete_vlan(vlan_id, **session_dict)

            # Delete BGP ASN and Router ID
            bgp.delete_bgp_asn(leaf_data['ospfvrf'], leaf_data['bgpasn'],
                               **session_dict)

            # Remove OSPF and Interfaces
            # Initialize upstream L2 interfaces
            for upstream in leaf_data['upstreaminterface']:
                interface.initialize_interface(upstream['interface'],
                                               **session_dict)

            # Delete Loopback interface
            interface.delete_interface(leaf_data['loopbackinterface'],
                                       **session_dict)

            # Delete an OSPFv2 Area for OSPF ID
            ospf.delete_ospf_area(leaf_data['ospfvrf'], leaf_data['ospfid'],
                                  leaf_data['ospfarea'], **session_dict)

            # Delete OSPFv2 ID
            ospf.delete_ospf_id(leaf_data['ospfvrf'], leaf_data['ospfid'],
                                **session_dict)

        except Exception as error:
            print('Ran into exception: {}. Logging out..'.format(error))

        session.logout(**session_dict)

    # Cleaning up Spines for Fabric Infrastructure
    print("Cleaning up Spines of Fabric Infrastructure...")
    for spine_data in data['spines']:
        if data['bypassproxy']:
            os.environ['no_proxy'] = spine_data['mgmtip']
            os.environ['NO_PROXY'] = spine_data['mgmtip']
        base_url = "https://{0}/rest/{1}/".format(spine_data['mgmtip'],
                                                  data['version'])
        try:
            print("Setting up Spine at %s" % spine_data['mgmtip'])
            session_dict = dict(s=session.login(base_url,
                                                spine_data['username'],
                                                spine_data['password']),
                                url=base_url)

            # Remove BGP configuration
            # Delete BGP ASN and Router ID
            bgp.delete_bgp_asn(spine_data['ospfvrf'], spine_data['bgpasn'],
                               **session_dict)

            # Initialize downstream L2 interfaces
            for downstream in spine_data['downstreaminterface']:
                interface.initialize_interface(downstream['interface'],
                                               **session_dict)

            # Create Loopback interface
            interface.delete_interface(spine_data['loopbackinterface'],
                                       **session_dict)

            # Create an OSPFv2 Area for OSPF ID
            ospf.delete_ospf_area(spine_data['ospfvrf'], spine_data['ospfid'],
                                  spine_data['ospfarea'], **session_dict)

            # Create OSPFv2 ID
            ospf.delete_ospf_id(spine_data['ospfvrf'], spine_data['ospfid'],
                                **session_dict)

        except Exception as error:
            print('Ran into exception: {}. Logging out..'.format(error))

        session.logout(**session_dict)
コード例 #6
0
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"):

            # Unconfigure RADIUS server host
            access_security.delete_radius_host_config(
                data['radius_server_host']['vrf'],
                data['radius_server_host']['hostname'],
                passkey=data['radius_server_host']['passkey'],
                **session_dict)

            # Disable 802.1x globally
            access_security.enable_disable_dot1x_globally(enable=False,
                                                          **session_dict)

            # Remove 802.1x from the L2 interface
            access_security.remove_auth_method_interface(
                data['802.1x']['port'], "802.1x", **session_dict)

            # Initialize L2 interface
            interface.initialize_interface(data['802.1x']['port'],
                                           **session_dict)

            # Disable MAC authentication globally
            access_security.enable_disable_mac_auth_globally(enable=False,
                                                             **session_dict)

            # Remove MAC authentication from the L2 interface
            access_security.remove_auth_method_interface(
                data['mac_auth']['port'], "mac-auth", **session_dict)

            # Initialize L2 interface
            interface.initialize_interface(data['mac_auth']['port'],
                                           **session_dict)

            # Disable port security globally
            access_security.enable_disable_port_security_globally(
                enable=False, **session_dict)

            # Clear reserved VLAN value for tunneled clients
            access_security.clear_ubt_client_vlan(**session_dict)

            # Delete reserved VLAN for tunneled clients
            vlan.delete_vlan(data['vlan']['id'], **session_dict)

            # Delete user-based-tunneling (UBT) zone
            access_security.remove_ubt_zone(data['zone']['vrf_name'],
                                            **session_dict)

            # Remove port access role
            access_security.remove_port_access_role(data['role']['name'],
                                                    **session_dict)

            # Remove MAC authentication from the client port
            access_security.remove_auth_method_interface(
                data['client_port']['port'], "mac-auth", **session_dict)

            # Clear limit of maximum allowable authorized clients on the client port
            access_security.clear_port_access_clients_limit(
                data['client_port']['port'], **session_dict)

            # Initialize L2 interface
            interface.initialize_interface(data['client_port']['port'],
                                           **session_dict)

            # Remove source IP address for UBT
            access_security.remove_source_ip_ubt(
                data['ubt_source_ip']['vrf_name'], **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)
コード例 #7
0
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)

        #  Remove global application of QoS queue profile and schedule profile
        qos.unapply_profiles_globally(**session_dict)

        # Delete queue profile entries
        for i in range(0, 8):
            qos.delete_queue_profile_entry(data['queueprofilename'], i,
                                           **session_dict)

        # Delete queue profile
        qos.delete_queue_profile(data['queueprofilename'], **session_dict)

        # Delete schedule profile entries
        for i in range(0, 8):
            qos.delete_schedule_profile_entry(data['scheduleprofilename'], i,
                                              **session_dict)

        # Delete schedule profile
        qos.delete_schedule_profile(data['scheduleprofilename'],
                                    **session_dict)

        #  Remove global setting of QoS trust mode
        qos.clear_trust_globally(**session_dict)

        # Reset DSCP code points to defaults
        qos.reset_dscp_entry(40, **session_dict)
        for i in range(41, 46):
            qos.reset_dscp_entry(i, **session_dict)
        qos.reset_dscp_entry(47, **session_dict)

        # Delete action on policy entry
        qos.delete_policy_entry_action(data['policy']['name'], 10,
                                       **session_dict)

        # Delete policy entry
        qos.delete_policy_entry(data['policy']['name'], 10, **session_dict)

        # Version-up the policy to complete the change
        qos.update_policy(data['policy']['name'], **session_dict)

        # Delete classifier policy
        qos.delete_policy(data['policy']['name'], **session_dict)

        # Delete traffic class entry
        qos.delete_traffic_class_entry(data['trafficclass']['name'],
                                       data['trafficclass']['type'], 10,
                                       **session_dict)

        # Version-up the traffic class to complete the change
        qos.update_traffic_class(data['trafficclass']['name'],
                                 data['trafficclass']['type'], **session_dict)

        # Delete traffic class
        qos.delete_traffic_class(data['trafficclass']['name'],
                                 data['trafficclass']['type'], **session_dict)

        # Clear trust mode on LAG interfaces and delete LAG interfaces
        for lag_data in data['lags']:
            qos.clear_trust_interface(lag_data['name'], **session_dict)

            lag.delete_lag_interface(lag_data['name'], lag_data['interfaces'],
                                     **session_dict)

        # Clear policy from L2 interface
        qos.clear_port_policy(data['portpolicyinterface'], **session_dict)

        interface.initialize_interface(data['portpolicyinterface'],
                                       **session_dict)

        # Clear rate limits from L2 interface
        qos.clear_port_rate_limits(data['portrateinterface'], **session_dict)

        interface.initialize_interface(data['portrateinterface'],
                                       **session_dict)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))
    session.logout(**session_dict)
コード例 #8
0
def main():
    # This is the yaml file that will be used for the vsx_configuration
    data = yaml_ops.read_yaml("vsx_data.yaml")

    if not data['primarymgmtip']:
        data['primarymgmtip'] = input("Switch Primary IP Address: ")

    if data['bypassproxy']:
        os.environ['no_proxy'] = data['primarymgmtip']
        os.environ['NO_PROXY'] = data['primarymgmtip']

    if not data['version']:
        data['version'] = "v1"

    # Clear VSX settings on Primary
    base_url_1 = "https://{0}/rest/{1}/".format(data['primarymgmtip'], data['version'])
    try:
        session_dict_1 = dict(s=session.login(base_url_1, data['primaryusername'], data['primarypassword']),
                              url=base_url_1)

        # Delete VSX settings from VLANs
        vsx.delete_vsx_interface_vlan(data['vlanid'], **session_dict_1)

        # Delete VSX Instance
        vsx.delete_vsx(**session_dict_1)

        # Delete VLANs
        vlan.delete_vlan_and_svi(data['vlanid'], data['vlanportname'], **session_dict_1)
        for islvlans in data['islvlans']:
            vlan.delete_vlan_and_svi(islvlans, 'vlan%s' % islvlans, **session_dict_1)

        # Delete Lag
        lag.delete_lag_interface(data['islport'], data['peer1isllaginterfaces'], **session_dict_1)
        lag.delete_lag_interface(data['mclagport'], data['peer1mclaginterfaces'], **session_dict_1)

        # Disable and initialize Interfaces
        for link in data['peer1isllaginterfaces']:
            interface.enable_disable_interface(link, state="down", **session_dict_1)
            interface.initialize_interface(link, **session_dict_1)
        for mclink in data['peer1mclaginterfaces']:
            interface.enable_disable_interface(mclink, state="down", **session_dict_1)
            interface.initialize_interface(mclink, **session_dict_1)
        interface.initialize_interface(data['primarykeepaliveinterface'], **session_dict_1)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))

    session.logout(**session_dict_1)

    # Setup VSX on Secondary
    if not data['secondarymgmtip']:
        data['secondarymgmtip'] = input("Switch Secondary IP Address: ")

    if data['bypassproxy']:
        os.environ['no_proxy'] = data['secondarymgmtip']
        os.environ['NO_PROXY'] = data['secondarymgmtip']

    base_url_2 = "https://{0}/rest/{1}/".format(data['secondarymgmtip'], data['version'])
    try:
        session_dict_2 = dict(s=session.login(base_url_2, data['secondaryusername'], data['secondarypassword']),
                              url=base_url_2)

        # Delete VSX settings from VLANs
        vsx.delete_vsx_interface_vlan(data['vlanid'], **session_dict_2)

        # Delete VSX Instance
        vsx.delete_vsx(**session_dict_2)

        # Delete VLANs
        vlan.delete_vlan_and_svi(data['vlanid'], data['vlanportname'], **session_dict_2)
        for islvlans in data['islvlans']:
            vlan.delete_vlan_and_svi(islvlans, 'vlan%s' % islvlans, **session_dict_2)

        # Delete Lag
        lag.delete_lag_interface(data['islport'], data['peer2isllaginterfaces'], **session_dict_2)
        lag.delete_lag_interface(data['mclagport'], data['peer2mclaginterfaces'], **session_dict_2)

        # Disable and initialize Interfaces
        for link in data['peer2isllaginterfaces']:
            interface.enable_disable_interface(link, state="down", **session_dict_2)
            interface.initialize_interface(link, **session_dict_2)
        for mclink in data['peer2mclaginterfaces']:
            interface.enable_disable_interface(mclink, state="down", **session_dict_2)
            interface.initialize_interface(mclink, **session_dict_2)
        interface.initialize_interface(data['secondarykeepaliveinterface'], **session_dict_2)

    except Exception as error:
        print('Ran into exception: {}. Logging out..'.format(error))

    session.logout(**session_dict_2)