forked from ytti/oxidized
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acos.rb
101 lines (87 loc) · 2.78 KB
/
acos.rb
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
class ACOS < Oxidized::Model
# A10 ACOS model for AX and Thunder series
comment '! '
# ACOS prompt changes depending on the state of the device
prompt /^([-\w.\/:?\[\]()]+[#>]\s?)$/
cmd :secret do |cfg|
cfg.gsub!(/community read encrypted (\S+)/, 'community read encrypted <hidden>') # snmp
cfg.gsub!(/secret encrypted (\S+)/, 'secret encrypted <hidden>') # tacacs-server
cfg.gsub!(/password encrypted (\S+)/, 'password encrypted <hidden>') # user
cfg
end
cmd 'show version' do |cfg|
cfg.gsub! /\s(Last configuration saved at).*/, ' \\1 <removed>'
cfg.gsub! /\s(Memory).*/, ' \\1 <removed>'
cfg.gsub! /\s(Current time is).*/, ' \\1 <removed>'
cfg.gsub! /\s(The system has been up).*/, ' \\1 <removed>'
comment cfg
end
cmd 'show bootimage' do |cfg|
comment cfg
end
cmd 'show license' do |cfg|
comment cfg
end
cmd 'show partition-config all' do |cfg|
cfg.gsub! /(Current configuration).*/, '\\1 <removed>'
cfg.gsub! /(Configuration last updated at).*/, '\\1 <removed>'
cfg.gsub! /(Configuration last saved at).*/, '\\1 <removed>'
cfg.gsub! /(Configuration last synchronized at).*/, '\\1 <removed>'
cfg
end
cmd 'show running-config all-partitions' do |cfg|
cfg.gsub! /(Current configuration).*/, '\\1 <removed>'
cfg.gsub! /(Configuration last updated at).*/, '\\1 <removed>'
cfg.gsub! /(Configuration last saved at).*/, '\\1 <removed>'
cfg.gsub! /(Configuration last synchronized at).*/, '\\1 <removed>'
cfg
end
cmd 'show aflex all-partitions' do |cfg|
comment cfg
end
cmd 'show aflex all-partitions' do |cfg|
@partitions_aflex = cfg.lines.each_with_object({}) do |l, h|
h[$1] = [] if l.match /partition: (.+)/
# only consider scripts that have passed syntax check
h[h.keys.last] << $1 if l.match /^([\w-]+) +Check/
end
''
end
cmd :all do |cfg, cmdstring|
new_cfg = comment "COMMAND: #{cmdstring}\n"
new_cfg << cfg.cut_both
end
pre do
unless @partitions_aflex.empty?
out = []
@partitions_aflex.each do |partition, arules|
out << "! partition: #{partition}"
arules.each do |name|
cmd("show aflex #{name} partition #{partition}") do |cfg|
content = cfg.split(/Content:/).last.strip
out << "aflex create #{name}"
out << content
out << ".\n"
end
end
end
out.join "\n"
end
end
cfg :telnet do
username /login:/
password /^Password:/
end
cfg :telnet, :ssh do
# preferred way to handle additional passwords
post_login do
pw = vars(:enable)
pw ||= ""
send "enable\r\n"
cmd pw
end
post_login 'terminal length 0'
post_login 'terminal width 0'
pre_logout "exit\nexit\nY\r\n"
end
end