chef 0.7.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +396 -0
- data/lib/chef/compile.rb +138 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +144 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +168 -0
- data/lib/chef/couchdb.rb +172 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +351 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +99 -0
- data/lib/chef/mixin/from_file.rb +36 -0
- data/lib/chef/mixin/generate_url.rb +48 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +253 -0
- data/lib/chef/provider.rb +40 -0
- data/lib/chef/provider/cron.rb +137 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/groupadd.rb +92 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +121 -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 +113 -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 +130 -0
- data/lib/chef/provider/package/yum-dump.py +104 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +134 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +129 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +126 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/template.rb +141 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +210 -0
- data/lib/chef/resource.rb +256 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +143 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -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/group.rb +68 -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/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 +20 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +176 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +123 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +345 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +262 -0
@@ -0,0 +1,51 @@
|
|
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/resource/execute'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Resource
|
23
|
+
class Script < Chef::Resource::Execute
|
24
|
+
|
25
|
+
def initialize(name, collection=nil, node=nil)
|
26
|
+
super(name, collection, node)
|
27
|
+
@resource_name = :script
|
28
|
+
@command = name
|
29
|
+
@code = nil
|
30
|
+
@interpreter = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def code(arg=nil)
|
34
|
+
set_or_return(
|
35
|
+
:code,
|
36
|
+
arg,
|
37
|
+
:kind_of => [ String ]
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def interpreter(arg=nil)
|
42
|
+
set_or_return(
|
43
|
+
:interpreter,
|
44
|
+
arg,
|
45
|
+
:kind_of => [ String ]
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#
|
2
|
+
# Author:: AJ Christensen (<aj@hjksolutions.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/resource'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Resource
|
23
|
+
class Service < Chef::Resource
|
24
|
+
|
25
|
+
def initialize(name, collection=nil, node=nil)
|
26
|
+
super(name, collection, node)
|
27
|
+
@resource_name = :service
|
28
|
+
@service_name = name
|
29
|
+
@enabled = nil
|
30
|
+
@running = nil
|
31
|
+
@pattern = service_name
|
32
|
+
@start_command = nil
|
33
|
+
@stop_command = nil
|
34
|
+
@status_command = nil
|
35
|
+
@restart_command = nil
|
36
|
+
@reload_command = nil
|
37
|
+
@action = "nothing"
|
38
|
+
@supports = { :restart => false, :reload => false, :status => false }
|
39
|
+
@allowed_actions.push(:enable, :disable, :start, :stop, :restart, :reload)
|
40
|
+
end
|
41
|
+
|
42
|
+
def service_name(arg=nil)
|
43
|
+
set_or_return(
|
44
|
+
:service_name,
|
45
|
+
arg,
|
46
|
+
:kind_of => [ String ]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
# regex for match against ps -ef when !supports[:has_status] && status == nil
|
51
|
+
def pattern(arg=nil)
|
52
|
+
set_or_return(
|
53
|
+
:pattern,
|
54
|
+
arg,
|
55
|
+
:kind_of => [ String ]
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
# command to call to start service
|
60
|
+
def start_command(arg=nil)
|
61
|
+
set_or_return(
|
62
|
+
:start_command,
|
63
|
+
arg,
|
64
|
+
:kind_of => [ String ]
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
# command to call to stop service
|
69
|
+
def stop_command(arg=nil)
|
70
|
+
set_or_return(
|
71
|
+
:stop_command,
|
72
|
+
arg,
|
73
|
+
:kind_of => [ String ]
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
# command to call to get status of service
|
78
|
+
def status_command(arg=nil)
|
79
|
+
set_or_return(
|
80
|
+
:status_command,
|
81
|
+
arg,
|
82
|
+
:kind_of => [ String ]
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
# command to call to restart service
|
87
|
+
def restart_command(arg=nil)
|
88
|
+
set_or_return(
|
89
|
+
:restart_command,
|
90
|
+
arg,
|
91
|
+
:kind_of => [ String ]
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
def reload_command(arg=nil)
|
96
|
+
set_or_return(
|
97
|
+
:reload_command,
|
98
|
+
arg,
|
99
|
+
:kind_of => [ String ]
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
# if the service is enabled or not
|
104
|
+
def enabled(arg=nil)
|
105
|
+
set_or_return(
|
106
|
+
:enabled,
|
107
|
+
arg,
|
108
|
+
:kind_of => [ TrueClass, FalseClass ]
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
# if the service is running or not
|
113
|
+
def running(arg=nil)
|
114
|
+
set_or_return(
|
115
|
+
:running,
|
116
|
+
arg,
|
117
|
+
:kind_of => [ TrueClass, FalseClass ]
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
def supports(args={})
|
122
|
+
if args.is_a? Array
|
123
|
+
args.each { |arg| @supports[arg] = true }
|
124
|
+
elsif args.any?
|
125
|
+
@supports = args
|
126
|
+
else
|
127
|
+
@supports
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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/resource/file'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Resource
|
23
|
+
class Template < Chef::Resource::File
|
24
|
+
|
25
|
+
def initialize(name, collection=nil, node=nil)
|
26
|
+
super(name, collection, node)
|
27
|
+
@resource_name = :template
|
28
|
+
@action = "create"
|
29
|
+
@source = "#{::File.basename(name)}.erb"
|
30
|
+
@cookbook = nil
|
31
|
+
@variables = Hash.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def source(file=nil)
|
35
|
+
set_or_return(
|
36
|
+
:source,
|
37
|
+
file,
|
38
|
+
:kind_of => [ String ]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def variables(args=nil)
|
43
|
+
set_or_return(
|
44
|
+
:variables,
|
45
|
+
args,
|
46
|
+
:kind_of => [ Hash ]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def cookbook(args=nil)
|
51
|
+
set_or_return(
|
52
|
+
:cookbook,
|
53
|
+
args,
|
54
|
+
:kind_of => [ String ]
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,98 @@
|
|
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/resource'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Resource
|
23
|
+
class User < Chef::Resource
|
24
|
+
|
25
|
+
def initialize(name, collection=nil, node=nil)
|
26
|
+
super(name, collection, node)
|
27
|
+
@resource_name = :user
|
28
|
+
@username = name
|
29
|
+
@comment = nil
|
30
|
+
@uid = nil
|
31
|
+
@gid = nil
|
32
|
+
@home = nil
|
33
|
+
@shell = nil
|
34
|
+
@password = nil
|
35
|
+
@action = :create
|
36
|
+
@supports = { :manage_home => false }
|
37
|
+
@allowed_actions.push(:create, :remove, :modify, :manage, :lock, :unlock)
|
38
|
+
end
|
39
|
+
|
40
|
+
def username(arg=nil)
|
41
|
+
set_or_return(
|
42
|
+
:username,
|
43
|
+
arg,
|
44
|
+
:kind_of => [ String ]
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def comment(arg=nil)
|
49
|
+
set_or_return(
|
50
|
+
:comment,
|
51
|
+
arg,
|
52
|
+
:kind_of => [ String ]
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def uid(arg=nil)
|
57
|
+
set_or_return(
|
58
|
+
:uid,
|
59
|
+
arg,
|
60
|
+
:kind_of => [ String, Integer ]
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def gid(arg=nil)
|
65
|
+
set_or_return(
|
66
|
+
:gid,
|
67
|
+
arg,
|
68
|
+
:kind_of => [ String, Integer ]
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def home(arg=nil)
|
73
|
+
set_or_return(
|
74
|
+
:home,
|
75
|
+
arg,
|
76
|
+
:kind_of => [ String ]
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def shell(arg=nil)
|
81
|
+
set_or_return(
|
82
|
+
:shell,
|
83
|
+
arg,
|
84
|
+
:kind_of => [ String ]
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
def password(arg=nil)
|
89
|
+
set_or_return(
|
90
|
+
:password,
|
91
|
+
arg,
|
92
|
+
:kind_of => [ String ]
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,176 @@
|
|
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/resource'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class ResourceCollection
|
23
|
+
include Enumerable
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@resources = Array.new
|
27
|
+
@resources_by_name = Hash.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def [](index)
|
31
|
+
@resources[index]
|
32
|
+
end
|
33
|
+
|
34
|
+
def []=(index, arg)
|
35
|
+
is_chef_resource(arg)
|
36
|
+
@resources[index] = arg
|
37
|
+
@resources_by_name[arg.to_s] = index
|
38
|
+
end
|
39
|
+
|
40
|
+
def <<(*args)
|
41
|
+
args.flatten.each do |a|
|
42
|
+
is_chef_resource(a)
|
43
|
+
@resources << a
|
44
|
+
@resources_by_name[a.to_s] = @resources.length - 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def push(*args)
|
49
|
+
args.flatten.each do |a|
|
50
|
+
is_chef_resource(a)
|
51
|
+
@resources.push(a)
|
52
|
+
@resources_by_name[a.to_s] = @resources.length - 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def each
|
57
|
+
@resources.each do |r|
|
58
|
+
yield r
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def each_index
|
63
|
+
@resources.each_index do |i|
|
64
|
+
yield i
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def lookup(resource)
|
69
|
+
lookup_by = nil
|
70
|
+
if resource.kind_of?(Chef::Resource)
|
71
|
+
lookup_by = resource.to_s
|
72
|
+
elsif resource.kind_of?(String)
|
73
|
+
lookup_by = resource
|
74
|
+
else
|
75
|
+
raise ArgumentError, "Must pass a Chef::Resource or String to lookup"
|
76
|
+
end
|
77
|
+
res = @resources_by_name[lookup_by]
|
78
|
+
unless res
|
79
|
+
raise ArgumentError, "Cannot find a resource matching #{lookup_by} (did you define it first?)"
|
80
|
+
end
|
81
|
+
@resources[res]
|
82
|
+
end
|
83
|
+
|
84
|
+
# Find existing resources by searching the list of existing resources. Possible
|
85
|
+
# forms are:
|
86
|
+
#
|
87
|
+
# resources(:file => "foobar")
|
88
|
+
# resources(:file => [ "foobar", "baz" ])
|
89
|
+
# resources("file[foobar]", "file[baz]")
|
90
|
+
# resources("file[foobar,baz]")
|
91
|
+
#
|
92
|
+
# Returns the matching resource, or an Array of matching resources.
|
93
|
+
#
|
94
|
+
# Raises an ArgumentError if you feed it bad lookup information
|
95
|
+
# Raises a Runtime Error if it can't find the resources you are looking for.
|
96
|
+
def resources(*args)
|
97
|
+
results = Array.new
|
98
|
+
args.each do |arg|
|
99
|
+
case arg
|
100
|
+
when Hash
|
101
|
+
results << find_resource_by_hash(arg)
|
102
|
+
when String
|
103
|
+
results << find_resource_by_string(arg)
|
104
|
+
else
|
105
|
+
raise ArgumentError, "resources takes arguments as a hash or strings!"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
flat_results = results.flatten
|
109
|
+
flat_results.length == 1 ? flat_results[0] : flat_results
|
110
|
+
end
|
111
|
+
|
112
|
+
# Serialize this object as a hash
|
113
|
+
def to_json(*a)
|
114
|
+
instance_vars = Hash.new
|
115
|
+
self.instance_variables.each do |iv|
|
116
|
+
instance_vars[iv] = self.instance_variable_get(iv)
|
117
|
+
end
|
118
|
+
results = {
|
119
|
+
'json_class' => self.class.name,
|
120
|
+
'instance_vars' => instance_vars
|
121
|
+
}
|
122
|
+
results.to_json(*a)
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.json_create(o)
|
126
|
+
collection = self.new()
|
127
|
+
o["instance_vars"].each do |k,v|
|
128
|
+
collection.instance_variable_set(k.to_sym, v)
|
129
|
+
end
|
130
|
+
collection
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def find_resource_by_hash(arg)
|
136
|
+
results = Array.new
|
137
|
+
arg.each do |resource_name, name_list|
|
138
|
+
names = name_list.kind_of?(Array) ? name_list : [ name_list ]
|
139
|
+
names.each do |name|
|
140
|
+
res_name = "#{resource_name.to_s}[#{name}]"
|
141
|
+
results << lookup(res_name)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
return results
|
145
|
+
end
|
146
|
+
|
147
|
+
def find_resource_by_string(arg)
|
148
|
+
results = Array.new
|
149
|
+
case arg
|
150
|
+
when /^(.+)\[(.+?),(.+)\]$/
|
151
|
+
resource_type = $1
|
152
|
+
arg =~ /^.+\[(.+)\]$/
|
153
|
+
resource_list = $1
|
154
|
+
resource_list.split(",").each do |name|
|
155
|
+
resource_name = "#{resource_type}[#{name}]"
|
156
|
+
results << lookup(resource_name)
|
157
|
+
end
|
158
|
+
when /^(.+)\[(.+)\]$/
|
159
|
+
resource_type = $1
|
160
|
+
name = $2
|
161
|
+
resource_name = "#{resource_type}[#{name}]"
|
162
|
+
results << lookup(resource_name)
|
163
|
+
else
|
164
|
+
raise ArgumentError, "You must have a string like resource_type[name]!"
|
165
|
+
end
|
166
|
+
return results
|
167
|
+
end
|
168
|
+
|
169
|
+
def is_chef_resource(arg)
|
170
|
+
unless arg.kind_of?(Chef::Resource)
|
171
|
+
raise ArgumentError, "Members must be Chef::Resource's"
|
172
|
+
end
|
173
|
+
true
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|