summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWild Kat <wk@users.noreply.github.com>2018-07-07 12:45:35 +0200
committerytti <saku@ytti.fi>2018-07-07 13:45:35 +0300
commit9db0c31f5656d1b689fd6261079730366f15591c (patch)
tree126079966b1d9eff0be48e55772150278a7f92c9
parent0dec0790f6e41cbeaf76de8fed106f7e845cd176 (diff)
use convenience methods in models
* use convenience methods in models for legibility * disable Style/SymbolProc in rubocop * introduce cut_both instead of cut_head.cut_tail chain * document cut_both convenience method
-rw-r--r--.rubocop.yml3
-rw-r--r--docs/Ruby-API.md5
-rw-r--r--lib/oxidized/model/acos.rb2
-rw-r--r--lib/oxidized/model/acsw.rb2
-rw-r--r--lib/oxidized/model/aen.rb2
-rw-r--r--lib/oxidized/model/aireos.rb2
-rw-r--r--lib/oxidized/model/aos.rb2
-rw-r--r--lib/oxidized/model/aos7.rb2
-rw-r--r--lib/oxidized/model/aosw.rb2
-rw-r--r--lib/oxidized/model/asa.rb2
-rw-r--r--lib/oxidized/model/awplus.rb2
-rw-r--r--lib/oxidized/model/c4cmts.rb6
-rw-r--r--lib/oxidized/model/casa.rb2
-rw-r--r--lib/oxidized/model/catos.rb2
-rw-r--r--lib/oxidized/model/comware.rb2
-rw-r--r--lib/oxidized/model/coriantgroove.rb8
-rw-r--r--lib/oxidized/model/cumulus.rb2
-rw-r--r--lib/oxidized/model/datacom.rb3
-rw-r--r--lib/oxidized/model/dcnos.rb2
-rw-r--r--lib/oxidized/model/eos.rb2
-rw-r--r--lib/oxidized/model/fiberdriver.rb2
-rw-r--r--lib/oxidized/model/firewareos.rb2
-rw-r--r--lib/oxidized/model/fujitsupy.rb2
-rw-r--r--lib/oxidized/model/gaiaos.rb2
-rw-r--r--lib/oxidized/model/gcombnps.rb2
-rw-r--r--lib/oxidized/model/hatteras.rb2
-rw-r--r--lib/oxidized/model/hirschmann.rb2
-rw-r--r--lib/oxidized/model/hpebladesystem.rb2
-rw-r--r--lib/oxidized/model/ios.rb2
-rw-r--r--lib/oxidized/model/ipos.rb6
-rw-r--r--lib/oxidized/model/isam.rb2
-rw-r--r--lib/oxidized/model/junos.rb2
-rw-r--r--lib/oxidized/model/masteros.rb5
-rw-r--r--lib/oxidized/model/ndms.rb2
-rw-r--r--lib/oxidized/model/netonix.rb2
-rw-r--r--lib/oxidized/model/nos.rb2
-rw-r--r--lib/oxidized/model/oneos.rb2
-rw-r--r--lib/oxidized/model/opnsense.rb2
-rw-r--r--lib/oxidized/model/pfsense.rb2
-rw-r--r--lib/oxidized/model/planet.rb2
-rw-r--r--lib/oxidized/model/procurve.rb2
-rw-r--r--lib/oxidized/model/saos.rb2
-rw-r--r--lib/oxidized/model/sros.rb2
-rw-r--r--lib/oxidized/model/stoneos.rb2
-rw-r--r--lib/oxidized/model/vrp.rb2
-rw-r--r--lib/oxidized/model/weos.rb2
-rw-r--r--lib/oxidized/string.rb5
47 files changed, 63 insertions, 56 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index c9feb24..f1332c2 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -33,6 +33,9 @@ Style/RescueModifier:
Style/MultilineBlockChain:
Enabled: false
+Style/SymbolProc:
+ Enabled: false
+
# Do not attempt to police vendored code, and exclude special cases
AllCops:
Exclude:
diff --git a/docs/Ruby-API.md b/docs/Ruby-API.md
index a9e130a..feea2dd 100644
--- a/docs/Ruby-API.md
+++ b/docs/Ruby-API.md
@@ -180,3 +180,8 @@ single line was present.
Returns a multi-line string without the first line, or an empty string if only a
single line was present.
+
+#### `cut_both`
+
+Returns a multi-line string without the first and last lines, or an empty string
+if fewer than three lines were present.
diff --git a/lib/oxidized/model/acos.rb b/lib/oxidized/model/acos.rb
index a2db89c..b75ee98 100644
--- a/lib/oxidized/model/acos.rb
+++ b/lib/oxidized/model/acos.rb
@@ -60,7 +60,7 @@ class ACOS < Oxidized::Model
cmd :all do |cfg, cmdstring|
new_cfg = comment "COMMAND: #{cmdstring}\n"
- new_cfg << cfg.each_line.to_a[1..-2].join
+ new_cfg << cfg.cut_both
end
pre do
diff --git a/lib/oxidized/model/acsw.rb b/lib/oxidized/model/acsw.rb
index c0857b3..f792347 100644
--- a/lib/oxidized/model/acsw.rb
+++ b/lib/oxidized/model/acsw.rb
@@ -4,7 +4,7 @@ class ACSW < Oxidized::Model
cmd :all do |cfg|
cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/aen.rb b/lib/oxidized/model/aen.rb
index 474e6d5..b2f4d8a 100644
--- a/lib/oxidized/model/aen.rb
+++ b/lib/oxidized/model/aen.rb
@@ -10,7 +10,7 @@ class AEN < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cfg :ssh do
diff --git a/lib/oxidized/model/aireos.rb b/lib/oxidized/model/aireos.rb
index a0378c7..d52f7ae 100644
--- a/lib/oxidized/model/aireos.rb
+++ b/lib/oxidized/model/aireos.rb
@@ -6,7 +6,7 @@ class Aireos < Oxidized::Model
prompt /^\([^\)]+\)\s>/
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
# show sysinfo?
diff --git a/lib/oxidized/model/aos.rb b/lib/oxidized/model/aos.rb
index fed78c8..d525021 100644
--- a/lib/oxidized/model/aos.rb
+++ b/lib/oxidized/model/aos.rb
@@ -5,7 +5,7 @@ class AOS < Oxidized::Model
comment '! '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'show system' do |cfg|
diff --git a/lib/oxidized/model/aos7.rb b/lib/oxidized/model/aos7.rb
index 00bee54..2f1696c 100644
--- a/lib/oxidized/model/aos7.rb
+++ b/lib/oxidized/model/aos7.rb
@@ -6,7 +6,7 @@ class AOS7 < Oxidized::Model
cmd :all do |cfg, cmdstring|
new_cfg = comment "COMMAND: #{cmdstring}\n"
- new_cfg << cfg.each_line.to_a[1..-2].join
+ new_cfg << cfg.cut_both
end
cmd 'show system' do |cfg|
diff --git a/lib/oxidized/model/aosw.rb b/lib/oxidized/model/aosw.rb
index 7543353..3e1fd53 100644
--- a/lib/oxidized/model/aosw.rb
+++ b/lib/oxidized/model/aosw.rb
@@ -13,7 +13,7 @@ class AOSW < Oxidized::Model
prompt /^\(?.+\)?\s[#>]/
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/asa.rb b/lib/oxidized/model/asa.rb
index dfd94b1..06de52f 100644
--- a/lib/oxidized/model/asa.rb
+++ b/lib/oxidized/model/asa.rb
@@ -6,7 +6,7 @@ class ASA < Oxidized::Model
comment '! '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/awplus.rb b/lib/oxidized/model/awplus.rb
index 7c88d60..cdbafa7 100644
--- a/lib/oxidized/model/awplus.rb
+++ b/lib/oxidized/model/awplus.rb
@@ -16,7 +16,7 @@ class AWPlus < Oxidized::Model
cfg.gsub! /\e\[K/, '' # example how to handle pager - cleareol EL0
cfg.gsub! /\e\[7m\e\[m/, '' # example how to handle pager - Reverse SGR7
cfg.gsub! /\r/, '' # Filters rogue ^M - see issue #415
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
# Remove passwords from config file.
diff --git a/lib/oxidized/model/c4cmts.rb b/lib/oxidized/model/c4cmts.rb
index 8ea27c6..222713d 100644
--- a/lib/oxidized/model/c4cmts.rb
+++ b/lib/oxidized/model/c4cmts.rb
@@ -18,8 +18,7 @@ class C4CMTS < Oxidized::Model
cmd 'show environment' do |cfg|
cfg.gsub! /\s+[\-\d]+\s+C\s+[\(\s\d]+\s+\F\)/, '' # remove temperature readings
- cfg.each_line.to_a[1..-2].join
- comment cfg
+ comment cfg.cut_both
end
cmd 'show version' do |cfg|
@@ -29,8 +28,7 @@ class C4CMTS < Oxidized::Model
end
cmd 'show running-config' do |cfg|
- cfg = cfg.each_line.to_a[1..-2].join
- cfg
+ cfg.cut_both
end
cfg :telnet do
diff --git a/lib/oxidized/model/casa.rb b/lib/oxidized/model/casa.rb
index e85c904..0ab85fb 100644
--- a/lib/oxidized/model/casa.rb
+++ b/lib/oxidized/model/casa.rb
@@ -14,7 +14,7 @@ class Casa < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'show system' do |cfg|
diff --git a/lib/oxidized/model/catos.rb b/lib/oxidized/model/catos.rb
index e97a0b6..8f6d3ce 100644
--- a/lib/oxidized/model/catos.rb
+++ b/lib/oxidized/model/catos.rb
@@ -3,7 +3,7 @@ class Catos < Oxidized::Model
comment '# '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'show system' do |cfg|
diff --git a/lib/oxidized/model/comware.rb b/lib/oxidized/model/comware.rb
index 6f65edb..cf82fa6 100644
--- a/lib/oxidized/model/comware.rb
+++ b/lib/oxidized/model/comware.rb
@@ -15,7 +15,7 @@ class Comware < Oxidized::Model
# cfg.gsub! /^.*\e\[42D/, '' # example how to handle pager
# skip rogue ^M
cfg = cfg.gsub /\r/, ''
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/coriantgroove.rb b/lib/oxidized/model/coriantgroove.rb
index 4972eb7..22cf7a1 100644
--- a/lib/oxidized/model/coriantgroove.rb
+++ b/lib/oxidized/model/coriantgroove.rb
@@ -8,17 +8,15 @@ class CoriantGroove < Oxidized::Model
end
cmd 'show inventory' do |cfg|
- cfg = cfg.each_line.to_a[0..-2].join
- comment cfg
+ comment cfg.cut_tail
end
cmd 'show softwareload' do |cfg|
- cfg = cfg.each_line.to_a[0..-2].join
- comment cfg
+ comment cfg.cut_tail
end
cmd 'show config | display commands' do |cfg|
- cfg.each_line.to_a[1..-1].join
+ cfg.cut_head
end
cfg :ssh do
diff --git a/lib/oxidized/model/cumulus.rb b/lib/oxidized/model/cumulus.rb
index f53ca73..c8e1707 100644
--- a/lib/oxidized/model/cumulus.rb
+++ b/lib/oxidized/model/cumulus.rb
@@ -8,7 +8,7 @@ class Cumulus < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
# show the persistent configuration
diff --git a/lib/oxidized/model/datacom.rb b/lib/oxidized/model/datacom.rb
index 5d5d220..b1c94da 100644
--- a/lib/oxidized/model/datacom.rb
+++ b/lib/oxidized/model/datacom.rb
@@ -7,8 +7,7 @@ class DataCom < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
- cfg.cut_head.cut_tail
+ cfg.cut_head.cut_both.cut_tail
end
cmd 'show firmware' do |cfg|
diff --git a/lib/oxidized/model/dcnos.rb b/lib/oxidized/model/dcnos.rb
index 59e6744..b5e2ce8 100644
--- a/lib/oxidized/model/dcnos.rb
+++ b/lib/oxidized/model/dcnos.rb
@@ -8,7 +8,7 @@ class DCNOS < Oxidized::Model
comment '! '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-1].join
+ cfg.cut_head
end
cmd 'show version' do |cfg|
diff --git a/lib/oxidized/model/eos.rb b/lib/oxidized/model/eos.rb
index f29910c..6bfef87 100644
--- a/lib/oxidized/model/eos.rb
+++ b/lib/oxidized/model/eos.rb
@@ -6,7 +6,7 @@ class EOS < Oxidized::Model
comment '! '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/fiberdriver.rb b/lib/oxidized/model/fiberdriver.rb
index 7cfa847..bdfe903 100644
--- a/lib/oxidized/model/fiberdriver.rb
+++ b/lib/oxidized/model/fiberdriver.rb
@@ -3,7 +3,7 @@ class FiberDriver < Oxidized::Model
comment "! "
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'show inventory' do |cfg|
comment cfg
diff --git a/lib/oxidized/model/firewareos.rb b/lib/oxidized/model/firewareos.rb
index bd0008d..db40157 100644
--- a/lib/oxidized/model/firewareos.rb
+++ b/lib/oxidized/model/firewareos.rb
@@ -3,7 +3,7 @@ class FirewareOS < Oxidized::Model
comment '-- '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
# Handle Logon Disclaimer added in XTM 11.9.3
diff --git a/lib/oxidized/model/fujitsupy.rb b/lib/oxidized/model/fujitsupy.rb
index a2db909..6e8f807 100644
--- a/lib/oxidized/model/fujitsupy.rb
+++ b/lib/oxidized/model/fujitsupy.rb
@@ -3,7 +3,7 @@ class FujitsuPY < Oxidized::Model
comment '! '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
# 1Gbe switch
diff --git a/lib/oxidized/model/gaiaos.rb b/lib/oxidized/model/gaiaos.rb
index 8f13bcb..c2598dd 100644
--- a/lib/oxidized/model/gaiaos.rb
+++ b/lib/oxidized/model/gaiaos.rb
@@ -8,7 +8,7 @@ class GaiaOS < Oxidized::Model
comment '# '
cmd :all do |cfg|
- cfg = cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/gcombnps.rb b/lib/oxidized/model/gcombnps.rb
index e92c7ba..0aa4a11 100644
--- a/lib/oxidized/model/gcombnps.rb
+++ b/lib/oxidized/model/gcombnps.rb
@@ -22,7 +22,7 @@ class GcomBNPS < Oxidized::Model
cmd :all do |cfg|
cfg = cfg.gsub " \e[73D\e[K", '' # remove garbage remaining from the pager
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/hatteras.rb b/lib/oxidized/model/hatteras.rb
index 7341cc4..a6072b6 100644
--- a/lib/oxidized/model/hatteras.rb
+++ b/lib/oxidized/model/hatteras.rb
@@ -17,7 +17,7 @@ class Hatteras < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd "show switch\r" do |cfg|
diff --git a/lib/oxidized/model/hirschmann.rb b/lib/oxidized/model/hirschmann.rb
index 858b198..e84b774 100644
--- a/lib/oxidized/model/hirschmann.rb
+++ b/lib/oxidized/model/hirschmann.rb
@@ -10,7 +10,7 @@ class Hirschmann < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'show sysinfo' do |cfg|
diff --git a/lib/oxidized/model/hpebladesystem.rb b/lib/oxidized/model/hpebladesystem.rb
index 75d2dbf..8eb83e2 100644
--- a/lib/oxidized/model/hpebladesystem.rb
+++ b/lib/oxidized/model/hpebladesystem.rb
@@ -11,7 +11,7 @@ class HPEBladeSystem < Oxidized::Model
cmd :all do |cfg|
cfg = cfg.delete("\r").each_line.to_a[0..-1].map { |line| line.rstrip }.join("\n") + "\n"
- cfg.each_line.to_a[0..-2].join
+ cfg.cut_tail
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/ios.rb b/lib/oxidized/model/ios.rb
index 8069f83..068ae05 100644
--- a/lib/oxidized/model/ios.rb
+++ b/lib/oxidized/model/ios.rb
@@ -20,7 +20,7 @@ class IOS < Oxidized::Model
# cfg.gsub! /\cH+/, '' # example how to handle pager
# get rid of errors for commands that don't work on some devices
cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/ipos.rb b/lib/oxidized/model/ipos.rb
index 753c6b1..7348592 100644
--- a/lib/oxidized/model/ipos.rb
+++ b/lib/oxidized/model/ipos.rb
@@ -6,15 +6,15 @@ class IPOS < Oxidized::Model
comment '! '
cmd 'show chassis' do |cfg|
- comment cfg.each_line.to_a[0..-2].join
+ comment cfg.cut_tail
end
cmd 'show hardware' do |cfg|
- comment cfg.each_line.to_a[0..-2].join
+ comment cfg.cut_tail
end
cmd 'show release' do |cfg|
- comment cfg.each_line.to_a[0..-2].join
+ comment cfg.cut_tail
end
cmd 'show configuration' do |cfg|
diff --git a/lib/oxidized/model/isam.rb b/lib/oxidized/model/isam.rb
index 8b8b5d5..511bb16 100644
--- a/lib/oxidized/model/isam.rb
+++ b/lib/oxidized/model/isam.rb
@@ -5,7 +5,7 @@ class ISAM < Oxidized::Model
comment '# '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cfg :telnet do
diff --git a/lib/oxidized/model/junos.rb b/lib/oxidized/model/junos.rb
index e987930..156417b 100644
--- a/lib/oxidized/model/junos.rb
+++ b/lib/oxidized/model/junos.rb
@@ -6,7 +6,7 @@ class JunOS < Oxidized::Model
end
cmd :all do |cfg|
- cfg = cfg.lines.to_a[1..-2].join if screenscrape
+ cfg = cfg.cut_both if screenscrape
cfg.gsub!(/ scale-subscriber (\s+)(\d+)/, ' scale-subscriber <count>')
cfg.lines.map { |line| line.rstrip }.join("\n") + "\n"
end
diff --git a/lib/oxidized/model/masteros.rb b/lib/oxidized/model/masteros.rb
index c03beb1..33388a0 100644
--- a/lib/oxidized/model/masteros.rb
+++ b/lib/oxidized/model/masteros.rb
@@ -10,13 +10,12 @@ class MasterOS < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
cfg.gsub /^(! Configuration ).*/, '!'
end
cmd 'show inventory' do |cfg|
- cfg = cfg.each_line.to_a[0..-2].join
- comment cfg
+ comment cfg.cut_tail
end
cmd 'show plugins' do |cfg|
diff --git a/lib/oxidized/model/ndms.rb b/lib/oxidized/model/ndms.rb
index 1947f91..57cb706 100644
--- a/lib/oxidized/model/ndms.rb
+++ b/lib/oxidized/model/ndms.rb
@@ -11,7 +11,7 @@ class NDMS < Oxidized::Model
end
cmd 'show running-config' do |cfg|
- cfg = cfg.each_line.to_a[1..-2]
+ cfg = cfg.cut_both
cfg = cfg.reject { |line| line.match /(clock date|checksum)/ }.join
cfg
end
diff --git a/lib/oxidized/model/netonix.rb b/lib/oxidized/model/netonix.rb
index 4624f83..f3ebe73 100644
--- a/lib/oxidized/model/netonix.rb
+++ b/lib/oxidized/model/netonix.rb
@@ -2,7 +2,7 @@ class Netonix < Oxidized::Model
prompt /^[\w\s.@_\/:-]+#/
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'cat config.json;echo'
diff --git a/lib/oxidized/model/nos.rb b/lib/oxidized/model/nos.rb
index 4049aa5..fbf7a49 100644
--- a/lib/oxidized/model/nos.rb
+++ b/lib/oxidized/model/nos.rb
@@ -5,7 +5,7 @@ class NOS < Oxidized::Model
comment '! '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'show version' do |cfg|
diff --git a/lib/oxidized/model/oneos.rb b/lib/oxidized/model/oneos.rb
index 35332c8..f1eaaba 100644
--- a/lib/oxidized/model/oneos.rb
+++ b/lib/oxidized/model/oneos.rb
@@ -18,7 +18,7 @@ class OneOS < Oxidized::Model
cmd :all do |cfg|
# cfg.gsub! /\cH+\s{8}/, '' # example how to handle pager
# cfg.gsub! /\cH+/, '' # example how to handle pager
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/opnsense.rb b/lib/oxidized/model/opnsense.rb
index a8f7a47..bbad777 100644
--- a/lib/oxidized/model/opnsense.rb
+++ b/lib/oxidized/model/opnsense.rb
@@ -3,7 +3,7 @@ class OpnSense < Oxidized::Model
# must enable SSH and password-based SSH access
cmd :all do |cfg|
- cfg.each_line.to_a[1..-1].join
+ cfg.cut_head
end
cmd 'cat /conf/config.xml' do |cfg|
diff --git a/lib/oxidized/model/pfsense.rb b/lib/oxidized/model/pfsense.rb
index 13a6370..08f2aa4 100644
--- a/lib/oxidized/model/pfsense.rb
+++ b/lib/oxidized/model/pfsense.rb
@@ -2,7 +2,7 @@ class PfSense < Oxidized::Model
# use other use than 'admin' user, 'admin' user cannot get ssh/exec. See issue #535
cmd :all do |cfg|
- cfg.each_line.to_a[1..-1].join
+ cfg.cut_head
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/planet.rb b/lib/oxidized/model/planet.rb
index 56e688c..045bd31 100644
--- a/lib/oxidized/model/planet.rb
+++ b/lib/oxidized/model/planet.rb
@@ -18,7 +18,7 @@ class Planet < Oxidized::Model
cmd :all do |cfg|
# cfg.gsub! /\cH+\s{8}/, '' # example how to handle pager
# cfg.gsub! /\cH+/, '' # example how to handle pager
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/procurve.rb b/lib/oxidized/model/procurve.rb
index f9175b1..de459a6 100644
--- a/lib/oxidized/model/procurve.rb
+++ b/lib/oxidized/model/procurve.rb
@@ -26,7 +26,7 @@ class Procurve < Oxidized::Model
end
cmd :all do |cfg|
- cfg = cfg.each_line.to_a[1..-2].join
+ cfg = cfg.cut_both
cfg = cfg.gsub /^\r/, ''
end
diff --git a/lib/oxidized/model/saos.rb b/lib/oxidized/model/saos.rb
index 97547b5..7c1a4f1 100644
--- a/lib/oxidized/model/saos.rb
+++ b/lib/oxidized/model/saos.rb
@@ -5,7 +5,7 @@ class SAOS < Oxidized::Model
comment '! '
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'configuration show' do |cfg|
diff --git a/lib/oxidized/model/sros.rb b/lib/oxidized/model/sros.rb
index d809147..aab7d0e 100644
--- a/lib/oxidized/model/sros.rb
+++ b/lib/oxidized/model/sros.rb
@@ -10,7 +10,7 @@ class SROS < Oxidized::Model
cmd :all do |cfg, cmdstring|
new_cfg = comment "COMMAND: #{cmdstring}\n"
- new_cfg << cfg.each_line.to_a[1..-2].join
+ new_cfg << cfg.cut_both
end
#
diff --git a/lib/oxidized/model/stoneos.rb b/lib/oxidized/model/stoneos.rb
index d2bc017..94f679f 100644
--- a/lib/oxidized/model/stoneos.rb
+++ b/lib/oxidized/model/stoneos.rb
@@ -10,7 +10,7 @@ class StoneOS < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'show configuration running'
diff --git a/lib/oxidized/model/vrp.rb b/lib/oxidized/model/vrp.rb
index 42762c2..0e9074e 100644
--- a/lib/oxidized/model/vrp.rb
+++ b/lib/oxidized/model/vrp.rb
@@ -11,7 +11,7 @@ class VRP < Oxidized::Model
end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cfg :telnet do
diff --git a/lib/oxidized/model/weos.rb b/lib/oxidized/model/weos.rb
index 2856666..dcde695 100644
--- a/lib/oxidized/model/weos.rb
+++ b/lib/oxidized/model/weos.rb
@@ -4,7 +4,7 @@ class WEOS < Oxidized::Model
prompt /^(\s[\w.@-]+[#>]\s?)$/
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
+ cfg.cut_both
end
cmd 'show running-config' do |cfg|
diff --git a/lib/oxidized/string.rb b/lib/oxidized/string.rb
index 9c09f61..64b7115 100644
--- a/lib/oxidized/string.rb
+++ b/lib/oxidized/string.rb
@@ -13,6 +13,11 @@ module Oxidized
Oxidized::String.new each_line.to_a[1..-1].join
end
+ # @return [Oxidized::String] copy of self with first and last lines removed
+ def cut_both
+ Oxidized::String.new each_line.to_a[1..-2].join
+ end
+
# sets @cmd and @name unless @name is already set
def set_cmd command
@cmd = command