Fixed error "warning: class variable access from toplevel" from OpenBSD service providers when running with ruby 1.9 series.

This commit is contained in:
Timo Mkinen 2012-07-02 12:13:24 +03:00
parent f21b658ed3
commit 52431fa155
2 changed files with 35 additions and 33 deletions

View file

@ -9,23 +9,25 @@ Puppet::Type.type(:service).provide :openbsd, :parent => :base do
confine :operatingsystemrelease => version
defaultfor :operatingsystem => :openbsd
@@rc_dir = '/etc/rc.d'
@@rcconf = '/etc/rc.conf'
@@rcconf_local = '/etc/rc.conf.local'
def rc_dir() '/etc/rc.d' end
def rcconf() '/etc/rc.conf' end
def rcconf_local() '/etc/rc.conf.local' end
if Facter["operatingsystemrelease"].value == "4.9"
@@pkg_scripts_var = "rc_scripts"
else
@@pkg_scripts_var = "pkg_scripts"
def pkg_scripts_var()
if Facter["operatingsystemrelease"].value == "4.9"
return "rc_scripts"
else
return "pkg_scripts"
end
end
def rcscript
return File.join(@@rc_dir, @resource[:name])
return File.join(rc_dir, @resource[:name])
end
def rcvar
name = @resource[:name]
File.open(@@rcconf).each do |line|
File.open(rcconf).each do |line|
if line =~ /^#{name}(_flags)?=/
line = line.sub(/#.*/, "")
return line.strip.split("=", 2)
@ -36,7 +38,7 @@ Puppet::Type.type(:service).provide :openbsd, :parent => :base do
def rcvar_local
name = @resource[:name]
File.open(@@rcconf_local).each do |line|
File.open(rcconf_local).each do |line|
if line =~ /^#{name}(_flags)?=/
line = line.sub(/#.*/, "")
return line.strip.split("=", 2)
@ -60,9 +62,9 @@ Puppet::Type.type(:service).provide :openbsd, :parent => :base do
end
def pkg_scripts
File.open(@@rcconf_local).each do |line|
if line =~ /^#{@@pkg_scripts_var}=/
return line.strip.gsub(/#{@@pkg_scripts_var}="?([^"]*)"?/, '\1').split
File.open(rcconf_local).each do |line|
if line =~ /^#{pkg_scripts_var}=/
return line.strip.gsub(/#{pkg_scripts_var}="?([^"]*)"?/, '\1').split
end
end
Array.new
@ -92,8 +94,8 @@ Puppet::Type.type(:service).provide :openbsd, :parent => :base do
start = @resource[:start]
binary = @resource[:binary]
s = ""
File.open(@@rcconf_local).each do |line|
next if line =~ /^(#{rcvar_name}|#{@@pkg_scripts_var})=/
File.open(rcconf_local).each do |line|
next if line =~ /^(#{rcvar_name}|#{pkg_scripts_var})=/
s += line
end
unless start.nil?
@ -109,8 +111,8 @@ Puppet::Type.type(:service).provide :openbsd, :parent => :base do
s += "%s=YES\n" % rcvar_name
end
pkg_scripts << name if rcvar.nil? and not pkg_scripts.include?(name)
s += "#{@@pkg_scripts_var}=\"%s\"\n" % pkg_scripts.join(" ")
File.open(@@rcconf_local, "w") { |f| f << s }
s += "#{pkg_scripts_var}=\"%s\"\n" % pkg_scripts.join(" ")
File.open(rcconf_local, "w") { |f| f << s }
end
def disable
@ -119,14 +121,14 @@ Puppet::Type.type(:service).provide :openbsd, :parent => :base do
rcvar_name = self.rcvar_name
pkg_scripts = self.pkg_scripts
s = ""
File.open(@@rcconf_local).each do |line|
next if line =~ /^(#{rcvar_name}|#{@@pkg_scripts_var})=/
File.open(rcconf_local).each do |line|
next if line =~ /^(#{rcvar_name}|#{pkg_scripts_var})=/
s += line
end
s += "%s=NO\n" % rcvar_name unless rcvar.nil?
pkg_scripts.delete(name)
s += "#{@@pkg_scripts_var}=\"%s\"\n" % pkg_scripts.join(" ")
File.open(@@rcconf_local, "w") { |f| f << s }
s += "#{pkg_scripts_var}=\"%s\"\n" % pkg_scripts.join(" ")
File.open(rcconf_local, "w") { |f| f << s }
end
def startcmd

View file

@ -9,12 +9,12 @@ Puppet::Type.type(:service).provide :openbsd_old, :parent => :base do
confine :operatingsystemrelease => version
defaultfor :operatingsystem => :openbsd
@@rclocal = "/etc/rc.local"
@@rcconf = "/etc/rc.conf"
@@rcconflocal = "/etc/rc.conf.local"
def rclocal() '/etc/rc.local' end
def rcconf() '/etc/rc.conf' end
def rcconflocal() '/etc/rc.conf.local' end
def getrcconf
File.readlines(@@rcconf).each { |line|
File.readlines(rcconf).each { |line|
if line =~ /^#{@resource[:name]}_flags=.*/
return "#{@resource[:name]}_flags"
elsif line =~ /^#{@resource[:name]}=.*/
@ -31,7 +31,7 @@ Puppet::Type.type(:service).provide :openbsd_old, :parent => :base do
end
flag = getrcconf()
if flag
File.readlines(@@rcconflocal).each { |line|
File.readlines(rcconflocal).each { |line|
line = line.strip.split(/=/, 2)
next unless line[0] == flag
if line[1] == "NO"
@ -42,7 +42,7 @@ Puppet::Type.type(:service).provide :openbsd_old, :parent => :base do
return :false
else
inlocal = false
File.readlines(@@rclocal).each { |line|
File.readlines(rclocal).each { |line|
line = line.strip
if not inlocal
next unless \
@ -65,7 +65,7 @@ Puppet::Type.type(:service).provide :openbsd_old, :parent => :base do
flag = getrcconf()
if flag
newdata = ""
File.readlines(@@rcconflocal).each { |line|
File.readlines(rcconflocal).each { |line|
if line.strip.split(/=/, 2)[0] == flag
next
else
@ -80,13 +80,13 @@ Puppet::Type.type(:service).provide :openbsd_old, :parent => :base do
end
newdata += "%s=\"%s\"\n" % [flag, args]
end
f = File.open(@@rcconflocal, "w")
f = File.open(rcconflocal, "w")
f.write(newdata)
f.close
else
newdata = ""
inlocal = false
File.readlines(@@rclocal).each { |line|
File.readlines(rclocal).each { |line|
if line == "# Add your local startup actions here.\n"
newdata += line
newdata += "echo -n \" %s\" ; %s\n" % [@resource[:name],
@ -95,7 +95,7 @@ Puppet::Type.type(:service).provide :openbsd_old, :parent => :base do
end
newdata += line
}
f = File.open(@@rclocal, "w")
f = File.open(rclocal, "w")
f.write(newdata)
f.close
end
@ -106,7 +106,7 @@ Puppet::Type.type(:service).provide :openbsd_old, :parent => :base do
flag = getrcconf()
if flag
newdata = ""
File.readlines(@@rcconflocal).each { |line|
File.readlines(rcconflocal).each { |line|
if line.strip.split(/=/, 2)[0] == flag
next
else
@ -116,7 +116,7 @@ Puppet::Type.type(:service).provide :openbsd_old, :parent => :base do
if flag == @resource[:name] or flag == "#{@resource[:name]}_flags"
newdata += "%s=NO\n" % flag
end
f = File.open(@@rcconflocal, "w")
f = File.open(rcconflocal, "w")
f.write(newdata)
f.close
else