runa-chef 0.8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +201 -0
- data/README.rdoc +136 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/bin/knife +27 -0
- data/bin/shef +45 -0
- data/distro/README +2 -0
- data/distro/common/man/man1/chef-indexer.1 +42 -0
- data/distro/common/man/man1/chef-server.1 +108 -0
- data/distro/common/man/man8/chef-client.8 +61 -0
- data/distro/common/man/man8/chef-solo.8 +58 -0
- data/distro/common/man/man8/knife.8 +359 -0
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/redhat/etc/init.d/chef-client +78 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +78 -0
- data/distro/redhat/etc/sysconfig/chef-client +10 -0
- data/distro/redhat/etc/sysconfig/chef-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-server +10 -0
- data/distro/suse/etc/init.d/chef-client +121 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/api_client.rb +269 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +214 -0
- data/lib/chef/application/knife.rb +138 -0
- data/lib/chef/application/server.rb +19 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/cache.rb +61 -0
- data/lib/chef/cache/checksum.rb +70 -0
- data/lib/chef/certificate.rb +154 -0
- data/lib/chef/client.rb +323 -0
- data/lib/chef/compile.rb +158 -0
- data/lib/chef/config.rb +195 -0
- data/lib/chef/cookbook.rb +198 -0
- data/lib/chef/cookbook/metadata.rb +487 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +273 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/data_bag.rb +216 -0
- data/lib/chef/data_bag_item.rb +227 -0
- data/lib/chef/exceptions.rb +39 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/knife.rb +300 -0
- data/lib/chef/knife/client_bulk_delete.rb +41 -0
- data/lib/chef/knife/client_create.rb +55 -0
- data/lib/chef/knife/client_delete.rb +37 -0
- data/lib/chef/knife/client_edit.rb +37 -0
- data/lib/chef/knife/client_list.rb +40 -0
- data/lib/chef/knife/client_reregister.rb +48 -0
- data/lib/chef/knife/client_show.rb +42 -0
- data/lib/chef/knife/configure.rb +84 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +47 -0
- data/lib/chef/knife/cookbook_delete.rb +41 -0
- data/lib/chef/knife/cookbook_download.rb +57 -0
- data/lib/chef/knife/cookbook_list.rb +41 -0
- data/lib/chef/knife/cookbook_metadata.rb +87 -0
- data/lib/chef/knife/cookbook_show.rb +75 -0
- data/lib/chef/knife/cookbook_upload.rb +173 -0
- data/lib/chef/knife/data_bag_create.rb +43 -0
- data/lib/chef/knife/data_bag_delete.rb +43 -0
- data/lib/chef/knife/data_bag_edit.rb +49 -0
- data/lib/chef/knife/data_bag_list.rb +42 -0
- data/lib/chef/knife/data_bag_show.rb +40 -0
- data/lib/chef/knife/ec2_instance_data.rb +46 -0
- data/lib/chef/knife/node_bulk_delete.rb +44 -0
- data/lib/chef/knife/node_create.rb +39 -0
- data/lib/chef/knife/node_delete.rb +36 -0
- data/lib/chef/knife/node_edit.rb +36 -0
- data/lib/chef/knife/node_from_file.rb +42 -0
- data/lib/chef/knife/node_list.rb +41 -0
- data/lib/chef/knife/node_run_list_add.rb +64 -0
- data/lib/chef/knife/node_run_list_remove.rb +45 -0
- data/lib/chef/knife/node_show.rb +46 -0
- data/lib/chef/knife/role_bulk_delete.rb +45 -0
- data/lib/chef/knife/role_create.rb +44 -0
- data/lib/chef/knife/role_delete.rb +36 -0
- data/lib/chef/knife/role_edit.rb +37 -0
- data/lib/chef/knife/role_from_file.rb +46 -0
- data/lib/chef/knife/role_list.rb +40 -0
- data/lib/chef/knife/role_show.rb +43 -0
- data/lib/chef/knife/search.rb +94 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +32 -0
- data/lib/chef/mixin/command.rb +390 -0
- data/lib/chef/mixin/convert_to_class_name.rb +57 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +33 -0
- data/lib/chef/mixin/find_preferred_file.rb +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +58 -0
- data/lib/chef/mixin/language.rb +107 -0
- data/lib/chef/mixin/language_include_attribute.rb +56 -0
- data/lib/chef/mixin/language_include_recipe.rb +53 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +79 -0
- data/lib/chef/mixin/template.rb +94 -0
- data/lib/chef/nanite.rb +100 -0
- data/lib/chef/node.rb +463 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +268 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/breakpoint.rb +36 -0
- data/lib/chef/provider/cron.rb +184 -0
- data/lib/chef/provider/deploy.rb +314 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/erl_call.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +195 -0
- data/lib/chef/provider/git.rb +203 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/dscl.rb +128 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/http_request.rb +106 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mdadm.rb +88 -0
- data/lib/chef/provider/mount.rb +117 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +109 -0
- data/lib/chef/provider/package/easy_install.rb +106 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +136 -0
- data/lib/chef/provider/package/yum-dump.py +125 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/package/zypper.rb +132 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +141 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +33 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +135 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +156 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +114 -0
- data/lib/chef/provider/subversion.rb +156 -0
- data/lib/chef/provider/template.rb +175 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/dscl.rb +280 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +108 -0
- data/lib/chef/recipe.rb +105 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/breakpoint.rb +35 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +359 -0
- data/lib/chef/resource/deploy_revision.rb +35 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/easy_install_package.rb +41 -0
- data/lib/chef/resource/erl_call.rb +83 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mdadm.rb +82 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +39 -0
- data/lib/chef/resource/scm.rb +137 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +34 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +101 -0
- data/lib/chef/resource_collection.rb +212 -0
- data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +298 -0
- data/lib/chef/role.rb +301 -0
- data/lib/chef/run_list.rb +164 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search/query.rb +71 -0
- data/lib/chef/shef.rb +220 -0
- data/lib/chef/shef/ext.rb +297 -0
- data/lib/chef/shef/shef_session.rb +175 -0
- data/lib/chef/streaming_cookbook_uploader.rb +185 -0
- data/lib/chef/tasks/chef_repo.rake +245 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- data/lib/chef/webui_user.rb +231 -0
- metadata +398 -0
data/lib/chef/runner.rb
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
require 'chef/mixin/params_validate'
|
|
20
|
+
require 'chef/node'
|
|
21
|
+
require 'chef/resource_collection'
|
|
22
|
+
require 'chef/platform'
|
|
23
|
+
|
|
24
|
+
class Chef
|
|
25
|
+
class Runner
|
|
26
|
+
|
|
27
|
+
include Chef::Mixin::ParamsValidate
|
|
28
|
+
|
|
29
|
+
def initialize(node, collection, definitions={}, cookbook_loader=nil)
|
|
30
|
+
validate(
|
|
31
|
+
{
|
|
32
|
+
:node => node,
|
|
33
|
+
:collection => collection,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
:node => {
|
|
37
|
+
:kind_of => Chef::Node,
|
|
38
|
+
},
|
|
39
|
+
:collection => {
|
|
40
|
+
:kind_of => Chef::ResourceCollection,
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
@node = node
|
|
45
|
+
@collection = collection
|
|
46
|
+
@definitions = definitions
|
|
47
|
+
@cookbook_loader = cookbook_loader
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def build_provider(resource)
|
|
51
|
+
provider_klass = resource.provider
|
|
52
|
+
provider_klass ||= Chef::Platform.find_provider_for_node(@node, resource)
|
|
53
|
+
Chef::Log.debug("#{resource} using #{provider_klass.to_s}")
|
|
54
|
+
provider = provider_klass.new(@node, resource, @collection, @definitions, @cookbook_loader)
|
|
55
|
+
provider.load_current_resource
|
|
56
|
+
provider
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def run_action(resource, ra)
|
|
60
|
+
provider = build_provider(resource)
|
|
61
|
+
provider.send("action_#{ra}")
|
|
62
|
+
|
|
63
|
+
if resource.updated
|
|
64
|
+
resource.actions.each_key do |action|
|
|
65
|
+
if resource.actions[action].has_key?(:immediate)
|
|
66
|
+
resource.actions[action][:immediate].each do |r|
|
|
67
|
+
Chef::Log.info("#{resource} sending #{action} action to #{r} (immediate)")
|
|
68
|
+
run_action(r, action)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
if resource.actions[action].has_key?(:delayed)
|
|
72
|
+
resource.actions[action][:delayed].each do |r|
|
|
73
|
+
@delayed_actions[r] = Hash.new unless @delayed_actions.has_key?(r)
|
|
74
|
+
@delayed_actions[r][action] = Array.new unless @delayed_actions[r].has_key?(action)
|
|
75
|
+
@delayed_actions[r][action] << lambda {
|
|
76
|
+
Chef::Log.info("#{resource} sending #{action} action to #{r} (delayed)")
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def converge
|
|
85
|
+
|
|
86
|
+
@delayed_actions = Hash.new
|
|
87
|
+
|
|
88
|
+
@collection.execute_each_resource do |resource|
|
|
89
|
+
begin
|
|
90
|
+
Chef::Log.debug("Processing #{resource}")
|
|
91
|
+
|
|
92
|
+
# Check if this resource has an only_if block - if it does, skip it.
|
|
93
|
+
if resource.only_if
|
|
94
|
+
unless Chef::Mixin::Command.only_if(resource.only_if)
|
|
95
|
+
Chef::Log.debug("Skipping #{resource} due to only_if")
|
|
96
|
+
next
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Check if this resource has a not_if block - if it does, skip it.
|
|
101
|
+
if resource.not_if
|
|
102
|
+
unless Chef::Mixin::Command.not_if(resource.not_if)
|
|
103
|
+
Chef::Log.debug("Skipping #{resource} due to not_if")
|
|
104
|
+
next
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Walk the actions for this resource, building the provider and running each.
|
|
109
|
+
action_list = resource.action.kind_of?(Array) ? resource.action : [ resource.action ]
|
|
110
|
+
action_list.each do |ra|
|
|
111
|
+
run_action(resource, ra)
|
|
112
|
+
end
|
|
113
|
+
rescue => e
|
|
114
|
+
Chef::Log.error("#{resource} (#{resource.source_line}) had an error:\n#{e}\n#{e.backtrace.join("\n")}")
|
|
115
|
+
raise e unless resource.ignore_failure
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Run all our :delayed actions
|
|
120
|
+
@delayed_actions.each do |resource, action_hash|
|
|
121
|
+
action_hash.each do |action, log_array|
|
|
122
|
+
log_array.each { |l| l.call } # Call each log message
|
|
123
|
+
run_action(resource, action)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
true
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
|
4
|
+
# License:: Apache License, Version 2.0
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
require 'chef/config'
|
|
20
|
+
require 'chef/node'
|
|
21
|
+
require 'chef/role'
|
|
22
|
+
require 'chef/data_bag'
|
|
23
|
+
require 'chef/data_bag_item'
|
|
24
|
+
require 'uri'
|
|
25
|
+
|
|
26
|
+
class Chef
|
|
27
|
+
class Search
|
|
28
|
+
class Query
|
|
29
|
+
|
|
30
|
+
attr_accessor :rest
|
|
31
|
+
|
|
32
|
+
def initialize(url=nil)
|
|
33
|
+
url ||= Chef::Config[:search_url]
|
|
34
|
+
@rest = Chef::REST.new(url)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Search Solr for objects of a given type, for a given query. If you give
|
|
38
|
+
# it a block, it will handle the paging for you dynamically.
|
|
39
|
+
def search(type, query="*:*", sort=nil, start=0, rows=20, &block)
|
|
40
|
+
unless type.kind_of?(String) || type.kind_of?(Symbol)
|
|
41
|
+
raise ArgumentError, "Type must be a string or a symbol!"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
response = @rest.get_rest("search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}")
|
|
45
|
+
if block
|
|
46
|
+
response["rows"].each { |o| block.call(o) unless o.nil?}
|
|
47
|
+
unless (response["start"] + response["rows"].length) >= response["total"]
|
|
48
|
+
nstart = response["start"] + rows
|
|
49
|
+
search(type, query, sort, nstart, rows, &block)
|
|
50
|
+
end
|
|
51
|
+
true
|
|
52
|
+
else
|
|
53
|
+
[ response["rows"], response["start"], response["total"] ]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def list_indexes
|
|
58
|
+
response = @rest.get_rest("search")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
def escape(s)
|
|
63
|
+
if s
|
|
64
|
+
URI.escape(s.to_s)
|
|
65
|
+
else
|
|
66
|
+
s
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/lib/chef/shef.rb
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
|
2
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
require "singleton"
|
|
19
|
+
require "pp"
|
|
20
|
+
require "etc"
|
|
21
|
+
require "mixlib/cli"
|
|
22
|
+
|
|
23
|
+
require "chef/client"
|
|
24
|
+
require "chef/config"
|
|
25
|
+
|
|
26
|
+
require "chef/shef/shef_session"
|
|
27
|
+
require "chef/shef/ext"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
module Shef
|
|
31
|
+
LEADERS = Hash.new("")
|
|
32
|
+
LEADERS[Chef::Recipe] = ":recipe"
|
|
33
|
+
LEADERS[Chef::Node] = ":attributes"
|
|
34
|
+
|
|
35
|
+
class << self
|
|
36
|
+
attr_accessor :client_type, :options
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Shef assumes it's running whenever it is defined
|
|
40
|
+
def self.running?
|
|
41
|
+
true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Set the irb_conf object to something other than IRB.conf
|
|
45
|
+
# usful for testing.
|
|
46
|
+
def self.irb_conf=(conf_hash)
|
|
47
|
+
@irb_conf = conf_hash
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.irb_conf
|
|
51
|
+
@irb_conf || IRB.conf
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.configure_irb
|
|
55
|
+
irb_conf[:HISTORY_FILE] = "~/.shef_history"
|
|
56
|
+
irb_conf[:SAVE_HISTORY] = 1000
|
|
57
|
+
|
|
58
|
+
irb_conf[:IRB_RC] = lambda do |conf|
|
|
59
|
+
m = conf.main
|
|
60
|
+
leader = LEADERS[m.class]
|
|
61
|
+
|
|
62
|
+
def m.help
|
|
63
|
+
shef_help
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
conf.prompt_c = "chef#{leader} > "
|
|
67
|
+
conf.return_format = " => %s \n"
|
|
68
|
+
conf.prompt_i = "chef#{leader} > "
|
|
69
|
+
conf.prompt_n = "chef#{leader} ?> "
|
|
70
|
+
conf.prompt_s = "chef#{leader}%l> "
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.session
|
|
75
|
+
client_type.instance.reset! unless client_type.instance.node_built?
|
|
76
|
+
client_type.instance
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def self.init
|
|
80
|
+
parse_json
|
|
81
|
+
configure_irb
|
|
82
|
+
|
|
83
|
+
session # trigger ohai run + session load
|
|
84
|
+
|
|
85
|
+
session.node.consume_attributes(@json_attribs)
|
|
86
|
+
|
|
87
|
+
greeting = begin
|
|
88
|
+
" #{Etc.getlogin}@#{Shef.session.node.name}"
|
|
89
|
+
rescue NameError
|
|
90
|
+
""
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
version
|
|
94
|
+
puts
|
|
95
|
+
|
|
96
|
+
puts "run `help' for help, `exit' or ^D to quit."
|
|
97
|
+
puts
|
|
98
|
+
puts "Ohai2u#{greeting}!"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def self.parse_json
|
|
102
|
+
if Chef::Config[:json_attribs]
|
|
103
|
+
begin
|
|
104
|
+
json_io = open(Chef::Config[:json_attribs])
|
|
105
|
+
rescue SocketError => error
|
|
106
|
+
fatal!("I cannot connect to #{Chef::Config[:json_attribs]}", 2)
|
|
107
|
+
rescue Errno::ENOENT => error
|
|
108
|
+
fatal!("I cannot find #{Chef::Config[:json_attribs]}", 2)
|
|
109
|
+
rescue Errno::EACCES => error
|
|
110
|
+
fatal!("Permissions are incorrect on #{Chef::Config[:json_attribs]}. Please chmod a+r #{Chef::Config[:json_attribs]}", 2)
|
|
111
|
+
rescue Exception => error
|
|
112
|
+
fatal!("Got an unexpected error reading #{Chef::Config[:json_attribs]}: #{error.message}", 2)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
begin
|
|
116
|
+
@json_attribs = JSON.parse(json_io.read)
|
|
117
|
+
rescue JSON::ParserError => error
|
|
118
|
+
fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def self.fatal!(message, exit_status)
|
|
124
|
+
Chef::Log.fatal(message)
|
|
125
|
+
exit exit_status
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def self.client_type
|
|
129
|
+
type = Shef::StandAloneSession
|
|
130
|
+
type = Shef::SoloSession if Chef::Config[:solo]
|
|
131
|
+
type = Shef::ClientSession if Chef::Config[:client]
|
|
132
|
+
type
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def self.parse_opts
|
|
136
|
+
@options = Options.new
|
|
137
|
+
@options.parse_opts
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
class Options
|
|
141
|
+
include Mixlib::CLI
|
|
142
|
+
|
|
143
|
+
option :config_file,
|
|
144
|
+
:short => "-c CONFIG",
|
|
145
|
+
:long => "--config CONFIG",
|
|
146
|
+
:description => "The configuration file to use"
|
|
147
|
+
|
|
148
|
+
option :help,
|
|
149
|
+
:short => "-h",
|
|
150
|
+
:long => "--help",
|
|
151
|
+
:description => "Show this message",
|
|
152
|
+
:on => :tail,
|
|
153
|
+
:boolean => true,
|
|
154
|
+
:show_options => true,
|
|
155
|
+
:exit => 0
|
|
156
|
+
|
|
157
|
+
option :standalone,
|
|
158
|
+
:short => "-a",
|
|
159
|
+
:long => "--standalone",
|
|
160
|
+
:description => "standalone shef session",
|
|
161
|
+
:default => true,
|
|
162
|
+
:boolean => true
|
|
163
|
+
|
|
164
|
+
option :solo,
|
|
165
|
+
:short => "-s",
|
|
166
|
+
:long => "--solo",
|
|
167
|
+
:description => "chef-solo shef session",
|
|
168
|
+
:boolean => true
|
|
169
|
+
|
|
170
|
+
option :client,
|
|
171
|
+
:short => "-z",
|
|
172
|
+
:long => "--client",
|
|
173
|
+
:description => "chef-client shef session",
|
|
174
|
+
:boolean => true
|
|
175
|
+
|
|
176
|
+
option :json_attribs,
|
|
177
|
+
:short => "-j JSON_ATTRIBS",
|
|
178
|
+
:long => "--json-attributes JSON_ATTRIBS",
|
|
179
|
+
:description => "Load attributes from a JSON file or URL",
|
|
180
|
+
:proc => nil
|
|
181
|
+
|
|
182
|
+
option :chef_server_url,
|
|
183
|
+
:short => "-S CHEFSERVERURL",
|
|
184
|
+
:long => "--server CHEFSERVERURL",
|
|
185
|
+
:description => "The chef server URL",
|
|
186
|
+
:proc => nil
|
|
187
|
+
|
|
188
|
+
option :version,
|
|
189
|
+
:short => "-v",
|
|
190
|
+
:long => "--version",
|
|
191
|
+
:description => "Show chef version",
|
|
192
|
+
:boolean => true,
|
|
193
|
+
:proc => lambda {|v| puts "Chef: #{::Chef::VERSION}"},
|
|
194
|
+
:exit => 0
|
|
195
|
+
|
|
196
|
+
def self.setup!
|
|
197
|
+
self.new.parse_opts
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def parse_opts
|
|
201
|
+
parse_options
|
|
202
|
+
config[:config_file] = config_file_for_shef_mode
|
|
203
|
+
config_msg = config[:config_file] || "none (standalone shef session)"
|
|
204
|
+
puts "loading configuration: #{config_msg}"
|
|
205
|
+
Chef::Config.from_file(config[:config_file]) if !config[:config_file].nil? && File.exists?(config[:config_file]) && File.readable?(config[:config_file])
|
|
206
|
+
Chef::Config.merge!(config)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
private
|
|
210
|
+
|
|
211
|
+
def config_file_for_shef_mode
|
|
212
|
+
return config[:config_file] if config[:config_file]
|
|
213
|
+
return "/etc/chef/solo.rb" if config[:solo]
|
|
214
|
+
return "/etc/chef/client.rb" if config[:client]
|
|
215
|
+
nil
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
end
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
|
2
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
|
3
|
+
# License:: Apache License, Version 2.0
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
module Shef
|
|
19
|
+
module Extensions
|
|
20
|
+
|
|
21
|
+
# Extensions to be included in object. These are methods that have to be
|
|
22
|
+
# defined on object but are not part of the user interface. Methods that
|
|
23
|
+
# are part of the user interface should have help text defined with the
|
|
24
|
+
# +desc+ macro, and need to be defined directly on Object in ext.rb
|
|
25
|
+
module Object
|
|
26
|
+
|
|
27
|
+
def ensure_session_select_defined
|
|
28
|
+
# irb breaks if you prematurely define IRB::JobMangager
|
|
29
|
+
# so these methods need to be defined at the latest possible time.
|
|
30
|
+
unless jobs.respond_to?(:select_session_by_context)
|
|
31
|
+
def jobs.select_session_by_context(&block)
|
|
32
|
+
@jobs.select { |job| block.call(job[1].context.main)}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
unless jobs.respond_to?(:session_select)
|
|
37
|
+
def jobs.select_shef_session(target_context)
|
|
38
|
+
session = if target_context.kind_of?(Class)
|
|
39
|
+
select_session_by_context { |main| main.kind_of?(target_context) }
|
|
40
|
+
else
|
|
41
|
+
select_session_by_context { |main| main.equal?(target_context) }
|
|
42
|
+
end
|
|
43
|
+
Array(session.first)[1]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def find_or_create_session_for(context_obj)
|
|
49
|
+
ensure_session_select_defined
|
|
50
|
+
if subsession = jobs.select_shef_session(context_obj)
|
|
51
|
+
jobs.switch(subsession)
|
|
52
|
+
else
|
|
53
|
+
irb(context_obj)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def help_banner(title=nil)
|
|
58
|
+
banner = []
|
|
59
|
+
banner << ""
|
|
60
|
+
banner << title if title
|
|
61
|
+
banner << "".ljust(80, "=")
|
|
62
|
+
banner << "| " + "Command".ljust(25) + "| " + "Description"
|
|
63
|
+
banner << "".ljust(80, "=")
|
|
64
|
+
self.class.all_help_descriptions.each do |cmd, description|
|
|
65
|
+
banner << "| " + cmd.ljust(25) + "| " + description
|
|
66
|
+
end
|
|
67
|
+
banner << "".ljust(80, "=")
|
|
68
|
+
banner << "\n"
|
|
69
|
+
banner.join("\n")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# helpfully returns +:on+ so we can have sugary syntax like `tracing on'
|
|
73
|
+
def on
|
|
74
|
+
:on
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# returns +:off+ so you can just do `tracing off'
|
|
78
|
+
def off
|
|
79
|
+
:off
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
module ClassMethods
|
|
83
|
+
|
|
84
|
+
def help_descriptions
|
|
85
|
+
@help_descriptions ||= []
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def all_help_descriptions
|
|
89
|
+
if sc = superclass
|
|
90
|
+
help_descriptions + sc.help_descriptions
|
|
91
|
+
else
|
|
92
|
+
help_descriptions
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def desc(help_text)
|
|
97
|
+
@desc = help_text
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def subcommands(subcommand_help={})
|
|
101
|
+
@subcommand_help = subcommand_help
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def method_added(mname)
|
|
105
|
+
if @desc
|
|
106
|
+
help_descriptions << [mname.to_s, @desc.to_s]
|
|
107
|
+
@desc = nil
|
|
108
|
+
end
|
|
109
|
+
if @subcommand_help
|
|
110
|
+
@subcommand_help.each do |subcommand, text|
|
|
111
|
+
help_descriptions << ["#{mname}.#{subcommand}", text.to_s]
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
@subcommand_help = {}
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
module String
|
|
122
|
+
def on_off_to_bool
|
|
123
|
+
case self
|
|
124
|
+
when "on"
|
|
125
|
+
true
|
|
126
|
+
when "off"
|
|
127
|
+
false
|
|
128
|
+
else
|
|
129
|
+
self
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
module Symbol
|
|
135
|
+
def on_off_to_bool
|
|
136
|
+
self.to_s.on_off_to_bool
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
module TrueClass
|
|
141
|
+
def to_on_off_str
|
|
142
|
+
"on"
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def on_off_to_bool
|
|
146
|
+
self
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
module FalseClass
|
|
151
|
+
def to_on_off_str
|
|
152
|
+
"off"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def on_off_to_bool
|
|
156
|
+
self
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
class String
|
|
164
|
+
include Shef::Extensions::String
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
class Symbol
|
|
168
|
+
include Shef::Extensions::Symbol
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
class TrueClass
|
|
172
|
+
include Shef::Extensions::TrueClass
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
class FalseClass
|
|
176
|
+
include Shef::Extensions::FalseClass
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
class Object
|
|
180
|
+
extend Shef::Extensions::Object::ClassMethods
|
|
181
|
+
include Shef::Extensions::Object
|
|
182
|
+
include FileUtils
|
|
183
|
+
|
|
184
|
+
desc "prints this help message"
|
|
185
|
+
def shef_help(title="Help: Shef")
|
|
186
|
+
#puts Shef::Extensions::Object.help_banner("Shef Help")
|
|
187
|
+
puts help_banner(title)
|
|
188
|
+
:ucanhaz_halp
|
|
189
|
+
end
|
|
190
|
+
alias :halp :shef_help
|
|
191
|
+
|
|
192
|
+
desc "prints information about chef"
|
|
193
|
+
def version
|
|
194
|
+
puts "This is shef, the Chef shell.\n" +
|
|
195
|
+
" Chef Version: #{::Chef::VERSION}\n" +
|
|
196
|
+
" http://www.opscode.com/chef\n" +
|
|
197
|
+
" http://wiki.opscode.com/display/chef/Home"
|
|
198
|
+
:ucanhaz_automation
|
|
199
|
+
end
|
|
200
|
+
alias :shef :version
|
|
201
|
+
|
|
202
|
+
desc "switch to recipe mode"
|
|
203
|
+
def recipe
|
|
204
|
+
find_or_create_session_for Shef.session.recipe
|
|
205
|
+
:recipe
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
desc "switch to attributes mode"
|
|
209
|
+
def attributes
|
|
210
|
+
find_or_create_session_for Shef.session.node
|
|
211
|
+
:attributes
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
desc "returns the current node (i.e., this host)"
|
|
215
|
+
def node
|
|
216
|
+
Shef.session.node
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
desc "pretty print the node's attributes"
|
|
220
|
+
def ohai(key=nil)
|
|
221
|
+
pp(key ? node.attribute[key] : node.attribute)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
desc "run chef using the current recipe"
|
|
225
|
+
def run_chef
|
|
226
|
+
Chef::Log.level = :debug
|
|
227
|
+
session = Shef.session
|
|
228
|
+
session.rebuild_collection
|
|
229
|
+
runrun = Chef::Runner.new(node, session.collection, session.definitions, session.cookbook_loader).converge
|
|
230
|
+
Chef::Log.level = :info
|
|
231
|
+
runrun
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
desc "returns an object to control a paused chef run"
|
|
235
|
+
subcommands :resume => "resume the chef run",
|
|
236
|
+
:step => "run only the next resource",
|
|
237
|
+
:skip_back => "move back in the run list",
|
|
238
|
+
:skip_forward => "move forward in the run list"
|
|
239
|
+
def chef_run
|
|
240
|
+
Shef.session.collection.iterator
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
desc "resets the current recipe"
|
|
244
|
+
def reset
|
|
245
|
+
Shef.session.reset!
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
desc "turns printout of return values on or off"
|
|
249
|
+
def echo(on_or_off)
|
|
250
|
+
conf.echo = on_or_off.on_off_to_bool
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
desc "says if echo is on or off"
|
|
254
|
+
def echo?
|
|
255
|
+
puts "echo is #{conf.echo.to_on_off_str}"
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
desc "turns on or off tracing of execution. *verbose*"
|
|
259
|
+
def tracing(on_or_off)
|
|
260
|
+
conf.use_tracer = on_or_off.on_off_to_bool
|
|
261
|
+
tracing?
|
|
262
|
+
end
|
|
263
|
+
alias :trace :tracing
|
|
264
|
+
|
|
265
|
+
desc "says if tracing is on or off"
|
|
266
|
+
def tracing?
|
|
267
|
+
puts "tracing is #{conf.use_tracer.to_on_off_str}"
|
|
268
|
+
end
|
|
269
|
+
alias :trace? :tracing?
|
|
270
|
+
|
|
271
|
+
desc "simple ls style command"
|
|
272
|
+
def ls(directory)
|
|
273
|
+
Dir.entries(directory)
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
class Chef
|
|
279
|
+
class Recipe
|
|
280
|
+
|
|
281
|
+
def shef_help
|
|
282
|
+
super("Help: Shef/Recipe")
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
alias :original_resources :resources
|
|
286
|
+
|
|
287
|
+
desc "list all the resources on the current recipe"
|
|
288
|
+
def resources(*args)
|
|
289
|
+
if args.empty?
|
|
290
|
+
pp collection.instance_variable_get(:@resources_by_name).keys
|
|
291
|
+
else
|
|
292
|
+
pp resources = original_resources(*args)
|
|
293
|
+
resources
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
end
|