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

won't this trigger the initial client registration? 

Is there no other way to check for this info?

Also, older lxc doesn't have lxc network (like lxd-client 2.x on Xenial)
that exits 1 and says 'unknown command'; 

Wouldn't it be better to check via iproute2?

% ip link show type bridge
9: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:d4:d2:41 brd ff:ff:ff:ff:ff:ff
126: lxdbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether fe:1d:80:7f:ab:f7 brd ff:ff:ff:ff:ff:ff

It's possible that lxd doesn't have a config for lxdbr0, but it's already defined.

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