예제 #1
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'] = "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 OSPFv2 ID
        ospf.create_ospf_id(data['ospfv2vrf'], data['ospfv2id'], **session_dict)

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

        # Create IPv4 L3 interface
        interface.add_l3_ipv4_interface(data['l3interfacev2'], data['l3interfacev2ipaddress'], **session_dict)
        interface.enable_disable_interface(data['l3interfacev2'], data['l3interfacestatusv2'], **session_dict)

        # Attach L3 interface to OSPF ID
        ospf.create_ospf_interface(data['ospfv2vrf'], data['ospfv2id'], data['ospfv2area'],
                                   data['l3interfacev2'], **session_dict)
        ospf.update_ospf_interface_authentication(data['ospfv2vrf'], data['ospfv2id'], data['l3interfacev2'],
                                                  data['ospfv2auth'], data['ospfv2digestkey'],
                                                  data['ospfv2password'], **session_dict)

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

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

        # Create IPv6 L3 interface
        interface.add_l3_ipv6_interface(data['l3interfacev3'], data['l3interfacev3ipaddress'], **session_dict)
        interface.enable_disable_interface(data['l3interfacev3'], data['l3interfacestatusv3'],
                                           **session_dict)

        # Attach L3 interface to OSPFv3 ID
        ospf.create_ospfv3_interface(data['ospfv3vrf'], data['ospfv3id'], data['ospfv3area'],
                                     data['l3interfacev3'], **session_dict)
        ospf.update_ospf_interface_authentication(data['ospfv3vrf'], data['ospfv3id'], data['l3interfacev2'],
                                                  data['ospfv3auth'], data['ospfv3digestkey'],
                                                  data['ospfv3password'], **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("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)
예제 #3
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'] = "v10.04"

    # Setup VSX 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)

        # Create VLANs
        for vlans in data['islvlans']:
            vlan.create_vlan_and_svi(vlans,
                                     "VLAN%s" % vlans,
                                     "vlan%s" % vlans,
                                     "vlan%s" % vlans,
                                     vlan_port_desc="ISL VLAN",
                                     **session_dict_1)

        vlan.create_vlan_and_svi(data['vlanid'], data['vlanname'],
                                 data['vlanportname'], data['vlanportname'],
                                 data['vlanportdescription'],
                                 data['primaryvlanip'], **session_dict_1)

        # Create LAG for ISL
        for link in data['peer1isllaginterfaces']:
            interface.enable_disable_interface(link,
                                               state="up",
                                               **session_dict_1)
        lag.create_l2_lag_interface(data['islport'],
                                    data['peer1isllaginterfaces'],
                                    lacp_mode=data['isllacp'],
                                    mc_lag=False,
                                    fallback_enabled=False,
                                    vlan_ids_list=(data['islvlans'] +
                                                   [data['vlanid']]),
                                    desc="ISL LAG",
                                    **session_dict_1)

        # Create Downstream MCLAG
        for mclink in data['peer1mclaginterfaces']:
            interface.enable_disable_interface(mclink,
                                               state="up",
                                               **session_dict_1)
        lag.create_l2_lag_interface(data['mclagport'],
                                    data['peer1mclaginterfaces'],
                                    lacp_mode=data['mclaglacp'],
                                    mc_lag=True,
                                    fallback_enabled=True,
                                    vlan_ids_list=data['mclagvlans'],
                                    desc="Downstream MCLAG",
                                    **session_dict_1)

        # Create VSX Instance
        vsx.create_vsx("primary", data['islport'],
                       data['secondarykeepaliveip'],
                       data['primarykeepaliveip'], data['keepalivevrf'],
                       data['vsxmac'], **session_dict_1)
        interface.add_l3_ipv4_interface(data['primarykeepaliveinterface'],
                                        data['primarykeepaliveip'],
                                        desc="Keepalive Link",
                                        **session_dict_1)
        interface.enable_disable_interface(data['primarykeepaliveinterface'],
                                           state="up",
                                           **session_dict_1)

        # Assign VSX Active-Gateways and synchronization options to VLANs
        vsx.update_vsx_interface_vlan(data['vlanid'], False,
                                      {'active-gateways', 'policies'},
                                      data['activegatewaymac'],
                                      data['activegatewayip'],
                                      **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)

        # Create VLANs
        for vlans in data['islvlans']:
            vlan.create_vlan_and_svi(vlans,
                                     "VLAN%s" % vlans,
                                     "vlan%s" % vlans,
                                     "vlan%s" % vlans,
                                     vlan_port_desc="ISL VLAN",
                                     **session_dict_2)

        vlan.create_vlan_and_svi(data['vlanid'], data['vlanname'],
                                 data['vlanportname'], data['vlanportname'],
                                 data['vlanportdescription'],
                                 data['secondaryvlanip'], **session_dict_2)

        # Create LAG for ISL
        for link in data['peer2isllaginterfaces']:
            interface.enable_disable_interface(link,
                                               state="up",
                                               **session_dict_2)
        lag.create_l2_lag_interface(data['islport'],
                                    data['peer2isllaginterfaces'],
                                    lacp_mode=data['isllacp'],
                                    mc_lag=False,
                                    fallback_enabled=False,
                                    vlan_ids_list=(data['islvlans'] +
                                                   [data['vlanid']]),
                                    desc="ISL LAG",
                                    **session_dict_2)

        # Create Downstream MCLAG
        for mclink in data['peer2mclaginterfaces']:
            interface.enable_disable_interface(mclink,
                                               state="up",
                                               **session_dict_2)
        lag.create_l2_lag_interface(data['mclagport'],
                                    data['peer2mclaginterfaces'],
                                    lacp_mode=data['mclaglacp'],
                                    mc_lag=True,
                                    fallback_enabled=True,
                                    vlan_ids_list=data['mclagvlans'],
                                    desc="Downstream MCLAG",
                                    **session_dict_2)

        # Create VSX Instance
        vsx.create_vsx("secondary", data['islport'],
                       data['primarykeepaliveip'],
                       data['secondarykeepaliveip'], data['keepalivevrf'],
                       data['vsxmac'], **session_dict_2)
        interface.add_l3_ipv4_interface(data['secondarykeepaliveinterface'],
                                        data['secondarykeepaliveip'],
                                        desc="Keepalive Link",
                                        **session_dict_2)
        interface.enable_disable_interface(data['secondarykeepaliveinterface'],
                                           state="up",
                                           **session_dict_2)

        # Assign VSX Active-Gateways to VLANs
        vsx.update_vsx_interface_vlan(data['vlanid'], False,
                                      {'active-gateways', 'policies'},
                                      data['activegatewaymac'],
                                      data['activegatewayip'],
                                      **session_dict_2)

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

    session.logout(**session_dict_2)
예제 #4
0
def main():
    data = yaml_ops.read_yaml("evpn_vxlan_data.yaml")

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

    # Setting up Spines for Fabric Infrastructure
    print("Setting up Spines for 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)

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

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

            # Create Loopback interface
            interface.create_loopback_interface(
                spine_data['loopbackinterface'], spine_data['ospfvrf'],
                spine_data['loopbackip'], **session_dict)
            ospf.create_ospf_interface(spine_data['ospfvrf'],
                                       spine_data['ospfid'],
                                       spine_data['ospfarea'],
                                       spine_data['loopbackinterface'],
                                       **session_dict)

            # Create downstream interfaces
            for downstream in spine_data['downstreaminterface']:
                interface.add_l3_ipv4_interface(downstream['interface'],
                                                downstream['ipaddress'],
                                                **session_dict)
                interface.enable_disable_interface(downstream['interface'],
                                                   "up", **session_dict)

                # Attach downstream interface to OSPF ID
                ospf.create_ospf_interface(spine_data['ospfvrf'],
                                           spine_data['ospfid'],
                                           spine_data['ospfarea'],
                                           downstream['interface'],
                                           **session_dict)
                ospf.update_ospf_interface_type(spine_data['ospfvrf'],
                                                spine_data['ospfid'],
                                                downstream['interface'],
                                                spine_data['ospftype'],
                                                **session_dict)

            # Create BGP ASN and Router ID
            bgp.create_bgp_asn(spine_data['ospfvrf'], spine_data['bgpasn'],
                               spine_data['bgprouterid'], **session_dict)
            # Set BGP Neighbors
            for neighbors in spine_data['neighborips']:
                bgp.create_bgp_neighbors(
                    spine_data['ospfvrf'],
                    spine_data['bgpasn'],
                    neighbors,
                    spine_data['addressfamilytype'],
                    reflector=True,
                    send_community=True,
                    local_interface=spine_data['loopbackinterface'],
                    **session_dict)

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

        session.logout(**session_dict)

    # Setting up Leafs for Fabric Infrastructure
    print("Setting 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("Setting up Leaf at %s" % leaf_data['mgmtip'])
            session_dict = dict(s=session.login(base_url,
                                                leaf_data['username'],
                                                leaf_data['password']),
                                url=base_url)

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

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

            # Create Loopback interface
            interface.create_loopback_interface(leaf_data['loopbackinterface'],
                                                leaf_data['ospfvrf'],
                                                leaf_data['loopbackip'],
                                                **session_dict)
            ospf.create_ospf_interface(leaf_data['ospfvrf'],
                                       leaf_data['ospfid'],
                                       leaf_data['ospfarea'],
                                       leaf_data['loopbackinterface'],
                                       **session_dict)

            # Create upstream interfaces
            for upstream in leaf_data['upstreaminterface']:
                interface.add_l3_ipv4_interface(upstream['interface'],
                                                upstream['ipaddress'],
                                                **session_dict)
                interface.enable_disable_interface(upstream['interface'], "up",
                                                   **session_dict)

                # Attach upstream interface to OSPF ID
                ospf.create_ospf_interface(leaf_data['ospfvrf'],
                                           leaf_data['ospfid'],
                                           leaf_data['ospfarea'],
                                           upstream['interface'],
                                           **session_dict)
                ospf.update_ospf_interface_type(leaf_data['ospfvrf'],
                                                leaf_data['ospfid'],
                                                upstream['interface'],
                                                leaf_data['ospftype'],
                                                **session_dict)

            # Create BGP ASN and Router ID
            bgp.create_bgp_asn(leaf_data['ospfvrf'], leaf_data['bgpasn'],
                               leaf_data['bgprouterid'], **session_dict)
            # Set BGP Neighbors
            for neighbors in leaf_data['neighborips']:
                bgp.create_bgp_neighbors(
                    leaf_data['ospfvrf'],
                    leaf_data['bgpasn'],
                    neighbors,
                    leaf_data['addressfamilytype'],
                    reflector=False,
                    send_community=True,
                    local_interface=leaf_data['loopbackinterface'],
                    **session_dict)

            # Create VLANs
            for vlan_id in leaf_data['vnivlans']:
                vlan.create_vlan(vlan_id, "VLAN%d" % vlan_id, **session_dict)

            # Create LAGs to Downstream Servers
            for lag_data in leaf_data['lagtoserver']:
                lag.create_l2_lag_interface(lag_data['name'],
                                            lag_data['interfaces'],
                                            lag_data['lacp_mode'],
                                            lag_data['mc_lag'], False,
                                            lag_data['trunk_vlans'],
                                            **session_dict)

            # Create VXLAN
            vxlan.create_vxlan_interface(leaf_data['vxlanname'],
                                         leaf_data['vxlanip'], **session_dict)

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

            # Create EVPN instance
            evpn.create_evpn_instance(**session_dict)

            # Configure EVPN Routes
            for vlan_id in leaf_data['vnivlans']:
                evpn.add_evpn_vlan(vlan_id, **session_dict)

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

        session.logout(**session_dict)

    # Setup Border Leaf
    print("Setting up Border Leaf...")
    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)
        # Create VRF to Core
        vrf.add_vrf(border_data['vrftocore'], border_data['rd'],
                    **session_dict)
        vrf.add_vrf_address_family(border_data['vrftocore'],
                                   border_data['addressfamilytype'],
                                   border_data['addressfamilyexports'],
                                   border_data['addressfamilyimports'],
                                   **session_dict)
        # Setup link to Core
        interface.add_l3_ipv4_interface(
            border_data['interfacetocore'],
            ip_address=border_data['interfacetocoreip'],
            vrf=border_data['vrftocore'],
            **session_dict)
        # Setup BGP to Core
        bgp.create_bgp_asn(border_data['vrftocore'],
                           border_data['neighbortocoreasn'], **session_dict)
        bgp.create_bgp_neighbors(border_data['vrftocore'],
                                 border_data['neighbortocoreasn'],
                                 border_data['neighbortocoreip'],
                                 border_data['addressfamilytype'],
                                 reflector=False,
                                 send_community=False,
                                 **session_dict)
        # Configure Leaf VRF Routes and Address-family
        for tenants in border_data['tenantvrfs']:
            vrf.add_vrf(tenants['name'], tenants['rd'], **session_dict)
            vrf.add_vrf_address_family(tenants['name'],
                                       border_data['addressfamilytype'],
                                       tenants['addressfamilyexports'],
                                       tenants['addressfamilyimports'],
                                       **session_dict)
            bgp.create_bgp_asn(tenants['name'], border_data['bgpasn'],
                               **session_dict)
            bgp.create_bgp_vrf(tenants['name'], border_data['bgpasn'],
                               tenants['redistribute'], **session_dict)

        # Attach Leaf VRFs and give IP Addresses to VLANs
        for border_vlan in border_data['interfacevlans']:
            vlan.create_vlan_and_svi(border_vlan['vlanid'],
                                     "VLAN%d" % border_vlan['vlanid'],
                                     "vlan%d" % border_vlan['vlanid'],
                                     "vlan%d" % border_vlan['vlanid'],
                                     vlan_desc=None,
                                     ipv4=border_vlan['vlanip'],
                                     vrf_name=border_vlan['vlanvrf'],
                                     **session_dict)
            vsx.update_vsx_interface_vlan(border_vlan['vlanid'], False, [],
                                          border_vlan['activegatewaymac'],
                                          border_vlan['activegatewayip'],
                                          **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("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("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)
예제 #7
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)

        # 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)
예제 #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)