elicro zrewidował ten Gist . Przejdź do rewizji
1 file changed, 163 insertions
convert-ltap-to-main.rsc(stworzono plik)
| @@ -0,0 +1,163 @@ | |||
| 1 | + | :do { | |
| 2 | + | :log info "Starting convert-ltap-to-main script" | |
| 3 | + | # ------------------------------------------------- | |
| 4 | + | # Bridge setup | |
| 5 | + | # ------------------------------------------------- | |
| 6 | + | :log info "convert-ltap-to-main script Step 1" | |
| 7 | + | /interface bridge | |
| 8 | + | :if ([:len [find name="@switch"]] = 0) do={ | |
| 9 | + | add name="@switch" vlan-filtering=yes | |
| 10 | + | } else={ | |
| 11 | + | set [find name="@switch"] vlan-filtering=yes disabled=no | |
| 12 | + | } | |
| 13 | + | ||
| 14 | + | # ------------------------------------------------- | |
| 15 | + | # Bridge port: ether1 untagged VLAN 1 | |
| 16 | + | # ------------------------------------------------- | |
| 17 | + | :log info "convert-ltap-to-main script Step 2" | |
| 18 | + | /interface bridge port | |
| 19 | + | :if ([:len [find bridge="@switch" and interface=ether1]] = 0) do={ | |
| 20 | + | add bridge="@switch" interface=ether1 pvid=1 | |
| 21 | + | } else={ | |
| 22 | + | set [find bridge="@switch" interface=ether1] pvid=1 disabled=no | |
| 23 | + | } | |
| 24 | + | ||
| 25 | + | # ------------------------------------------------- | |
| 26 | + | # Ensure LAN interface list exists | |
| 27 | + | # ------------------------------------------------- | |
| 28 | + | :log info "convert-ltap-to-main script Step 3" | |
| 29 | + | /interface list | |
| 30 | + | :if ([:len [find name="LAN"]] = 0) do={ | |
| 31 | + | add name="LAN" | |
| 32 | + | } | |
| 33 | + | ||
| 34 | + | # ------------------------------------------------- | |
| 35 | + | # VLAN DEFINITIONS | |
| 36 | + | # Format per VLAN: | |
| 37 | + | # VLAN_ID | IP | POOL_START | POOL_END | NETWORK | GATEWAY | |
| 38 | + | # ------------------------------------------------- | |
| 39 | + | ||
| 40 | + | :local vlans { | |
| 41 | + | "1|10.0.0.254/24|10.0.0.1|10.0.0.80|10.0.0.0/24|10.0.0.254"; | |
| 42 | + | "10|192.168.10.254/24|192.168.10.1|192.168.10.80|192.168.10.0/24|192.168.10.254"; | |
| 43 | + | "20|192.168.0.254/24|192.168.0.1|192.168.0.80|192.168.0.0/24|192.168.0.254"; | |
| 44 | + | "30|192.168.30.254/24|192.168.30.1|192.168.30.80|192.168.30.0/24|192.168.30.254"; | |
| 45 | + | "40|192.168.40.254/24|192.168.40.1|192.168.40.80|192.168.40.0/24|192.168.40.254"; | |
| 46 | + | "50|192.168.50.254/24|192.168.50.1|192.168.50.80|192.168.50.0/24|192.168.50.254"; | |
| 47 | + | "60|192.168.60.254/24|192.168.60.1|192.168.60.80|192.168.60.0/24|192.168.60.254" | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | # ------------------------------------------------- | |
| 51 | + | # VLAN LOOP | |
| 52 | + | # ------------------------------------------------- | |
| 53 | + | :log info "convert-ltap-to-main script Step 4" | |
| 54 | + | :foreach v in=$vlans do={ | |
| 55 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $v ." /1") | |
| 56 | + | ||
| 57 | + | :local vid [:pick $v 0 [:find $v "|"]] | |
| 58 | + | :local rest [:pick $v ([:find $v "|"] + 1) [:len $v]] | |
| 59 | + | ||
| 60 | + | :local ip [:pick $rest 0 [:find $rest "|"]] | |
| 61 | + | :set rest [:pick $rest ([:find $rest "|"] + 1) [:len $rest]] | |
| 62 | + | ||
| 63 | + | :local poolS [:pick $rest 0 [:find $rest "|"]] | |
| 64 | + | :set rest [:pick $rest ([:find $rest "|"] + 1) [:len $rest]] | |
| 65 | + | ||
| 66 | + | :local poolE [:pick $rest 0 [:find $rest "|"]] | |
| 67 | + | :set rest [:pick $rest ([:find $rest "|"] + 1) [:len $rest]] | |
| 68 | + | ||
| 69 | + | :local net [:pick $rest 0 [:find $rest "|"]] | |
| 70 | + | :local gw [:pick $rest ([:find $rest "|"] + 1) [:len $rest]] | |
| 71 | + | ||
| 72 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $vid ." /2") | |
| 73 | + | :local vName ("vlan" . $vid) | |
| 74 | + | :local poolName ("pool-" . $vName) | |
| 75 | + | :local dhcpName ("dhcp-" . $vName) | |
| 76 | + | ||
| 77 | + | # VLAN interface | |
| 78 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $vid ." /3") | |
| 79 | + | /interface vlan | |
| 80 | + | :if ([:len [find name=$vName]] = 0) do={ | |
| 81 | + | add name=$vName interface="@switch" vlan-id=$vid | |
| 82 | + | } else={ | |
| 83 | + | set [find name=$vName] interface="@switch" vlan-id=$vid disabled=no | |
| 84 | + | } | |
| 85 | + | ||
| 86 | + | # IP address | |
| 87 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $vid ." /4") | |
| 88 | + | /ip address | |
| 89 | + | :if ([:len [find interface=$vName address=$ip]] = 0) do={ | |
| 90 | + | add interface=$vName address=$ip | |
| 91 | + | } | |
| 92 | + | ||
| 93 | + | # IP pool | |
| 94 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $vid ." /5") | |
| 95 | + | /ip pool | |
| 96 | + | :if ([:len [find name=$poolName]] = 0) do={ | |
| 97 | + | add name=$poolName ranges=("$poolS-$poolE") | |
| 98 | + | } else={ | |
| 99 | + | set [find name=$poolName] ranges=("$poolS-$poolE") | |
| 100 | + | } | |
| 101 | + | ||
| 102 | + | # DHCP server | |
| 103 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $vid ." /6") | |
| 104 | + | /ip dhcp-server | |
| 105 | + | :if ([:len [find name=$dhcpName]] = 0) do={ | |
| 106 | + | add name=$dhcpName interface=$vName address-pool=$poolName disabled=no | |
| 107 | + | } else={ | |
| 108 | + | set [find name=$dhcpName] interface=$vName address-pool=$poolName disabled=no | |
| 109 | + | } | |
| 110 | + | ||
| 111 | + | # DHCP network | |
| 112 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $vid ." /7") | |
| 113 | + | /ip dhcp-server network | |
| 114 | + | :if ([:len [find address=$net]] = 0) do={ | |
| 115 | + | add address=$net gateway=$gw dns-server=8.8.8.8,1.1.1.1 | |
| 116 | + | } else={ | |
| 117 | + | set [find address=$net] gateway=$gw dns-server=8.8.8.8,1.1.1.1 | |
| 118 | + | } | |
| 119 | + | ||
| 120 | + | # Interface list | |
| 121 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $vid ." /8") | |
| 122 | + | /interface list member | |
| 123 | + | :if ([:len [find list=LAN interface=$vName]] = 0) do={ | |
| 124 | + | add list=LAN interface=$vName | |
| 125 | + | } | |
| 126 | + | :log info ("convert-ltap-to-main script Step 4 for vlan". $vid ." /9") | |
| 127 | + | } | |
| 128 | + | ||
| 129 | + | # ------------------------------------------------- | |
| 130 | + | # Add bridge itself to LAN | |
| 131 | + | # ------------------------------------------------- | |
| 132 | + | :log info "convert-ltap-to-main script Step 5" | |
| 133 | + | /interface list member | |
| 134 | + | :if ([:len [find list=LAN and interface="@switch"]] = 0) do={ | |
| 135 | + | add list=LAN interface="@switch" | |
| 136 | + | } | |
| 137 | + | ||
| 138 | + | # ------------------------------------------------- | |
| 139 | + | # Bridge VLAN table | |
| 140 | + | # ------------------------------------------------- | |
| 141 | + | :log info "convert-ltap-to-main script Step 6" | |
| 142 | + | /interface bridge vlan | |
| 143 | + | remove [find bridge="@switch" and dynamic=no] | |
| 144 | + | ||
| 145 | + | # VLAN 1 untagged ether1 | |
| 146 | + | :if ([:len [find bridge="@switch" and vlan-ids=1 and dynamic=no]] = 0) do={ | |
| 147 | + | add bridge="@switch" vlan-ids=1 tagged="@switch" untagged=ether1 | |
| 148 | + | } else={ | |
| 149 | + | set [find bridge="@switch" and vlan-ids=1 and dynamic=no] tagged="@switch" untagged=ether1 | |
| 150 | + | } | |
| 151 | + | ||
| 152 | + | # VLANs 10-60 tagged | |
| 153 | + | :log info "convert-ltap-to-main script Step 7" | |
| 154 | + | :if ([:len [find bridge="@switch" vlan-ids=10,20,30,40,50,60 and dynamic=no]] = 0) do={ | |
| 155 | + | add bridge="@switch" vlan-ids=10,20,30,40,50,60 tagged="@switch,ether1" | |
| 156 | + | } else={ | |
| 157 | + | set [find bridge="@switch" and vlan-ids=10,20,30,40,50,60 and dynamic=no] tagged="@switch,ether1" | |
| 158 | + | } | |
| 159 | + | ||
| 160 | + | :log info "VLAN bridge @switch configuration completed successfully" | |
| 161 | + | } on-error={ | |
| 162 | + | :log warning "Error running convert-ltap-to-main script" | |
| 163 | + | } | |
Nowsze
Starsze