lxd-container-running

Example:

# Launch/create (if necessary) a container from a local image
- lxd-container-running:
    image_name: my-local-image
    name: my-container-name

Description

Makes sure a specific lxd image is running on this machine.

Can (optionally) install lxd on the target machine before launching the container.

Variables

Name Type Default Description

image_name

string --

The image name or alias.

Use 'lxc image list images:' or similar to get a name of lists. Required

name

string --

A name to identify this container with. Required

config

dict --

The config for the container.

devices

dict --

Devices for the container.

ensure_lxd_installed

boolean False

Install LXD if not already present.

image_server

string --

The server that hosts the image.

image_server_protocol

string simplestreams

The protocol the specified image server uses.

profiles

list ['default']

The lxd profile to use for this container.

register_target

string --

The key to register the container network details under.

users

list --

A list of users who will be added to the 'lxd' group.

Examples

Example 1

Launch/create (if necessary) a container from a local image

Code
- lxd-container-running:
    image_name: my-local-image
    name: my-container-name

Example 2

Launch/create (if necessary) a container from a remote image

Code
- lxd-container-running:
    image_name: debian/10
    image_server: https://images.linuxcontainers.org

Code

doc:
  short_help: Makes sure a specific lxd container is running on this machine.
  help: |
    Makes sure a specific lxd image is running on this machine.

    Can (optionally) install lxd on the target machine before launching the container.
  examples:
  - title: Launch/create (if necessary) a container from a local image
    vars:
      image_name: my-local-image
      name: my-container-name
  - title: Launch/create (if necessary) a container from a remote image
    vars:
      image_name: debian/10
      image_server: https://images.linuxcontainers.org

args:
  _import: lxd-service
  name:
    doc:
      short_help: A name to identify this container with.
    type: string
    required: true
  ensure_lxd_installed:
    doc:
      short_help: Install LXD if not already present.
    type: boolean
    required: false
    default: false
  image_name:
    doc:
      short_help: The image name or alias.
      help: |
        The image name or alias.

        Use 'lxc image list images:' or similar to get a name of lists.
    type: string
    required: true
  image_server:
    doc:
      short_help: The server that hosts the image.
    type: string
    required: false
#    default: "https://images.linuxcontainers.org"
    cli:
      show_default: true
  image_server_protocol:
    doc:
      short_help: The protocol the specified image server uses.
    type: string
    required: false
    default: simplestreams
    allowed:
    - simplestreams
    - lxd
  register_target:
    doc:
      short_help: The key to register the container network details under.
    type: string
    required: false
  profiles:
    doc:
      short_help: The lxd profile to use for this container.
    type: list
    schema:
      type: string
    empty: false
    default:
    - default
    required: false
  config:
    doc:
      short_help: The config for the container.
    type: dict
    empty: true
    required: false
  devices:
    doc:
      short_help: Devices for the container.
    type: dict
    required: false
    empty: true

frecklets:
- lxd-service:
    frecklet::skip: '{{:: ensure_lxd_installed | negate ::}}'
    users: '{{:: users ::}}'
- frecklet:
    name: lxd_container
    type: ansible-module
    desc:
      short: "create/launch container '{{:: name ::}}'"
    properties:
      idempotent: true
    register:
      target: '{{:: register_target ::}}'
  vars:
    name: '{{:: name ::}}'
    state: started
    source:
      type: image
      mode: pull
      server: '{{:: image_server ::}}'
      protocol: '{{:: image_server_protocol ::}}'
      alias: '{{:: image_name ::}}'
    profiles: '{{:: profiles ::}}'
    wait_for_ipv4_addresses: true
    timeout: 600
    config: '{{:: config ::}}'
    devices: '{{:: devices ::}}'
frecklecute lxd-container-running --help

Usage: frecklecute lxd-container-running [OPTIONS]

  Makes sure a specific lxd image is running on this machine.

  Can (optionally) install lxd on the target machine before launching the
  container.

