00000004
ˆ
ƒšw_•I|¥‰ÓMdœv ©ƒ&íK<óo¬¿Ã ß
Index of /FSS-BCZ/root/usr/share/doc/libgsf
Index of /FSS-BCZ/root/usr/share/doc/libgsf
$ ˆl–Ðz¾”ji?u4 \¸î*bÑ¿Â
„.¾÷ÁÀÄ 5æ # Copyright (C) 2016 Canonical Ltd.
#
# Author: Wesley Wiedenmeier
#
# This file is part of cloud-init. See LICENSE file for license information.
"""LXD: configure lxd with ``lxd init`` and optionally lxd-bridge"""
import logging
import os
from typing import List, Tuple
import yaml
from cloudinit import subp, util
from cloudinit.cloud import Cloud
from cloudinit.config import Config
from cloudinit.config.schema import MetaSchema
from cloudinit.settings import PER_INSTANCE
LOG = logging.getLogger(__name__)
_DEFAULT_NETWORK_NAME = "lxdbr0"
meta: MetaSchema = {
"id": "cc_lxd",
"distros": ["ubuntu"],
"frequency": PER_INSTANCE,
"activate_by_schema_keys": ["lxd"],
}
def supplemental_schema_validation(init_cfg, bridge_cfg, preseed_str):
"""Validate user-provided lxd network and bridge config option values.
@raises: ValueError describing invalid values provided.
"""
errors = []
if not isinstance(init_cfg, dict):
errors.append(
f"lxd.init config must be a dictionary. found a"
f" '{type(init_cfg).__name__}'",
)
if not isinstance(bridge_cfg, dict):
errors.append(
f"lxd.bridge config must be a dictionary. found a"
f" '{type(bridge_cfg).__name__}'",
)
if not isinstance(preseed_str, str):
errors.append(
f"lxd.preseed config must be a string. found a"
f" '{type(preseed_str).__name__}'",
)
if preseed_str and (init_cfg or bridge_cfg):
incompat_cfg = ["lxd.init"] if init_cfg else []
incompat_cfg += ["lxd.bridge"] if bridge_cfg else []
errors.append(
"Unable to configure LXD. lxd.preseed config can not be provided"
f" with key(s): {', '.join(incompat_cfg)}"
)
if errors:
raise ValueError(". ".join(errors))
def handle_init_cfg(init_cfg):
"""Set up lxd if init config is given.
:param init_cfg: dict of lxd init configuration options to provide
to `lxd init --auto`
"""
# type is known, number of elements is not
# in the case of the ubuntu+lvm backend workaround
init_keys: Tuple[str, ...] = (
"network_address",
"network_port",
"storage_backend",
"storage_create_device",
"storage_create_loop",
"storage_pool",
"trust_password",
)
cmd = ["lxd", "init", "--auto"]
for k in init_keys:
if init_cfg.get(k):
cmd.extend(["--%s=%s" % (k.replace("_", "-"), str(init_cfg[k]))])
try:
subp.subp(cmd)
except subp.ProcessExecutionError:
if init_cfg["storage_backend"] != "lvm":
raise
LOG.i