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 push(): dn = Domain() dn.uid = str(uuid.uuid4()) dn.name = request.form['domain'] dn.status = "legitimate" if not re.match(r'^[a-zA-Z0-9-_\\.]+$', dn.name): raise BadRequest('Invalid domain name') while dn.name.startswith('*.'): dn.name = dn.name.split('.', 1)[1] keywords = app.config['SUSPICIOUS_KEYWORDS'] matches = [] for k in keywords: matches.extend([{ "keyword": k, "matched": word, "score": score } for word, score in fuzzy_process.extractBests(k, (dn.name, ), score_cutoff=70)]) if matches or request.form.get('from-ui'): dn.status = "check-queued" try: db.session.add(dn) db.session.commit() except IntegrityError: db.session.rollback() if request.form.get('from-ui'): return redirect('/') return jsonify({"status": "already-exists", "matches": matches}) else: if matches or request.form.get('from-ui'): rs.rpush('screen-jobs', json.dumps({"uid": dn.uid})) if request.form.get('from-ui'): return redirect('/') return jsonify({"status": dn.status, "matches": matches})
def create_domain(domain, domain_title, user): """Creates a new domain, if none already exists with that identifier. The user will become an admin on the newly created domain, and the domain will be added to the list of domains of the user. The updates will be stored in the datastore. Args: domain: The domain identifier of the new domain. Must be a lowercase alphanumeric string of length less than 100. The identifier must match the VALID_DOMAIN_IDENTIFIER regexp. domain_title: The string title of the new domain. The string must be non-empty. user: Instance of the User model that creates the domain. Returns: The newly created Domain instance. |user| will be set as admin of the new domain. Returns None if a domain already exists with that identifier, the identifier is not valid or the domain_title is empty. """ # TODO(tijmen): Use multiple entity group transaction here domain_title = domain_title.splitlines()[0].strip() if (not re.match(VALID_DOMAIN_IDENTIFIER, domain) or not domain_title): return None existing = Domain.get_by_key_name(domain) if existing: return None new_domain = Domain(key_name=domain, name=domain_title, admins=[user.key().name()]) new_domain.put() def txn(user_key): txn_user = User.get(user_key) if not domain in txn_user.domains: txn_user.domains.append(domain) txn_user.put() db.run_in_transaction(txn, user.key()) return new_domain