Options:
  --image-name IMAGE_NAME         The image name or alias.  [required]
  --name NAME                     A name to identify this container with.
                                  [required]
  --config CONFIG                 The config for the container.
  --devices DEVICES               Devices for the container.
  --ensure-lxd-installed / --no-ensure-lxd-installed
                                  Install LXD if not already present.
  --image-server IMAGE_SERVER     The server that hosts the image.
  --image-server-protocol IMAGE_SERVER_PROTOCOL
                                  The protocol the specified image server
                                  uses.
  --profiles PROFILES             The lxd profile to use for this container.
  --register-target REGISTER_TARGET
                                  The key to register the container network
                                  details under.
  -u, --user USER                 A list of users who will be added to the
                                  'lxd' group.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.lxd_container_running.LxdContainerRunning
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class LxdContainerRunning(AutoPycklet):
    """Makes sure a specific lxd image is running on this machine.

     Can (optionally) install lxd on the target machine before launching the container.

       Args:
         config: The config for the container.
         devices: Devices for the container.
         ensure_lxd_installed: Install LXD if not already present.
         image_name: The image name or alias.
         image_server: The server that hosts the image.
         image_server_protocol: The protocol the specified image server uses.
         name: A name to identify this container with.
         profiles: The lxd profile to use for this container.
         register_target: The key to register the container network details under.
         users: A list of users who will be added to the 'lxd' group.

    """

    FRECKLET_ID = "lxd-container-running"

    config: Dict = None
    devices: Dict = None
    ensure_lxd_installed: bool = None
    image_name: str = None
    image_server: str = None
    image_server_protocol: str = None
    name: str = None
    profiles: List = None
    register_target: str = None
    users: List = None


    def __post_init__(self):
        super(LxdContainerRunning, self).__init__(var_names=["config", "devices", "ensure_lxd_installed", "image_name", "image_server", "image_server_protocol", "name", "profiles", "register_target", "users"])


frecklet_class = LxdContainerRunning
# -*- coding: utf-8 -*-


#
# module path: pycklets.lxd_container_running.LxdContainerRunning
#


from pyckles import AutoPycklet

class LxdContainerRunning(AutoPycklet):
    """Makes sure a specific lxd image is running on this machine.

     Can (optionally) install lxd on the target machine before launching the container.

       Args:
         config: The config for the container.
         devices: Devices for the container.
         ensure_lxd_installed: Install LXD if not already present.
         image_name: The image name or alias.
         image_server: The server that hosts the image.
         image_server_protocol: The protocol the specified image server uses.
         name: A name to identify this container with.
         profiles: The lxd profile to use for this container.
         register_target: The key to register the container network details under.
         users: A list of users who will be added to the 'lxd' group.

    """

    FRECKLET_ID = "lxd-container-running"

    def __init__(self, config=None, devices=None, ensure_lxd_installed=None, image_name=None, image_server=None, image_server_protocol="simplestreams", name=None, profiles=['default'], register_target=None, users=None):

        super(LxdContainerRunning, self).__init__(var_names=["config", "devices", "ensure_lxd_installed", "image_name", "image_server", "image_server_protocol", "name", "profiles", "register_target", "users"])
        self._config = config
        self._devices = devices
        self._ensure_lxd_installed = ensure_lxd_installed
        self._image_name = image_name
        self._image_server = image_server
        self._image_server_protocol = image_server_protocol
        self._name = name
        self._profiles = profiles
        self._register_target = register_target
        self._users = users

    @property
    def config(self):
        return self._config

    @config.setter
    def config(self, config):
        self._config = config

    @property
    def devices(self):
        return self._devices

    @devices.setter
    def devices(self, devices):
        self._devices = devices

    @property
    def ensure_lxd_installed(self):
        return self._ensure_lxd_installed

    @ensure_lxd_installed.setter
    def ensure_lxd_installed(self, ensure_lxd_installed):
        self._ensure_lxd_installed = ensure_lxd_installed

    @property
    def image_name(self):
        return self._image_name

    @image_name.setter
    def image_name(self, image_name):
        self._image_name = image_name

    @property
    def image_server(self):
        return self._image_server

    @image_server.setter
    def image_server(self, image_server):
        self._image_server = image_server

    @property
    def image_server_protocol(self):
        return self._image_server_protocol

    @image_server_protocol.setter
    def image_server_protocol(self, image_server_protocol):
        self._image_server_protocol = image_server_protocol

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        self._name = name

    @property
    def profiles(self):
        return self._profiles

    @profiles.setter
    def profiles(self, profiles):
        self._profiles = profiles

    @property
    def register_target(self):
        return self._register_target

    @register_target.setter
    def register_target(self, register_target):
        self._register_target = register_target

    @property
    def users(self):
        return self._users

    @users.setter
    def users(self, users):
        self._users = users



frecklet_class = LxdContainerRunning