From 4da2e3fd5466c5f0b3131370f2184774df66c24f Mon Sep 17 00:00:00 2001 From: Nick Hilliard Date: Fri, 9 Feb 2024 23:50:30 +0000 Subject: [PATCH 1/4] Added support for IP Infusion OcNOS --- CHANGELOG.md | 1 + docs/Supported-OS-Types.md | 1 + lib/oxidized/model/ocnos.rb | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 lib/oxidized/model/ocnos.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fc05e805..c06aad816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - added SCP input (@aeiodelic) - Added `linux/arm64` and `linux/amd64` platforms to Docker build/publish. (@disaac) - Added verion info for Vyatta (@systeembeheerder) +- model for IP Infusion OcNOS ## Changed - tp-link: fixed enable mode post login entrance (@mirackle-spb) diff --git a/docs/Supported-OS-Types.md b/docs/Supported-OS-Types.md index f3d028d78..30c68c502 100644 --- a/docs/Supported-OS-Types.md +++ b/docs/Supported-OS-Types.md @@ -108,6 +108,7 @@ |Huawei |VRP |[vrp](/lib/oxidized/model/vrp.rb) | |[VRP-Huawei](Model-Notes/VRP-Huawei.md) | |SmartAX series |[smartax](/lib/oxidized/model/smartax.rb) | |[SmartAX-Huawei](Model-Notes/SmartAX-Huawei.md) |Icotera |6400 series |[icotera](/lib/oxidized/model/icotera.rb) +|IP Infusion |OcNOS |[ocnos](/lib/oxidized/model/ocnos.rb) |Juniper |JunOS |[junos](/lib/oxidized/model/junos.rb) | |[MX/QFX/EX/SRX/J Series](Model-Notes/JunOS.md) | |ScreenOS (Netscreen) |[screenos](/lib/oxidized/model/screenos.rb) |LANCOM Systems GmbH |LCOS |[lancom](/lib/oxidized/model/lancom.rb) diff --git a/lib/oxidized/model/ocnos.rb b/lib/oxidized/model/ocnos.rb new file mode 100644 index 000000000..8aa16d6ab --- /dev/null +++ b/lib/oxidized/model/ocnos.rb @@ -0,0 +1,42 @@ +class OcNOS < Oxidized::Model + using Refinements + + prompt /([\w.@-]+[#>]\s?)$/ + comment '# ' + + cfg :ssh do + post_login 'terminal length 0' + pre_logout do + send "disable\r" + send "logout\r" + end + end + + cmd :all do |cfg| + cfg.lines.to_a[1..-2].join + end + + cmd 'show version' do |cfg| + comment cfg + end + + cmd 'show system fru' do |cfg| + comment cfg + end + + cmd 'show system-information board-info' do |cfg| + comment cfg + end + + cmd 'show forwarding profile limit' do |cfg| + comment cfg + end + + cmd 'show license' do |cfg| + comment cfg + end + + cmd 'show running-config' do |cfg| + cfg + end +end From 28c6bd1528fdf3e5b2f4cd106c4a4f6d606e6fa9 Mon Sep 17 00:00:00 2001 From: Robert Cheramy Date: Thu, 15 Feb 2024 13:37:21 +0100 Subject: [PATCH 2/4] Fix Debug/Warnings in rake test - debug needs explicity to be set to "false" in order to avoid DEBUG messages - Net::SSH.start needs a Hash for its options - use asset_nil and not assert_equal --- spec/input/ssh_spec.rb | 47 +++++++++++++++++++++++----------------- spec/node_spec.rb | 1 + spec/nodes_spec.rb | 1 + spec/refinements_spec.rb | 4 +++- spec/source/http_spec.rb | 4 ++-- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/spec/input/ssh_spec.rb b/spec/input/ssh_spec.rb index 5361d4e8d..9e462d03e 100644 --- a/spec/input/ssh_spec.rb +++ b/spec/input/ssh_spec.rb @@ -4,6 +4,7 @@ describe Oxidized::SSH do before(:each) do Oxidized.asetus = Asetus.new + Oxidized.asetus.cfg.debug = false Oxidized.setup_logger Oxidized.config.timeout = 30 Oxidized.config.input.ssh.secure = true @@ -31,16 +32,19 @@ proxy = mock Net::SSH::Proxy::Command.expects(:new).with("ssh test.com -W [%h]:%p").returns(proxy) - Net::SSH.expects(:start).with('93.184.216.34', 'alma', port: 22, - verify_host_key: Oxidized.config.input.ssh.secure ? :always : :never, - append_all_supported_algorithms: true, - keepalive: true, - forward_agent: false, - password: 'armud', - timeout: Oxidized.config.timeout, - number_of_password_prompts: 0, - auth_methods: %w[none publickey password], - proxy: proxy) + ssh_options = { + port: 22, + verify_host_key: Oxidized.config.input.ssh.secure ? :always : :never, + append_all_supported_algorithms: true, + keepalive: true, + forward_agent: false, + password: 'armud', + timeout: Oxidized.config.timeout, + number_of_password_prompts: 0, + auth_methods: %w[none publickey password], + proxy: proxy + } + Net::SSH.expects(:start).with('93.184.216.34', 'alma', ssh_options) ssh.instance_variable_set("@exec", true) ssh.connect(@node) @@ -64,16 +68,19 @@ proxy = mock Net::SSH::Proxy::Command.expects(:new).with("ssh test.com -W [%h]:%p").returns(proxy) - Net::SSH.expects(:start).with('example.com', 'alma', port: 22, - verify_host_key: Oxidized.config.input.ssh.secure ? :always : :never, - append_all_supported_algorithms: true, - keepalive: true, - forward_agent: false, - password: 'armud', - timeout: Oxidized.config.timeout, - number_of_password_prompts: 0, - auth_methods: %w[none publickey password], - proxy: proxy) + ssh_options = { + port: 22, + verify_host_key: Oxidized.config.input.ssh.secure ? :always : :never, + append_all_supported_algorithms: true, + keepalive: true, + forward_agent: false, + password: 'armud', + timeout: Oxidized.config.timeout, + number_of_password_prompts: 0, + auth_methods: %w[none publickey password], + proxy: proxy + } + Net::SSH.expects(:start).with('example.com', 'alma', ssh_options) ssh.instance_variable_set("@exec", true) ssh.connect(@node) diff --git a/spec/node_spec.rb b/spec/node_spec.rb index eb1b73f43..fec39d45e 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -3,6 +3,7 @@ describe Oxidized::Node do before(:each) do Oxidized.asetus = Asetus.new + Oxidized.asetus.cfg.debug = false Oxidized.setup_logger Oxidized::Node.any_instance.stubs(:resolve_repo) diff --git a/spec/nodes_spec.rb b/spec/nodes_spec.rb index 71d81c872..a6467e55c 100644 --- a/spec/nodes_spec.rb +++ b/spec/nodes_spec.rb @@ -4,6 +4,7 @@ before(:each) do Resolv.any_instance.stubs(:getaddress) Oxidized.asetus = Asetus.new + Oxidized.asetus.cfg.debug = false Oxidized.setup_logger opts = { diff --git a/spec/refinements_spec.rb b/spec/refinements_spec.rb index b7f116f8e..cd568d511 100644 --- a/spec/refinements_spec.rb +++ b/spec/refinements_spec.rb @@ -117,7 +117,9 @@ _(str2.instance_variable_get(:@cmd)).must_equal str1.instance_variable_get(:@cmd) _(str2.instance_variable_get(:@name)).must_equal str1.instance_variable_get(:@name) - _(str2.instance_variable_get(:@type)).must_equal str1.instance_variable_get(:@type) + # :@type is always nil + _(str2.instance_variable_get(:@type)).must_be_nil + _(str1.instance_variable_get(:@type)).must_be_nil end end end diff --git a/spec/source/http_spec.rb b/spec/source/http_spec.rb index ccc725876..860b823b6 100644 --- a/spec/source/http_spec.rb +++ b/spec/source/http_spec.rb @@ -23,10 +23,10 @@ _(Oxidized::HTTP.new.send(:string_navigate, h1, "inventory[0].ip")).must_equal "10.10.10.10" end it "should return nil on non-existing string key" do - _(Oxidized::HTTP.new.send(:string_navigate, h1, "jotain.3")).must_equal nil + _(Oxidized::HTTP.new.send(:string_navigate, h1, "jotain.3")).must_be_nil end it "should return nil on non-existing array index" do - _(Oxidized::HTTP.new.send(:string_navigate, h1, "inventory[3]")).must_equal nil + _(Oxidized::HTTP.new.send(:string_navigate, h1, "inventory[3]")).must_be_nil end end end From 8624169a50293c9bd333aa9265c7f3d56cf45174 Mon Sep 17 00:00:00 2001 From: Robert Cheramy Date: Thu, 15 Feb 2024 14:01:24 +0100 Subject: [PATCH 3/4] Rubocop Fixes --- spec/input/ssh_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/input/ssh_spec.rb b/spec/input/ssh_spec.rb index 9e462d03e..41c2b2669 100644 --- a/spec/input/ssh_spec.rb +++ b/spec/input/ssh_spec.rb @@ -79,8 +79,8 @@ number_of_password_prompts: 0, auth_methods: %w[none publickey password], proxy: proxy - } - Net::SSH.expects(:start).with('example.com', 'alma', ssh_options) + } + Net::SSH.expects(:start).with('example.com', 'alma', ssh_options) ssh.instance_variable_set("@exec", true) ssh.connect(@node) From bb01c8971690001f02ad4fcd705ab8973cfa2e2b Mon Sep 17 00:00:00 2001 From: Robert Cheramy Date: Fri, 16 Feb 2024 12:20:52 +0100 Subject: [PATCH 4/4] Reverting PR #2498 as it broke old procurve models - Reverting PR #2498 as it broke old procurve models (2510G, 2610, 2824). - Fixes #2833, #2871 - Removed "Invalid input" on unsupported commands - Adding myself as model maintainter for HP/Aruba devices I have access to. Multiple model maintainters per model are welcome, just add yourself :-) --- CHANGELOG.md | 1 + docs/Supported-OS-Types.md | 6 +++--- lib/oxidized/model/procurve.rb | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15561e511..c424e7411 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - Fixed pre_logout for BDCOM switches - Fix 'wpa passphrase' hashed secret for SonicOS devices with built-in wireless #3036 (@lazynooblet) - Fix potential busy wait when retries and/or next_adds_job is enabled (@gs-kamnas) +- Reverting PR #2498 as it broke old procurve models (2510G, 2610, 2824). Fixes #2833, #2871 (@robertcheramy) ## [0.29.1 - 2023-04-24] diff --git a/docs/Supported-OS-Types.md b/docs/Supported-OS-Types.md index f3d028d78..b8e7a6027 100644 --- a/docs/Supported-OS-Types.md +++ b/docs/Supported-OS-Types.md @@ -20,7 +20,7 @@ |Arbor Networks |ArbOS |[arbos](/lib/oxidized/model/arbos.rb) | |[ArbOS](Model-Notes/ArbOS.md) |Arista |EOS |[eos](/lib/oxidized/model/eos.rb) | |[EOS](Model-Notes/EOS.md) |Arris |C4CMTS |[c4cmts](/lib/oxidized/model/c4cmts.rb) -|Aruba |AOS-CX |[aoscx](/lib/oxidized/model/aoscx.rb) +|Aruba |AOS-CX |[aoscx](/lib/oxidized/model/aoscx.rb) |@robertcheramy | |AOSW |[Aaosw](/lib/oxidized/model/aosw.rb) |Asterfusion |AsterNOS |[asternos](/lib/oxidized/model/asternos.rb) |AudioCodes |AudioCodes |[audiocodes](/lib/oxidized/model/audiocodes.rb) @@ -99,8 +99,8 @@ |Hillstone Networks |StoneOS |[stoneos](/lib/oxidized/model/stoneos.rb) |Hirschmann |Classic |[hirschmann](/lib/oxidized/model/hirschmann.rb) | |HiOS |[hios](/lib/oxidized/model/hios.rb) -|HP |Comware (HP A-series, H3C, 3Com)|[comware](/lib/oxidized/model/comware.rb) | |[Comware](Model-Notes/Comware.md) -| |Procurve |[procurve](/lib/oxidized/model/procurve.rb) +|HP |Comware (HP A-series, H3C, 3Com)|[comware](/lib/oxidized/model/comware.rb) |@robertcheramy |[Comware](Model-Notes/Comware.md) +| |Procurve |[procurve](/lib/oxidized/model/procurve.rb) |@robertcheramy | |BladeSystem (Onboard Administrator)|[hpebladesystem](/lib/oxidized/model/hpebladesystem.rb) | |MSA |[hpemsa](/lib/oxidized/model/hpemsa.rb) | |MSM (Wireless Controller) |[hpmsm](/lib/oxidized/model/hpmsm.rb) diff --git a/lib/oxidized/model/procurve.rb b/lib/oxidized/model/procurve.rb index 6d65a9c46..c4d776d64 100644 --- a/lib/oxidized/model/procurve.rb +++ b/lib/oxidized/model/procurve.rb @@ -5,7 +5,7 @@ class Procurve < Oxidized::Model # ssh switches prompt may start with \r, followed by the prompt itself, regex ([\w\s.-]+[#>] ), which ends the line # telnet switches may start with various vt100 control characters, regex (\e\[24;[0-9][hH]), followed by the prompt, followed # by at least 3 other vt100 characters - prompt /(^\r|\e\[24;[0-9][hH])?([\w\s.-]+(\((config|vlan-[0-9]{1,4}|y\/n)\)|\(o\)nce)?[#>:?\]] {1,2})($|(\e\[24;[0-9][0-9]?[hH]){3})/ + prompt /(^\r|\e\[24;[0-9][hH])?([\w\s.-]+[#>] )($|(\e\[24;[0-9][0-9]?[hH]){3})/ comment '! ' @@ -36,6 +36,8 @@ class Procurve < Oxidized::Model cfg.gsub! /\e\[\??\d+(;\d+)*[A-Za-z]/, '' # Additional filtering for power usage reporting which obviously changes over time cfg.gsub! /^(.*AC [0-9]{3}V\/?([0-9]{3}V)?) *([0-9]{1,3}) (.*)/, '\\1 \\4' + # Remove failed commands that are not supported on all models + cfg.gsub! /^Invalid input: [A-Za-z-]+\n/, '' cfg end