示例#1
0
    def addProjects(self):
        """Add the users/projects file based info to iRODS."""

        self.logger.info("Checking if there are new projects to be added")

#        if (self.logger.getEffectiveLevel() == 10):
#            pp = pprint.PrettyPrinter(indent=4)
#            pp.pprint(self.projects)            

        # the project/group is in the list, but not in iRODS
        for proj_name in [x for x in self.projects.keys()
                          if not(x in self.irods_projects.keys())]:
            self.logger.info("Checking if the new project: " + proj_name
                           + " should be added")
            filterObj = Filters(self.logger)
            if filterObj.attr_filters(self.projects[proj_name], self.conf.condition):
                if not(self.dryrun):
                    newGroupFlag = self.irodsu.createIrodsGroup(proj_name)
                    if not self.conf.irods_group_home:
                        self.irodsu.deleteGroupHome(proj_name)
                    if not newGroupFlag:
                        if self.conf.notification_active:
                            message = "creation of the irods group " + proj_name \
                                    + " failed"
                            mailsnd = MailSender()
                            mailsnd.send(message, self.conf.notification_sender,
                                         self.conf.notification_receiver)
                        self.logger.info("failed to create the irods group %s", 
                                         proj_name)
                    else:
                        self.logger.info("Created irods group %s", proj_name)
                else:
                    print "created irods group " + proj_name
                self.addUsersToProject(proj_name, self.projects[proj_name], True)
                self._addSubGroups(proj_name, self.projects[proj_name])
示例#2
0
    def _addSubGroups(self, proj_name, project):
        """Internal: create sub-groups and add users to them"""

        newGroupFlag = False
        self.logger.info("adding sub-groups to the project %s", proj_name)

        #        if (self.logger.getEffectiveLevel() == 10):
        #            pp = pprint.PrettyPrinter(indent=4)
        #            pp.pprint(projects)

        if (isinstance(project, dict)) and ('groups' in project.keys()):
            for user in project['groups'].keys():

                #### erastova: added creation of the irods user

                userinfo = self.irodsu.getIrodsUser(user)
                if (userinfo is not None) and \
                   ("No rows found" in userinfo.splitlines()[0]):
                    if not (self.dryrun):
                        response = self.irodsu.createIrodsUsers(user)
                        if response[0] != 0:
                            if self.conf.notification_active:
                                message = "creation of the irods user " \
                                          + user + " failed"
                                mailsnd = MailSender()
                                mailsnd.send(message,
                                             self.conf.notification_sender,
                                             self.conf.notification_receiver)
                            self.logger.error(
                                "failed to create the irods user %s" % user)
                        else:
                            self.logger.debug("created user %s" % user)
                    else:
                        self.logger.info("created user %s" % (user))
示例#3
0
    def updateProjects(self):
        """Update the users/projects file based info to iRODS."""

        self.logger.info("Checking if an update for the projects is required")

        for proj_name in [x for x in self.projects.keys() 
                          if x in self.irods_projects.keys()]:
            self.logger.info("Updating the project: " + proj_name)
            # users are in the UserDB and not in iRODS
            self.addUsersToProject(proj_name, self.projects[proj_name])
            # add users from irods externals
            user_list = self.projects[proj_name]['members']
            for sg in self.projects[proj_name]['groups'].keys():
                user_list += self.projects[proj_name]['groups'][sg]
            user_list = set(user_list)
            # users are in iRODS and not in the userDB
            for user in [x for x in self.irods_projects[proj_name]['members'] 
                         if not(x in user_list)]:
                self.logger.info("Deleting the user: "******", from the group: "
                                 + proj_name)
                if not(self.dryrun):
                    if self.conf.notification_active:
                        message = "user " + user + " should be deleted from " \
                                + "project " + proj_name
                        mailsnd = MailSender()
                        mailsnd.send(message, self.conf.notification_sender, 
                                     self.conf.notification_receiver)
                        self.logger.info("Request for user deletion sent")
                else:
                    print "user " + user + " should be deleted from project " \
                         + proj_name
            self._addSubGroups(proj_name, self.projects[proj_name])
示例#4
0
    def _thresholdAlarm(self, project_usage, proj_name, old_used_space_perc):
        """Notification mechanism to alert about over quota events"""

        message = ""
        threshold_soft = 95
        threshold_hard = 100
        if (proj_name in self.conf.mirrored_projects):
            threshold_soft = 95 * 2
            threshold_hard = 100 * 2
        if ((project_usage['used_space_perc'] > threshold_soft)
                and (project_usage['used_space_perc'] > old_used_space_perc)):
            message = "project " + proj_name + " is reaching its quota limit " \
                    + "(used space > 95%): " + str(project_usage['used_space'])\
                    + " " + self.conf.storage_space_unity
        if (project_usage['used_space_perc'] >= threshold_hard):
            message = "project " + proj_name + " reached its quota limit " \
                    + "(used space > 100%): " + str(project_usage['used_space'])\
                    + " " + self.conf.storage_space_unity
        if (len(message) > 0):
            mailsnd = MailSender()
            mailsnd.send(message, self.conf.notification_sender,
                         self.conf.notification_receiver)
            logger.debug(
                "sent alert for quota over limit related to project: " +
                proj_name)
