loe-iclassify-interface 1.0.12 → 1.0.13

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.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  gem.summary = %Q{Module for interfacing with iclassify.}
9
9
  gem.email = "andrew@andrewloe.com"
10
10
  gem.homepage = "http://github.com/loe/iclassify-interface"
11
- gem.authors = ["W. Andrew Loe III"]
11
+ gem.authors = ["Adam Jacob", "W. Andrew Loe III"]
12
12
  gem.add_dependency("uuidtools", '>= 2.0.0')
13
13
  gem.add_dependency("rake", ">= 0.8.3")
14
14
  gem.add_dependency("launchy")
@@ -53,7 +53,7 @@ Rake::RDocTask.new do |rdoc|
53
53
  end
54
54
 
55
55
  rdoc.rdoc_dir = 'rdoc'
56
- rdoc.title = "icagent2 #{version}"
56
+ rdoc.title = "iclassify-interface #{version}"
57
57
  rdoc.rdoc_files.include('README*')
58
58
  rdoc.rdoc_files.include('lib/**/*.rb')
59
59
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.12
1
+ 1.0.13
data/bin/icpuppet ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # iClassify - A node classification service.
4
+ # Copyright (C) 2007 HJK Solutions and Adam Jacob (<adam@hjksolutions.com>)
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License along
17
+ # with this program; if not, write to the Free Software Foundation, Inc.,
18
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
+ #
20
+ # Puppet node integration; turns an IClassify node into a puppet node.
21
+ #
22
+
23
+ require 'rubygems'
24
+ require File.dirname(__FILE__) + '/../lib/iclassify-interface'
25
+ require 'optparse'
26
+ require 'highline/import'
27
+
28
+ config = {}
29
+ args = ARGV
30
+ opts = OptionParser.new do |opts|
31
+ opts.banner = "Usage: #{$0} [-s server] hostname"
32
+ opts.on("-s SERVER", "--server", "iClassify Server URL") do |s|
33
+ config[:server] = s
34
+ end
35
+ opts.on("-u user", "--user user", "User to authenticate with, defaults to USER env variable") do |u|
36
+ config[:user] = u
37
+ end
38
+ opts.on("-p passwd", "--passwd passwd", "Password to authenticate with") do |p|
39
+ config[:passwd] = p
40
+ end
41
+ opts.on_tail("-h", "--help", "Show this message") do
42
+ puts opts
43
+ exit
44
+ end
45
+ end
46
+ opts.parse!(args)
47
+
48
+ unless args.length == 1
49
+ puts "You must supply a hostname or fqdn. You supplied: "
50
+ puts args.join(" ")
51
+ puts opts.help
52
+ exit 1
53
+ end
54
+
55
+ unless config[:passwd]
56
+ config[:passwd] = HighLine.ask("Password: ") { |q| q.echo = "*" }
57
+ end
58
+
59
+ unless config[:user] && config[:passwd]
60
+ puts "You must provide a username and password."
61
+ puts opts.help
62
+ exit 1
63
+ end
64
+
65
+
66
+ hostname = args[0]
67
+
68
+ client = IClassify::Client.new(config[:server], config[:user], config[:passwd])
69
+ begin
70
+ results = client.search("hostname:#{hostname} OR fqdn:#{hostname}")
71
+ rescue SocketError
72
+ $stderr.puts("Error: Could not connect to server.")
73
+ exit 1
74
+ end
75
+
76
+ if results.length > 1
77
+ STDERR.puts "Hostname #{hostname} has more than one node definition!"
78
+ exit 10
79
+ end
80
+ # FIXME: This should go away when real support for parents/children shows up.
81
+ base_node = client.search("description:\"Base node\"")
82
+ if base_node.length == 1
83
+ base_node[0].tags.each do |tag|
84
+ results[0].tags << tag unless results[0].tags.detect { |t| t == tag }
85
+ end
86
+ end
87
+ results.each do |node|
88
+ puts node.to_puppet
89
+ end
90
+ exit 0
data/bin/icsearch CHANGED
@@ -26,8 +26,6 @@ require 'optparse'
26
26
  require 'highline/import'
