1
# Manage NetInfo POSIX objects.
3
# This provider has been deprecated. You should be using the directoryservice
4
# nameservice provider instead.
7
require 'puppet/provider/nameservice'
9
class Puppet::Provider::NameService
10
class NetInfo < Puppet::Provider::NameService
12
attr_writer :netinfodir
15
# We have to initialize manually because we're not using
19
commands :lookupd => "/usr/sbin/lookupd"
21
# Attempt to flush the database, but this doesn't seem to work at all.
25
rescue Puppet::ExecutionFailure
26
# Don't throw an error; it's just a failed cache flush
27
Puppet.err "Could not flush lookupd cache: %s" % output
31
# Similar to posixmethod, what key do we use to get data? Defaults
32
# to being the object name.
34
if defined? @netinfodir
37
return @resource_type.name.to_s + "s"
51
warnonce "The NetInfo provider is deprecated; use directoryservice instead"
52
report(@resource_type.validproperties).collect do |hash|
57
# Convert a NetInfo line into a hash of data.
58
def self.line2hash(line, params)
59
values = line.split(/\t/)
62
params.zip(values).each do |param, value|
63
next if value == '#NoValue#'
64
hash[param] = if value =~ /^[-0-9]+$/
73
# What field the value is stored under.
74
def self.netinfokey(name)
75
name = symbolize(name)
76
self.option(name, :key) || name
79
# Retrieve the data, yo.
80
# FIXME This should retrieve as much information as possible,
81
# rather than retrieving it one at a time.
82
def self.report(*params)
83
dir = self.netinfodir()
84
cmd = [command(:nireport), "/", "/%s" % dir]
88
# We require the name in order to know if we match. There's no
89
# way to just report on our individual object, we have to get the
91
params.unshift :name unless params.include? :name
93
params.each do |param|
94
if key = netinfokey(param)
97
raise Puppet::DevError,
98
"Could not find netinfokey for property %s" %
104
output = execute(cmd)
105
rescue Puppet::ExecutionFailure => detail
106
Puppet.err "Failed to call nireport: %s" % detail
110
return output.split("\n").collect { |line|
111
line2hash(line, params)
115
# How to add an object.
117
creatorcmd("-create")
121
cmd = [command(:niutil)]
124
cmd << "/" << "/%s/%s" % [self.class.netinfodir(), @resource[:name]]
129
creatorcmd("-destroy")
137
warnonce "The NetInfo provider is deprecated; use directoryservice instead"
140
# Because our stupid type can't create the whole thing at once,
141
# we have to do this hackishness. Yay.
143
@resource.class.validproperties.each do |name|
144
next if name == :ensure
146
# LAK: We use property.sync here rather than directly calling
147
# the settor method because the properties might do some kind
148
# of conversion. In particular, the user gid property might
149
# have a string and need to convert it to a number
150
if @resource.should(name)
151
@resource.property(name).sync
152
elsif value = autogen(name)
153
self.send(name.to_s + "=", value)
161
# Retrieve a specific value by name.
163
hash = getinfo(false)
171
# Retrieve everything about this object at once, instead of separately.
172
def getinfo(refresh = false)
173
if refresh or (! defined? @infohash or ! @infohash)
174
properties = [:name] + self.class.resource_type.validproperties
175
properties.delete(:ensure) if properties.include? :ensure
176
@infohash = single_report(*properties)
182
def modifycmd(param, value)
183
cmd = [command(:niutil)]
184
# if value.is_a?(Array)
185
# warning "Netinfo providers cannot currently handle multiple values"
188
cmd << "-createprop" << "/" << "/%s/%s" % [self.class.netinfodir, @resource[:name]]
190
value = [value] unless value.is_a?(Array)
191
if key = netinfokey(param)
195
raise Puppet::DevError,
196
"Could not find netinfokey for property %s" %
202
# Determine the flag to pass to our command.
204
self.class.netinfokey(name)
207
# Get a report for a single resource, not the whole table
208
def single_report(*properties)
209
warnonce "The NetInfo provider is deprecated; use directoryservice instead"
210
self.class.report(*properties).find do |hash| hash[:name] == self.name end
213
def setuserlist(group, list)
214
cmd = [command(:niutil), "-createprop", "/", "/groups/%s" % group, "users", list.join(",")]
216
output = execute(cmd)
217
rescue Puppet::ExecutionFailure => detail
218
raise Puppet::Error, "Failed to set user list on %s: %s" %