summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2010-06-16 17:06:04 -0700
committerDaniel DeLeo <dan@opscode.com>2010-06-16 17:06:04 -0700
commit43327f7c7d665e1b92a7c436fe0ee4bdf583fbce (patch)
treed8367c24a5d64eb622899f033bb3e3762fa89d7d
parent24993907701f35a8ff177478901de26c4f083a3d (diff)
parentd22559abfc8240c2033e1343ae7cdee6fccdac5a (diff)
downloadchef-43327f7c7d665e1b92a7c436fe0ee4bdf583fbce.tar.gz
Merge branch 'PL-502'
-rw-r--r--chef/distro/common/man/man8/knife.88
-rw-r--r--chef/distro/common/markdown/knife.mkd6
-rw-r--r--chef/lib/chef/couchdb.rb6
-rw-r--r--chef/lib/chef/knife/cookbook_bulk_delete.rb13
-rw-r--r--chef/lib/chef/knife/cookbook_delete.rb14
5 files changed, 35 insertions, 12 deletions
diff --git a/chef/distro/common/man/man8/knife.8 b/chef/distro/common/man/man8/knife.8
index 8c07ee7f36..8dc9e7b75e 100644
--- a/chef/distro/common/man/man8/knife.8
+++ b/chef/distro/common/man/man8/knife.8
@@ -252,6 +252,10 @@ Cookbooks are the fundamental unit of distribution in Chef. They encapsulate all
.P
\fBcookbook bulk delete REGEX\fR \fI(options)\fR
.
+.TP
+\fB\-p\fR, \fB\-\-purge\fR
+Purge files from backing store. This will disable any cookbook that contains any of the same files as the cookbook being purged.
+.
.P
Delete cookbooks on the Chef Server based on a regular expression. The regular expression (\fIREGEX\fR) should be in quotes, not in //'s.
.
@@ -262,6 +266,10 @@ Delete cookbooks on the Chef Server based on a regular expression. The regular e
\fB\-a\fR, \fB\-\-all\fR
Delete all versions
.
+.TP
+\fB\-p\fR, \fB\-\-purge\fR
+Purge files from backing store. This will disable any cookbook that contains any of the same files as the cookbook being purged.
+.
.P
Delete the specified \fIVERSION\fR of the named \fICOOKBOOK\fR. If no version is specified, and only one version exists on the server, that version will be deleted. If multiple versions are available on the server, you will be prompted for a version to delete.
.
diff --git a/chef/distro/common/markdown/knife.mkd b/chef/distro/common/markdown/knife.mkd
index 994ade66cc..b18811f015 100644
--- a/chef/distro/common/markdown/knife.mkd
+++ b/chef/distro/common/markdown/knife.mkd
@@ -161,6 +161,9 @@ Cookbooks are the fundamental unit of distribution in Chef. They encapsulate all
__cookbook bulk delete REGEX__ _(options)_
+ * `-p`, `--purge`:
+ Purge files from backing store. This will disable any cookbook that contains any of the same files as the cookbook being purged.
+
Delete cookbooks on the Chef Server based on a regular expression. The regular expression (_REGEX_) should be in quotes, not in //'s.
__cookbook delete COOKBOOK [VERSION]__ _(options)_
@@ -168,6 +171,9 @@ __cookbook delete COOKBOOK [VERSION]__ _(options)_
* `-a`, `--all`:
Delete all versions
+ * `-p`, `--purge`:
+ Purge files from backing store. This will disable any cookbook that contains any of the same files as the cookbook being purged.
+
Delete the specified _VERSION_ of the named _COOKBOOK_. If no version is specified, and only one version exists on the server, that version will be deleted. If multiple versions are available on the server, you will be prompted for a version to delete.
__cookbook download COOKBOOK [VERSION]__ _(options)_
diff --git a/chef/lib/chef/couchdb.rb b/chef/lib/chef/couchdb.rb
index 61f1c8b312..2278639530 100644
--- a/chef/lib/chef/couchdb.rb
+++ b/chef/lib/chef/couchdb.rb
@@ -160,9 +160,11 @@ class Chef
end
response = @rest.delete_rest("#{couchdb_database}/#{uuid}?rev=#{rev}")
response.couchdb = self if response.respond_to?(:couchdb=)
- Chef::Log.info("Sending #{obj_type}(#{uuid}) to the index queue for deletion..")
- object.delete_from_index(:database => couchdb_database, :id => uuid, :type => obj_type)
+ if object.respond_to?(:delete_from_index)
+ Chef::Log.info("Sending #{obj_type}(#{uuid}) to the index queue for deletion..")
+ object.delete_from_index(:database => couchdb_database, :id => uuid, :type => obj_type)
+ end
response
end
diff --git a/chef/lib/chef/knife/cookbook_bulk_delete.rb b/chef/lib/chef/knife/cookbook_bulk_delete.rb
index 7a40cd6fa6..95332b9ad5 100644
--- a/chef/lib/chef/knife/cookbook_bulk_delete.rb
+++ b/chef/lib/chef/knife/cookbook_bulk_delete.rb
@@ -24,6 +24,8 @@ class Chef
class Knife
class CookbookBulkDelete < Knife
+ option :purge, :short => '-p', :long => '--purge', :boolean => true, :description => 'Permanently remove files from backing data store'
+
banner "Sub-Command: cookbook bulk delete REGEX (options)"
def run
@@ -41,10 +43,12 @@ class Chef
confirm("Do you really want to delete these cookbooks? All versions will be deleted. (Y/N) ", false)
+ confirm("Files that are common to multiple cookbooks are shared, so purging the files may disable other cookbooks. Are you sure you want to purge files instead of just deleting the cookbooks") if config[:purge]
+
cookbooks_names.each do |cookbook_name|
versions = rest.get_rest("cookbooks/#{cookbook_name}").values.flatten
versions.each do |version|
- object = rest.delete_rest("cookbooks/#{cookbook_name}/#{version}")
+ object = rest.delete_rest("cookbooks/#{cookbook_name}/#{version}#{config[:purge] ? "?purge=true" : ""}")
Chef::Log.info("Deleted cookbook #{cookbook_name.ljust(25)} [#{version}]")
end
end
@@ -52,10 +56,3 @@ class Chef
end
end
end
-
-
-
-
-
-
-
diff --git a/chef/lib/chef/knife/cookbook_delete.rb b/chef/lib/chef/knife/cookbook_delete.rb
index b1f9826993..946bd5470d 100644
--- a/chef/lib/chef/knife/cookbook_delete.rb
+++ b/chef/lib/chef/knife/cookbook_delete.rb
@@ -24,9 +24,12 @@ class Chef
option :all, :short => '-a', :long => '--all', :boolean => true, :description => 'delete all versions'
+ option :purge, :short => '-p', :long => '--purge', :boolean => true, :description => 'Permanently remove files from backing data store'
+
banner "Sub-Command: cookbook delete COOKBOOK VERSION (options)"
def run
+ confirm("Files that are common to multiple cookbooks are shared, so purging the files may disable other cookbooks. Are you sure you want to purge files instead of just deleting the cookbook") if config[:purge]
@cookbook_name, @version = name_args
if @cookbook_name && @version
delete_explicit_version
@@ -43,7 +46,7 @@ class Chef
def delete_explicit_version
delete_object(Chef::CookbookVersion, "#{@cookbook_name} version #{@version}", "cookbook") do
- rest.delete_rest("cookbooks/#{@cookbook_name}/#{@version}")
+ delete_request("cookbooks/#{@cookbook_name}/#{@version}", config[:purge])
end
end
@@ -112,7 +115,7 @@ class Chef
end
def delete_version_without_confirmation(version)
- object = rest.delete_rest("cookbooks/#{@cookbook_name}/#{version}")
+ object = delete_request("cookbooks/#{@cookbook_name}/#{version}", config[:purge])
output(format_for_display(object)) if config[:print_after]
Chef::Log.info("Deleted cookbook[#{@cookbook_name}][#{version}]")
end
@@ -127,6 +130,13 @@ class Chef
end
end
end
+
+ private
+
+ def delete_request(path, purge)
+ url = "cookbooks/#{@cookbook_name}/#{@version}#{purge ? "?purge=true" : ""}"
+ rest.delete_rest(url)
+ end
end
end