Skip to content

Commit 0032da3

Browse files
committed
added in initial erl_call provider/resource
1 parent cff2291 commit 0032da3

2 files changed

Lines changed: 140 additions & 0 deletions

File tree

chef/lib/chef/provider/erl_call.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# Author:: Joe Williams (<joe@joetify.com>)
3+
# Copyright:: Copyright (c) 2009 Joe Williams
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/log'
20+
require 'chef/mixin/command'
21+
require 'chef/provider'
22+
23+
class Chef
24+
class Provider
25+
class ErlCall < Chef::Provider
26+
include Chef::Mixin::Command
27+
28+
def initialize(node, new_resource)
29+
super(node, new_resource)
30+
action_run
31+
end
32+
33+
def action_run
34+
case @new_resource.name_type
35+
when "sname"
36+
node = "-sname #{@new_resource.node_name}"
37+
when "name"
38+
node = "-name #{@new_resource.node_name}"
39+
end
40+
41+
if @new_resource.cookie
42+
cookie = "-c #{@new_resource.cookie}"
43+
else
44+
cookie = ""
45+
end
46+
47+
if @new_resource.distributed
48+
distributed = "-s"
49+
else
50+
distributed = ""
51+
end
52+
53+
status = popen4("erl_call -e #{distributed} #{cookie} #{node}") do |pid, stdin, stdout, stderr|
54+
Chef::Log.info("Running erl_call '#{@new_resource.name}' on '#{@new_resource.node_name}'")
55+
@new_resource.code.each { |line| stdin.puts "#{line}" }
56+
stdin.close
57+
Chef::Log.debug("Output from erl_call on '#{@new_resource.node_name}': ")
58+
stdout.each { |line| Chef::Log.debug("#{line}")}
59+
end
60+
end
61+
62+
end
63+
end
64+
end

chef/lib/chef/resource/erl_call.rb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# Author:: Joe Williams (<joe@joetify.com>)
3+
# Copyright:: Copyright (c) 2009 Joe Williams
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 ErlCall < Chef::Resource
24+
25+
def initialize(name, collection=nil, node=nil)
26+
super(name, collection, node)
27+
@resource_name = :erl_call
28+
@cookie = nil
29+
@node_name = "chef@localhost"
30+
@name_type = "sname"
31+
@distributed = false
32+
end
33+
34+
def cookie(arg=nil)
35+
set_or_return(
36+
:cookie,
37+
arg,
38+
:kind_of => [ String ]
39+
)
40+
end
41+
42+
def distributed(arg=nil)
43+
set_or_return(
44+
:distributed,
45+
arg,
46+
:kind_of => [ TrueClass, FalseClass ]
47+
)
48+
end
49+
50+
def name(arg=nil)
51+
set_or_return(
52+
:name,
53+
arg,
54+
:kind_of => [ String ]
55+
)
56+
end
57+
58+
def name_type(arg=nil)
59+
set_or_return(
60+
:sname,
61+
arg,
62+
:kind_of => [ String ]
63+
)
64+
end
65+
66+
def node_name(arg=nil)
67+
set_or_return(
68+
:name,
69+
arg,
70+
:kind_of => [ String ]
71+
)
72+
end
73+
74+
end
75+
end
76+
end

0 commit comments

Comments
 (0)