Permalink
Browse files

Merging iclassify-interface and icagent.

  • Loading branch information...
0 parents commit 148daff9ee205c9f99073a6546a9dba8ad6f0beb @loe committed Jul 23, 2009
Showing with 858 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +31 −0 README
  3. +60 −0 Rakefile
  4. +1 −0 VERSION
  5. +92 −0 bin/icagent
  6. +120 −0 bin/icsearch
  7. +94 −0 bin/icwatcher
  8. +57 −0 iclassify-interface.gemspec
  9. +4 −0 lib/iclassify-interface.rb
  10. +155 −0 lib/iclassify-interface/agent.rb
  11. +108 −0 lib/iclassify-interface/client.rb
  12. +134 −0 lib/iclassify-interface/node.rb
@@ -0,0 +1,2 @@
+.DS_Store
+pkg
31 README
@@ -0,0 +1,31 @@
+= iclassify-interface
+
+http://github.com/loe/iclassify-interface
+
+== DESCRIPTION:
+
+Module for interfacing with iclassify.
+
+== INSTALL:
+
+sudo gem install loe-iclassify-interface
+
+== LICENSE:
+
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Mods:: W. Andrew Loe III (<andrew@andrewloe.com>)
+# Copyright:: Copyright (c) 2007 HJK Solutions, LLC
+# License:: GNU General Public License version 2.1
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2.1
+# as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
@@ -0,0 +1,60 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "iclassify-interface"
+ gem.summary = %Q{TODO}
+ gem.email = "andrew@andrewloe.com"
+ gem.homepage = "http://github.com/loe/iclassify-interface"
+ gem.authors = ["W. Andrew Loe III"]
+ gem.add_dependency("uuidtools", '1.0.7')
+ gem.add_dependency("rake", ">= 0.8.3")
+ gem.add_dependency("launchy")
+ gem.add_dependency("builder")
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ end
+
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/*_test.rb'
+ test.verbose = true
+end
+
+begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/*_test.rb'
+ test.verbose = true
+ end
+rescue LoadError
+ task :rcov do
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
+ end
+end
+
+
+task :default => :test
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ if File.exist?('VERSION.yml')
+ config = YAML.load(File.read('VERSION.yml'))
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
+ else
+ version = ""
+ end
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "icagent2 #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
@@ -0,0 +1 @@
+1.0.6
@@ -0,0 +1,92 @@
+#!/usr/bin/env ruby
+#
+# iClassify - A node classification service.
+# Copyright (C) 2007 HJK Solutions and Adam Jacob (<adam@hjksolutions.com>)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# icagent registers a node with iclassify, and lets you use small DSL for
+# classifiying them.
+
+require 'rubygems'
+require File.dirname(__FILE__) + '/../lib/iclassify'
+require 'optparse'
+
+config = {
+ :uuidfile => '/etc/icagent/icagent.uuid',
+ :directory => File.dirname(__FILE__) + '/../recipes'
+}
+
+opts = OptionParser.new do |opts|
+ opts.banner = "Usage: #{$0} [-d DIR|-r FILE] (options)"
+ opts.on("-d DIRECTORY", "--directory DIRECTORY", "Path to icagent recipes") do |d|
+ config[:directory] = d
+ end
+ opts.on("-r RECIPE", "--recipe RECIPE", "Path to a single icagent recipe") do |r|
+ config[:recipe] = r
+ end
+ opts.on("-u UUIDFILE", "--uuidfile UUIDFILE", "Path to the uuid file") do |u|
+ config[:uuidfile] = u
+ end
+ opts.on("-s SERVER", "--server", "iClassify Server URL") do |s|
+ config[:server] = s
+ end
+ opts.on("-n", "--no-action", "Don't update anything, just print.") do |n|
+ config[:dryrun] = true
+ end
+ opts.on("-w WAIT", "--wait TIME", "Wait for up to TIME seconds.") do |w|
+ config[:wait] = w.to_i
+ end
+ opts.on_tail("-h", "--help", "Show this message") do
+ puts opts
+ exit
+ end
+end
+opts.parse!(ARGV)
+
+unless config.has_key?(:recipe) || config.has_key?(:directory)
+ puts "You must specify either a recipe (-r) or a directory (-d)"
+ puts opts
+ exit
+end
+
+if config.has_key?(:wait)
+ splay = rand(config[:wait])
+ sleep(splay)
+end
+
+agent = IClassify::Agent.new(config[:uuidfile], config[:server])
+begin
+ agent.load
+rescue SocketError
+ $stderr.puts("Error: Cannot connect to server.")
+ exit 1
+end
+
+if config.has_key?(:recipe)
+ agent.run_script(File.expand_path(config[:recipe]))
+end
+if config.has_key?(:directory)
+ Dir.glob(File.join(File.expand_path(config[:directory]), '*.rb')).sort.each do |file|
+ if File.file?(file)
+ agent.run_script(file)
+ end
+ end
+end
+if config.has_key?(:dryrun) && config[:dryrun]
+ puts agent.to_s
+else
+ agent.update
+end
@@ -0,0 +1,120 @@
+#!/usr/bin/env ruby
+#
+# iClassify - A node classification service.
+# Copyright (C) 2007 HJK Solutions and Adam Jacob (<adam@hjksolutions.com>)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# A very simple search utility for iclassify.
+#
+
+require 'rubygems'
+require File.dirname(__FILE__) + '/../lib/iclassify'
+require 'optparse'
+require 'highline/import'
+
+config = {
+ :server => 'https://iclassify',
+ :user => ENV.has_key?('USER') ? ENV['USER'] : 'puppet',
+ :only => nil,
+ :quiet => nil
+}
+opts = OptionParser.new do |opts|
+ opts.banner = "Usage: #{$0} (options) query"
+ opts.on("-a one,two,three", "--attrib one,two,three", Array, "Attributes to print") do |a|
+ config[:attribs] = a
+ end
+ opts.on("-t", "--tags", "Print tags or not, if attribs specified") do |t|
+ config[:tags] = t
+ end
+ opts.on("-u user", "--user user", "User to authenticate with, defaults to USER env variable") do |u|
+ config[:user] = u
+ end
+ opts.on("-p passwd", "--passwd passwd", "Password to authenticate with") do |p|
+ config[:passwd] = p
+ end
+ opts.on("-s server", "--server server", "iClassify Server URL") do |s|
+ config[:server] = s
+ end
+ opts.on("-o", "--only", "Print only the attributes specified on the command line") do |o|
+ config[:only] = o
+ end
+ opts.on("-q", "--quiet", "Do not print the header") do |q|
+ config[:quiet] = q
+ end
+ opts.on_tail("-h", "--help", "Show this message") do
+ puts opts
+ exit
+ end
+end
+args = ARGV
+opts.parse!(args)
+
+if args.length != 1
+ puts "You must specify a single query."
+ puts opts.help
+ exit 1
+end
+
+unless config[:passwd]
+ config[:passwd] = HighLine.ask("Password: ") { |q| q.echo = "*" }
+end
+
+unless config[:user] && config[:passwd]
+ puts "You must provide a username and password."
+ puts opts.help
+ exit 1
+end
+
+query = args[0]
+
+client = IClassify::Client.new(config[:server], config[:user], config[:passwd])
+begin
+ results = client.search(query, config[:attribs] ? config[:attribs] : [])
+rescue SocketError
+ $stderr.puts("Error: Could not connect to server.")
+ exit 1
+end
+
+if config.has_key?(:attribs)
+ header = "# "
+ if config[:only]
+ header += "#{config[:attribs].join(',')}"
+ else
+ header += "description,uuid,#{config[:attribs].join(',')}"
+ end
+ header << ",tags" if config.has_key?(:tags)
+ puts header unless config[:quiet]
+ results.each do |node|
+ line = Array.new
+ line << "#{node.description}" unless config[:only]
+ line << "#{node.uuid}" unless config[:only]
+ config[:attribs].each do |attrib|
+ na = node.attribs.detect { |a| a[:name] == attrib }
+ if na
+ line << "#{na[:values].join(':')}"
+ else
+ line << ""
+ end
+ end
+ line << "\"#{node.tags.join(' ')}\"" if config.has_key?(:tags)
+ puts line.join(",")
+ end
+else
+ results.each do |node|
+ puts "#\n# Node #{node.uuid}\n#"
+ puts node.to_s
+ end
+end
Oops, something went wrong.

0 comments on commit 148daff

Please sign in to comment.