217: def update(name, is, should)
218: if should[:ensure] == :absent
219: Puppet.info "Removing %s from ldap" % dn(name)
220: delete(name)
221: return
222: end
223:
224:
225: if is.empty? or is[:ensure] == :absent
226: Puppet.info "Creating %s in ldap" % dn(name)
227:
228: attrs = ldap_convert(should)
229: create(name, attrs)
230: return
231: end
232:
233:
234:
235: mods = []
236:
237:
238: [is.keys, should.keys].flatten.uniq.each do |property|
239:
240: next if is[property] == should[property]
241:
242: attributes = ldap_convert(should)
243:
244: prop_name = ldap_name(property).to_s
245:
246:
247: if is[property] == :absent or is[property].nil?
248: mods << LDAP::Mod.new(LDAP::LDAP_MOD_ADD, prop_name, attributes[prop_name])
249: next
250: end
251:
252:
253: if should[property] == :absent or should[property].nil?
254: mods << LDAP::Mod.new(LDAP::LDAP_MOD_DELETE, prop_name, [])
255: next
256: end
257:
258:
259: mods << LDAP::Mod.new(LDAP::LDAP_MOD_REPLACE, prop_name, attributes[prop_name])
260: end
261:
262: modify(name, mods)
263: end