示例#5
0
    def deleteProjects(self):
        """Delete the projects from iRODS according to the userDB file based info."""

        self.logger.info("Checking if there are projects to be deleted")
        # generate a list of all the sub-groups
        sg_list = self._getSubGroupsList()

        #        if (self.logger.getEffectiveLevel() == 10):
        #            print "Sub-groups:"
        #            pp = pprint.PrettyPrinter(indent=4)
        #            pp.pprint(sg_list)

        s = set(self.conf.internal_project_list)
        for proj_name in [x for x in self.irods_projects.keys() if x not in s]:
            ##TODO add filtering criteria as in addProjects
            # projects are in iRODS and not in userDB
            if (not (proj_name in sg_list.keys())
                    #and (not(proj_name in self.projects.keys()) or quotaFlag)):
                    and (not (proj_name in self.projects.keys()))):
                self.logger.info("The project: " + proj_name +
                                 " should be deleted")
                if not (self.dryrun):
                    if self.conf.notification_active:
                        # send message
                        message = "project " + proj_name + " should be " \
                                + "deleted from irods"
                        mailsnd = MailSender()
                        mailsnd.send(message, self.conf.notification_sender,
                                     self.conf.notification_receiver)
                        self.logger.debug(
                            "project [%s]: request for deletion sent" %
                            proj_name)
                else:
                    self.logger.info(
                        "project %s should be deleted from irods" % proj_name)
示例#6
0
    def addUsersToProject(self, proj_name, project, new_project_flag=False):
        """Add the users to iRODS groups (projects)."""

        self.logger.info(
            "checking if there are users to be added to the group " +
            proj_name)
        if (isinstance(project, dict)) and ('members' in project.keys()):
            user_list = project['members']
            for user in [
                    x for x in user_list if (new_project_flag or not (
                        x in self.irods_projects[proj_name]['members']))
            ]:
                self.logger.info(user)
                if not (self.dryrun):
                    if not (user in self.irods_users.keys()):
                        response = self.irodsu.createIrodsUsers(user)
                        if response[0] != 0:
                            if self.conf.notification_active:
                                message = "creation of the irods user " + user \
                                        + " failed"
                                mailsnd = MailSender()
                                mailsnd.send(message,
                                             self.conf.notification_sender,
                                             self.conf.notification_receiver)
                            self.logger.error(
                                "failed to create the irods user %s" % user)
                        else:
                            self.logger.debug("created irods user %s" % user)
                    self.irodsu.addIrodsUserToGroup(user, proj_name)
                    self.logger.debug("added irods user %s to the group %s" %
                                      (user, proj_name))
                else:
                    self.logger.info("added user %s to the group %s" %
                                     (user, proj_name))
示例#7
0
    def addUsersToProject(self, proj_name, project, new_project_flag=False):
        """Add the users to iRODS groups (projects)."""

        self.logger.info("checking if there are users to be added to the group "
                    + proj_name)
        user_list = project['members']
        for user in [x for x in user_list
                     if (new_project_flag or 
                         not(x in self.irods_projects[proj_name]['members']))]:
            self.logger.info(user)
            if not(self.dryrun):
                if not(user in self.irods_users.keys()):
                    response = self.irodsu.createIrodsUsers(user)
                    if response[0] != 0:
                        if self.conf.notification_active:
                            message = "creation of the irods user " + user \
                                    + " failed"
                            mailsnd = MailSender()
                            mailsnd.send(message, self.conf.notification_sender,
                                         self.conf.notification_receiver)
                        self.logger.error("failed to create the irods user %s", user)
                    else:
                        self.logger.debug("created irods user %s", user)
                self.irodsu.addIrodsUserToGroup(user, proj_name)
                self.logger.debug("added irods user %s to the group %s", 
                             user, proj_name)
            else:
                print "added user %s to the group %s" % (user, proj_name)
示例#8
0
    def _addSubGroups(self, proj_name, project):
        """Internal: create sub-groups and add users to them"""

        newGroupFlag = False
        self.logger.info("adding sub-groups to the project %s", proj_name)
                        
