Skip to content

Instantly share code, notes, and snippets.

@joewilliams
Created September 11, 2009 03:54
Show Gist options
  • Save joewilliams/185065 to your computer and use it in GitHub Desktop.
Save joewilliams/185065 to your computer and use it in GitHub Desktop.
#
# Author:: Joe Williams (<[email protected]>)
# Copyright:: Copyright (c) 2009 Joe Williams
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/log'
require 'chef/mixin/command'
require 'chef/provider'
class Chef
class Provider
class ErlCall < Chef::Provider
include Chef::Mixin::Command
def initialize(node, new_resource)
super(node, new_resource)
action_run
end
def action_run
case @new_resource.name_type
when "sname"
node = "-sname #{@new_resource.node_name}"
when "name"
node = "-name #{@new_resource.node_name}"
end
if @new_resource.cookie
cookie = "-c #{@new_resource.cookie}"
else
cookie = ""
end
if @new_resource.distributed
distributed = "-s"
else
distributed = ""
end
status = popen4("erl_call -e #{distributed} #{cookie} #{node}") do |pid, stdin, stdout, stderr|
Chef::Log.info("Running erl_call '#{@new_resource.name}' on '#{@new_resource.node_name}'")
@new_resource.code.each { |line| stdin.puts "#{line}" }
stdin.close
Chef::Log.debug("Output from erl_call on '#{@new_resource.node_name}': ")
stdout.each { |line| Chef::Log.debug("#{line}")}
end
end
end
end
end
#
# Author:: Joe Williams (<[email protected]>)
# Copyright:: Copyright (c) 2009 Joe Williams
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/resource'
class Chef
class Resource
class ErlCall < Chef::Resource
def initialize(name, collection=nil, node=nil)
super(name, collection, node)
@resource_name = :erl_call
@cookie = nil
@node_name = "chef@localhost"
@name_type = "sname"
@distributed = false
end
def cookie(arg=nil)
set_or_return(
:cookie,
arg,
:kind_of => [ String ]
)
end
def distributed(arg=nil)
set_or_return(
:distributed,
arg,
:kind_of => [ TrueClass, FalseClass ]
)
end
def name(arg=nil)
set_or_return(
:name,
arg,
:kind_of => [ String ]
)
end
def name_type(arg=nil)
set_or_return(
:sname,
arg,
:kind_of => [ String ]
)
end
def node_name(arg=nil)
set_or_return(
:name,
arg,
:kind_of => [ String ]
)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment