[lxc-devel] [PATCH 1/4] Honor network type and link from lxc-create -f

Serge Hallyn serge.hallyn at canonical.com
Thu Oct 11 15:10:03 UTC 2012


Quoting Dwight Engen (dwight.engen at oracle.com):
> Make the oracle template honor the lxc.network.type and
> lxc.network.link configuration items if a "base" configuration file is
> passed to lxc-create. If no configuration file is passed, the template
> falls back to the default name created by libvirt.
> 
> Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
> ---
>  templates/lxc-oracle.in |   16 ++++++++++++----
>  1 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/templates/lxc-oracle.in b/templates/lxc-oracle.in
> index ba62f8f..2d62396 100644
> --- a/templates/lxc-oracle.in
> +++ b/templates/lxc-oracle.in
> @@ -27,10 +27,6 @@
>  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
>  #
>  
> -# use virbr0 that is setup by default by libvirtd
> -lxc_network_type=veth
> -lxc_network_link=virbr0
> -
>  die()
>  {
>      echo "failed: $1"
> @@ -250,6 +246,18 @@ container_config_create()
>  		      head -1 |awk '{print $2}' | cut -c1-10 |\
>  		      sed 's/\(..\)/\1:/g; s/.$//'`"
>      mkdir -p $cfg_dir || die "unable to create config dir $cfg_dir"
> +
> +    # see if the network settings are specified in the file thats handed to us
> +    lxc_network_type=`grep '^lxc.network.type' $cfg_dir/config | awk -F'[= \t]+' '{ print $2 }'`
> +    if [ -z "$lxc_network_type" ]; then
> +	lxc_network_type="veth"
> +    fi
> +
> +    lxc_network_link=`grep '^lxc.network.link' $cfg_dir/config | awk -F'[= \t]+' '{ print $2 }'`
> +    if [ -z "$lxc_network_link" ]; then
> +	lxc_network_link="virbr0"
> +    fi
> +

Hi,

the creator might want to put other things in the initial config, such as
lxc.cgroup.devices entries.

When you do 'lxc-create -t TEMPLATE -n p1 -f CONFIG", lxc-create will
copy CONFIG to /var/lib/lxc/p1/config.  I think it would be better for
your template to not remove the config copied over by lxc-create.  So
don't do the above steps.  If you want the default to be to use virbr0,
just check whether 'lxc.network.type' is not in the config yet, and if
it is not then set 

lxc_network_type=veth
lxc_network_link=virbr0

as you were before.  (I'm sure you know this, but to be clear, if there
is no 'lxc.network.type' at all then the container will share the host's
network, and if it is 'lxc.network.type = empty' then it will have a
private netns with only loopback.  So you can pick what you want for
a default, but this way the distro, by setting a default
/etc/lxc/lxc.conf, can easily choose a default bridge for
lxc.network.link while the template can choose what to do if nothing is
specified.

>      rm -f $cfg_dir/config
>      cat <<EOF >> $cfg_dir/config || die "unable to create $cfg_dir/config"
>  # Container configuration for Oracle Linux $release_major.$release_minor
> -- 
> 1.7.1
> 




More information about the lxc-devel mailing list