rubiojr-chef_knives 0.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,11 @@
1
- === 1.0.0 / 2009-09-09
1
+ === 0.3 / 2009-11-09
2
2
 
3
- * 1 major enhancement
3
+ * chef_node_find script added
4
4
 
5
- * Birthday!
5
+ === 0.2 / 2009-10-09
6
6
 
7
+ * chef_node_stats script added
8
+
9
+ === 0.1 / 2009-09-09
10
+
11
+ * initial release
data/Manifest.txt CHANGED
@@ -2,6 +2,9 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
+ bin/chef_node_find
5
6
  bin/chef_node_fs_usage
6
7
  bin/chef_node_mem_usage
8
+ bin/chef_node_stats
9
+ chef_knives.gemspec
7
10
  lib/chef/knives.rb
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'couchrest'
4
+ require 'chef'
5
+ require 'choice'
6
+ require 'pp'
7
+
8
+ CHEF_DB_URL = 'http://localhost:5984/chef'
9
+
10
+ def humanize_bytes(bytes)
11
+ return "0 Bytes" if bytes == 0
12
+ m = bytes.to_i
13
+ units = %w[Bits Bytes MB GB TB PB]
14
+ while (m/1024.0) >= 1
15
+ m = m/1024.0
16
+ units.shift
17
+ end
18
+ return m.round.to_s + " #{units[0]}"
19
+ end
20
+
21
+ def main
22
+ Choice.options do
23
+ header ''
24
+ header 'Available options:'
25
+
26
+ option :help do
27
+ long '--help'
28
+ short '-h'
29
+ desc 'Show this message'
30
+ action do
31
+ Choice.help
32
+ exit
33
+ end
34
+ end
35
+
36
+ option :match do
37
+ default '.*'
38
+ long '--match'
39
+ short '-m'
40
+ desc 'Match only the nodes with an FQDN matching this value'
41
+ end
42
+ end
43
+
44
+ db = CouchRest.database(CHEF_DB_URL)
45
+
46
+ db.documents['rows'].each do |doc|
47
+ if doc['id'] =~ /node_/
48
+ node = db.get(doc['id'])
49
+ next if node.fqdn !~ /#{Choice.choices[:match]}/
50
+ plat = node.platform+node.platform_version
51
+ fqdn = node.fqdn
52
+ puts fqdn
53
+ puts "-------------"
54
+ puts "Platform: " + plat
55
+ puts "Uptime: " + node.uptime
56
+ puts "Memory Total: " + humanize_bytes(node.memory.total.gsub('kB','').to_i * 1024)
57
+ puts "Memory Free: " + humanize_bytes(node.memory.free.gsub('kB','').to_i * 1024)
58
+ puts "Network Interfaces: "
59
+ puts "Is a Virtual Machine?: #{(node.virtualization.role == 'guest') rescue false}"
60
+ node.network.interfaces.each_key do |iface|
61
+ next unless node.network.interfaces[iface][:addresses]
62
+ puts " #{iface}"
63
+ node.network.interfaces[iface].addresses.each_key do |a|
64
+ print " #{a}".ljust(30)
65
+ puts " [#{node.network.interfaces[iface].addresses[a].family}]"
66
+ end
67
+ end
68
+ puts
69
+ end
70
+ end
71
+ end
72
+
73
+ main
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'couchrest'
4
+ require 'chef'
5
+ require 'choice'
6
+ require 'pp'
7
+
8
+ CHEF_DB_URL = 'http://localhost:5984/chef'
9
+
10
+ def main
11
+ Choice.options do
12
+ header ''
13
+ header 'Available options:'
14
+
15
+ option :help do
16
+ long '--help'
17
+ short '-h'
18
+ desc 'Show this message'
19
+ action do
20
+ Choice.help
21
+ exit
22
+ end
23
+ end
24
+
25
+ option :match do
26
+ default '.*'
27
+ long '--match'
28
+ short '-m'
29
+ desc 'Match only the nodes with an FQDN matching this value'
30
+ end
31
+ end
32
+
33
+ db = CouchRest.database(CHEF_DB_URL)
34
+
35
+ counter = 0
36
+ platforms = {}
37
+ vguests = 0
38
+ phynodes = 0
39
+ virt_hosts = 0
40
+ db.documents['rows'].each do |doc|
41
+ if doc['id'] =~ /node_/
42
+ node = db.get(doc['id'])
43
+ next if node.fqdn !~ /#{Choice.choices[:match]}/
44
+ plat = node.platform+node.platform_version
45
+ platforms[plat] = 0 if platforms[plat].nil?
46
+ platforms[plat] += 1
47
+ if node.virtualization and node.virtualization['role'] == 'guest'
48
+ vguests += 1
49
+ end
50
+ if node.virtualization['role'] == 'host'
51
+ virt_hosts += 1
52
+ end
53
+ if node.virtualization.empty?
54
+ phynodes += 1
55
+ end
56
+ counter += 1
57
+ end
58
+ end
59
+ puts "Chef Server Stats"
60
+ puts "------------------"
61
+ puts "Registered Nodes:".ljust(30) + counter.to_s
62
+ puts " Virtual Nodes (Guests):".ljust(30) + vguests.to_s
63
+ puts " Host Nodes:".ljust(30) + virt_hosts.to_s
64
+ puts " Physical Nodes:".ljust(30) + phynodes.to_s
65
+ puts "Nodes by platform:"
66
+ platforms.each do |p,count|
67
+ puts " #{p}: #{count}"
68
+ end
69
+
70
+ end
71
+
72
+ main
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{chef_knives}
3
+ s.version = "0.3"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Sergio Rubio"]
7
+ s.date = %q{2009-09-11}
8
+ s.description = %q{Unofficial Chef Server scripts and related stuff. http://wiki.opscode.com/display/chef}
9
+ s.email = ["sergio@rubio.name"]
10
+ s.executables = ["chef_node_find", "chef_node_fs_usage", "chef_node_mem_usage", "chef_node_stats"]
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"]
13
+ s.homepage = %q{http://github.com/rubiojr/chef-knives}
14
+ s.rdoc_options = ["--main", "README.txt"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{chef_knives}
17
+ s.rubygems_version = %q{1.3.3}
18
+ s.summary = %q{Chef addons to become a cooking master!}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
26
+ else
27
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
28
+ end
29
+ else
30
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
31
+ end
32
+ end
data/lib/chef/knives.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Chef
2
2
  module Knives
3
- VERSION = '0.1'
3
+ VERSION = '0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubiojr-chef_knives
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Rubio
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-09 00:00:00 -07:00
12
+ date: 2009-09-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -26,8 +26,10 @@ description: Unofficial Chef Server scripts and related stuff. http://wiki.opsco
26
26
  email:
27
27
  - sergio@rubio.name
28
28
  executables:
29
+ - chef_node_find
29
30
  - chef_node_fs_usage
30
31
  - chef_node_mem_usage
32
+ - chef_node_stats
31
33
  extensions: []
32
34
 
33
35
  extra_rdoc_files:
@@ -39,11 +41,15 @@ files:
39
41
  - Manifest.txt
40
42
  - README.txt
41
43
  - Rakefile
44
+ - bin/chef_node_find
42
45
  - bin/chef_node_fs_usage
43
46
  - bin/chef_node_mem_usage
47
+ - bin/chef_node_stats
48
+ - chef_knives.gemspec
44
49
  - lib/chef/knives.rb
45
50
  has_rdoc: false
46
51
  homepage: http://github.com/rubiojr/chef-knives
52
+ licenses:
47
53
  post_install_message:
48
54
  rdoc_options:
49
55
  - --main
@@ -65,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
71
  requirements: []
66
72
 
67
73
  rubyforge_project: chef_knives
68
- rubygems_version: 1.2.0
74
+ rubygems_version: 1.3.5
69
75
  signing_key:
70
76
  specification_version: 3
71
77
  summary: Chef addons to become a cooking master!