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

View file

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