#        if (self.logger.getEffectiveLevel() == 10):
#            pp = pprint.PrettyPrinter(indent=4)
#            pp.pprint(projects)
            
        if 'groups' in project.keys():
            for user in project['groups'].keys():
            
            #### erastova: added creation of the irods user
        
                userinfo = self.irodsu.getIrodsUser(user)
                if (userinfo is not None) and \
                   ("No rows found" in userinfo.splitlines()[0]):
                    if not(self.dryrun):
                        response = self.irodsu.createIrodsUsers(user)
                        if response[0] != 0:
                            if self.conf.notification_active:
                                message = "creation of the irods user " \
                                          + user + " failed"
                                mailsnd = MailSender()
                                mailsnd.send(message, 
                                    self.conf.notification_sender, 
                                    self.conf.notification_receiver)
                            self.logger.error("failed to create the irods user %s", user)
                        else:
                            self.logger.debug("created user %s", user)
                    else:
                        print "created user %s" % (user)
示例#9
0
    def deleteProjects(self):
        """Delete the projects from iRODS according to the userDB file based info."""

        self.logger.info("Checking if there are projects to be deleted")
        # generate a list of all the sub-groups
        sg_list = self._getSubGroupsList()

#        if (self.logger.getEffectiveLevel() == 10):
#            print "Sub-groups:"
#            pp = pprint.PrettyPrinter(indent=4)
#            pp.pprint(sg_list)

        s = set(self.conf.internal_project_list)
        for proj_name in [x for x in self.irods_projects.keys() if x not in s]:
##TODO add filtering criteria as in addProjects
            # projects are in iRODS and not in userDB
            if (not(proj_name in sg_list.keys())
                #and (not(proj_name in self.projects.keys()) or quotaFlag)):
                and (not(proj_name in self.projects.keys()) )):
                self.logger.info("The project: " + proj_name + " should be deleted")
                if not(self.dryrun):
                    if self.conf.notification_active:
                        # send message
                        message = "project " + proj_name + " should be " \
                                + "deleted from irods"
                        mailsnd = MailSender()
                        mailsnd.send(message, self.conf.notification_sender, 
                                     self.conf.notification_receiver)
                        self.logger.debug("project [%s]: request for deletion "
                                     + "sent", proj_name)
                else:
                    print "project " + proj_name + " should be deleted from " \
                        + "irods"
示例#10
0
    def addUsersToProject(self, proj_name, project, new_project_flag=False):
        """Add the users to iRODS groups (projects)."""

        self.logger.info(
            "checking if there are users to be added to the group " +
            proj_name)
        user_list = project['members']
        if 'PI' in project.keys():
            user_list.append(project['PI'])
            # eliminate duplicates when a PI is also a member of the project
            user_list = set(user_list)
        for user in [
                x for x in user_list
                if (new_project_flag
                    or not (x in self.irods_projects[proj_name]['members']))
        ]:
            self.logger.info(user)
            if not (self.dryrun):
                if not (user in self.irods_users.keys()):
                    response = self.irodsu.createIrodsUsers(user)
                    if response[0] != 0:
                        if self.conf.notification_active:
                            message = "creation of the irods user " + user \
                                    + " failed"
                            mailsnd = MailSender()
                            mailsnd.send(message,
                                         self.conf.notification_sender,
                                         self.conf.notification_receiver)
                        self.logger.error("failed to create the irods user %s",
                                          user)
                    else:
                        self.logger.debug("created irods user %s", user)
                        if self.conf.quota_active:
                            # quota from userDB is set in GB, while iRODS uses bytes
                            quota = self.toBytes(
                                int(project[self.conf.quota_attribute]),
                                self.conf.quota_unity)
                else:
                    if self.conf.quota_active:
                        quota_limit = self.irodsu.listIrodsUserQuota(user)
                        # quota from userDB is set in GB, while iRODS uses bytes
                        quota = quota_limit + self.toBytes(
                            int(project[self.conf.quota_attribute]),
                            self.conf.quota_unity)
                        self.irodsu.setIrodsUserQuota(user, str(quota))
                        self.logger.debug(
                            "defined quota limit to %s GB for the user %s",
                            str(quota), user)
                self.irodsu.addIrodsUserToGroup(user, proj_name)
                self.logger.debug("added irods user %s to the group %s", user,
                                  proj_name)
            else:
                print "added user %s to the group %s" % (user, proj_name)
                if self.conf.quota_active:
                    quotaGB = project[self.conf.quota_attribute]
                    print "and set the related user quota limit to %s GB" \
                          % (quotaGB,)
