diff --git a/Rakefile b/Rakefile index d3dbe53..cac7b1b 100644 --- a/Rakefile +++ b/Rakefile @@ -10,6 +10,9 @@ begin gem.email = "adam@opscode.com" gem.homepage = "http://github.com/opscode/chef-rundeck" gem.authors = ["Adam Jacob"] + gem.add_dependency "sinatra" + gem.add_dependency "chef" + gem.add_dependency "mixlib-cli" gem.add_development_dependency "rspec", ">= 1.2.9" gem.add_development_dependency "yard", ">= 0" # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings @@ -19,15 +22,15 @@ rescue LoadError puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" end -require 'spec/rake/spectask' -Spec::Rake::SpecTask.new(:spec) do |spec| - spec.libs << 'lib' << 'spec' - spec.spec_files = FileList['spec/**/*_spec.rb'] +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.rspec_opts = [ '-I', 'lib', '-I', 'spec' ] + spec.pattern = FileList['spec/**/*_spec.rb'] end -Spec::Rake::SpecTask.new(:rcov) do |spec| - spec.libs << 'lib' << 'spec' - spec.pattern = 'spec/**/*_spec.rb' +RSpec::Core::RakeTask.new(:rcov) do |spec| + spec.rspec_opts = [ '-I', 'lib', '-I', 'spec' ] + spec.pattern = FileList['spec/**/*_spec.rb'] spec.rcov = true end diff --git a/VERSION b/VERSION index 6e8bf73..341cf11 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +0.2.0 \ No newline at end of file diff --git a/bin/chef-rundeck b/bin/chef-rundeck index 5ea22d7..3d8858b 100755 --- a/bin/chef-rundeck +++ b/bin/chef-rundeck @@ -46,6 +46,13 @@ class ChefRundeckCLI :long => "--port PORT", :description => "The port to run on, default 9980", :default => 9980 + + option :env_node_only, + :short => "-e", + :long => "--env-node-only", + :description => "Get nodes and their envs only", + :boolean => true + end cli = ChefRundeckCLI.new @@ -54,6 +61,7 @@ cli.parse_options ChefRundeck.config_file = cli.config[:config_file] ChefRundeck.username = cli.config[:username] ChefRundeck.web_ui_url = cli.config[:web_ui_url] +ChefRundeck.env_node_only = cli.config[:env_node_only] ChefRundeck.configure ChefRundeck.run! :host => 'localhost', :port => cli.config[:port] diff --git a/chef-rundeck.gemspec b/chef-rundeck.gemspec new file mode 100644 index 0000000..8c98205 --- /dev/null +++ b/chef-rundeck.gemspec @@ -0,0 +1,62 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = "chef-rundeck" + s.version = "0.1.0" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Adam Jacob"] + s.date = "2011-11-07" + s.description = "Provides a resource endpoint for RunDeck from a Chef Server" + s.email = "adam@opscode.com" + s.executables = ["chef-rundeck"] + s.extra_rdoc_files = [ + "LICENSE", + "README.rdoc" + ] + s.files = [ + ".document", + "LICENSE", + "NOTICE", + "README.rdoc", + "Rakefile", + "VERSION", + "bin/chef-rundeck", + "lib/chef-rundeck.rb", + "spec/chef-rundeck_spec.rb", + "spec/spec.opts", + "spec/spec_helper.rb" + ] + s.homepage = "http://github.com/opscode/chef-rundeck" + s.require_paths = ["lib"] + s.rubygems_version = "1.8.10" + s.summary = "Integrates Chef with RunDeck" + + if s.respond_to? :specification_version then + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) + s.add_development_dependency(%q, [">= 1.2.9"]) + s.add_development_dependency(%q, [">= 0"]) + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 1.2.9"]) + s.add_dependency(%q, [">= 0"]) + end + else + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 1.2.9"]) + s.add_dependency(%q, [">= 0"]) + end +end + diff --git a/lib/chef-rundeck.rb b/lib/chef-rundeck.rb index 0b30985..8343748 100644 --- a/lib/chef-rundeck.rb +++ b/lib/chef-rundeck.rb @@ -27,6 +27,7 @@ class << self attr_accessor :config_file attr_accessor :username attr_accessor :web_ui_url + attr_accessor :env_node_only def configure Chef::Config.from_file(ChefRundeck.config_file) @@ -34,30 +35,66 @@ def configure end end + set :environment, :production + set :lock, true get '/' do + + content_type 'text/xml' response = '' - Chef::Node.list(true).each do |node_array| - node = node_array[1] - #-- - # Certain features in Rundeck require the osFamily value to be set to 'unix' to work appropriately. - SRK - #++ - os_family = node[:kernel][:os] =~ /windows/i ? 'windows' : 'unix' - response << <<-EOH - + if ChefRundeck.env_node_only + #Get all Chef envs, get all nodes for each env + #Use inflate = false to reduce load time + #Tag nodes with their envs in a hash + #Expand hash into response + node_hash = {} + Chef::Environment.list(false).each do |envr| + Chef::Node.list_by_environment(envr[0], false).each do |node_info| + #print envr[0], "->", node_arr[0], "->", node_arr[1], "\n" + node = node_info[0] + if node_hash.has_key?(node) + node_hash[node] = "#{node_hash[node]} , #{envr[0]}" + else + node_hash[node] = envr[0] + end + end + end + node_hash.sort_by{ |envs, nodes| nodes } + node_hash.each_pair do |nodename, nodeenv| + nodename = xml_escape(nodename) + response << <<-EOH + +EOH + end + response << "" + response + else + Chef::Node.list(true).each do |node_array| + node = node_array[1] + #-- + # Certain features in Rundeck require the osFamily value to be set to 'unix' to work appropriately. - SRK + #++ + os_family = node[:kernel][:os] =~ /windows/i ? 'windows' : 'unix' + response << <<-EOH + EOH + end + response << "" + response end - response << "" - response end end -