summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-04-12 19:42:05 +0300
committerSaku Ytti <saku@ytti.fi>2014-04-12 19:42:05 +0300
commitdce76a16f5ecf8bfc239ef5d1ee1bbbd349251bc (patch)
tree8bba9d9896432d55988b22efac2fdc57a85541e2
parentfb2d7d5ce2a8b7f07dcb3e4fcccf4abdd915da77 (diff)
enable loading subset of all nodes
potential use in perhaps upcoming CLI: [fisakytt@lan-login1 ~/projects/oxidized-cli]% ./oxi S-2250219.fi.cpe.tdc.net 'show ver' Dec 2 2009 00:19:01 Q.11.25 106 [fisakytt@lan-login1 ~/projects/oxidized-cli]% ./oxi 62.236.123.197 'show ver' Cisco IOS Software, C3560 Software (C3560-IPBASEK9-M), Version 12.2(55)SE1, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by Cisco Systems, Inc. Compiled Thu 02-Dec-10 07:16 by prod_rel_team Image text-base: 0x01000000, data-base: 0x02D00000 ROM: Bootstrap program is C3560 boot loader BOOTLDR: C3560 Boot Loader (C3560-HBOOT-M) Version 12.2(35r)SE2, RELEASE SOFTWARE (fc1) S-1035880.fi uptime is 7 weeks, 3 days, 15 hours, 43 minutes System returned to ROM by power-on System restarted at 00:54:59 UTC Wed Feb 19 2014 System image file is "flash:c3560-ipbasek9-mz.122-55.SE1.bin" This product contains cryptographic features and is subject to United States and local country laws governing import, export, transfer and use. Delivery of Cisco cryptographic products does not imply third-party authority to import, export, distribute or use encryption. Importers, exporters, distributors and users are responsible for compliance with U.S. and local country laws. By using this product you agree to comply with applicable laws and regulations. If you are unable to comply with U.S. and local laws, return this product immediately. A summary of U.S. laws governing Cisco cryptographic products may be found at: http://www.cisco.com/wwl/export/crypto/tool/stqrg.html If you require further assistance please contact us by sending email to export@cisco.com. cisco WS-C3560-8PC (PowerPC405) processor (revision F0) with 131072K bytes of memory. Processor board ID FOC1449W2ZU Last reset from power-on 2 Virtual Ethernet interfaces 8 FastEthernet interfaces 1 Gigabit Ethernet interface The password-recovery mechanism is enabled. 512K bytes of flash-simulated non-volatile configuration memory. Base ethernet MAC Address : 10:8C:CF:F0:68:80 Motherboard assembly number : 73-10612-09 Power supply part number : 341-0207-02 Motherboard serial number : FOC14493DDW Power supply serial number : LIT14430ZXA Model revision number : F0 Motherboard revision number : A0 Model number : WS-C3560-8PC-S System serial number : FOC1449W2ZU Top Assembly Part Number : 800-28131-04 Top Assembly Revision Number : C0 Version ID : V04 CLEI Code Number : COML900ARA Hardware Board Revision Number : 0x01 Switch Ports Model SW Version SW Image ------ ----- ----- ---------- ---------- * 1 9 WS-C3560-8PC 12.2(55)SE1 C3560-IPBASEK9-M Configuration register is 0xF [fisakytt@lan-login1 ~/projects/oxidized-cli]% cat oxi require 'pry' require 'pp' require 'oxidized' require 'resolv' module Oxidized class Oxi def cmd command @model.cmd command end def disconnect @input.disconnect_cli end alias_method :close, :disconnect private def initialize node Oxidized.mgr = Manager.new @node = Nodes.new(:node=>node).first @model = @node.model @input = nil connect if block_given? yield self disconnect end end def connect @node.input.each do |input| begin @node.model.input = input.new @node.model.input.connect @node break rescue end end @input = @node.model.input @input.connect_cli end end end Oxidized::Oxi.new(ARGV[0]) do |cli| puts cli.cmd ARGV[1] end [fisakytt@lan-login1 ~/projects/oxidized-cli]% ls -la total 12 drwxrwxr-x 2 fisakytt fisakytt 4096 Apr 12 19:39 . drwxrwxr-x 7 fisakytt fisakytt 4096 Apr 12 17:52 .. -rwxr-xr-x 1 fisakytt fisakytt 820 Apr 12 19:39 oxi
-rw-r--r--lib/oxidized/nodes.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb
index b2c3542..8d49443 100644
--- a/lib/oxidized/nodes.rb
+++ b/lib/oxidized/nodes.rb
@@ -5,12 +5,19 @@ module Oxidized
class Nodes < Array
attr_accessor :source
alias :put :unshift
- def load
+ def load node_want=nil
with_lock do
new = []
@source = CFG.source[:default]
Oxidized.mgr.add_source @source
Oxidized.mgr.source[@source].new.load.each do |node|
+
+ # we want to load one specific node(s), not all of them
+ if node_want
+ next unless node[:name].to_s.match(node_want) or
+ node[:ip].to_s.match(node_want)
+ end
+
begin
_node = Node.new node
new.push _node
@@ -70,10 +77,11 @@ module Oxidized
private
- def initialize *args
- super
+ def initialize opts={}
+ super()
+ node = opts.delete :node
@mutex= Mutex.new # we compete for the nodes with webapi thread
- load if args.empty?
+ load node
end
def with_lock &block