Class Puppet::Provider::NameService::NetInfo
In: lib/puppet/provider/nameservice/netinfo.rb
Parent: Puppet::Provider::NameService

Methods

Attributes

netinfodir  [W] 

Public Class methods

[Source]

    # File lib/puppet/provider/nameservice/netinfo.rb, line 41
41:     def self.finish
42:         case self.name
43:         when :uid:
44:             noautogen
45:         when :gid:
46:             noautogen
47:         end
48:     end

Attempt to flush the database, but this doesn‘t seem to work at all.

[Source]

    # File lib/puppet/provider/nameservice/netinfo.rb, line 22
22:     def self.flush
23:         begin
24:             lookupd "-flushcache"
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
28:         end
29:     end

[Source]

    # File lib/puppet/provider/nameservice/netinfo.rb, line 50
50:     def self.instances
51:         warnonce "The NetInfo provider is deprecated; use directoryservice instead"
52:         report(@resource_type.validproperties).collect do |hash|
53:             self.new(hash)
54:         end
55:     end

Convert a NetInfo line into a hash of data.

[Source]

    # File lib/puppet/provider/nameservice/netinfo.rb, line 58
58:     def self.line2hash(line, params)
59:         values = line.split(/\t/)
60: 
61:         hash = {}
62:         params.zip(values).each do |param, value|
63:             next if value == '#NoValue#'
64:             hash[param] = if value =~ /^[-0-9]+$/
65:                 Integer(value)
66:             else
67:                 value
68:             end
69:         end
70:         hash
71:     end

Similar to posixmethod, what key do we use to get data? Defaults to being the object name.

[Source]

    # File lib/puppet/provider/nameservice/netinfo.rb, line 33
33:     def self.netinfodir
34:         if defined? @netinfodir
35:             return @netinfodir
36:         else
37:             return @resource_type.name.to_s + "s"
38:         end
39:     end

What field the value is stored under.

[Source]

    # File lib/puppet/provider/nameservice/netinfo.rb, line 74
74:     def self.netinfokey(name)
75:         name = symbolize(name)
76:         self.option(name, :key) || name
77:     end

Retrieve the data, yo. FIXME This should retrieve as much information as possible, rather than retrieving it one at a time.

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 82
 82:     def self.report(*params)
 83:         dir = self.netinfodir()
 84:         cmd = [command(:nireport), "/", "/%s" % dir]
 85:         
 86:         params.flatten!
 87: 
 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
 90:         # whole list.
 91:         params.unshift :name unless params.include? :name
 92: 
 93:         params.each do |param|
 94:             if key = netinfokey(param)
 95:                 cmd << key.to_s
 96:             else
 97:                 raise Puppet::DevError,
 98:                     "Could not find netinfokey for property %s" %
 99:                     self.class.name
100:             end
101:         end
102: 
103:         begin
104:             output = execute(cmd)
105:         rescue Puppet::ExecutionFailure => detail
106:             Puppet.err "Failed to call nireport: %s" % detail
107:             return nil
108:         end
109: 
110:         return output.split("\n").collect { |line|
111:             line2hash(line, params)
112:         }
113:     end

Public Instance methods

How to add an object.

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 116
116:     def addcmd
117:         creatorcmd("-create")
118:     end

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 120
120:     def creatorcmd(arg)
121:         cmd = [command(:niutil)]
122:         cmd << arg
123: 
124:         cmd << "/" << "/%s/%s" % [self.class.netinfodir(), @resource[:name]]
125:         return cmd
126:     end

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 128
128:     def deletecmd
129:         creatorcmd("-destroy")
130:     end

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 132
132:     def destroy
133:         delete()
134:     end

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 136
136:     def ensure=(arg)
137:         warnonce "The NetInfo provider is deprecated; use directoryservice instead"
138:         super
139: 
140:         # Because our stupid type can't create the whole thing at once,
141:         # we have to do this hackishness.  Yay.
142:         if arg == :present
143:             @resource.class.validproperties.each do |name|
144:                 next if name == :ensure
145: 
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)
154:                 else
155:                     next
156:                 end
157:             end
158:         end
159:     end

Retrieve a specific value by name.

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 162
162:     def get(param)
163:         hash = getinfo(false)
164:         if hash
165:             return hash[param]
166:         else
167:             return :absent
168:         end
169:     end

Retrieve everything about this object at once, instead of separately.

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 172
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)
177:         end
178: 
179:         return @infohash
180:     end

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 182
182:     def modifycmd(param, value)
183:         cmd = [command(:niutil)]
184:         # if value.is_a?(Array)
185:         #     warning "Netinfo providers cannot currently handle multiple values"
186:         # end
187: 
188:         cmd << "-createprop" << "/" << "/%s/%s" % [self.class.netinfodir, @resource[:name]]
189: 
190:         value = [value] unless value.is_a?(Array)
191:         if key = netinfokey(param)
192:             cmd << key
193:             cmd += value
194:         else
195:             raise Puppet::DevError,
196:                 "Could not find netinfokey for property %s" %
197:                 self.class.name
198:         end
199:         cmd
200:     end

Determine the flag to pass to our command.

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 203
203:     def netinfokey(name)
204:         self.class.netinfokey(name)
205:     end

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 213
213:     def setuserlist(group, list)
214:         cmd = [command(:niutil), "-createprop", "/", "/groups/%s" % group, "users", list.join(",")]
215:         begin
216:             output = execute(cmd)
217:         rescue Puppet::ExecutionFailure => detail
218:             raise Puppet::Error, "Failed to set user list on %s: %s" %
219:                 [group, detail]
220:         end
221:     end

Get a report for a single resource, not the whole table

[Source]

     # File lib/puppet/provider/nameservice/netinfo.rb, line 208
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
211:     end

[Validate]