Class: ChefRundeck
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- ChefRundeck
- Includes:
- Chef::Mixin::XMLEscape
- Defined in:
- lib/chef-rundeck.rb
Class Attribute Summary collapse
-
.api_url ⇒ Object
Returns the value of attribute api_url.
-
.client_key ⇒ Object
Returns the value of attribute client_key.
-
.config_file ⇒ Object
Returns the value of attribute config_file.
-
.project_config ⇒ Object
Returns the value of attribute project_config.
-
.username ⇒ Object
Returns the value of attribute username.
-
.web_ui_url ⇒ Object
Returns the value of attribute web_ui_url.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.api_url ⇒ Object
Returns the value of attribute api_url.
40 41 42 |
# File 'lib/chef-rundeck.rb', line 40 def api_url @api_url end |
.client_key ⇒ Object
Returns the value of attribute client_key.
41 42 43 |
# File 'lib/chef-rundeck.rb', line 41 def client_key @client_key end |
.config_file ⇒ Object
Returns the value of attribute config_file.
37 38 39 |
# File 'lib/chef-rundeck.rb', line 37 def config_file @config_file end |
.project_config ⇒ Object
Returns the value of attribute project_config.
42 43 44 |
# File 'lib/chef-rundeck.rb', line 42 def project_config @project_config end |
.username ⇒ Object
Returns the value of attribute username.
38 39 40 |
# File 'lib/chef-rundeck.rb', line 38 def username @username end |
.web_ui_url ⇒ Object
Returns the value of attribute web_ui_url.
39 40 41 |
# File 'lib/chef-rundeck.rb', line 39 def web_ui_url @web_ui_url end |
Class Method Details
.configure ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/chef-rundeck.rb', line 44 def configure Chef::Config.from_file(ChefRundeck.config_file) Chef::Log.level = Chef::Config[:log_level] unless ChefRundeck.api_url ChefRundeck.api_url = Chef::Config[:chef_server_url] end unless ChefRundeck.client_key ChefRundeck.client_key = Chef::Config[:client_key] end if (File.exists?(ChefRundeck.project_config)) then Chef::Log.info("Using JSON project file #{ChefRundeck.project_config}") projects = File.open(ChefRundeck.project_config, "r") { |f| JSON.parse(f.read) } projects.keys.each do | project | get "/#{project}" do content_type 'text/xml' Chef::Log.info("Loading nodes for /#{project}") response = build_project projects[project]['pattern'], projects[project]['username'], (projects[project]['hostname'].nil? ? "fqdn" : projects[project]['hostname']), projects[project]['attributes'] response end end end get '/' do content_type 'text/xml' Chef::Log.info("Loading all nodes for /") response = build_project response end end |
Instance Method Details
#build_project(pattern = "*:*", username = ChefRundeck.username, hostname = "fqdn", custom_attributes = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/chef-rundeck.rb', line 78 def build_project (pattern="*:*", username=ChefRundeck.username, hostname="fqdn", custom_attributes=nil) response = '<?xml version="1.0" encoding="UTF-8"?>' response << '<!DOCTYPE project PUBLIC "-//DTO Labs Inc.//DTD Resources Document 1.0//EN" "project.dtd">' response << '<project>' q = Chef::Search::Query.new q.search("node",pattern) do |node| begin if node_is_valid? node response << build_node(node, username, hostname, custom_attributes) else Chef::Log.warn("invalid node element: #{node.inspect}") end rescue Exception => e Chef::Log.error("=== could not generate xml for Node: #{node.name} - #{e.}") Chef::Log.debug(e.backtrace.join('\n')) end end response << "</project>" Chef::Log.debug(response) return response end |