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

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_addresses

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_addresses:
    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

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:
      var: '{{:: register_addresses ::}}'
      query: /addresses
  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
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]
  --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-addresses REGISTER_ADDRESSES
                                  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:
         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_addresses: 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"

    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_addresses: str = None
    users: List = None


    def __post_init__(self):
        super(LxdContainerRunning, self).__init__(var_names=["ensure_lxd_installed", "image_name", "image_server", "image_server_protocol", "name", "profiles", "register_addresses", "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:
         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_addresses: 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, ensure_lxd_installed=None, image_name=None, image_server=None, image_server_protocol="simplestreams", name=None, profiles=['default'], register_addresses=None, users=None):

        super(LxdContainerRunning, self).__init__(var_names=["ensure_lxd_installed", "image_name", "image_server", "image_server_protocol", "name", "profiles", "register_addresses", "users"])
        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_addresses = register_addresses
        self._users = users

    @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_addresses(self):
        return self._register_addresses

    @register_addresses.setter
    def register_addresses(self, register_addresses):
        self._register_addresses = register_addresses

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

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



frecklet_class = LxdContainerRunning