예제 #1
0
def launch(image, name):
    """
    Create and start a container.

    \b
    <image>     -   Image to use as source. e.g. ubuntu/18.04 or alpine/3.11.
                    Only images in https://images.linuxcontainers.org
                    are supported at this time. Run 'yurt images' to list them.
    NAME        -   Container name

    \b
    Container names must:
    * be between 1 and 63 characters long
    * be made up exclusively of letters, numbers and dashes from the ASCII table
    * not start with a digit or a dash
    * not end with a dash

    EXAMPLES:

    \b
    $ yurt launch ubuntu/18.04 c1       -   Create and start an ubuntu 18.04 container.

    """

    try:
        vm.ensure_is_ready()

        lxc.launch("images", image, name)

    except YurtException as e:
        logging.error(e.message)
예제 #2
0
def init():
    """
    Initialize the VM.
    """

    try:
        vm.ensure_is_ready(prompt_init=False, prompt_start=True)
    except YurtException as e:
        logging.error(e.message)
예제 #3
0
def ssh():
    """
    SSH into the VM.
    """
    try:
        vm.ensure_is_ready()
        vm.launch_ssh()
    except YurtException as e:
        logging.error(e.message)
예제 #4
0
def restart(force):
    """
    Restart the VM.
    """

    try:
        if vm.state() == vm.State.Running:
            vm.stop(force=force)
        vm.ensure_is_ready(prompt_init=True, prompt_start=False)
    except YurtException as e:
        logging.error(e.message)
예제 #5
0
def start_vm():
    """
    Start up the VM.
    """

    try:
        if vm.state() == vm.State.Running:
            logging.info("Yurt is already running.")
        else:
            vm.ensure_is_ready(prompt_init=True, prompt_start=False)
    except YurtException as e:
        logging.error(e.message)
예제 #6
0
def info():
    """
    Show information about the Yurt VM.
    """

    try:
        for k, v in vm.info().items():
            click.echo(f"{k}: {v}")

        vm.ensure_is_ready()
    except YurtException as e:
        logging.error(e.message)
예제 #7
0
def delete(instances):
    """
    Delete one or more containers.
    """

    full_help_if_missing(instances)

    try:
        vm.ensure_is_ready()

        lxc.delete(list(instances))

    except YurtException as e:
        logging.error(e.message)
예제 #8
0
def stop(instances):
    """
    Stop one or more containers.
    """

    full_help_if_missing(instances)

    try:
        vm.ensure_is_ready()

        click.echo(lxc.stop(list(instances)))

    except YurtException as e:
        logging.error(e.message)
예제 #9
0
파일: cli.py 프로젝트: simhaonline/yurt
def delete(instances, force):
    """
    Delete an instance.
    """

    full_help_if_missing(instances)

    try:
        vm.ensure_is_ready()

        lxc.delete(list(instances), force=force)

    except YurtException as e:
        logging.error(e.message)
예제 #10
0
파일: cli.py 프로젝트: simhaonline/yurt
def stop(instances, force):
    """
    Stop an instance.
    """

    full_help_if_missing(instances)

    try:
        vm.ensure_is_ready()

        click.echo(lxc.stop(list(instances), force=force))

    except YurtException as e:
        logging.error(e.message)
예제 #11
0
파일: cli.py 프로젝트: simhaonline/yurt
def start(instances):
    """
    Start a 'Stopped' instance.
    """

    full_help_if_missing(instances)

    try:
        vm.ensure_is_ready()

        lxc.start(list(instances))

    except YurtException as e:
        logging.error(e.message)
예제 #12
0
def shell(instance):
    """
    Start a shell in a container as root.

    The interactive terminal launched is not very sophisticated and is intended for
    bootstrapping your container. It starts a shell as root in <name>.
    Use it to create and configure users who can SSH using the container's
    IP address.
    """

    try:
        vm.ensure_is_ready()
        lxc.shell(instance)
    except YurtException as e:
        logging.error(e.message)
예제 #13
0
파일: cli.py 프로젝트: simhaonline/yurt
def shell(instance):
    """
    Start a shell in an instance.

    This is intended for bootstrapping your instances. It starts a shell
    as root in <instance>.
    Use it to create and configure users who can SSH using the instance's
    IP address.
    """

    try:
        vm.ensure_is_ready()
        lxc.shell(instance)
    except YurtException as e:
        logging.error(e.message)
예제 #14
0
파일: cli.py 프로젝트: simhaonline/yurt
def list_():
    """
    List instances.
    """

    try:
        vm.ensure_is_ready()

        instances = tabulate(lxc.list_(), headers="keys")
        if instances:
            click.echo(instances)
        else:
            click.echo(
                "No instances found. Create one with 'yurt launch <image> <name>'")

    except YurtException as e:
        logging.error(e.message)
예제 #15
0
def images(remote):
    """
    List images that can be used to launch a container.

    """

    remote_server = "images"
    try:
        vm.ensure_is_ready()

        if remote:
            images = tabulate(lxc.list_remote_images(remote_server),
                              headers="keys",
                              disable_numparse=True)
        else:
            images = tabulate(lxc.list_cached_images(),
                              headers="keys",
                              disable_numparse=True)

        click.echo(images)

    except YurtException as e:
        logging.error(e.message)
예제 #16
0
파일: cli.py 프로젝트: simhaonline/yurt
def images(cached):
    """
    List available images.

    At this time, only images at https://images.linuxcontainers.org are supported.
    """

    remote = "images"
    try:
        vm.ensure_is_ready()

        if cached:
            images = tabulate(
                lxc.list_cached_images(), headers="keys", disable_numparse=True
            )
        else:
            images = tabulate(
                lxc.list_remote_images(remote), headers="keys", disable_numparse=True
            )

        click.echo(images)

    except YurtException as e:
        logging.error(e.message)