def register(domain): ip_addr = request.remote_addr nodes = len(domain) cpus = 0 total_memory = 0 total_bandwidth = 0 total_mflops = 0 for node in domain: # Parse cpuinfo file processors = _parse_file(node['cpuinfo'], CPUinfoParser, CPUinfoLexer, cpuinfo.Evaluator) # Parse meminfo file memory_stats = _parse_file(node['meminfo'], MeminfoParser, MeminfoLexer, meminfo.Evaluator) # Update domain global information cpus += len(processors) total_memory += int(memory_stats['MemTotal'].split()[0]) total_bandwidth += float(node.get('mpi_bandwidth')) total_mflops += float(node.get('mflops')) * cpus try: domain = Domain.get(ip=ip_addr) except Domain.DoesNotExist: domain = Domain(ip=ip_addr) domain.nodes = nodes domain.cpus = cpus domain.mflops = total_mflops domain.mpi_bandwidth = total_bandwidth / nodes domain.memory = total_memory domain.save() return {"id": domain.get_id()}
def get_all_domains_for_user(user): """ Returns a list with domain instances of the domains that the given user is a member of. Args: user: An instance of the User model Returns: A list of Domain model instances. """ keys = [db.Key.from_path('Domain', domain) for domain in user.domains] return Domain.get(keys)