cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #05032
Re: [Merge] ~smoser/cloud-init:fix/lxd-only-create-network-if-noexist into cloud-init:master
Diff comments:
> diff --git a/cloudinit/config/cc_lxd.py b/cloudinit/config/cc_lxd.py
> index 09374d2..b6ee756 100644
> --- a/cloudinit/config/cc_lxd.py
> +++ b/cloudinit/config/cc_lxd.py
> @@ -251,4 +257,47 @@ def bridge_to_cmd(bridge_cfg):
>
> return cmd_create, cmd_attach
>
> +
> +def _network_exists(name):
> + """Return boolean indicating if network exists."""
> + try:
> + _out, _err = util.subp(["lxc", "network", "show", name],
@ryan,
a.) older lxc wont take this path.. it will take the debconf-communicate path. this path is only taken if we have anlxd that has a 'network' subcommand.
b.) checking via any mechanism other than asking lxc is just asking for problems. The thing that knows is lxd, so ask it. even simpler than 'ip route' is just os.path.exists("/sys/class/net/lxdbr0") but that is baking in knowledge of lxc that I idon't have to k now.
c.) "initial client registration" was going to happen anyway when we *create* the network.
if you all are insistent on not using lxc to ask lxd if it has a network, then i'd just use the is_bridge path, but honestly that could be brittle to lxd implementations behavior.
> + update_env={'LC_ALL': 'C'})
> + return True
> + except util.ProcessExecutionError as e:
> + if e.exit_code != 1 or "not found" not in e.stderr.lower():
> + raise e
> + return False
> +
> +
> +def _network_delete(name):
> + util.subp(["lxc", "network", "delete", name])
> +
> +
> +def maybe_delete_network(cfg, default=None):
> + """Some versions of lxd init automatically create a lxdbr0.
> + If cfg specified to create that name, then we need to delete it
> + so that the creation will work. If cfg specified a name other
> + than default, or mode == existing, then do not do anything.
> +
> + https://github.com/lxc/lxd/issues/4649
> + """
> +
> + if default is None:
> + default = _DEFAULT_NETWORK_NAME
> +
> + if cfg.get("mode", "new") == "existing":
> + return
> +
> + name = cfg.get("name", default)
> + if name != default:
> + return
> +
> + if not _network_exists(name):
> + return
> +
> + LOG.debug("Removing lxd network '%s'", name)
> + _network_delete(name)
> +
> +
> # vi: ts=4 expandtab
--
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/348005
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:fix/lxd-only-create-network-if-noexist into cloud-init:master.
References