示例#11
0
    def addUsersToProject(self, proj_name, project, new_project_flag=False):
        """Add the users to iRODS groups (projects)."""

        self.logger.info("checking if there are users to be added to the group "
                    + proj_name)
        user_list = project['members']
        if 'PI' in project.keys():
            user_list.append(project['PI'])
            # eliminate duplicates when a PI is also a member of the project
            user_list = set(user_list)
        for user in [x for x in user_list
                     if (new_project_flag or 
                         not(x in self.irods_projects[proj_name]['members']))]:
            self.logger.info(user)
            if not(self.dryrun):
                if not(user in self.irods_users.keys()):
                    response = self.irodsu.createIrodsUsers(user)
                    if response[0] != 0:
                        if self.conf.notification_active:
                            message = "creation of the irods user " + user \
                                    + " failed"
                            mailsnd = MailSender()
                            mailsnd.send(message, self.conf.notification_sender,
                                         self.conf.notification_receiver)
                        self.logger.error("failed to create the irods user %s", user)
                    else:
                        self.logger.debug("created irods user %s", user)
                        if self.conf.quota_active:
                            # quota from userDB is set in GB, while iRODS uses bytes
                            quota = self.toBytes(
                                         int(project[self.conf.quota_attribute]),
                                         self.conf.quota_unity)
                else:
                    if self.conf.quota_active:
                        quota_limit = self.irodsu.listIrodsUserQuota(user)
                        # quota from userDB is set in GB, while iRODS uses bytes
                        quota = quota_limit + self.toBytes(
                                int(project[self.conf.quota_attribute] 
                                   ), self.conf.quota_unity)
                        self.irodsu.setIrodsUserQuota(user,str(quota))
                        self.logger.debug("defined quota limit to %s GB for the user %s",
                                     str(quota), user)                                     
                self.irodsu.addIrodsUserToGroup(user, proj_name)
                self.logger.debug("added irods user %s to the group %s", 
                             user, proj_name)
            else:
                print "added user %s to the group %s" % (user, proj_name)
                if self.conf.quota_active:
                    quotaGB = project[self.conf.quota_attribute]
                    print "and set the related user quota limit to %s GB" \
                          % (quotaGB,)
示例#12
0
    def updateProjects(self):
        """Update the users/projects file based info to iRODS."""

        self.logger.info("Checking if an update for the projects is required")

        for proj_name in [
                x for x in self.projects.keys()
                if x in self.irods_projects.keys()
        ]:
            self.logger.info("Updating the project: " + proj_name)
            # users are in the UserDB and not in iRODS
            self.addUsersToProject(proj_name, self.projects[proj_name])
            # add users from irods externals
            if (isinstance(self.projects[proj_name], dict)
                    and ('members' in self.projects[proj_name].keys())):
                user_list = self.projects[proj_name]['members']
            else:
                user_list = []
            if (isinstance(self.projects[proj_name], dict)
                    and ('groups' in self.projects[proj_name].keys())):
                for sg in self.projects[proj_name]['groups'].keys():
                    user_list += self.projects[proj_name]['groups'][sg]
            user_list = set(user_list)
            # users are in iRODS and not in the userDB
            for user in [
                    x for x in self.irods_projects[proj_name]['members']
                    if not (x in user_list)
            ]:
                self.logger.info("Deleting the user: "******", from the group: " + proj_name)
                if not (self.dryrun):
                    if self.conf.notification_active:
                        message = "user " + user + " should be deleted from " \
                                + "project " + proj_name
                        mailsnd = MailSender()
                        mailsnd.send(message, self.conf.notification_sender,
                                     self.conf.notification_receiver)
                        self.logger.info("Request for user deletion sent")
                else:
                    self.logger.info("user " + user + " should be deleted from project " \
                         + proj_name)
            self._addSubGroups(proj_name, self.projects[proj_name])
示例#13
0
    def addProjects(self):
        """Add the users/projects file based info to iRODS."""

        self.logger.info("Checking if there are new projects to be added")

        #        if (self.logger.getEffectiveLevel() == 10):
        #            pp = pprint.PrettyPrinter(indent=4)
        #            pp.pprint(self.projects)

        # the project/group is in the list, but not in iRODS
        for proj_name in [
                x for x in self.projects.keys()
                if not (x in self.irods_projects.keys())
        ]:
            self.logger.info("Checking if the new project: " + proj_name +
                             " should be added")
            filterObj = Filters(self.logger)
            if filterObj.attr_filters(self.projects[proj_name],
                                      self.conf.condition):
                if not (self.dryrun):
                    if self.conf.quota_active:
                        self._updateQuota(proj_name)
                        self.logger.info("Added quota info for project: " +
                                         proj_name)
                    newGroupFlag = self.irodsu.createIrodsGroup(proj_name)
                    if not newGroupFlag:
                        if self.conf.notification_active:
                            message = "creation of the irods group " + proj_name \
                                    + " failed"
                            mailsnd = MailSender()
                            mailsnd.send(message,
                                         self.conf.notification_sender,
                                         self.conf.notification_receiver)
                        self.logger.info("failed to create the irods group %s",
                                         proj_name)
                    else:
                        self.logger.info("Created irods group %s", proj_name)
                else:
                    print "created irods group " + proj_name
                self.addUsersToProject(proj_name, self.projects[proj_name],
                                       True)
                self._addSubGroups(proj_name, self.projects[proj_name])