27
27
 
28
28
  config = {
29
- :server => 'https://iclassify',
30
- :user => ENV.has_key?('USER') ? ENV['USER'] : 'puppet',
31
29
  :only => nil,
32
30
  :quiet => nil
33
31
  }
@@ -2,13 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{iclassify-interface}
5
- s.version = "1.0.12"
5
+ s.version = "1.0.13"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["W. Andrew Loe III"]
9
- s.date = %q{2009-07-29}
8
+ s.authors = ["Adam Jacob", "W. Andrew Loe III"]
9
+ s.date = %q{2009-08-12}
10
10
  s.email = %q{andrew@andrewloe.com}
11
- s.executables = ["icagent", "icsearch", "icwatcher"]
11
+ s.executables = ["icagent", "icpuppet", "icsearch", "icwatcher"]
12
12
  s.extra_rdoc_files = [
13
13
  "README"
14
14
  ]
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  "Rakefile",
19
19
  "VERSION",
20
20
  "bin/icagent",
21
+ "bin/icpuppet",
21
22
  "bin/icsearch",
22
23
  "bin/icwatcher",
23
24
  "iclassify-interface.gemspec",
data/recipes/02_ec2.rb CHANGED
@@ -1,27 +1,44 @@
1
1
  require 'net/http'
2
2
 
3
- ec2 = false
4
- domain = attrib?('domain')
5
- ec2 = true if domain =~ /(\.amazonaws.com|compute-1.internal)$/
6
-
7
- if ec2
8
- replace_attrib("ec2", "true")
9
- else
10
- replace_attrib("ec2", "false")
11
- end
12
-
13
- def get_from_ec2(thing="/")
14
- base_url = "http://169.254.169.254/latest/meta-data" + thing
3
+ def get_from_ec2(key = '')
4
+ base_url = "http://instance-data.ec2.internal/latest/meta-data/" + key
15
5
  url = URI.parse(base_url)
16
6
  req = Net::HTTP::Get.new(url.path)
17
- res = Net::HTTP.start(url.host, url.port) {|http|
7
+ res = Net::HTTP.start(url.host, url.port) do |http|
18
8
  http.request(req)
19
- }
9
+ end
10
+
20
11
  res.body
21
12
  end
22
13
 
23
- if ec2
24
- get_from_ec2.split("\n").each do |key|
25
- add_attrib("ec2-#{key}", get_from_ec2("/#{key}"))
14
+ def get_keys(key = '')
15
+ keys = get_from_ec2(key).split("\n")
16
+
17
+ keys.inject([]) do |accum, k|
18
+ if k =~ /\/$/
19
+ get_keys(key + k).each do |k|
20
+ accum << k
21
+ end
22
+
23
+ accum
24
+ elsif k =~ /=/
25
+ get_keys(key + $` + '/').each do |k|
26
+ accum << k
27
+ end
28
+
29
+ accum
30
+ else
31
+ accum << key + k
32
+
33
+ accum
34
+ end
26
35
  end
27
36
  end
37
+
38
+ if attrib?('domain') =~ /(\.amazonaws.com|compute-1.internal|ec2.internal)$/
39
+ replace_attrib("ec2", "true")
40
+
41
+ get_keys.each do |key|
42
+ replace_attrib("ec2-#{key.gsub('/', '-')}", get_from_ec2("#{key}"))
43
+ end
44
+ end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loe-iclassify-interface
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
+ - Adam Jacob
7
8
  - W. Andrew Loe III
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-07-29 00:00:00 -07:00
13
+ date: 2009-08-12 00:00:00 -07:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -56,6 +57,7 @@ description:
56
57
  email: andrew@andrewloe.com
57
58
  executables:
58
59
  - icagent
60
+ - icpuppet
59
61
  - icsearch
60
62
  - icwatcher
61
63
  extensions: []
@@ -68,6 +70,7 @@ files:
68
70
  - Rakefile
69
71
  - VERSION
70
72
  - bin/icagent
73
+ - bin/icpuppet
71
74
  - bin/icsearch
72
75
  - bin/icwatcher
73
76
  - iclassify-interface.gemspec