← Back to team overview

cloud-init-dev team mailing list archive

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],

Instead of either option, could we just use cloudinit.net.is_bridge('lxdbr0')?

> +                               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