chef 12.5.0.alpha.1 → 12.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +21 -25
- data/Gemfile +46 -0
- data/README.md +4 -4
- data/Rakefile +5 -110
- data/distro/common/html/knife_cookbook_site.html +18 -18
- data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
- data/lib/chef/application.rb +1 -1
- data/lib/chef/application/apply.rb +19 -1
- data/lib/chef/application/client.rb +11 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/windows_service_manager.rb +9 -7
- data/lib/chef/chef_class.rb +39 -0
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
- data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
- data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
- data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
- data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
- data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
- data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
- data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
- data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
- data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
- data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
- data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
- data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
- data/lib/chef/client.rb +2 -3
- data/lib/chef/config.rb +34 -2
- data/lib/chef/cookbook/metadata.rb +25 -3
- data/lib/chef/cookbook/synchronizer.rb +1 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
- data/lib/chef/cookbook_version.rb +3 -3
- data/lib/chef/deprecation/mixin/template.rb +1 -2
- data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
- data/lib/chef/deprecation/provider/file.rb +1 -1
- data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
- data/lib/chef/deprecation/provider/remote_file.rb +1 -2
- data/lib/chef/deprecation/provider/template.rb +1 -1
- data/lib/chef/deprecation/warnings.rb +3 -4
- data/lib/chef/dsl/reboot_pending.rb +3 -2
- data/lib/chef/dsl/recipe.rb +6 -5
- data/lib/chef/dsl/resources.rb +2 -2
- data/lib/chef/event_dispatch/base.rb +12 -7
- data/lib/chef/event_dispatch/dispatcher.rb +21 -6
- data/lib/chef/exceptions.rb +22 -0
- data/lib/chef/file_content_management/tempfile.rb +1 -1
- data/lib/chef/formatters/base.rb +3 -0
- data/lib/chef/formatters/doc.rb +53 -5
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
- data/lib/chef/formatters/minimal.rb +2 -2
- data/lib/chef/knife.rb +35 -55
- data/lib/chef/knife/bootstrap.rb +41 -0
- data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
- data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
- data/lib/chef/knife/bootstrap/templates/README.md +3 -4
- data/lib/chef/knife/cookbook_create.rb +1 -1
- data/lib/chef/knife/cookbook_site_download.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +6 -6
- data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
- data/lib/chef/knife/core/bootstrap_context.rb +12 -4
- data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
- data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
- data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
- data/lib/chef/knife/core/node_presenter.rb +24 -1
- data/lib/chef/knife/core/object_loader.rb +1 -0
- data/lib/chef/knife/core/subcommand_loader.rb +131 -146
- data/lib/chef/knife/node_run_list_remove.rb +12 -1
- data/lib/chef/knife/null.rb +10 -0
- data/lib/chef/knife/rehash.rb +62 -0
- data/lib/chef/knife/search.rb +3 -3
- data/lib/chef/knife/ssh.rb +52 -30
- data/lib/chef/local_mode.rb +5 -0
- data/lib/chef/log.rb +5 -1
- data/lib/chef/mixin/deprecation.rb +8 -8
- data/lib/chef/mixin/params_validate.rb +2 -2
- data/lib/chef/mixin/template.rb +48 -0
- data/lib/chef/mixin/which.rb +1 -1
- data/lib/chef/mixin/wide_string.rb +72 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
- data/lib/chef/mixin/windows_env_helper.rb +4 -1
- data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
- data/lib/chef/monkey_patches/win32/registry.rb +72 -0
- data/lib/chef/node.rb +97 -3
- data/lib/chef/node_map.rb +2 -2
- data/lib/chef/platform/provider_mapping.rb +5 -6
- data/lib/chef/platform/query_helpers.rb +46 -4
- data/lib/chef/platform/service_helpers.rb +30 -32
- data/lib/chef/policy_builder.rb +1 -8
- data/lib/chef/policy_builder/dynamic.rb +186 -0
- data/lib/chef/policy_builder/expand_node_object.rb +30 -15
- data/lib/chef/policy_builder/policyfile.rb +155 -18
- data/lib/chef/property.rb +38 -9
- data/lib/chef/provider.rb +104 -12
- data/lib/chef/provider/batch.rb +8 -0
- data/lib/chef/provider/deploy.rb +2 -2
- data/lib/chef/provider/directory.rb +14 -2
- data/lib/chef/provider/dsc_resource.rb +5 -9
- data/lib/chef/provider/group/pw.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -2
- data/lib/chef/provider/mount.rb +7 -3
- data/lib/chef/provider/package/dpkg.rb +5 -11
- data/lib/chef/provider/package/rpm.rb +2 -2
- data/lib/chef/provider/package/rubygems.rb +1 -1
- data/lib/chef/provider/package/windows/msi.rb +2 -2
- data/lib/chef/provider/package/yum.rb +17 -5
- data/lib/chef/provider/powershell_script.rb +27 -4
- data/lib/chef/provider/remote_directory.rb +190 -102
- data/lib/chef/provider/service.rb +12 -2
- data/lib/chef/provider/service/aix.rb +1 -1
- data/lib/chef/provider/service/debian.rb +3 -5
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/gentoo.rb +3 -3
- data/lib/chef/provider/service/init.rb +3 -3
- data/lib/chef/provider/service/insserv.rb +2 -4
- data/lib/chef/provider/service/invokercd.rb +2 -4
- data/lib/chef/provider/service/openbsd.rb +2 -1
- data/lib/chef/provider/service/redhat.rb +52 -16
- data/lib/chef/provider/service/simple.rb +2 -2
- data/lib/chef/provider/service/systemd.rb +3 -5
- data/lib/chef/provider/service/upstart.rb +4 -6
- data/lib/chef/provider/subversion.rb +13 -7
- data/lib/chef/provider/template/content.rb +16 -6
- data/lib/chef/provider/user/solaris.rb +32 -4
- data/lib/chef/provider/windows_script.rb +3 -5
- data/lib/chef/provider_resolver.rb +2 -2
- data/lib/chef/resource.rb +85 -27
- data/lib/chef/resource/action_class.rb +83 -0
- data/lib/chef/resource/chef_gem.rb +3 -3
- data/lib/chef/resource/deploy.rb +8 -2
- data/lib/chef/resource/dsc_script.rb +2 -0
- data/lib/chef/resource/file/verification.rb +1 -1
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/service.rb +10 -2
- data/lib/chef/resource/subversion.rb +5 -0
- data/lib/chef/resource/windows_script.rb +6 -2
- data/lib/chef/resource/yum_package.rb +10 -1
- data/lib/chef/resource_resolver.rb +3 -3
- data/lib/chef/run_context.rb +6 -8
- data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
- data/lib/chef/run_lock.rb +30 -21
- data/lib/chef/util/powershell/ps_credential.rb +4 -0
- data/lib/chef/util/windows.rb +0 -32
- data/lib/chef/util/windows/net_group.rb +85 -106
- data/lib/chef/util/windows/net_use.rb +35 -71
- data/lib/chef/util/windows/net_user.rb +0 -1
- data/lib/chef/util/windows/volume.rb +19 -19
- data/lib/chef/version.rb +3 -3
- data/lib/chef/win32/api.rb +1 -0
- data/lib/chef/win32/api/file.rb +20 -0
- data/lib/chef/win32/api/net.rb +163 -43
- data/lib/chef/win32/api/registry.rb +51 -0
- data/lib/chef/win32/api/system.rb +23 -0
- data/lib/chef/win32/api/unicode.rb +0 -43
- data/lib/chef/win32/crypto.rb +2 -1
- data/lib/chef/win32/file.rb +28 -3
- data/lib/chef/win32/mutex.rb +1 -2
- data/lib/chef/win32/net.rb +162 -8
- data/lib/chef/win32/process.rb +13 -0
- data/lib/chef/win32/registry.rb +25 -28
- data/lib/chef/win32/security.rb +1 -1
- data/lib/chef/win32/security/token.rb +1 -1
- data/lib/chef/win32/system.rb +62 -0
- data/lib/chef/win32/unicode.rb +7 -2
- data/lib/chef/win32/version.rb +0 -4
- data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
- data/spec/data/dsc_lcm.pfx +0 -0
- data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
- data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
- data/spec/functional/knife/ssh_spec.rb +16 -0
- data/spec/functional/resource/deploy_revision_spec.rb +1 -1
- data/spec/functional/resource/dsc_resource_spec.rb +2 -0
- data/spec/functional/resource/dsc_script_spec.rb +91 -2
- data/spec/functional/resource/group_spec.rb +67 -44
- data/spec/functional/resource/powershell_script_spec.rb +104 -15
- data/spec/functional/resource/windows_service_spec.rb +1 -1
- data/spec/functional/run_lock_spec.rb +368 -189
- data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
- data/spec/integration/client/client_spec.rb +51 -0
- data/spec/integration/knife/download_spec.rb +4 -0
- data/spec/integration/knife/list_spec.rb +8 -0
- data/spec/integration/knife/upload_spec.rb +1 -1
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
- data/spec/integration/recipes/remote_directory.rb +74 -0
- data/spec/integration/recipes/resource_action_spec.rb +42 -22
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
- data/spec/integration/recipes/resource_load_spec.rb +206 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/platform_helpers.rb +13 -0
- data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
- data/spec/support/shared/functional/windows_script.rb +63 -26
- data/spec/support/shared/unit/mock_shellout.rb +46 -0
- data/spec/support/shared/unit/provider/file.rb +10 -4
- data/spec/unit/application/client_spec.rb +16 -3
- data/spec/unit/application/knife_spec.rb +2 -2
- data/spec/unit/chef_class_spec.rb +0 -4
- data/spec/unit/client_spec.rb +6 -1
- data/spec/unit/config_spec.rb +31 -0
- data/spec/unit/cookbook/metadata_spec.rb +23 -3
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
- data/spec/unit/deprecation_spec.rb +3 -6
- data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
- data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
- data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
- data/spec/unit/formatters/doc_spec.rb +32 -0
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
- data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
- data/spec/unit/knife/bootstrap_spec.rb +55 -3
- data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
- data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
- data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
- data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
- data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
- data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
- data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
- data/spec/unit/mixin/template_spec.rb +5 -1
- data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
- data/spec/unit/node_spec.rb +213 -0
- data/spec/unit/platform/query_helpers_spec.rb +146 -3
- data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
- data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
- data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
- data/spec/unit/property/validation_spec.rb +5 -0
- data/spec/unit/property_spec.rb +152 -26
- data/spec/unit/provider/deploy_spec.rb +5 -5
- data/spec/unit/provider/directory_spec.rb +35 -0
- data/spec/unit/provider/dsc_resource_spec.rb +3 -10
- data/spec/unit/provider/ifconfig_spec.rb +22 -2
- data/spec/unit/provider/mount/aix_spec.rb +2 -1
- data/spec/unit/provider/mount/mount_spec.rb +6 -0
- data/spec/unit/provider/mount/windows_spec.rb +14 -0
- data/spec/unit/provider/mount_spec.rb +12 -1
- data/spec/unit/provider/package/dpkg_spec.rb +8 -1
- data/spec/unit/provider/package/rpm_spec.rb +18 -1
- data/spec/unit/provider/package/rubygems_spec.rb +18 -0
- data/spec/unit/provider/package/yum_spec.rb +97 -24
- data/spec/unit/provider/powershell_script_spec.rb +52 -26
- data/spec/unit/provider/remote_directory_spec.rb +1 -2
- data/spec/unit/provider/service/aix_service_spec.rb +3 -3
- data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
- data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
- data/spec/unit/provider/service/redhat_spec.rb +88 -8
- data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
- data/spec/unit/provider/service/windows_spec.rb +211 -200
- data/spec/unit/provider/subversion_spec.rb +50 -31
- data/spec/unit/provider/template/content_spec.rb +93 -2
- data/spec/unit/provider/user/solaris_spec.rb +66 -9
- data/spec/unit/provider_resolver_spec.rb +707 -650
- data/spec/unit/resource/deploy_spec.rb +7 -1
- data/spec/unit/resource/dsc_script_spec.rb +4 -0
- data/spec/unit/resource/file/verification_spec.rb +1 -1
- data/spec/unit/resource/powershell_script_spec.rb +17 -13
- data/spec/unit/resource/service_spec.rb +4 -4
- data/spec/unit/resource/subversion_spec.rb +4 -0
- data/spec/unit/resource/yum_package_spec.rb +10 -1
- data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
- data/spec/unit/win32/registry_spec.rb +394 -0
- data/tasks/external_tests.rb +47 -23
- data/tasks/maintainers.rb +155 -14
- metadata +51 -26
- data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
- data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
- data/spec/unit/registry_helper_spec.rb +0 -390
@@ -109,8 +109,8 @@ class Chef
|
|
109
109
|
puts "Synchronizing cookbooks"
|
110
110
|
end
|
111
111
|
|
112
|
-
# Called when cookbook +
|
113
|
-
def synchronized_cookbook(cookbook_name)
|
112
|
+
# Called when cookbook +cookbook+ has been sync'd
|
113
|
+
def synchronized_cookbook(cookbook_name, cookbook)
|
114
114
|
print "."
|
115
115
|
end
|
116
116
|
|
data/lib/chef/knife.rb
CHANGED
@@ -87,6 +87,7 @@ class Chef
|
|
87
87
|
def self.inherited(subclass)
|
88
88
|
unless subclass.unnamed?
|
89
89
|
subcommands[subclass.snake_case_name] = subclass
|
90
|
+
subcommand_files[subclass.snake_case_name] += [caller[0].split(/:\d+/).first]
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
@@ -121,17 +122,29 @@ class Chef
|
|
121
122
|
end
|
122
123
|
|
123
124
|
def self.subcommand_loader
|
124
|
-
@subcommand_loader ||= Knife::SubcommandLoader.
|
125
|
+
@subcommand_loader ||= Chef::Knife::SubcommandLoader.for_config(chef_config_dir)
|
125
126
|
end
|
126
127
|
|
127
128
|
def self.load_commands
|
128
129
|
@commands_loaded ||= subcommand_loader.load_commands
|
129
130
|
end
|
130
131
|
|
132
|
+
def self.guess_category(args)
|
133
|
+
subcommand_loader.guess_category(args)
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.subcommand_class_from(args)
|
137
|
+
subcommand_loader.command_class_from(args) || subcommand_not_found!(args)
|
138
|
+
end
|
139
|
+
|
131
140
|
def self.subcommands
|
132
141
|
@@subcommands ||= {}
|
133
142
|
end
|
134
143
|
|
144
|
+
def self.subcommand_files
|
145
|
+
@@subcommand_files ||= Hash.new([])
|
146
|
+
end
|
147
|
+
|
135
148
|
def self.subcommands_by_category
|
136
149
|
unless @subcommands_by_category
|
137
150
|
@subcommands_by_category = Hash.new { |hash, key| hash[key] = [] }
|
@@ -142,30 +155,6 @@ class Chef
|
|
142
155
|
@subcommands_by_category
|
143
156
|
end
|
144
157
|
|
145
|
-
# Print the list of subcommands knife knows about. If +preferred_category+
|
146
|
-
# is given, only subcommands in that category are shown
|
147
|
-
def self.list_commands(preferred_category=nil)
|
148
|
-
load_commands
|
149
|
-
|
150
|
-
category_desc = preferred_category ? preferred_category + " " : ''
|
151
|
-
msg "Available #{category_desc}subcommands: (for details, knife SUB-COMMAND --help)\n\n"
|
152
|
-
|
153
|
-
if preferred_category && subcommands_by_category.key?(preferred_category)
|
154
|
-
commands_to_show = {preferred_category => subcommands_by_category[preferred_category]}
|
155
|
-
else
|
156
|
-
commands_to_show = subcommands_by_category
|
157
|
-
end
|
158
|
-
|
159
|
-
commands_to_show.sort.each do |category, commands|
|
160
|
-
next if category =~ /deprecated/i
|
161
|
-
msg "** #{category.upcase} COMMANDS **"
|
162
|
-
commands.sort.each do |command|
|
163
|
-
msg subcommands[command].banner if subcommands[command]
|
164
|
-
end
|
165
|
-
msg
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
158
|
# Shared with subclasses
|
170
159
|
@@chef_config_dir = nil
|
171
160
|
|
@@ -206,7 +195,6 @@ class Chef
|
|
206
195
|
Chef::Log.level(:debug)
|
207
196
|
end
|
208
197
|
|
209
|
-
load_commands
|
210
198
|
subcommand_class = subcommand_class_from(args)
|
211
199
|
subcommand_class.options = options.merge!(subcommand_class.options)
|
212
200
|
subcommand_class.load_deps
|
@@ -215,34 +203,6 @@ class Chef
|
|
215
203
|
instance.run_with_pretty_exceptions
|
216
204
|
end
|
217
205
|
|
218
|
-
def self.guess_category(args)
|
219
|
-
category_words = args.select {|arg| arg =~ /^(([[:alnum:]])[[:alnum:]\_\-]+)$/ }
|
220
|
-
category_words.map! {|w| w.split('-')}.flatten!
|
221
|
-
matching_category = nil
|
222
|
-
while (!matching_category) && (!category_words.empty?)
|
223
|
-
candidate_category = category_words.join(' ')
|
224
|
-
matching_category = candidate_category if subcommands_by_category.key?(candidate_category)
|
225
|
-
matching_category || category_words.pop
|
226
|
-
end
|
227
|
-
matching_category
|
228
|
-
end
|
229
|
-
|
230
|
-
def self.subcommand_class_from(args)
|
231
|
-
command_words = args.select {|arg| arg =~ /^(([[:alnum:]])[[:alnum:]\_\-]+)$/ }
|
232
|
-
|
233
|
-
subcommand_class = nil
|
234
|
-
|
235
|
-
while ( !subcommand_class ) && ( !command_words.empty? )
|
236
|
-
snake_case_class_name = command_words.join("_")
|
237
|
-
unless subcommand_class = subcommands[snake_case_class_name]
|
238
|
-
command_words.pop
|
239
|
-
end
|
240
|
-
end
|
241
|
-
# see if we got the command as e.g., knife node-list
|
242
|
-
subcommand_class ||= subcommands[args.first.gsub('-', '_')]
|
243
|
-
subcommand_class || subcommand_not_found!(args)
|
244
|
-
end
|
245
|
-
|
246
206
|
def self.dependency_loaders
|
247
207
|
@dependency_loaders ||= []
|
248
208
|
end
|
@@ -265,7 +225,13 @@ class Chef
|
|
265
225
|
# Error out and print usage. probably because the arguments given by the
|
266
226
|
# user could not be resolved to a subcommand.
|
267
227
|
def self.subcommand_not_found!(args)
|
268
|
-
ui.fatal("Cannot find
|
228
|
+
ui.fatal("Cannot find subcommand for: '#{args.join(' ')}'")
|
229
|
+
|
230
|
+
# Mention rehash when the subcommands cache(plugin_manifest.json) is used
|
231
|
+
if subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::HashedCommandLoader) ||
|
232
|
+
subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::CustomManifestLoader)
|
233
|
+
ui.info("If this is a recently installed plugin, please run 'knife rehash' to update the subcommands cache.")
|
234
|
+
end
|
269
235
|
|
270
236
|
if category_commands = guess_category(args)
|
271
237
|
list_commands(category_commands)
|
@@ -280,6 +246,20 @@ class Chef
|
|
280
246
|
exit 10
|
281
247
|
end
|
282
248
|
|
249
|
+
def self.list_commands(preferred_category=nil)
|
250
|
+
category_desc = preferred_category ? preferred_category + " " : ''
|
251
|
+
msg "Available #{category_desc}subcommands: (for details, knife SUB-COMMAND --help)\n\n"
|
252
|
+
subcommand_loader.list_commands(preferred_category).sort.each do |category, commands|
|
253
|
+
next if category =~ /deprecated/i
|
254
|
+
msg "** #{category.upcase} COMMANDS **"
|
255
|
+
commands.sort.each do |command|
|
256
|
+
subcommand_loader.load_command(command)
|
257
|
+
msg subcommands[command].banner if subcommands[command]
|
258
|
+
end
|
259
|
+
msg
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
283
263
|
def self.reset_config_path!
|
284
264
|
@@chef_config_dir = nil
|
285
265
|
end
|
data/lib/chef/knife/bootstrap.rb
CHANGED
@@ -143,6 +143,22 @@ class Chef
|
|
143
143
|
:proc => lambda { |o| o.split(/[\s,]+/) },
|
144
144
|
:default => []
|
145
145
|
|
146
|
+
option :policy_name,
|
147
|
+
:long => "--policy-name POLICY_NAME",
|
148
|
+
:description => "Policyfile name to use (--policy-group must also be given)",
|
149
|
+
:default => nil
|
150
|
+
|
151
|
+
option :policy_group,
|
152
|
+
:long => "--policy-group POLICY_GROUP",
|
153
|
+
:description => "Policy group name to use (--policy-name must also be given)",
|
154
|
+
:default => nil
|
155
|
+
|
156
|
+
option :tags,
|
157
|
+
:long => "--tags TAGS",
|
158
|
+
:description => "Comma separated list of tags to apply to the node",
|
159
|
+
:proc => lambda { |o| o.split(/[\s,]+/) },
|
160
|
+
:default => []
|
161
|
+
|
146
162
|
option :first_boot_attributes,
|
147
163
|
:short => "-j JSON_ATTRIBS",
|
148
164
|
:long => "--json-attributes",
|
@@ -309,6 +325,7 @@ class Chef
|
|
309
325
|
|
310
326
|
def run
|
311
327
|
validate_name_args!
|
328
|
+
validate_options!
|
312
329
|
|
313
330
|
$stdout.sync = true
|
314
331
|
|
@@ -357,6 +374,17 @@ class Chef
|
|
357
374
|
end
|
358
375
|
end
|
359
376
|
|
377
|
+
def validate_options!
|
378
|
+
if incomplete_policyfile_options?
|
379
|
+
ui.error("--policy-name and --policy-group must be specified together")
|
380
|
+
exit 1
|
381
|
+
elsif policyfile_and_run_list_given?
|
382
|
+
ui.error("Policyfile options and --run-list are exclusive")
|
383
|
+
exit 1
|
384
|
+
end
|
385
|
+
true
|
386
|
+
end
|
387
|
+
|
360
388
|
def knife_ssh
|
361
389
|
ssh = Chef::Knife::Ssh.new
|
362
390
|
ssh.ui = ui
|
@@ -389,6 +417,19 @@ class Chef
|
|
389
417
|
|
390
418
|
command
|
391
419
|
end
|
420
|
+
|
421
|
+
private
|
422
|
+
|
423
|
+
# True if policy_name and run_list are both given
|
424
|
+
def policyfile_and_run_list_given?
|
425
|
+
!config[:run_list].empty? && !!config[:policy_name]
|
426
|
+
end
|
427
|
+
|
428
|
+
# True if one of policy_name or policy_group was given, but not both
|
429
|
+
def incomplete_policyfile_options?
|
430
|
+
(!!config[:policy_name] ^ config[:policy_group])
|
431
|
+
end
|
432
|
+
|
392
433
|
end
|
393
434
|
end
|
394
435
|
end
|
@@ -20,6 +20,7 @@ require 'chef/node'
|
|
20
20
|
require 'chef/rest'
|
21
21
|
require 'chef/api_client/registration'
|
22
22
|
require 'chef/api_client'
|
23
|
+
require 'chef/knife/bootstrap'
|
23
24
|
require 'tmpdir'
|
24
25
|
|
25
26
|
class Chef
|
@@ -90,6 +91,16 @@ class Chef
|
|
90
91
|
knife_config[:run_list]
|
91
92
|
end
|
92
93
|
|
94
|
+
# @return [String] policy_name from the knife_config
|
95
|
+
def policy_name
|
96
|
+
knife_config[:policy_name]
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [String] policy_group from the knife_config
|
100
|
+
def policy_group
|
101
|
+
knife_config[:policy_group]
|
102
|
+
end
|
103
|
+
|
93
104
|
# @return [Hash,Array] Object representation of json first-boot attributes from the knife_config
|
94
105
|
def first_boot_attributes
|
95
106
|
knife_config[:first_boot_attributes]
|
@@ -140,6 +151,11 @@ class Chef
|
|
140
151
|
node.run_list(normalized_run_list)
|
141
152
|
node.normal_attrs = first_boot_attributes if first_boot_attributes
|
142
153
|
node.environment(environment) if environment
|
154
|
+
node.policy_name = policy_name if policy_name
|
155
|
+
node.policy_group = policy_group if policy_group
|
156
|
+
(knife_config[:tags] || []).each do |tag|
|
157
|
+
node.tags << tag
|
158
|
+
end
|
143
159
|
node
|
144
160
|
end
|
145
161
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
This directory contains bootstrap templates which can be used with the -d flag
|
2
2
|
to 'knife bootstrap' to install Chef in different ways. To simplify installation,
|
3
3
|
and reduce the matrix of common installation patterns to support, we have
|
4
|
-
standardized on the [Omnibus](https://github.com/
|
4
|
+
standardized on the [Omnibus](https://github.com/chef/omnibus) built installation
|
5
5
|
packages.
|
6
6
|
|
7
7
|
The 'chef-full' template downloads a script which is used to determine the correct
|
8
|
-
Omnibus package for this system from the [Omnitruck](https://
|
9
|
-
in the future.
|
8
|
+
Omnibus package for this system from the [Omnitruck](https://docs.chef.io/api_omnitruck.html) API.
|
10
9
|
|
11
10
|
You can still utilize custom bootstrap templates on your system if your installation
|
12
|
-
needs are unique. Additional information can be found on the [docs site](
|
11
|
+
needs are unique. Additional information can be found on the [docs site](https://docs.chef.io/knife_bootstrap.html#custom-templates).
|
@@ -84,7 +84,7 @@ class Chef
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def download_cookbook
|
87
|
-
ui.info "Downloading #{@name_args[0]} from
|
87
|
+
ui.info "Downloading #{@name_args[0]} from Supermarket at version #{version} to #{download_location}"
|
88
88
|
noauth_rest.sign_on_redirect = false
|
89
89
|
tf = noauth_rest.get_rest desired_cookbook_data["file"], true
|
90
90
|
|
@@ -93,7 +93,7 @@ class Chef
|
|
93
93
|
|
94
94
|
# TODO: it'd be better to store these outside the cookbook repo and
|
95
95
|
# keep them around, e.g., in ~/Library/Caches on OS X.
|
96
|
-
ui.info("
|
96
|
+
ui.info("Removing downloaded tarball")
|
97
97
|
File.unlink(upstream_file)
|
98
98
|
|
99
99
|
if @repo.finalize_updates_to(@cookbook_name, downloader.version)
|
@@ -48,7 +48,7 @@ class Chef
|
|
48
48
|
:short => '-n',
|
49
49
|
:boolean => true,
|
50
50
|
:default => false,
|
51
|
-
:description => "Don't take action, only print what files will be
|
51
|
+
:description => "Don't take action, only print what files will be uploaded to Supermarket."
|
52
52
|
|
53
53
|
def run
|
54
54
|
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
@@ -94,7 +94,7 @@ class Chef
|
|
94
94
|
Chef::Log.debug("Removing local staging directory at #{tmp_cookbook_dir}")
|
95
95
|
FileUtils.rm_rf tmp_cookbook_dir
|
96
96
|
rescue => e
|
97
|
-
ui.error("Error uploading cookbook #{cookbook_name} to
|
97
|
+
ui.error("Error uploading cookbook #{cookbook_name} to Supermarket: #{e.message}. Increase log verbosity (-VV) for more information.")
|
98
98
|
Chef::Log.debug("\n#{e.backtrace.join("\n")}")
|
99
99
|
exit(1)
|
100
100
|
end
|
@@ -108,15 +108,15 @@ class Chef
|
|
108
108
|
|
109
109
|
def get_category(cookbook_name)
|
110
110
|
begin
|
111
|
-
data = noauth_rest.get_rest("
|
111
|
+
data = noauth_rest.get_rest("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}")
|
112
112
|
if !data["category"] && data["error_code"]
|
113
|
-
ui.fatal("Received an error from
|
113
|
+
ui.fatal("Received an error from Supermarket: #{data["error_code"]}. On the first time you upload it, you are required to specify the category you want to share this cookbook to.")
|
114
114
|
exit(1)
|
115
115
|
else
|
116
116
|
data['category']
|
117
117
|
end
|
118
118
|
rescue => e
|
119
|
-
ui.fatal("Unable to reach
|
119
|
+
ui.fatal("Unable to reach Supermarket: #{e.message}. Increase log verbosity (-VV) for more information.")
|
120
120
|
Chef::Log.debug("\n#{e.backtrace.join("\n")}")
|
121
121
|
exit(1)
|
122
122
|
end
|
@@ -136,7 +136,7 @@ class Chef
|
|
136
136
|
if http_resp.code.to_i != 201
|
137
137
|
if res['error_messages']
|
138
138
|
if res['error_messages'][0] =~ /Version already exists/
|
139
|
-
ui.error "The same version of this cookbook already exists on
|
139
|
+
ui.error "The same version of this cookbook already exists on Supermarket."
|
140
140
|
exit(1)
|
141
141
|
else
|
142
142
|
ui.error "#{res['error_messages'][0]}"
|
@@ -38,7 +38,7 @@ class Chef
|
|
38
38
|
exit 1
|
39
39
|
end
|
40
40
|
|
41
|
-
confirm "Do you really want to unshare the cookbook #{@cookbook_name}"
|
41
|
+
confirm "Do you really want to unshare all versions of the cookbook #{@cookbook_name}"
|
42
42
|
|
43
43
|
begin
|
44
44
|
rest.delete_rest "https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}"
|
@@ -48,7 +48,7 @@ class Chef
|
|
48
48
|
exit 1
|
49
49
|
end
|
50
50
|
|
51
|
-
ui.info "Unshared cookbook #{@cookbook_name}"
|
51
|
+
ui.info "Unshared all versions of the cookbook #{@cookbook_name}"
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
@@ -40,7 +40,7 @@ class Chef
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def bootstrap_environment
|
43
|
-
@chef_config[:environment]
|
43
|
+
@chef_config[:environment]
|
44
44
|
end
|
45
45
|
|
46
46
|
def validation_key
|
@@ -128,7 +128,7 @@ CONFIG
|
|
128
128
|
client_path = @chef_config[:chef_client_path] || 'chef-client'
|
129
129
|
s = "#{client_path} -j /etc/chef/first-boot.json"
|
130
130
|
s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2
|
131
|
-
s << " -E #{bootstrap_environment}"
|
131
|
+
s << " -E #{bootstrap_environment}" unless bootstrap_environment.nil?
|
132
132
|
s
|
133
133
|
end
|
134
134
|
|
@@ -163,11 +163,19 @@ CONFIG
|
|
163
163
|
end
|
164
164
|
|
165
165
|
def first_boot
|
166
|
-
(@config[:first_boot_attributes] || {}).
|
166
|
+
(@config[:first_boot_attributes] || {}).tap do |attributes|
|
167
|
+
if @config[:policy_name] && @config[:policy_group]
|
168
|
+
attributes.merge!(:policy_name => @config[:policy_name], :policy_group => @config[:policy_group])
|
169
|
+
else
|
170
|
+
attributes.merge!(:run_list => @run_list)
|
171
|
+
end
|
172
|
+
|
173
|
+
attributes.merge!(:tags => @config[:tags]) if @config[:tags] && !@config[:tags].empty?
|
174
|
+
end
|
167
175
|
end
|
168
176
|
|
169
177
|
private
|
170
|
-
|
178
|
+
|
171
179
|
# Returns a string for copying the trusted certificates on the workstation to the system being bootstrapped
|
172
180
|
# This string should contain both the commands necessary to both create the files, as well as their content
|
173
181
|
def trusted_certs_content
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'chef/version'
|
18
|
+
class Chef
|
19
|
+
class Knife
|
20
|
+
class SubcommandLoader
|
21
|
+
|
22
|
+
#
|
23
|
+
# Load a subcommand from a user-supplied
|
24
|
+
# manifest file
|
25
|
+
#
|
26
|
+
class CustomManifestLoader < Chef::Knife::SubcommandLoader
|
27
|
+
attr_accessor :manifest
|
28
|
+
def initialize(chef_config_dir, plugin_manifest)
|
29
|
+
super(chef_config_dir)
|
30
|
+
@manifest = plugin_manifest
|
31
|
+
end
|
32
|
+
|
33
|
+
# If the user has created a ~/.chef/plugin_manifest.json file, we'll use
|
34
|
+
# that instead of inspecting the on-system gems to find the plugins. The
|
35
|
+
# file format is expected to look like:
|
36
|
+
#
|
37
|
+
# { "plugins": {
|
38
|
+
# "knife-ec2": {
|
39
|
+
# "paths": [
|
40
|
+
# "/home/alice/.rubymanagerthing/gems/knife-ec2-x.y.z/lib/chef/knife/ec2_server_create.rb",
|
41
|
+
# "/home/alice/.rubymanagerthing/gems/knife-ec2-x.y.z/lib/chef/knife/ec2_server_delete.rb"
|
42
|
+
# ]
|
43
|
+
# }
|
44
|
+
# }
|
45
|
+
# }
|
46
|
+
#
|
47
|
+
# Extraneous content in this file is ignored. This is intentional so that we
|
48
|
+
# can adapt the file format for potential behavior changes to knife in
|
49
|
+
# the future.
|
50
|
+
def find_subcommands_via_manifest
|
51
|
+
# Format of subcommand_files is "relative_path" (something you can
|
52
|
+
# Kernel.require()) => full_path. The relative path isn't used
|
53
|
+
# currently, so we just map full_path => full_path.
|
54
|
+
subcommand_files = {}
|
55
|
+
manifest["plugins"].each do |plugin_name, plugin_manifest|
|
56
|
+
plugin_manifest["paths"].each do |cmd_path|
|
57
|
+
subcommand_files[cmd_path] = cmd_path
|
58
|
+
end
|
59
|
+
end
|
60
|
+
subcommand_files.merge(find_subcommands_via_dirglob)
|
61
|
+
end
|
62
|
+
|
63
|
+
def subcommand_files
|
64
|
+
subcommand_files ||= (find_subcommands_via_manifest.values + site_subcommands).flatten.uniq
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|