Giter Site home page Giter Site logo

ucphhpc / multiplespawner Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 1.0 167 KB

A JupyterHub Spawner that enables multiple different Spawners to be used in combination with the ability to request and orchestrate a cloud resource on which their notebook should be hosted.

License: MIT License

Python 96.99% Makefile 3.01%
jupyterhub-spawner jupyterhub jupyter spawner spawn-notebook-servers

multiplespawner's Introduction

multiplespawner

https://travis-ci.com/ucphhpc/multiplespawner.svg?branch=master

A JupyterHub Spawner that allows to select which resource their notebook should be spawned on. Internally it then uses spawner specific configurations to orchestrate the user on the given resources.

Currently the plan is to support either a VM or container deployment on a set of user selectable hardware configurations

Usage

To use the MultipleSpawner, the JupyterHub configuration has to specify that it should use the MultipleSpawner:

c = get_config()
c.JupyterHub.spawner_class = "multiplespawner.MultipleSpawner"

Configuration

To configure which Spawners the MultipleSpawner should support and how a particular Notebook should be spawned, the Spawner expects two configuration files. Namely the Spawner Template configuration and the Spawner Deployment configurations.

By default, the spawner expects these to be present in the ~/.multiplespawner directory as the spawner_templates.json and spawner_deployment.json files. It is however possible, to override this expectation by defining other paths via the MULTIPLE_SPAWNER_TEMPLATE_FILE and MULTIPLE_SPAWNER_DEPLOYMENT_FILE environment variables.

Spawner Template Configuration

This configuration defines which Spawner should be supported and how they should be utilized. The expected structure of this configuration file can be seen below:

[
    {
        "name": "",                 # Name to show for the Spawner configuration
        "resource_type": "",        # The resource_type that the Spawner expects (virtual_machine,container,bare_metal)
        "providers": [""],          # Which cloud providers support this spawner?
        "spawner": {
            "class": "",            # The Spawner class that should be used by the MultipleSpawner to spawn the instance
            "kwargs": {}            # The property values that should be set for the specified Spawner.
        },
        "configurer": {             # If so required, the configurer to apply to the target resource
            "class": "",            # Configurer class
                                    # Any additional keys will be applied to the class at instantiation

        },
        "authenticator": {          # A required field for specifying which authenticator should be used to configure the resource
                                    # and before the MultipleSpawner can connect to the resource
            "class": "",            # Class path to the designated authenticator
            "kwargs": {}            # Kwargs that should be passed to the constructor
        }
    }
]

An example of how such a file might be defined can be seen in the following example:

[
    {
        "name": "VirtualMachine Spawner",
        "resource_type": "virtual_machine",
        "providers": ["oci"],
        "spawner": {
            "class": "sshspawner.sshspawner.SSHSpawner",
            "kwargs": {
                "remote_hosts": ["{endpoint}"],
                "remote_port": "22",
                "ssh_keyfile": "~/.corc/ssh/id_rsa",
                "remote_port_command": "/usr/bin/python3 \
                    /usr/local/bin/get_port.py"
            }
        },
        "configurer": {
            "class": "corc.configurer.AnsibleConfigurer",
            "options": {
                "host_variables": {
                    "ansible_user": "opc",
                    "ansible_become": "yes",
                    "ansible_become_method": "sudo",
                    "new_username": "{JUPYTERHUB_USER}"
                },
                "host_settings": {
                    "group": "compute",
                    "port": "22"
                },
                "apply_kwargs": {
                    "playbook_path": "setup_ssh_spawner.yml"
                }
            }
        },
        "authenticator": {
            "class": "corc.authenticator.SSHAuthenticator",
            "kwargs": {"create_certificate": "True"}
        }
    }
]

As shown in the above example, the Spawner Template Configuration supports the definition of multiple Spawners via the encapsulating list that contains each individual spawner's configuration as a dictionary.

In the provided example, a VirtualMachine Spawner is introduced. It is configured to use be supports by the oci cloud provider. Furthermore, it uses the SSHSpawner to spawn the Notebook, in addition, because the SSHSpawner expects a number of attributes to be defined before it can connect to a given resource, the kwargs key defines which attributes that should be passed to the SSHSpaner's constructor at instantiation. The same approach applies to the configurer and the authenticator keys in the dictionary.

Spawner Deployment Configuration

The Spawner Deployment Configuration is for defining how a particular Jupyter session should be spawned. An example of the deployment configuration file structure can be seen below:

{
    "": [  # The key must defined the ``resource_type`` that the subdeployment configurations uses

        {} # The underlying list contains the set of attributes and their values
           # that should be passed to the Spawner before it spawns the Jupyter Session
    ]
}

Currently the MultipleSpawner supports three different kinds of resource_types (container, virtual_machine, and bare_metal) as define by the multiplespawner.runtime.resource.ResourceTypes class. A hello world example of the Spawner Deployment Configuration can be seen below:

{
    "container": [
        {
            "name": "python_notebook",
            "image": "nielsbohr/python-notebook"
        }
    ],
    "virtual_machine": [
        {
            "name": "oracle_linux_7_8",
            "provider": "oci",
            "image": "Oracle Linux 7.8"
        }
    ],
    "bare_metal": [
        {
            "name": "local_machine",
            "provider": "local"
        }
    ]
}

Status

The MultipleSpawner still needs additional testings and refinement to ensure that it is stable and versitile enough for large scale deployment

multiplespawner's People

Contributors

dependabot[bot] avatar rasmunk avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.