chef_knives 0.3.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -3
- data/Manifest.txt +1 -0
- data/README.txt +1 -0
- data/Rakefile +5 -0
- data/bin/chef_vlan_stats +86 -0
- data/chef_knives.gemspec +19 -4
- data/lib/chef/knives.rb +1 -1
- metadata +54 -2
data/History.txt
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
=== 0.
|
1
|
+
=== 0.4 / 2009-14-09
|
2
|
+
|
3
|
+
* added chef_vlan_stats command
|
4
|
+
|
5
|
+
=== 0.3.3 / 2009-11-09
|
2
6
|
|
3
7
|
* fixes in chef_node_find
|
4
8
|
* added --no-ifaces flag to chef_node_find
|
5
9
|
|
6
|
-
=== 0.3.2 / 2009-11-
|
10
|
+
=== 0.3.2 / 2009-11-09
|
7
11
|
|
8
12
|
* fixes in chef_node_fs_usage
|
9
13
|
|
10
|
-
=== 0.3.1 / 2009-11-
|
14
|
+
=== 0.3.1 / 2009-11-09
|
11
15
|
|
12
16
|
* fixes in chef_node_fs_usage
|
13
17
|
|
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
data/Rakefile
CHANGED
@@ -9,6 +9,11 @@ Hoe.new('chef_knives', Chef::Knives::VERSION) do |p|
|
|
9
9
|
p.summary = 'Chef addons to become a cooking master!'
|
10
10
|
p.description = 'Unofficial Chef Server scripts and related stuff. http://wiki.opscode.com/display/chef'
|
11
11
|
p.url = 'http://github.com/rubiojr/chef-knives'
|
12
|
+
p.extra_deps << [ 'ip' ]
|
13
|
+
p.extra_deps << [ 'choice' ]
|
14
|
+
p.extra_deps << [ 'chef', '= 0.7.10' ]
|
15
|
+
p.extra_deps << [ 'json' ]
|
16
|
+
p.extra_deps << [ 'couchrest' ]
|
12
17
|
end
|
13
18
|
|
14
19
|
# vim: syntax=Ruby
|
data/bin/chef_vlan_stats
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'couchrest'
|
4
|
+
require 'chef'
|
5
|
+
require 'choice'
|
6
|
+
require 'pp'
|
7
|
+
require 'ip'
|
8
|
+
|
9
|
+
CHEF_DB_URL = 'http://localhost:5984/chef'
|
10
|
+
CONFIG_FILE = File.expand_path('~/.chef_knives')
|
11
|
+
|
12
|
+
begin
|
13
|
+
CONFIG = YAML.load_file(CONFIG_FILE)
|
14
|
+
rescue Exception => e
|
15
|
+
$stderr.puts "Error reading config file #{CONFIG_FILE}"
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def guess_vlan(addr)
|
20
|
+
if not CONFIG.has_key?('vlan_mapping')
|
21
|
+
$stderr.puts 'No vlan_mapping defined in config file'
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
mapping = CONFIG['vlan_mapping']
|
25
|
+
mapping.each do |k, v|
|
26
|
+
cidr = IP::CIDR.new v
|
27
|
+
if cidr.includes? IP::Address::IPv4.parse(addr.strip.chomp)
|
28
|
+
return k
|
29
|
+
end
|
30
|
+
end
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def main
|
35
|
+
Choice.options do
|
36
|
+
header ''
|
37
|
+
header 'Available options:'
|
38
|
+
|
39
|
+
option :help do
|
40
|
+
long '--help'
|
41
|
+
short '-h'
|
42
|
+
desc 'Show this message'
|
43
|
+
action do
|
44
|
+
Choice.help
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
db = CouchRest.database(CHEF_DB_URL)
|
52
|
+
|
53
|
+
stats = {}
|
54
|
+
db.documents['rows'].each do |doc|
|
55
|
+
if doc['id'] =~ /node_/
|
56
|
+
node = db.get(doc['id'])
|
57
|
+
node.network.interfaces.each_key do |iface|
|
58
|
+
next if not node.network.interfaces[iface].keys.include? 'addresses'
|
59
|
+
node.network.interfaces[iface].addresses.each do |addr|
|
60
|
+
next if (addr[1]['family'] != 'inet') or (addr[0] == '127.0.0.1')
|
61
|
+
ip, mask = addr[0], addr[1]['netmask']
|
62
|
+
vlan = guess_vlan(ip) || 'none'
|
63
|
+
stats[vlan] = [] if stats[vlan].nil?
|
64
|
+
stats[vlan] << "#{ip}/#{mask}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
puts "Chef VLAN Stats"
|
70
|
+
puts "------------------"
|
71
|
+
puts "VLANs Registered: #{stats.keys.size}"
|
72
|
+
puts "VLAN Usage:"
|
73
|
+
stats.each do |k, v|
|
74
|
+
vlan_size = 0
|
75
|
+
cidr = IP::CIDR.new(v[0])
|
76
|
+
vlan_size = cidr.range.size
|
77
|
+
percent_used = (100 * (stats[k].size + 2))/vlan_size
|
78
|
+
puts " VLAN #{k}:".ljust(15) + "#{stats[k].size} Assigned, #{vlan_size - 2 - stats[k].size} Free".ljust(25) + "(#{percent_used}% Used)"
|
79
|
+
end
|
80
|
+
puts "IPs from Unknown VLAN:"
|
81
|
+
stats['none'].each do |addr|
|
82
|
+
puts " #{addr}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
main
|
data/chef_knives.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{chef_knives}
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.4"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Sergio Rubio"]
|
7
|
-
s.date = %q{2009-09-
|
7
|
+
s.date = %q{2009-09-14}
|
8
8
|
s.description = %q{Unofficial Chef Server scripts and related stuff. http://wiki.opscode.com/display/chef}
|
9
9
|
s.email = ["sergio@rubio.name"]
|
10
|
-
s.executables = ["chef_node_find", "chef_node_fs_usage", "chef_node_mem_usage", "chef_node_stats"]
|
10
|
+
s.executables = ["chef_node_find", "chef_node_fs_usage", "chef_node_mem_usage", "chef_node_stats", "chef_vlan_stats"]
|
11
11
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
12
|
-
s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/chef_node_find", "bin/chef_node_fs_usage", "bin/chef_node_mem_usage", "bin/chef_node_stats", "chef_knives.gemspec", "lib/chef/knives.rb"]
|
12
|
+
s.files = ["AUTHORS", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/chef_node_find", "bin/chef_node_fs_usage", "bin/chef_node_mem_usage", "bin/chef_node_stats", "bin/chef_vlan_stats", "chef_knives.gemspec", "lib/chef/knives.rb"]
|
13
13
|
s.homepage = %q{http://github.com/rubiojr/chef-knives}
|
14
14
|
s.rdoc_options = ["--main", "README.txt"]
|
15
15
|
s.require_paths = ["lib"]
|
@@ -22,11 +22,26 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.specification_version = 3
|
23
23
|
|
24
24
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
25
|
+
s.add_runtime_dependency(%q<ip>, [">= 0"])
|
26
|
+
s.add_runtime_dependency(%q<choice>, [">= 0"])
|
27
|
+
s.add_runtime_dependency(%q<chef>, ["= 0.7.10"])
|
28
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
29
|
+
s.add_runtime_dependency(%q<couchrest>, [">= 0"])
|
25
30
|
s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
|
26
31
|
else
|
32
|
+
s.add_dependency(%q<ip>, [">= 0"])
|
33
|
+
s.add_dependency(%q<choice>, [">= 0"])
|
34
|
+
s.add_dependency(%q<chef>, ["= 0.7.10"])
|
35
|
+
s.add_dependency(%q<json>, [">= 0"])
|
36
|
+
s.add_dependency(%q<couchrest>, [">= 0"])
|
27
37
|
s.add_dependency(%q<hoe>, [">= 2.3.3"])
|
28
38
|
end
|
29
39
|
else
|
40
|
+
s.add_dependency(%q<ip>, [">= 0"])
|
41
|
+
s.add_dependency(%q<choice>, [">= 0"])
|
42
|
+
s.add_dependency(%q<chef>, ["= 0.7.10"])
|
43
|
+
s.add_dependency(%q<json>, [">= 0"])
|
44
|
+
s.add_dependency(%q<couchrest>, [">= 0"])
|
30
45
|
s.add_dependency(%q<hoe>, [">= 2.3.3"])
|
31
46
|
end
|
32
47
|
end
|
data/lib/chef/knives.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef_knives
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.4"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Rubio
|
@@ -9,9 +9,59 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-14 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ip
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: choice
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: chef
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.7.10
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: json
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: couchrest
|
57
|
+
type: :runtime
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
15
65
|
- !ruby/object:Gem::Dependency
|
16
66
|
name: hoe
|
17
67
|
type: :development
|
@@ -30,6 +80,7 @@ executables:
|
|
30
80
|
- chef_node_fs_usage
|
31
81
|
- chef_node_mem_usage
|
32
82
|
- chef_node_stats
|
83
|
+
- chef_vlan_stats
|
33
84
|
extensions: []
|
34
85
|
|
35
86
|
extra_rdoc_files:
|
@@ -46,6 +97,7 @@ files:
|
|
46
97
|
- bin/chef_node_fs_usage
|
47
98
|
- bin/chef_node_mem_usage
|
48
99
|
- bin/chef_node_stats
|
100
|
+
- bin/chef_vlan_stats
|
49
101
|
- chef_knives.gemspec
|
50
102
|
- lib/chef/knives.rb
|
51
103
|
has_rdoc: true
|