示例#14
0
    def _thresholdAlarm(self, project_usage, proj_name, old_used_space_perc):
        """Notification mechanism to alert about over quota events"""

        message = ""
        threshold_soft = 95
        threshold_hard = 100
        if (proj_name in self.conf.mirrored_projects):
            threshold_soft = 95*2
            threshold_hard = 100*2
        if ((project_usage['used_space_perc'] > threshold_soft) and 
            (project_usage['used_space_perc'] > old_used_space_perc)):
            message = "project " + proj_name + " is reaching its quota limit " \
                    + "(used space > 95%): " + str(project_usage['used_space'])\
                    + " " + self.conf.storage_space_unity
        if (project_usage['used_space_perc'] >= threshold_hard):
            message = "project " + proj_name + " reached its quota limit " \
                    + "(used space > 100%): " + str(project_usage['used_space'])\
                    + " " + self.conf.storage_space_unity
        if (len(message) > 0):
            mailsnd = MailSender()
            mailsnd.send(message, self.conf.notification_sender, 
                         self.conf.notification_receiver)
            logger.debug("sent alert for quota over limit related to project: "
                         + proj_name)
示例#15
0
    def updateUsers(self):
        """Update the users according to the userDB file based info."""

        self.logger.info("Checking if there are updates related to the users")
        for user in self.irods_users.keys():

            self.logger.debug("Updating the info for user: "******"Updating the dn mapping for user: "******"rossim /O=IT/OU=...")
                    dn_list.append(line[len(user) + 1:])
            # the user is in the map file, but not in irods
            if (self.dn_map is not None and user in self.dn_map.keys()):
                for dn in self.dn_map[user]:
                    if not (dn in dn_list):
                        self.logger.debug(
                            "the dn %s is not in irods for user " +
                            "%s, so it will be added", dn, user)
                        if not (self.dryrun):
                            self.irodsu.addDNToUser(user, dn)
                            self.logger.info(
                                "the dn %s has been added for user " + "%s",
                                dn, user)
                        else:
                            self.logger.info("the dn " + dn[0] +
                                             " has been added for user " +
                                             user)

            # the user is in irods, but not in the map file
            if (self.dn_map is not None):
                for dn in dn_list:
                    if not(user in self.dn_map.keys()) \
                        or not(dn in self.dn_map[user]):
                        if not (self.dryrun):
                            self.logger.debug(
                                "the dn %s is not in map file for " +
                                "user %s, so it will be removed", dn, user)
                            self.irodsu.removeUserDN(user, dn)
                            if self.conf.notification_active:
                                message = "removed user " + user + "'s DN: " + dn
                                mailsnd = MailSender()
                                mailsnd.send(message,
                                             self.conf.notification_sender,
                                             self.conf.notification_receiver)
                            self.logger.info(
                                "the dn %s has been removed for " + "user %s",
                                dn, user)
                        else:
                            self.logger.info("the dn " + dn + " is not in map file for " \
                                             + "user " + user + ", so it will be removed")
                            self.logger.info("the dn " + dn + " has been removed for " \
                                             + "user " + user)
示例#16
0
    def updateUsers(self):
        """Update the users according to the userDB file based info."""

        self.logger.info("Checking if there are updates related to the users")
        for user in self.irods_users.keys():

            self.logger.debug("Updating the info for user: "******"Updating the dn mapping for user: "******"rossim /O=IT/OU=...")
                    dn_list.append(line[len(user)+1:])
            # the user is in the map file, but not in irods
            if (self.dn_map is not None and user in self.dn_map.keys()):
                for dn in self.dn_map[user]:
                    if not(dn in dn_list):
                        self.logger.debug("the dn %s is not in irods for user "
                                          + "%s, so it will be added", dn, user)
                        if not(self.dryrun):
                            self.irodsu.addDNToUser(user,dn)
                            self.logger.info("the dn %s has been added for user "
                                             + "%s", dn, user)
                        else:
                            print "the dn {} has been added for user {}".format(
                                                                        dn,user)
            # the user is in irods, but not in the map file
            if (self.dn_map is not None):
                for dn in dn_list:
                    if not(user in self.dn_map.keys()) \
                        or not(dn in self.dn_map[user]):
                        if not(self.dryrun):
                            self.logger.debug("the dn %s is not in map file for "
                                     + "user %s, so it will be removed", 
                                     dn, user)
                            self.irodsu.removeUserDN(user,dn)
                            if self.conf.notification_active:
                                message = "removed user " + user + "'s DN: " + dn
                                mailsnd = MailSender()
                                mailsnd.send(message, self.conf.notification_sender,
                                             self.conf.notification_receiver)
                            self.logger.info("the dn %s has been removed for "
                                        + "user %s", dn, user)
                        else:
                            print "the dn " + dn + " is not in map file for " \
                                     + "user " + user + ", so it will be removed"
                            print "the dn " + dn + " has been removed for " \
                                + "user " + user
