diff options
author | Nuo Yan <nuo@opscode.com> | 2011-04-08 13:16:49 -0700 |
---|---|---|
committer | Nuo Yan <nuo@opscode.com> | 2011-04-08 13:16:49 -0700 |
commit | 9fdb0a1ee93ae878448cc0fced0b17b730e0efba (patch) | |
tree | 9230e89edeb3d2e7fa3d5e3c3d47d3fc856844cc | |
parent | fc38476b914472bf6feedd5da132ed578495f3ab (diff) | |
download | chef-9fdb0a1ee93ae878448cc0fced0b17b730e0efba.tar.gz |
Fix node/client/role bulk delete
-rw-r--r-- | chef/lib/chef/api_client.rb | 71 | ||||
-rw-r--r-- | chef/lib/chef/node.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/role.rb | 1 |
3 files changed, 38 insertions, 35 deletions
diff --git a/chef/lib/chef/api_client.rb b/chef/lib/chef/api_client.rb index a202bccb27..148090d7be 100644 --- a/chef/lib/chef/api_client.rb +++ b/chef/lib/chef/api_client.rb @@ -7,9 +7,9 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,22 +25,23 @@ require 'chef/certificate' require 'chef/index_queue' require 'chef/mash' require 'chef/json_compat' +require 'chef/search/query' class Chef - class ApiClient - + class ApiClient + include Chef::Mixin::FromFile include Chef::Mixin::ParamsValidate include Chef::IndexQueue::Indexable - - + + DESIGN_DOCUMENT = { "version" => 1, "language" => "javascript", "views" => { "all" => { "map" => <<-EOJS - function(doc) { + function(doc) { if (doc.chef_type == "client") { emit(doc.name, doc); } @@ -49,7 +50,7 @@ class Chef }, "all_id" => { "map" => <<-EOJS - function(doc) { + function(doc) { if (doc.chef_type == "client") { emit(doc.name, doc.name); } @@ -60,10 +61,10 @@ class Chef } attr_accessor :couchdb_rev, :couchdb_id, :couchdb - + # Create a new Chef::ApiClient object. def initialize(couchdb=nil) - @name = '' + @name = '' @public_key = nil @private_key = nil @couchdb_rev = nil @@ -76,7 +77,7 @@ class Chef # # @params [Optional String] The name must be alpha-numeric plus - and _. # @return [String] The current value of the name. - def name(arg=nil) + def name(arg=nil) set_or_return( :name, arg, @@ -84,7 +85,7 @@ class Chef ) end - # Gets or sets whether this client is an admin. + # Gets or sets whether this client is an admin. # # @params [Optional True/False] Should be true or false - default is false. # @return [True/False] The current value @@ -97,10 +98,10 @@ class Chef end # Gets or sets the public key. - # - # @params [Optional String] The string representation of the public key. + # + # @params [Optional String] The string representation of the public key. # @return [String] The current value. - def public_key(arg=nil) + def public_key(arg=nil) set_or_return( :public_key, arg, @@ -109,10 +110,10 @@ class Chef end # Gets or sets the private key. - # + # # @params [Optional String] The string representation of the private key. # @return [String] The current value. - def private_key(arg=nil) + def private_key(arg=nil) set_or_return( :private_key, arg, @@ -122,7 +123,7 @@ class Chef # Creates a new public/private key pair, and populates the public_key and # private_key attributes. - # + # # @return [True] def create_keys results = Chef::Certificate.gen_keypair(self.name) @@ -133,7 +134,7 @@ class Chef # The hash representation of the object. Includes the name and public_key, # but never the private key. - # + # # @return [Hash] def to_hash result = { @@ -148,12 +149,12 @@ class Chef end # The JSON representation of the object. - # + # # @return [String] the JSON string. def to_json(*a) to_hash.to_json(*a) end - + def self.json_create(o) client = Chef::ApiClient.new client.name(o["name"] || o["clientname"]) @@ -164,7 +165,7 @@ class Chef client.index_id = client.couchdb_id client end - + # List all the Chef::ApiClient objects in the CouchDB. If inflate is set # to true, you will get the full list of all ApiClients, fully inflated. def self.cdb_list(inflate=false, couchdb=nil) @@ -172,7 +173,7 @@ class Chef lookup = (inflate ? "value" : "key") rs["rows"].collect { |r| r[lookup] } end - + def self.list(inflate=false) if inflate response = Hash.new @@ -185,15 +186,15 @@ class Chef Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("clients") end end - + # Load a client by name from CouchDB - # + # # @params [String] The name of the client to load # @return [Chef::ApiClient] The resulting Chef::ApiClient object def self.cdb_load(name, couchdb=nil) (couchdb || Chef::CouchDB.new).load("client", name) end - + # Load a client by name via the API def self.load(name) response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("clients/#{name}") @@ -205,7 +206,7 @@ class Chef client end end - + # Remove this client from the CouchDB # # @params [String] The name of the client to delete @@ -213,17 +214,17 @@ class Chef def cdb_destroy @couchdb.delete("client", @name, @couchdb_rev) end - + # Remove this client via the REST API def destroy Chef::REST.new(Chef::Config[:chef_server_url]).delete_rest("clients/#{@name}") end - + # Save this client to the CouchDB def cdb_save @couchdb_rev = @couchdb.store("client", @name, self)["rev"] end - + # Save this client via the REST API, returns a hash including the private key def save(new_key=false, validation=false) if validation @@ -237,23 +238,23 @@ class Chef rescue Net::HTTPServerException => e # If that fails, go ahead and try and update it if e.response.code == "409" - r.put_rest("clients/#{name}", { :name => self.name, :admin => self.admin, :private_key => new_key }) + r.put_rest("clients/#{name}", { :name => self.name, :admin => self.admin, :private_key => new_key }) else raise e end end - end - + end + # Create the client via the REST API def create Chef::REST.new(Chef::Config[:chef_server_url]).post_rest("clients", self) end - + # Set up our CouchDB design document def self.create_design_document(couchdb=nil) (couchdb ||= Chef::CouchDB.new).create_design_document("clients", DESIGN_DOCUMENT) end - + # As a string def to_s "client[#{@name}]" diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb index 4399e97616..68cf553f6b 100644 --- a/chef/lib/chef/node.rb +++ b/chef/lib/chef/node.rb @@ -36,6 +36,7 @@ require 'chef/node/attribute' require 'chef/index_queue' require 'chef/mash' require 'chef/json_compat' +require 'chef/search/query' class Chef class Node diff --git a/chef/lib/chef/role.rb b/chef/lib/chef/role.rb index 48c5cf074a..18d293d0b2 100644 --- a/chef/lib/chef/role.rb +++ b/chef/lib/chef/role.rb @@ -26,6 +26,7 @@ require 'chef/run_list' require 'chef/index_queue' require 'chef/mash' require 'chef/json_compat' +require 'chef/search/query' class Chef class Role |