Some small clarifying refactors and change to objectadd to allow subclasses of

with a uid not need to be a single class us use modify

I don't like logic about subclasses in a parent class, but not in a position to
address.
This commit is contained in:
Andrew Shafer 2008-10-01 18:00:17 -06:00
Родитель 4a863c38ce
Коммит 2fba85af73
2 изменённых файлов: 25 добавлений и 49 удалений

Просмотреть файл

@ -179,11 +179,33 @@ class Puppet::Provider::NameService < Puppet::Provider
end
def create
self.ensure = :present
if exists?
info "already exists"
# The object already exists
return nil
end
begin
execute(self.addcmd)
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not create %s %s: %s" %
[@resource.class.name, @resource.name, detail]
end
end
def delete
self.ensure = :absent
unless exists?
info "already absent"
# the object already doesn't exist
return nil
end
begin
execute(self.deletecmd)
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not delete %s %s: %s" %
[@resource.class.name, @resource.name, detail]
end
end
def ensure
@ -194,43 +216,6 @@ class Puppet::Provider::NameService < Puppet::Provider
end
end
# This is only used when creating or destroying the object.
def ensure=(value)
cmd = nil
event = nil
case value
when :absent
# we need to remove the object...
unless exists?
info "already absent"
# the object already doesn't exist
return nil
end
# again, needs to be set by the ind. property or its
# parent
cmd = self.deletecmd
type = "delete"
when :present
if exists?
info "already exists"
# The object already exists
return nil
end
# blah blah, define elsewhere, blah blah
cmd = self.addcmd
type = "create"
end
begin
execute(cmd)
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not %s %s %s: %s" %
[type, @resource.class.name, @resource.name, detail]
end
end
# Does our object exist?
def exists?
if getinfo(true)

Просмотреть файл

@ -2,15 +2,6 @@ require 'puppet/provider/nameservice'
class Puppet::Provider::NameService
class ObjectAdd < Puppet::Provider::NameService
# Does the object already exist?
def self.exists?(obj)
if obj.getinfo(true)
return true
else
return false
end
end
def deletecmd
[command(:delete), @resource[:name]]
end
@ -23,7 +14,7 @@ class ObjectAdd < Puppet::Provider::NameService
def modifycmd(param, value)
cmd = [command(:modify), flag(param), value]
if @resource.allowdupe? && ((param == :uid and self.class.name == :useradd) || (param == :gid and self.class.name == :groupadd))
if @resource.allowdupe? && ((param == :uid) || (param == :gid and self.class.name == :groupadd))
cmd << "-o"
end
cmd << @resource[:name]