def mutate_and_get_payload(cls, root, info, owner, labbook_name, no_cache=False, client_mutation_id=None): username = get_logged_in_username() if BuildImage.get_container_status(labbook_name, owner, username): raise ValueError(f'Cannot build image for running container {owner}/{labbook_name}') lb = InventoryManager().load_labbook(username, owner, labbook_name, author=get_logged_in_author()) # Generate Dockerfile # TODO BVB - Move to build_image ?? ib = ImageBuilder(lb) ib.assemble_dockerfile(write=True) # Kick off building in a background thread d = Dispatcher() build_kwargs = { 'path': lb.root_dir, 'username': username, 'nocache': no_cache } metadata = {'labbook': lb.key, 'method': 'build_image'} res = d.dispatch_task(jobs.build_labbook_image, kwargs=build_kwargs, metadata=metadata) return BuildImage(environment=Environment(owner=owner, name=labbook_name), background_job_key=res.key_str)
def mutate_and_get_payload(cls, root, info, owner, labbook_name, filename, mount_path, client_mutation_id=None): if len(mount_path) > 0 and mount_path[0] == '~': mount_path = mount_path.replace('~', '/home/giguser') if not cls._is_target_valid(mount_path): raise ValueError(f"Mount path {mount_path} is not a valid path") username = get_logged_in_username() lb = InventoryManager().load_labbook(username, owner, labbook_name, author=get_logged_in_author()) with lb.lock(): secstore = SecretStore(lb, username) secstore[filename] = mount_path cls._record_insert_activity(secstore, filename, lb, mount_path) env = Environment(owner=owner, name=lb.name) return InsertSecretsEntry(environment=env)
def mutate_and_get_payload(cls, root, info, owner, labbook_name, client_mutation_id=None): username = get_logged_in_username() lb = InventoryManager().load_labbook(username, owner, labbook_name, author=get_logged_in_author()) with lb.lock(): cls._stop_container(lb, username) return StopContainer(environment=Environment(owner=owner, name=labbook_name))
def mutate_and_get_payload(cls, root, info, owner, labbook_name, client_mutation_id=None): username = get_logged_in_username() lb = InventoryManager().load_labbook(username, owner, labbook_name, author=get_logged_in_author()) with lb.lock(): lb, container_id = ContainerOperations.start_container( labbook=lb, username=username) logger.info(f'Started new {lb} container ({container_id})') return StartContainer(environment=Environment(owner=owner, name=labbook_name))
def mutate_and_get_payload(cls, root, info, owner, labbook_name, client_mutation_id=None): username = get_logged_in_username() lb = LabBook(author=get_logged_in_author()) lb.from_name(username, owner, labbook_name) # TODO - Should we cehck if a custom docker component already exists? cm = ComponentManager(lb) cm.remove_docker_snippet(cm.DEFAULT_CUSTOM_DOCKER_NAME) return RemoveCustomDocker( updated_environment=Environment(owner=owner, name=labbook_name))
def mutate_and_get_payload(cls, root, info, owner, labbook_name, docker_content, client_mutation_id=None): username = get_logged_in_username() lb = LabBook(author=get_logged_in_author()) lb.from_name(username, owner, labbook_name) docker_lines = [n for n in docker_content.strip().split('\n') if n] cm = ComponentManager(lb) cm.add_docker_snippet(cm.DEFAULT_CUSTOM_DOCKER_NAME, docker_lines) return AddCustomDocker( updated_environment=Environment(owner=owner, name=labbook_name))
def mutate_and_get_payload(cls, root, info, owner, labbook_name, client_mutation_id=None): username = get_logged_in_username() lb = LabBook(author=get_logged_in_author()) lb.from_name(username, owner, labbook_name) lb, container_id, ports = ContainerOperations.start_container( labbook=lb, username=username) logger.info( f'Started new {lb} container ({container_id}) with ports {ports}') return StartContainer( environment=Environment(owner=owner, name=labbook_name))
def mutate_and_get_payload(cls, root, info, owner, labbook_name, app_name, client_mutation_id=None): username = get_logged_in_username() lb = InventoryManager().load_labbook(username, owner, labbook_name, author=get_logged_in_author()) bam = BundledAppManager(lb) with lb.lock(): bam.remove_bundled_app(app_name) return SetBundledApp( environment=Environment(name=labbook_name, owner=owner))
def mutate_and_get_payload(cls, root, info, owner, labbook_name, filename, client_mutation_id=None): username = get_logged_in_username() lb = InventoryManager().load_labbook(username, owner, labbook_name, author=get_logged_in_author()) with lb.lock(): secstore = SecretStore(lb, username) secstore.delete_file(filename) env = Environment(owner=owner, name=lb.name) return DeleteSecretsFile(environment=env)
def mutate_and_process_upload(cls, info, upload_file_path, upload_filename, **kwargs): if not upload_file_path: logger.error('No file uploaded') raise ValueError('No file uploaded') username = get_logged_in_username() owner = kwargs.get('owner') labbook_name = kwargs.get('labbook_name') lb = InventoryManager().load_labbook(username, owner, labbook_name) with lb.lock(): secret_store = SecretStore(lb, username) inserted_path = secret_store.insert_file( upload_file_path, dst_filename=upload_filename) env = Environment(owner=owner, name=lb.name) return UploadSecretsFile(environment=env)
def mutate_and_get_payload(cls, root, info, owner, labbook_name, filename, client_mutation_id=None): username = get_logged_in_username() lb = InventoryManager().load_labbook(username, owner, labbook_name, author=get_logged_in_author()) with lb.lock(): secret_store = SecretStore(lb, username) del secret_store[filename] cls._record_remove_activity(secret_store, filename, lb) env = Environment(owner=owner, name=lb.name) return InsertSecretsEntry(environment=env)
def mutate_and_get_payload(cls, root, info, owner, labbook_name, no_cache=False, client_mutation_id=None): username = get_logged_in_username() if BuildImage.get_container_status(labbook_name, owner, username): raise ValueError( f'Cannot build image for running container {owner}/{labbook_name}' ) labbook_dir = os.path.expanduser( os.path.join(Configuration().config['git']['working_directory'], username, owner, 'labbooks', labbook_name)) lb = LabBook(author=get_logged_in_author()) lb.from_directory(labbook_dir) # Generate Dockerfile ib = ImageBuilder(lb) ib.assemble_dockerfile(write=True) # Kick off building in a background thread d = Dispatcher() build_kwargs = { 'path': labbook_dir, 'username': username, 'nocache': no_cache } metadata = {'labbook': lb.key, 'method': 'build_image'} res = d.dispatch_task(jobs.build_labbook_image, kwargs=build_kwargs, metadata=metadata) return BuildImage(environment=Environment(owner=owner, name=labbook_name), background_job_key=res.key_str)
def mutate_and_get_payload(cls, root, info, owner, labbook_name, client_mutation_id=None): username = get_logged_in_username() lb = LabBook(author=get_logged_in_author()) lb.from_name(username, owner, labbook_name) lb_ip, _ = ContainerOperations.get_labbook_ip(lb, username) stop_labbook_monitor(lb, username) lb, stopped = ContainerOperations.stop_container(labbook=lb, username=username) try: # We know `git gc` fails on windows, so just give best effort fire-and-forget wf = GitWorkflow(lb) wf.garbagecollect() except Exception as e: logger.error(e) # Try to remove route from proxy lb_port = 8888 lb_endpoint = f'http://{lb_ip}:{lb_port}' pr = confhttpproxy.ProxyRouter.get_proxy( lb.labmanager_config.config['proxy']) routes = pr.routes est_target = [ k for k in routes.keys() if lb_endpoint in routes[k]['target'] and 'jupyter' in k ] if len(est_target) == 1: pr.remove(est_target[0][1:]) if not stopped: raise ValueError(f"Failed to stop labbook {labbook_name}") return StopContainer( environment=Environment(owner=owner, name=labbook_name))
def resolve_environment(self, info): """""" return Environment(id=f"{self.owner}&{self.name}", owner=self.owner, name=self.name)