From efb9ec2f8028655f78be6aed148d5a72677bda16 Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 13 Nov 2016 03:19:54 +0100 Subject: [PATCH] switch configuration for 3com-4200G --- salt-pillar/hosts/init.sls | 6 ++ salt-pillar/subnets/init.sls | 2 +- salt-pillar/switches/init.sls | 46 +++++++++++++++ salt-pillar/top.sls | 2 + salt-pillar/vlans/init.sls | 12 ++-- salt/switches/3com-4200G.expect | 101 ++++++++++++++++++++++++++++++++ salt/switches/TL-SG3210.expect | 2 - 7 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 salt/switches/3com-4200G.expect diff --git a/salt-pillar/hosts/init.sls b/salt-pillar/hosts/init.sls index 40b7d30..d3eceed 100644 --- a/salt-pillar/hosts/init.sls +++ b/salt-pillar/hosts/init.sls @@ -1,4 +1,10 @@ hosts-inet: + mgmt: + server1: 10.0.0.1 + switch-b1: 10.0.0.10 + switch-b2: 10.0.0.11 + switch-c1: 10.0.0.12 + switch-d1: 10.0.0.13 core: server1: 172.20.72.1 serv-gw: 172.20.72.2 diff --git a/salt-pillar/subnets/init.sls b/salt-pillar/subnets/init.sls index a1e3bfa..e5b1301 100644 --- a/salt-pillar/subnets/init.sls +++ b/salt-pillar/subnets/init.sls @@ -4,4 +4,4 @@ subnets-inet: pub: 172.20.76.0/23 priv1: 172.20.74.0/28 priv2: 172.20.75.0/28 - mgm: 10.0.0.0/24 + mgmt: 10.0.0.0/24 diff --git a/salt-pillar/switches/init.sls b/salt-pillar/switches/init.sls index fed2750..ccdc50e 100644 --- a/salt-pillar/switches/init.sls +++ b/salt-pillar/switches/init.sls @@ -1,4 +1,50 @@ switches: + switch-b1: + model: '3com-4200G' + location: Haus B Souterrain + ports: + switch-b2: + mode: trunk + ports: + - 25 + - 26 + - 27 + - 28 + vlans: + - mgmt + - pub + switch-c1: + mode: trunk + ports: + - 29 + - 30 + - 31 + - 32 + vlans: + - mgmt + - pub + switch-d1: + mode: trunk + ports: + - 33 + - 34 + - 35 + - 36 + vlans: + - mgmt + - pub + mgmt: + mode: access + ports: + - 1 + pub: + mode: access + ports: + - 2 + - 3 + - 24 + - 37 + - 48 switch-d1: model: 'TL-SG3210' location: Turm D Keller diff --git a/salt-pillar/top.sls b/salt-pillar/top.sls index d690657..d6d4288 100644 --- a/salt-pillar/top.sls +++ b/salt-pillar/top.sls @@ -7,3 +7,5 @@ base: - dhcp 'upstream1': - upstream.upstream1 + 'server1': + - switches diff --git a/salt-pillar/vlans/init.sls b/salt-pillar/vlans/init.sls index f7cf537..6f3698a 100644 --- a/salt-pillar/vlans/init.sls +++ b/salt-pillar/vlans/init.sls @@ -1,5 +1,9 @@ vlans: - core: 1 - serv: 2 - pub: 3 - mgmt: 4 + mgmt: 1 + core: 2 + serv: 3 + pub: 4 + up1: 10 + up2: 11 + up3: 12 + up4: 13 diff --git a/salt/switches/3com-4200G.expect b/salt/switches/3com-4200G.expect new file mode 100644 index 000000000..7eb09b9 --- /dev/null +++ b/salt/switches/3com-4200G.expect @@ -0,0 +1,101 @@ +{# http://h20628.www2.hp.com/km-ext/kmcsdirect/emr_na-c02586144-1.pdf #} +{%- import_yaml "netmasks.yaml" as netmasks -%} +#!/usr/bin/expect -f + +spawn telnet {{ pillar['hosts-inet']['mgmt'][hostname] }} +expect "Password:" +send "secret\r" +expect ">" +send "system-view\r" +expect "]" + +send "sysname {{ hostname }}\r" +expect "]" + +send "user-interface vty 0 4\r" +expect "ui-vty0-4]" +send "screen-length 0\r" +expect "ui-vty0-4]" +send "user privilege level 3\r" +expect "ui-vty0-4]" +send "set authentication password simple secret\r" +expect "ui-vty0-4]" +send "quit\r" +expect "{{ hostname }}]" + +send "local-user admin\r" +expect -- "-luser-admin]" +send "password simple secret\r" +expect -- "-luser-admin]" +send "quit\r" +expect "{{ hostname }}]" + +{%- for name, vlan in pillar['vlans'].items() %} + +send "vlan {{ vlan }}\r" +expect -- "-vlan{{ vlan }}]" +send "description {{ name }}\r" +expect -- "-vlan{{ vlan }}]" +send "quit\r" +expect "{{ hostname }}]" + +{# Actually only used for mgmt_vlan, switches are not routers #} +send "interface Vlan-interface {{ vlan }}\r" +expect "]" +send "description {{ name }}\r" +expect "]" +{%- set net_hosts = pillar['hosts-inet'].get(name) %} +{%- set ipaddr = net_hosts and net_hosts.get(hostname) %} +{%- if ipaddr %} +send "ip address {{ ipaddr }} {{ netmasks[pillar['subnets-inet'][name].split('/')[1]] }}\r" +expect "]" +{%- endif %} +send "quit\r" +expect "{{ hostname }}]" + +{%- endfor %} + +{%- set group = 0 %} +{%- for name, conf in switch['ports'].items() %} +{%- if conf['mode'] == 'trunk' %} +{%- set group = group + 1 %} +{%- for port in conf['ports'] %} +send "interface gigabitEthernet 1/0/{{ port }}\r" +expect "]" +send "lacp enable\r" +expect "]" +send "port link-aggregation group {{ group }}\r" +expect "]" +send "port link-type trunk\r" +expect "]" +{%- for vlan_name in conf['vlans'] %} +send "port trunk permit vlan {{ pillar['vlans'][vlan_name] }}\r" +expect "]" +{%- endfor %} +send "quit\r" +expect "{{ hostname }}]" +{%- endfor %} + +{%- elif conf['mode'] == 'access' %} +{%- for port in conf['ports'] %} +send "interface gigabitEthernet 1/0/{{ port }}\r" +expect "]" +send "port link-type access\r" +expect "]" +send "port access vlan {{ pillar['vlans'][name] }}\r" +send "quit\r" +expect "{{ hostname }}]" +{%- endfor %} + +{%- endif %} +{%- endfor %} + +send "save main\r" +expect "Y/N]" +send "YES\r" +expect "press the enter key):" +send "\r" +expect "]" +send "quit\r" +expect ">" +send "quit\r" diff --git a/salt/switches/TL-SG3210.expect b/salt/switches/TL-SG3210.expect index 9513ad1..7fc6fe1 100644 --- a/salt/switches/TL-SG3210.expect +++ b/salt/switches/TL-SG3210.expect @@ -8,8 +8,6 @@ spawn telnet {{ pillar['hosts-inet']['mgmt'][hostname] }} expect "Password:" send "secret\r" expect ">" -send "\r" -expect ">" send "enable\r" expect "Password:" send "secret\r"