Ejemplo n.º 1
0
    def parseSAs_fromLG(self):
        default_dict = { \
            "seUniqueID": self.getUniqueID(),
            "accessLatency": "online",
            "retention": "replica",
        }
        def itemgetter(x, y):
            return cmp(x.get('total', 0), y.get('total', ))
        log.info(self.handler.links)
        sorted_poolgroups = self.handler.poolgroups.values()
        sorted_poolgroups.sort(itemgetter)
        has_seen_matching_poolgroup = False

        has_links = False
        for linkgroup in self.handler.linkgroups.values():
            has_links = True
            info = dict(default_dict)
            space = linkgroup.get('name', None)
            if not space:
                continue
            info['name'] = space
            info['path'] = self.getPathForSA(space, vo='', return_default=True,
                section=self._section)
            if linkgroup.get('nearlineAllowed', False):
                info['accessLatency'] = 'nearline'
            info['totalOnline'] = linkgroup.get('total', 0) / 1000**3
            info['reservedOnline'] = linkgroup.get('reserved', 0) / 1000**3
            info['usedOnline'] = linkgroup.get('used', 0) / 1000**3
            info['freeOnline'] = linkgroup.get('free', 0) / 1000**3
            info['usedSpace'] = linkgroup.get('used', 0) / 1024
            info['availableSpace'] = linkgroup.get('free', 0) / 1024
            info['saName'] = '%s:%s:%s' % (info['name'], info['retention'],
                info['accessLatency'])
            info['saLocalID'] = info['saName']
            acbr_attr = 'GlueSAAccessControlBaseRule: %s'
            log.info(linkgroup['acbrs'])
            acbr = '\n'.join([acbr_attr % i for i in getLGAllowedVOs(self._cp,
                linkgroup.get('acbrs', ''), info['name'])])
            info['acbr'] = acbr
            if len(acbr) == 0:
                continue

            # Look at all the pool groups and see if the size of any one of them
            # is approximately the size of our link group.  If so, assume we've
            # seen the pools in the pool group.
            # Do not do this if the total size is zero.
            if not info['totalOnline']:
                continue
            for pool_group in sorted_poolgroups:
                if abs(pool_group.get('total', 0) - linkgroup['total']) / \
                        float(linkgroup['total']) <= 0.01:
                    self.seen_pools.update(pool_group.get('pools', sets.Set()))
                    has_seen_matching_poolgroup = True
                    break
            self.sas.append(info)
        # Unfortunately, the info provider has no mechanism for matching link
        # groups to pool groups.  Hence, if we haven't matched the link group
        # then we assume that we've seen the whole SE.
        if has_links and not has_seen_matching_poolgroup:
            self.seen_pools.update(self.handler.pools.keys())
Ejemplo n.º 2
0
    def parseVOInfos_fromReservations(self):
        log.debug("Starting 'parseVOInfos_fromReservations'")
        seUniqueID = self.getUniqueID()

        # The VOInfo objects should correspond to reservation DESCRIPTIONs,
        # which may map to multiple reservations
        voinfo = {}
        log.debug("There are %i reservations." % len(self.handler.reservations))
        for id, reservation in self.handler.reservations.items():
            desc = reservation.get('description', 'DEFAULT')
            if desc.lower() == 'null':
                desc = 'DEFAULT'
            reservation_set = voinfo.setdefault(desc, [])
            reservation_set.append(reservation)

        log.debug("VOInfo objects: %s" % str(voinfo))

        # Iterate through all the link groups, and then go through all the
        # reservations in that link group.
        for lgid, linkgroup in self.handler.linkgroups.items():
            # Determine ACBRs and allowed VOs
            found_reservation_vos = sets.Set()
            allowed_acbrs = getLGAllowedVOs(self._cp,
                linkgroup.get('acbrs', ''), linkgroup.get('name', ''))
            fqans = [normalizeFQAN(i) for i in allowed_acbrs]
            all_lg_vos = sets.Set([i.split('/')[1] for i in fqans])

            # Find the corresponding SA
            found_sa = False
            lgname = linkgroup.get('name', '')
            for sa in self.sas:
                if sa.get('name', None) != lgname:
                    continue
                found_sa = True
                break
            if not found_sa:
                continue

            # Advertise the right tag for any VO which has a space reservation
            # in this link group.
            for tag, reservations_set in voinfo.items():
                for info in reservations_set:
                    if info.get('linkgroupref', None) != lgid:
                        continue
                    log.debug("Analyzing reservation: %s" % str(info))
                    # Regardless of who owns the reservation, anyone who can
                    # write into the LG can write into the reservation.
                    #if len(str(info.get('FQAN', ''))) == 0:
                    #    allowed_acbrs = getLGAllowedVOs(self._cp, info.get(
                    #        'acbrs', ''))
                    #else:
                    #    allowed_acbrs = ['VOMS:' +str(info.get('FQAN', ''))]
                    fqans = [normalizeFQAN(i) for i in allowed_acbrs]
                    vos = [i.split('/')[1] for i in fqans]
                    found_reservation_vos.update(vos)
                    if len(vos) == 0:
                        continue
                    path = self.getPathForSA(lgname, vos[0],
                        section=self._section)
                    myid = '%s:%s' % (tag, info.get('id', 'UNKNOWN'))
                    info = {'voInfoID': myid,
                            'seUniqueID': seUniqueID,
                            'name': myid,
                            'path': path,
                            'tag': tag,
                            'acbr': '\n'.join(['GlueVOInfoAccessControlBaseRule: '\
                                '%s' % i for i in allowed_acbrs]),
                            'saLocalID': sa['saLocalID'],
                            }
                    self.vos.append(info)


            # For any VO with no pre-existing reservation, but which is allowed
            # to make reservations, also do a VOInfo object.
            for vo in all_lg_vos.difference(found_reservation_vos):
                vo = normalizeFQAN(i).split('/')[1]
                path = self.getPathForSA(lgname, vo,
                    section=self._section)
                id = '%s' % vo
                info = {'voInfoID': id,
                        'seUniqueID': seUniqueID,
                        'name': id,
                        'path': path,
                        'tag': '%s with no reserved space' % vo,
                        'acbr': 'GlueVOInfoAccessControlBaseRule: VO:%s' % vo,
                        'saLocalID': sa['saLocalID'],
                       }
                self.vos.append(info)