示例#17
0
    def _addSubGroups(self, proj_name, project):
        """Internal: create sub-groups and add users to them"""

        newGroupFlag = False
        self.logger.info("adding sub-groups to the project %s", proj_name)

        #        if (self.logger.getEffectiveLevel() == 10):
        #            pp = pprint.PrettyPrinter(indent=4)
        #            pp.pprint(projects)

        if 'groups' in project.keys():
            for sg in project['groups'].keys():

                newGroupFlag = False
                if not (sg in self.irods_projects.keys()):
                    if not (self.dryrun):
                        newGroupFlag = self.irodsu.createIrodsGroup(sg)
                        if not newGroupFlag:
                            if self.conf.notification_active:
                                message = "creation of the irods group: " + sg \
                                        + " failed, related to the project: " \
                                        + proj_name
                                mailsnd = MailSender()
                                mailsnd.send(message,
                                             self.conf.notification_sender,
                                             self.conf.notification_receiver)
                            self.logger.debug(
                                "failed to create the irods group %s " +
                                "related to the project %s", sg, proj_name)
                        else:
                            self.logger.debug(
                                "created group %s related to the project %s",
                                sg, proj_name)
                            if not self.conf.irods_subgroup_home:
                                self.irodsu.deleteGroupHome(sg)
                                self.logger.debug(
                                    "deleted group %s's home " +
                                    "related to the project %s", sg, proj_name)
                    else:
                        newGroupFlag = True
                        print 'created group ' + sg + ' ' \
                            + 'related to the project ' + proj_name + ' and ' \
                            + 'deleted its home'
                else:
                    self.logger.debug("group %s has already been created", sg)

                for user in project['groups'][sg]:

                    userinfo = self.irodsu.getIrodsUser(user)
                    if (userinfo is not None) and \
                       ("No rows found" in userinfo.splitlines()[0]):
                        #                    if not(user in self.irods_users.keys()):
                        if not (self.dryrun):
                            response = self.irodsu.createIrodsUsers(user)
                            if response[0] != 0:
                                if self.conf.notification_active:
                                    message = "creation of the irods user " \
                                              + user + " failed"
                                    mailsnd = MailSender()
                                    mailsnd.send(
                                        message, self.conf.notification_sender,
                                        self.conf.notification_receiver)
                                self.logger.error(
                                    "failed to create the irods user %s", user)
                            else:
                                self.logger.debug("created user %s", user)
                                if self.conf.quota_active:
                                    # quota from userDB is set in GB, while iRODS uses bytes
                                    quota = self.toBytes(
                                        int(project[
                                            self.conf.quota_attribute]),
                                        self.conf.quota_unity)
                                    self.irodsu.setIrodsUserQuota(
                                        user, str(quota))
                                    self.logger.debug(
                                        "set the irods quota limit to " +
                                        str(quota))
                        else:
                            print "created user %s" % (user)
                            if self.conf.quota_active:
                                quotaGB = project[self.conf.quota_attribute]
                                print "and set the irods quota limit to " \
                                      + quotaGB + " GB"

                    # add a new user to the sub-group only if the sub-group is new
                    # or it is old, but the user is not included among its members yet
                    if (newGroupFlag) \
                        or (sg in self.irods_projects.keys() \
                        and not (user in self.irods_projects[sg]['members'])):
                        if not (self.dryrun):
                            self.irodsu.addIrodsUserToGroup(user, sg)
                            self.logger.debug("added user %s to the group %s",
                                              user, sg)
                        else:
                            print "added user %s to the group %s" % (user, sg)
示例#18
0
    def _addSubGroups(self, proj_name, project):
        """Internal: create sub-groups and add users to them"""

        newGroupFlag = False
        self.logger.info("adding sub-groups to the project %s", proj_name)

        # if (self.logger.getEffectiveLevel() == 10):
        #     pp = pprint.PrettyPrinter(indent=4)
        #     pp.pprint(projects)

        if 'groups' in project.keys():
            for sg in project['groups'].keys():

                newGroupFlag = False
                if not(sg in self.irods_projects.keys()):
                    if not(self.dryrun):
                        newGroupFlag = self.irodsu.createIrodsGroup(sg)
                        if not newGroupFlag:
                            if self.conf.notification_active:
                                message = "creation of the irods group: " + sg \
                                        + " failed, related to the project: " \
                                        + proj_name
                                mailsnd = MailSender()
                                mailsnd.send(message,
                                             self.conf.notification_sender,
                                             self.conf.notification_receiver)
                            self.logger.debug("failed to create the irods " +
                                              "group %s related to the " +
                                              "project %s", sg, proj_name)
                        else:
                            self.logger.debug("created group %s related to " +
                                              "the project %s", sg, proj_name)
                            if not self.conf.irods_subgroup_home:
                                self.irodsu.deleteGroupHome(sg)
                                self.logger.debug("deleted group %s's home " +
                                                  "related to the project %s",
                                                  sg, proj_name)
                    else:
                        newGroupFlag = True
                        print 'created group ' + sg + ' ' \
                            + 'related to the project ' + proj_name
                        if not self.conf.irods_subgroup_home:
                            print ' and deleted its home'
                else:
                    self.logger.debug("group %s has already been created", sg)

                for user in project['groups'][sg]:

                    userinfo = self.irodsu.getIrodsUser(user)
                    if (userinfo is not None) and \
                       ("No rows found" in userinfo.splitlines()[0]):
                        if not(self.dryrun):
                            response = self.irodsu.createIrodsUsers(user)
                            if response[0] != 0:
                                if self.conf.notification_active:
                                    message = "creation of the irods user " \
                                              + user + " failed"
                                    mailsnd = MailSender()
                                    mailsnd.send(
                                        message, self.conf.notification_sender,
                                        self.conf.notification_receiver)
                                self.logger.error("failed to create the " +
                                                  "irods user %s", user)
                            else:
                                self.logger.debug("created user %s", user)
                        else:
                            print "created user %s" % (user)
                    # add a new user to the sub-group only if the sub-group is
                    # new or it is old, but the user is not included among its
                    # members yet
                    if ((newGroupFlag) or
                        (sg in self.irods_projects.keys() and
                         not (user in self.irods_projects[sg]['members']))):
                        if not(self.dryrun):
                            self.irodsu.addIrodsUserToGroup(user, sg)
                            self.logger.debug("added user %s to the group %s",
                                              user, sg)
                        else:
                            print "added user %s to the group %s" % (user, sg)
示例#19
0
    def updateUsers(self):
        """Update the users according to the userDB file based info."""

        self.logger.info("Checking if there are updates related to the users")
        for user in self.irods_users.keys():

            self.logger.debug("Updating the info for user: "******"set the new quota limit for user %s to %s GB", 
                                          user, str(self.fromBytes(total_quota_limit,
                                                                   self.conf.quota_unity)))
                    else:
                        self.logger.debug("no need to set new quota limit for user %s", user)
            else:
                if self.conf.quota_active:
                    old_quota_limit = self.irodsu.listIrodsUserQuota(user)
                    if not old_quota_limit or old_quota_limit != total_quota_limit:
                        print("set the new quota limit for user " + user + " to "
                              + str(self.fromBytes(total_quota_limit, 
                                    self.conf.quota_unity)) + " GB")
                    else:
                        print("no need to set new quota limit for user " + user)

            # managing the dn of a user
            self.logger.debug("Updating the dn mapping for user: "******"rossim /O=IT/OU=...")
                    dn_list.append(line[len(user)+1:])
            # the user is in the map file, but not in irods
            if (self.dn_map is not None and user in self.dn_map.keys()):
                for dn in self.dn_map[user]:
                    if not(dn in dn_list):
                        self.logger.debug("the dn %s is not in irods for user "
                                          + "%s, so it will be added", dn, user)
                        if not(self.dryrun):
                            self.irodsu.addDNToUser(user,dn)
                            self.logger.info("the dn %s has been added for user "
                                             + "%s", dn, user)
                            if (self.conf.gridftp_active 
                                and dn != self.conf.gridftp_server_dn):
                                with open(self.conf.gridmapfile, 'a+') as mapf:
                                    mapf.write('"' + dn + '"' + " " + user + "\n")
                                    self.logger.info("the dn %s associated to the"
                                              + " user %s has been added to "
                                              + "the gridmapfile %s", dn, user, 
                                              self.conf.gridmapfile)
                        else:
                            print "the dn " + dn + " has been added for user " \
                                  + user

            # the user is in irods, but not in the map file
            if (self.dn_map is not None):
                for dn in dn_list:
                    if not(user in self.dn_map.keys()) \
                        or not(dn in self.dn_map[user]):
                        self.logger.debug("the dn %s is not in map file for "
                                     + "user %s, so it will be removed", 
                                     dn, user)
                        if not(self.dryrun):
                            self.irodsu.removeUserDN(user,dn)
                            if self.conf.notification_active:
                                message = "removed user " + user + "'s DN: " + dn
                                mailsnd = MailSender()
                                mailsnd.send(message, self.conf.notification_sender,
                                             self.conf.notification_receiver)
                            self.logger.info("the dn %s has been removed for "
                                        + "user %s", dn, user)
                            if (self.conf.gridftp_active
                                and dn != self.conf.gridftp_server_dn):
                                statinfo = os.stat(self.conf.gridmapfile)
                                # If the original gridmafile has size > 0 then
                                # create a backup
                                if statinfo.st_size > 0:
                                    try:
                                        dest = self.conf.gridmapfile + ".bak"
                                        shutil.copy(self.conf.gridmapfile, dest)
                                    except IOError as e:
                                        self.logger.error("Impossible to create"
                                                          " a backup: " + e.strerror)
                                with open(self.conf.gridmapfile, 'w+') as mapf:
                                    content = mapf.readlines()
                                    for line in content:
                                        if not (dn in line.split()):
                                            mapf.write(line)
                                    self.logger.info("the dn %s associated to the"
                                              + " user %s has been removed from"
                                              + " the gridmapfile %s", dn, user,
                                              self.conf.gridmapfile)
                        else:
                            print "the dn " + dn + " has been removed for " \
                                + "user " + user
示例#20
0
    def updateUsers(self):
        """Update the users according to the userDB file based info."""

        self.logger.info("Checking if there are updates related to the users")
        for user in self.irods_users.keys():

            self.logger.debug("Updating the info for user: "******"set the new quota limit for user %s to %s GB",
                            user,
                            str(
                                self.fromBytes(total_quota_limit,
                                               self.conf.quota_unity)))
                    else:
                        self.logger.debug(
                            "no need to set new quota limit for user %s", user)
            else:
                if self.conf.quota_active:
                    old_quota_limit = self.irodsu.listIrodsUserQuota(user)
                    if not old_quota_limit or old_quota_limit != total_quota_limit:
                        print(
                            "set the new quota limit for user " + user +
                            " to " + str(
                                self.fromBytes(total_quota_limit,
                                               self.conf.quota_unity)) + " GB")
                    else:
                        print("no need to set new quota limit for user " +
                              user)

            # managing the dn of a user
            self.logger.debug("Updating the dn mapping for user: "******"rossim /O=IT/OU=...")
                    dn_list.append(line[len(user) + 1:])
            # the user is in the map file, but not in irods
            if (self.dn_map is not None and user in self.dn_map.keys()):
                for dn in self.dn_map[user]:
                    if not (dn in dn_list):
                        self.logger.debug(
                            "the dn %s is not in irods for user " +
                            "%s, so it will be added", dn, user)
                        if not (self.dryrun):
                            self.irodsu.addDNToUser(user, dn)
                            self.logger.info(
                                "the dn %s has been added for user " + "%s",
                                dn, user)
                            if (self.conf.gridftp_active
                                    and dn != self.conf.gridftp_server_dn):
                                with open(self.conf.gridmapfile, 'a+') as mapf:
                                    mapf.write('"' + dn + '"' + " " + user +
                                               "\n")
                                    self.logger.info(
                                        "the dn %s associated to the" +
                                        " user %s has been added to " +
                                        "the gridmapfile %s", dn, user,
                                        self.conf.gridmapfile)
                        else:
                            print "the dn " + dn + " has been added for user " \
                                  + user

            # the user is in irods, but not in the map file
            if (self.dn_map is not None):
                for dn in dn_list:
                    if not(user in self.dn_map.keys()) \
                        or not(dn in self.dn_map[user]):
                        self.logger.debug(
                            "the dn %s is not in map file for " +
                            "user %s, so it will be removed", dn, user)
                        if not (self.dryrun):
                            self.irodsu.removeUserDN(user, dn)
                            if self.conf.notification_active:
                                message = "removed user " + user + "'s DN: " + dn
                                mailsnd = MailSender()
                                mailsnd.send(message,
                                             self.conf.notification_sender,
                                             self.conf.notification_receiver)
                            self.logger.info(
                                "the dn %s has been removed for " + "user %s",
                                dn, user)
                            if (self.conf.gridftp_active
                                    and dn != self.conf.gridftp_server_dn):
                                statinfo = os.stat(self.conf.gridmapfile)
                                # If the original gridmafile has size > 0 then
                                # create a backup
                                if statinfo.st_size > 0:
                                    try:
                                        dest = self.conf.gridmapfile + ".bak"
                                        shutil.copy(self.conf.gridmapfile,
                                                    dest)
                                    except IOError as e:
                                        self.logger.error(
                                            "Impossible to create"
                                            " a backup: " + e.strerror)
                                with open(self.conf.gridmapfile, 'w+') as mapf:
                                    content = mapf.readlines()
                                    for line in content:
                                        if not (dn in line.split()):
                                            mapf.write(line)
                                    self.logger.info(
                                        "the dn %s associated to the" +
                                        " user %s has been removed from" +
                                        " the gridmapfile %s", dn, user,
                                        self.conf.gridmapfile)
                        else:
                            print "the dn " + dn + " has been removed for " \
                                + "user " + user