-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
123 lines (104 loc) · 4.41 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
require 'rbconfig'
require 'machine-nics'
require 'yaml'
NET_CONFIGUATION = 'network.yml'
BRDG = YAML.load_file(NET_CONFIGUATION)
BRDG.each_key do |host|
desc "Make nics for #{host}"
tree = MachineNics::Tree.create_from_hash({host => BRDG[host]})
actions = MachineNics::Actions.new(RbConfig::CONFIG['host_os'])
task "nics_#{host}" do |t|
tree.traverse_df(tree.root, 0) do |nic, level|
next if level <= 0
actions.display('create', nic, level, tree.children[nic] )
actions.create!(nic, tree.children[nic], tree)
end
end
desc "Destroy nics for #{host}"
task "rem_nics_for_#{host}" do |t|
tree.traverse_df(tree.root, 0) do |nic, level|
next if level <= 0
actions.display('destroy', nic, level, tree.children[nic] )
actions.destroy!(nic, tree.children[nic])
end
end
end
desc "Destroy everything."
task clobber: [:rem_ip] do |t|
BRDG.each_key do |host|
tree = MachineNics::Tree.create_from_hash({host => BRDG[host]})
actions = MachineNics::Actions.new(RbConfig::CONFIG['host_os'])
tree.traverse_df(tree.root, 0) do |nic, level|
next if level <= 0
actions.display('destroy', nic, level, tree.children[nic] )
actions.destroy!(nic, tree.children[nic])
end
end
end
desc "Add cluster ehaelix"
task add_blastors: [:nics_b1, :nics_b2]
desc "Remove cluster ehaelix"
task rem_blastors: [:rem_nics_for_b1, :rem_nics_for_b2]
desc "Add cluster FW"
task add_fws: [:nics_fw1, :nics_fw2]
desc "Add ips routers for freebsd"
task :add_ip_freebsd do |t|
if `ifconfig vlan101 2>/dev/null`.split.empty?
`sudo ifconfig vlan10100 172.143.112.67/26`
else
`sudo ifconfig vlan101 172.143.112.67/26`
end
`sudo sysctl net.inet.ip.forwarding=1`
`sudo sysctl net.link.bridge.ipfw=0`
`sudo sysctl net.link.bridge.pfil_local_phys=0`
`sudo sysctl net.link.bridge.pfil_member=0`
`sudo sysctl net.link.bridge.pfil_bridge=0`
`sudo sysctl net.link.bridge.ipfw_arp=0`
`sudo sysctl net.link.bridge.pfil_onlyip=0`
`sudo /etc/rc.d/pf reload`
`sudo route add 172.143.115.35/27 172.143.112.71` # router cfg
`sudo route add 172.143.114.192/27 172.143.112.71` # router cfg
end
desc "Add ips routers for linux"
task :add_ip_linux do |t|
`sudo modprobe bonding 2>&1 >/dev/null; sudo modprobe 8021q 2>&1 >/dev/null;`
# seems it cannot be on the laggX.101 interface.
`sudo ifconfig bridge0 172.143.112.67/26`
`sudo sysctl net.ipv4.ip_forward=1`
`sudo sh -c 'if=$(ip r |awk "/default/{print \\$NF}");ip=$(ip a show $if | awk "/inet /{print \\$2}" | cut -d"/" -f1) ; iptables -I POSTROUTING 1 -t nat -o $if \! -s $ip -j SNAT --to $ip'`
`sudo ip r add 172.143.115.32/27 via 172.143.112.71` # router cfg
`sudo ip r add 172.143.114.192/27 via 172.143.112.71` # router cfg
end
desc "Remove ips routers for freebsd"
task :rem_ip_freebsd do |t|
`sudo route del 172.143.115.35/27 172.143.112.71` # router cfg
`sudo route del 172.143.114.192/27 172.143.112.71` # router cfg
`sudo ifconfig vlan10100 -alias 172.143.112.67 2>/dev/null`
`sudo ifconfig vlan101 -alias 172.143.112.67 2>/dev/null`
end
desc "Remove ips routers for linux"
task :rem_ip_linux do |t|
`sudo ip r del 172.143.115.32/27 via 172.143.112.71` # router cfg
`sudo ip r del 172.143.114.192/27 via 172.143.112.71` # router cfg
`sudo ip a flush lagg4.101 2>/dev/null`
`sudo ip a flush lagg2.101 2>/dev/null`
`sudo sh -c 'if=$(ip r |awk "/default/{print \\$NF}");ip=$(ip a show $if | awk "/inet /{print \\$2}" | cut -d"/" -f1) ; iptables -D POSTROUTING -t nat -o $if \! -s $ip -j SNAT --to $ip'`
end
task_name_rem_ip = 'rem_ip_' + RbConfig::CONFIG['host_os'].downcase.gsub(/\d/,'').gsub(/-.*/,'')
task_name_rem_ip = task_name_rem_ip.to_sym
task_name_add_ip = 'add_ip_' + RbConfig::CONFIG['host_os'].downcase.gsub(/\d/,'').gsub(/-.*/,'')
task_name_add_ip = task_name_add_ip.to_sym
desc "Remove ips routers for your plateform"
task rem_ip: [task_name_rem_ip]
desc "Add ips routers for your plateform"
task add_ip: [task_name_add_ip]
desc "Remove cluster FW"
task rem_fws: [:rem_nics_for_fw1, :rem_nics_for_fw2]
desc "Add eNovance"
task add_enovance: [:add_blastors, :add_fws, :add_ip]
desc "Add eNovance Small: fw1, b1, puppet"
task add_enovance_small: [:nics_b1, :nics_fw1, :nics_puppet, :add_ip ]
desc "Remove eNovance Small: fw1, b1, puppet"
task rem_enovance_small: [:rem_nics_for_b1, :rem_nics_for_fw1, :rem_nics_for_puppet, :rem_ip ]
desc "Remove eNovance"
task rem_enovance: [:rem_ip, :rem_fws, :rem_blastors ]