corona 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e49adab5f337e985451474bbe92fafb21843669
4
- data.tar.gz: db98d73fb163e1b7ade57187f6d1b13fcc0bdd4b
3
+ metadata.gz: b8a730fb90e6e3cb07e7ec195ecac7473a40a2fd
4
+ data.tar.gz: 3f8d44209ae05c40c6276f6f241a3252842ee4c4
5
5
  SHA512:
6
- metadata.gz: f3135206c5e6c516028e6c7eb7a0a24d97418d7da354d89bac8567786318c576eb6616111ba545fa0c1afe74e17a807baea64a31d3c8bb6bf8b55bc9525f716c
7
- data.tar.gz: ba8bac0dfb90302c83bc07d6ce06bc23e8c96c824fe6a5793629b4b9ea93b93e99deccc2cca8380f2188c36886b05c4599e805030e51ec5c73add8c62732921c
6
+ metadata.gz: f44d1f153235dff6f0da01527abde190c4ee2591e2f44ea0e3f08072c653d0928dd156ea1ec065d559955277bd5a5401524eb264c1109948b080cd950977d857
7
+ data.tar.gz: 010693ac9b69c6691f707ecb8cbe5534a0709413238a95f420ce7ff5cfe5da3ef01df649296075a76099ea0292205113633fce0a0023af822286b8bcbc581695
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- corona (0.0.8)
4
+ corona (0.0.9)
5
5
  sequel
6
6
  slop
7
7
  snmp
data/corona.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'corona'
3
- s.version = '0.0.8'
3
+ s.version = '0.0.9'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ 'Saku Ytti' ]
6
6
  s.email = %w( saku@ytti.fi )
data/lib/corona/cli.rb CHANGED
@@ -1,27 +1,57 @@
1
1
  module Corona
2
2
  class CLI
3
+ MAX_DELETE = 1
3
4
  require 'corona'
4
5
  require 'slop'
5
6
 
6
- def run cidr=@cidr
7
- Corona.new :cidr=>cidr
7
+ def run
8
+ if @opts[:poll]
9
+ Corona.new :cidr=>@opts[:poll]
10
+ elsif @opts[:remove]
11
+ remove_from_db @opts[:remove]
12
+ else
13
+ Corona.new
14
+ end
8
15
  end
9
16
 
10
17
  private
11
18
 
12
19
  def initialize
13
- args, opts = opts_parse
14
- @cidr = args.shift
15
- CFG.debug = true if opts[:debug]
20
+ args, @opts = opts_parse
21
+ @arg = args.shift
22
+ CFG.debug = true if @opts[:debug]
16
23
  end
17
24
 
18
25
  def opts_parse
19
26
  opts = Slop.parse(:help=>true) do
20
- banner 'Usage: corona [cidr]'
21
- on 'd', 'debug', 'Debugging on'
27
+ banner 'Usage: corona [options] [argument]'
28
+ on 'd', 'debug', 'Debugging on'
29
+ on 'p=', 'poll', 'Poll CIDR [argument]'
30
+ on 'r=', 'remove', 'Remove [argument] from DB'
31
+ on 'm=', 'max-delete', "Maximum number to detel, default #{MAX_DELETE}"
32
+ on 's', 'simulate', 'Simulate, do not change DB'
22
33
  end
23
34
  [opts.parse!, opts]
24
35
  end
25
36
 
37
+ def remove_from_db name
38
+ max_del = @opts['max-delete'] ? @opts['max-delete'] : MAX_DELETE
39
+ DB.new
40
+ devs = DB::Device.filter(Sequel.like(:ptr, "%#{name}%")).all
41
+ if devs.size > max_del.to_i
42
+ puts 'Too many matching devices:'
43
+ devs.each do |dev|
44
+ puts ' %s (%s)' % [dev.ptr, dev.ip]
45
+ end
46
+ puts 'Be more specific'
47
+ else
48
+ puts 'Deleting records:'
49
+ devs.each do |dev|
50
+ puts ' %s (%s)' % [dev.ptr, dev.ip]
51
+ dev.delete unless @opts[:simulate]
52
+ end
53
+ end
54
+ end
55
+
26
56
  end
27
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel