Repository navigation
Expand file tree
/
Copy pathcomware.rb
More file actions
91 lines (78 loc) · 2.55 KB
/
Copy pathcomware.rb
File metadata and controls
91 lines (78 loc) · 2.55 KB
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
class Comware < Oxidized::Model
# HP (A-series)/H3C/3Com Comware
using Refinements
# sometimes the prompt might have a leading nul or trailing ASCII Bell (^G)
prompt /^\0*(<[\w.-]+>).?$/
comment '# '
# example how to handle pager
# expect /^\s*---- More ----$/ do |data, re|
# send ' '
# data.sub re, ''
# end
cmd :all do |cfg|
# cfg.gsub! /^.*\e\[42D/, '' # example how to handle pager
# skip rogue ^M
cfg = cfg.delete "\r"
cfg.cut_both
end
cmd :secret do |cfg|
cfg.gsub! /^( snmp-agent community).*/, '\\1 <configuration removed>'
cfg.gsub! /(password hash).*/, '\\1 <configuration removed>'
cfg.gsub! /^( password cipher).*/, '\\1 <configuration removed>'
cfg.gsub! /(key (authentication )?cipher) \S+/, '\\1 <configuration removed>'
cfg.gsub! /(cipher authentication-mode (md5|sha)).\S+ (privacy-mode (des56|3des|aes\d{0,3})) .\S+/, '\\1 <auth-pass> \\3 <priv-pass>'
cfg
end
cfg :telnet do
username /^(Username|[Ll]ogin):/
password /^Password:/
end
cfg :telnet, :ssh do
# handle enable passwords
post_login do
if vars(:enable) == true
cmd "super"
elsif vars(:enable)
cmd "super", /^\s?[pP]assword:/
cmd vars(:enable)
end
end
# enable command-line mode on SMB comware switches (HP V1910, V1920)
# autodetection is hard, because the 'summary' command is paged, and
# the pager cannot be disabled before _cmdline-mode on.
if vars :comware_cmdline
post_login do
# HP V1910, V1920
cmd '_cmdline-mode on', /(#{@node.prompt}|Continue)/
cmd 'y', /(#{@node.prompt}|input password)/
cmd vars(:comware_cmdline)
# HP V1950 r2432P06
cmd 'xtd-cli-mode on', /(#{@node.prompt}|Continue)/
cmd 'y', /(#{@node.prompt}|input password)/
cmd vars(:comware_cmdline)
# HP V1950 OS r3208 (v7.1)
# HPE Office Connect 1950
cmd 'xtd-cli-mode', /(#{@node.prompt}|Continue|Switch)/
cmd 'y', /(#{@node.prompt}|input password|Password:)/
cmd vars(:comware_cmdline)
end
end
post_login 'screen-length disable'
post_login 'undo terminal monitor'
pre_logout 'quit'
end
cmd 'display version' do |cfg|
cfg = cfg.each_line.reject { |l| l.match /uptime/i }.join
comment cfg
end
cmd 'display device' do |cfg|
comment cfg
end
cmd 'display device manuinfo' do |cfg|
cfg = cfg.each_line.reject { |l| l.match 'FF'.hex.chr }.join
comment cfg
end
cmd 'display current-configuration' do |cfg|
cfg
end
end