From b4989028c6c3c3162378fc1a5df5cdee3eb5106a Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 13 Sep 2021 22:33:07 +0200 Subject: [PATCH] switch-b1: replace with model linksys-srw2048 --- salt-pillar/switches/init.sls | 120 +++++++++++++-------------- salt/switches/linksys-srw2048.expect | 107 ++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 63 deletions(-) create mode 100644 salt/switches/linksys-srw2048.expect diff --git a/salt-pillar/switches/init.sls b/salt-pillar/switches/init.sls index b76827c..a4add34 100644 --- a/salt-pillar/switches/init.sls +++ b/salt-pillar/switches/init.sls @@ -1,22 +1,19 @@ #!yaml|gpg switches: switch-b1: - model: '3com-4200G' + model: 'linksys-srw2048' location: Haus B Souterrain # Ports 1-24 oben # Ports 25-48 unten - # Ports 49-52 unten seitlich (optisch) - # 10GE hinten ports: switch-b2: mode: bond group: 3 ports: - - TenGigabitEthernet 1/1/1 - - GigabitEthernet 1/0/25 - - GigabitEthernet 1/0/26 - - GigabitEthernet 1/0/27 - - GigabitEthernet 1/0/28 + - g25 + - g26 + - g27 + - g28 vlans: &switch_b_vlans - mgmt - core @@ -53,23 +50,23 @@ switches: mgmt: mode: access ports: - - GigabitEthernet1/0/1 + - g1 iso1: mode: access ports: - - GigabitEthernet 1/0/2 + - g2 iso2: mode: access ports: - - GigabitEthernet 1/0/3 + - g3 iso3: mode: access ports: - - GigabitEthernet 1/0/4 + - g4 ap8: mode: trunk ports: - - GigabitEthernet 1/0/16 + - g16 vlans: - mgmt - pub @@ -78,7 +75,7 @@ switches: ap23: mode: trunk ports: - - GigabitEthernet 1/0/10 + - g10 vlans: - mgmt - pub @@ -87,10 +84,10 @@ switches: mode: bond group: 2 ports: - - GigabitEthernet1/0/29 - - GigabitEthernet1/0/30 - - GigabitEthernet1/0/31 - - GigabitEthernet1/0/32 + - g29 + - g30 + - g31 + - g32 vlans: - mgmt - pub @@ -134,12 +131,9 @@ switches: - iso15 - iso16 switch-d1: - mode: bond - group: 5 + mode: trunk ports: - # 33 is not currently plugged - - GigabitEthernet1/0/33 - - GigabitEthernet1/0/34 + - g34 vlans: - mgmt - core @@ -152,13 +146,12 @@ switches: - priv38 - priv40 server1: - mode: bond - group: 7 + mode: trunk ports: - - GigabitEthernet1/0/46 - - GigabitEthernet1/0/47 - - GigabitEthernet1/0/48 - - GigabitEthernet1/0/24 + # - g46 + # - g47 + # - g48 + - g24 vlans: &server1_vlans - mgmt - pub @@ -219,19 +212,19 @@ switches: mode: bond group: 1 ports: - - GigabitEthernet1/0/12 - - GigabitEthernet1/0/38 - - GigabitEthernet1/0/39 - - GigabitEthernet1/0/40 + - g12 + - g38 + - g39 + - g40 vlans: *server1_vlans c3d2-server5: mode: bond group: 6 ports: - - GigabitEthernet1/0/17 - - GigabitEthernet1/0/18 - - GigabitEthernet1/0/19 - - GigabitEthernet1/0/20 + - g17 + - g18 + - g19 + - g20 vlans: &server_vlans - mgmt - pub @@ -245,52 +238,53 @@ switches: mode: bond group: 8 ports: - - GigabitEthernet1/0/5 - - GigabitEthernet1/0/6 - - GigabitEthernet1/0/7 - - GigabitEthernet1/0/8 + - g5 + - g6 + - g7 + - g8 vlans: *server_vlans c3d2-server7: mode: bond - group: 9 + group: 7 ports: - - GigabitEthernet1/0/9 - - GigabitEthernet1/0/11 - - GigabitEthernet1/0/14 - - GigabitEthernet1/0/15 + - g9 + - g11 + - g14 + - g15 vlans: *server_vlans c3d2-server8: mode: bond - group: 10 + group: 5 ports: - - GigabitEthernet1/0/35 - - GigabitEthernet1/0/36 - - GigabitEthernet1/0/37 - - GigabitEthernet1/0/13 + - g35 + - g36 + - g37 + - g13 vlans: *server_vlans serv: mode: access ports: # vps1 - - GigabitEthernet1/0/22 - c3d2-monit: - mode: trunk - ports: - - GigabitEthernet1/0/21 - - GigabitEthernet1/0/45 - access: c3d2 + - g22 + # c3d2-monit: + # mode: trunk + # ports: + # - g21 + # - g45 + # vlans: + # - c3d2 c3d2: mode: access ports: - - GigabitEthernet1/0/23 + - g23 switch-c3d2-main: mode: bond group: 4 ports: - - GigabitEthernet 1/0/41 - - GigabitEthernet 1/0/42 - - GigabitEthernet 1/0/43 - - GigabitEthernet 1/0/44 + - g41 + - g42 + - g43 + - g44 vlans: - mgmt - pub diff --git a/salt/switches/linksys-srw2048.expect b/salt/switches/linksys-srw2048.expect new file mode 100644 index 000000000..68138a0 --- /dev/null +++ b/salt/switches/linksys-srw2048.expect @@ -0,0 +1,107 @@ +{# https://www.crc.id.au/real-console-on-linksys-srw2024-switch/ #} +{%- import_yaml "netmasks.yaml" as netmasks -%} +#!/usr/bin/expect -f + +spawn telnet {{ pillar['hosts-inet']['mgmt'][hostname] }} +expect "Password:" +send "admin\t{{ switch['password'] }}\r" + +# ^z +send "\x1A" +expect ">" +send "lcli\r" + +expect "User Name:" +send "admin\r" +expect "Password:" +send "{{ switch['password'] }}\r" + +expect "# " +send "configure\r" +expect "(config)# " +send "hostname {{ hostname }}\r" +expect "(config)# " +send "management vlan 4094\r" +expect "(config)# " +send "vlan database\r" +expect "(config-vlan)# " +{%- for name, vlan in pillar['vlans'].items() %} +{%- if name != 'mgmt' %} +send "no vlan {{ vlan }}\r" +{%- endif %} +send "vlan {{ vlan }}\r" +expect "(config-vlan)#" +{%- endfor %} +send "exit\r" +expect "(config)#" +{%- for name, vlan in pillar['vlans'].items() %} +send "interface vlan {{ vlan }}\r" +expect "(config-if)#" +send "name {{ name }}\r" +expect "(config-if)#" +send "exit\r" +expect "(config)#" +{%- endfor %} + +{%- for name, conf in switch['ports'].items() %} + +{%- if conf['mode'] == 'trunk' %} +{%- for port in conf['ports'] %} +send "interface ethernet {{ port }}\r" +expect "(config-if)#" +send "no channel-group\r" +expect "(config-if)#" +send "switchport mode trunk\r" +expect "(config-if)#" +{%- set vlan_ids = [] %} +{%- for name in conf['vlans'] %} +{%- if vlan_ids.append('' ~ pillar['vlans'][name]) %} +{%- endif %} +{%- endfor %} +send "switchport trunk allowed vlan add {{ ','.join(vlan_ids) }}\r" +expect "(config-if)#" +send "exit\r" +expect "(config)#" +{%- endfor %} + +{%- elif conf['mode'] == 'bond' %} +send "interface range ethernet {{ ','.join(conf['ports']) }}\r" +expect "(config-if)#" +send "switchport trunk allowed vlan remove all\r" +expect "(config-if)#" +send "channel-group {{ conf['group'] }} mode auto\r" +expect "(config-if)#" +send "interface port-channel {{ conf['group'] }}\r" +expect "(config-if)#" +send "exit\r" + +send "interface port-channel {{ conf['group'] }}\r" +expect "(config-if)#" +send "switchport mode trunk\r" +expect "(config-if)#" +{%- set vlan_ids = [] %} +{%- for name in conf['vlans'] %} +{%- if vlan_ids.append('' ~ pillar['vlans'][name]) %} +{%- endif %} +{%- endfor %} +send "switchport trunk allowed vlan add {{ ','.join(vlan_ids) }}\r" +expect "(config-if)#" + +send "exit\r" +expect "(config)#" + +{%- elif conf['mode'] == 'access' %} +{%- for port in conf['ports'] %} +send "interface ethernet {{ port }}\r" +expect "(config-if)#" +send "no channel-group\r" +expect "(config-if)#" +send "switchport mode access\r" +expect "(config-if)#" +send "switchport access vlan {{ pillar['vlans'][name] }}\r" +expect "(config-if)#" +send "exit\r" +expect "(config)#" +{%- endfor %} +{%- endif %} +{%- endfor %}