def register_backend(self): name = gethostname() local_ip = None backend = BackendServer.objects(name=name).first() if not backend: for local_ip in local_ipv4_addresses(): backend = BackendServer.objects(ip=local_ip).first() if backend: break if not backend and not local_ip: log.error(_("No IP address found for local backend!")) return if backend: if backend.autodetect: self.update_backend(backend) else: log.info(_("Local backend not found, registering as '{name}' " "with IP {ip}").format(name=name, ip=local_ip)) backend = BackendServer(name=name, ip=local_ip, is_enabled=False, cpu_cores=cpu_count(), memory_mb=backend_total_memory()) backend.save() return backend
def create_backend(request): name = gethostname() backend = BackendServer.objects(name=name).first() if backend: backend.delete() backend = BackendServer(name=name, ip='127.0.0.1', memory_mb=512, cpu_cores=1) backend.save() def cleanup(): backend.delete() request.addfinalizer(cleanup) request.instance.backend = backend request.instance.backend_name = name
def create_backend_list(request): backends = [] for i in range(0, 10): name = 'backend%d' % i backend = BackendServer.objects(name=name).first() if backend: backend.delete() backend = BackendServer(name=name, ip='127.0.0.%d' % i, memory_mb=512, cpu_cores=1) backend.save() backends.append(backend) def cleanup(): for backend in backends: backend.delete() request.addfinalizer(cleanup) request.instance.backend_list = backends