def getSEVersion(cp, admin=None): """ Get the version info from the dCache system. @param cp: A config parser object which holds the dCache login information @type cp: ConfigParser @keyword admin: An instance of the L{dCacheAdmin} interface. If it is None, then `cp` will be used to log in to the admin interface. @return: The dCache version number; UNKNOWN if it can't be determined. """ if admin == None: admin = connect_admin(cp) pools = admin.execute("PoolManager", "cm ls") pool = None for line in pools.split('\n'): pool = line.split('=')[0] break if pool == None: log.warning("No pools found attached to dCache.") return "UNKNOWN" pool_info = admin.execute(pool, "info") version = None for line in pool_info.split('\n'): line_info = line.split() if line_info[0].strip() == 'Version': version = line_info[2].strip() break if version == None: log.warning("Unable to parse version info from pool %s." % str(pool)) return "UNKNOWN" version_re = re.compile("(.*)-(.*)-(.*)-(.*)-(.*)\((.*)\)") m = version_re.match(version) if m: kind, major, minor, bugfix, patch, revision = m.groups() if kind != "production": return "%s.%s.%s-%s (r%s), %s" % (major, minor, bugfix, patch, revision, kind) else: return "%s.%s.%s-%s" % (major, minor, bugfix, patch) else: return version
def getdCacheSESpace(cp, admin=None, gb=False, total=False): """ Get the total amount of space available in a dCache instance. By default, return the information in Kilobytes. @param cp: Site configuration @type cp: ConfigParser @keyword admin: If set, reuse this admin interface instead of making a new connection. @keyword gb: If True, then return the results in GB, not KB. @keyword total: If True, also return the total amount of space in the SE. @returns: Returns the used space, free space. If C{total=true}, also return the total space. If C{gb=True}, return the numbers in GB; otherwise the numbers are in kilobytes. """ global dCacheSpace_cache # pylint: disable-msg=W0603 if admin == None: admin = connect_admin(cp) if not dCacheSpace_cache: pools = lookupPoolStorageInfo(admin, log) used = 0L # In KB free = 0L # In KB tot = 0L # In KB for pool in pools: used += pool.usedSpaceKB free += pool.freeSpaceKB tot += pool.totalSpaceKB dCacheSpace_cache = used, free, tot else: used, free, tot = dCacheSpace_cache if gb: used /= 1000000L free /= 1000000L tot /= 1000000L if total: return used, free, tot return used, free