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