def sync_membership(): for i in ad.openstack_groups(c): log.logger.debug("Syncing group: adsync - %s" % i[12:]) #users_ad = [ u['username'] for u in ad.users_in_group(c,i) ] users_ad = [ u for u in ad.openstack_users_in_group(c,i) ] if ks.get_id_ks_group(ksclient,"adsync - %s" % i[12:]): users_ks = [u.name for u in ksclient.users.list(group=ks.get_id_ks_group(ksclient,"adsync - %s" % i[12:]))] added = [x for x in users_ad if x not in users_ks] removed = [x for x in users_ks if x not in users_ad] for u in added: log.logger.debug("Trying to add user %s to group %s" % (u,"adsync - %s" % i[12:])) #### if ks.add_user_to_group(ksclient,"adsync - %s" % i[12:],u): log.logger.info("Added user %s to group %s" % (u,"adsync - %s" % i[12:])) else: log.logger.error("Adding user %s to group %s failed" % (u,"adsync - %s" % i[12:])) #### for u in removed: log.logger.debug("Trying to remove user %s from group %s" % (u,"adsync - %s" % i[12:])) #### if ks.remove_user_from_group(ksclient,"adsync - %s" % i[12:],u): log.logger.info("Removed user %s to group %s" % (u,"adsync - %s" % i[12:])) else: log.logger.error("Removing user %s to group %s failed" % (u,"adsync - %s" % i[12:])) #### else: log.logger.warning("Group %s does not available!" % i)
def sync_groups(): ad_groups = [] for g in ad.openstack_groups(c): ad_groups.append(str(g).replace('Openstack - ', 'adsync - ')) ks_group_list = [ g.name for g in ksclient.groups.list() if g.name[:9] == 'adsync - ' ] ad_added_groups = [x for x in ad_groups if x not in ks_group_list] ad_removed_groups = [x for x in ks_group_list if x not in ad_groups] for g in ad_added_groups: log.logger.debug("Trying to add group %s" % g) #### if ks.create_group(ksclient, g): log.logger.info("Succesfully created group %s" % g) else: log.logger.error("Unable to create group %s" % g) #### for g in ad_removed_groups: log.logger.debug("Trying to remove group %s" % g) #### if ks.delete_group(ksclient, g): log.logger.info("Succesfully deleted group %s" % g) else: log.logger.error("Unable to delete group %s" % g)
def sync_membership(): for i in ad.openstack_groups(c): log.logger.debug("Syncing group: adsync - %s" % i[12:]) #users_ad = [ u['username'] for u in ad.users_in_group(c,i) ] users_ad = [u for u in ad.openstack_users_in_group(c, i)] if ks.get_id_ks_group(ksclient, "adsync - %s" % i[12:]): users_ks = [ u.name for u in ksclient.users.list( group=ks.get_id_ks_group(ksclient, "adsync - %s" % i[12:])) ] added = [x for x in users_ad if x not in users_ks] removed = [x for x in users_ks if x not in users_ad] for u in added: log.logger.debug("Trying to add user %s to group %s" % (u, "adsync - %s" % i[12:])) #### if ks.add_user_to_group(ksclient, "adsync - %s" % i[12:], u): log.logger.info("Added user %s to group %s" % (u, "adsync - %s" % i[12:])) else: log.logger.error("Adding user %s to group %s failed" % (u, "adsync - %s" % i[12:])) #### for u in removed: log.logger.debug("Trying to remove user %s from group %s" % (u, "adsync - %s" % i[12:])) #### if ks.remove_user_from_group(ksclient, "adsync - %s" % i[12:], u): log.logger.info("Removed user %s to group %s" % (u, "adsync - %s" % i[12:])) else: log.logger.error("Removing user %s to group %s failed" % (u, "adsync - %s" % i[12:])) #### else: log.logger.warning("Group %s does not available!" % i)
def sync_groups(): ad_groups = [] for g in ad.openstack_groups(c): ad_groups.append(str(g).replace('Openstack - ','adsync - ')) ks_group_list = [g.name for g in ksclient.groups.list() if g.name[:9] == 'adsync - '] ad_added_groups = [x for x in ad_groups if x not in ks_group_list] ad_removed_groups = [x for x in ks_group_list if x not in ad_groups] for g in ad_added_groups: log.logger.debug("Trying to add group %s" % g) #### if ks.create_group(ksclient,g): log.logger.info("Succesfully created group %s" % g) else: log.logger.error("Unable to create group %s" % g) #### for g in ad_removed_groups: log.logger.debug("Trying to remove group %s" % g) #### if ks.delete_group(ksclient,g): log.logger.info("Succesfully deleted group %s" % g) else: log.logger.error("Unable to delete group %s" % g)