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

2012-10-17 Thread Dwight Engen
Thanks, sounds good.

On Mon, 15 Oct 2012 15:30:39 -0500
Serge Hallyn  wrote:

> Thanks, Dwight, works like a charm for me.  I've pulled patches 1-4
> into my github tree, and have asked Stephane to review for the
> official staging tree.
> 
> -serge
> 
> Quoting Dwight Engen (dwight.en...@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 and the
> > host system is Oracle or Fedora, the template assumes a type of
> > veth and the default name created by libvirt.
> > 
> > Signed-off-by: Dwight Engen 
> > ---
> >  templates/lxc-oracle.in |   17 +
> >  1 files changed, 13 insertions(+), 4 deletions(-)
> > 
> > diff --git a/templates/lxc-oracle.in b/templates/lxc-oracle.in
> > index 84c3c33..f080dab 100644
> > --- a/templates/lxc-oracle.in
> > +++ b/templates/lxc-oracle.in
> > @@ -250,7 +250,6 @@ 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"
> > -rm -f $cfg_dir/config
> >  cat <> $cfg_dir/config || die "unable to create
> > $cfg_dir/config" # Container configuration for Oracle Linux
> > $release_major.$release_minor lxc.arch = $arch
> > @@ -261,9 +260,19 @@ lxc.pts = 1024
> >  lxc.rootfs = $container_rootfs
> >  lxc.mount  = $cfg_dir/fstab
> >  # Networking
> > -lxc.network.type = $lxc_network_type
> > -lxc.network.flags = up
> > -lxc.network.link = $lxc_network_link
> > +EOF
> > +
> > +# see if the network settings were already specified
> > +lxc_network_type=`grep '^lxc.network.type' $cfg_dir/config |
> > awk -F'[= \t]+' '{ print $2 }'`
> > +if [ -z "$lxc_network_type" -a \
> > +$host_distribution = "OracleServer" -o \
> > +$host_distribution = "Fedora" ]; then
> > +   echo "lxc.network.type = veth" >>$cfg_dir/config
> > +   echo "lxc.network.flags = up" >>$cfg_dir/config
> > +   echo "lxc.network.link = virbr0" >>$cfg_dir/config
> > +fi
> > +
> > +cat <> $cfg_dir/config || die "unable to create
> > $cfg_dir/config" lxc.network.name = eth0
> >  lxc.network.mtu = 1500
> >  lxc.network.hwaddr = $hwaddr
> > -- 
> > 1.7.1
> > 


--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH 5/5] Add distro config file /etc/lxc/lxc.conf

2012-10-17 Thread Dwight Engen
On Mon, 15 Oct 2012 14:49:26 -0500
Serge Hallyn  wrote:

> Quoting Dwight Engen (dwight.en...@oracle.com):
> > On Mon, 15 Oct 2012 12:42:57 -0500
> > Serge Hallyn  wrote:
> > 
> > > Quoting Dwight Engen (dwight.en...@oracle.com):
> > > > This allows a distro to put the distro specific default network
> > > > configuration (for example bridge device, link type), or other
> > > > lxc configuration in the case that -f is not passed by the user
> > > > to lxc-create, in which case lxc-create will use the distro
> > > > conf file as the basis for the containers config.
> > > 
> > > I think this is great.  Note though that debian does not have an
> > > lxcbr0, only Ubuntu does.
> > 
> > Ahh, so what should we use for distro detection? I went looking a
> > bit and systemd's configure.ac looks for an /etc/os-release but I
> > didn't find that on any distro I looked at except fedora 17, so I
> > don't think that will work for older distros. I guess we could use
> > lsb_release --id?
> 
> That would work.  Or since /etc/lsb-release on an ubuntu system will
> contain DISTRIB_ID=Ubuntu you can just do
> 
> [ -f /etc/lsb-release ] && grep -q DISTRIB_ID=Ubuntu /etc/lsb-release
> && osname=ubuntu || true

So what I did was look and see how other packages were detecting
the distribution, and I copied from what NetworkManager did. Renamed
lxc.conf.debian to lxc.conf.ubuntu. Note that HAVE_DEBIAN gets set for
both debian and ubuntu so the python stuff ends up in the right place.
Updated patch follows.
 
> > > This is getting "out there", but I wonder if, for the unknown os
> > > case, it would be reliable to look at the default nic, and check
> > > if it is a bridge, and use that bridge if so.
> > 
> > By "default nic" do you mean do something like `brctl show` and use
> > the first bridge name found?
> 
> Offhand I was thinking look at the device for 0.0.0.0 route in route
> -n output (or probably better '^default' in 'ip route' output), then
> check if it is on a bridge.  Not sure if there is a better way.
> 
> Anyway since distros can override this the empty default is fine.
> This would be cool, but might be fragile.  In my own case my default
> nic often changes anyway.

I decided not to try this right now :)

--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH 5/5 v2] Add distro config file /etc/lxc/lxc.conf

2012-10-17 Thread Dwight Engen
This allows a distro to put the distro specific default network
configuration (for example bridge device, link type), or other lxc
configuration in the case that -f is not passed by the user to
lxc-create, in which case lxc-create will use the distro conf file as
the basis for the containers config.

Signed-off-by: Dwight Engen 
---
 Makefile.am |2 +-
 config/Makefile.am  |9 +
 config/lxc.conf.libvirt |3 +++
 config/lxc.conf.ubuntu  |3 +++
 config/lxc.conf.unknown |1 +
 configure.ac|   42 +++---
 lxc.spec.in |1 +
 src/lxc/lxc-create.in   |   23 +--
 8 files changed, 66 insertions(+), 18 deletions(-)
 create mode 100644 config/lxc.conf.libvirt
 create mode 100644 config/lxc.conf.ubuntu
 create mode 100644 config/lxc.conf.unknown

diff --git a/Makefile.am b/Makefile.am
index c66ecc6..2f7606f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
 
 ACLOCAL_AMFLAGS = -I config
 
-SUBDIRS = src templates doc
+SUBDIRS = config src templates doc
 DIST_SUBDIRS = config src templates doc
 EXTRA_DIST = autogen.sh lxc.spec CONTRIBUTING MAINTAINERS ChangeLog
 
diff --git a/config/Makefile.am b/config/Makefile.am
index 783ba73..f9949a7 100644
--- a/config/Makefile.am
+++ b/config/Makefile.am
@@ -1,2 +1,11 @@
+configdir = $(sysconfdir)/lxc
+config_DATA = lxc.conf
+conffile = @LXC_CONFFILE@
+
+EXTRA_DIST = lxc.conf.ubuntu lxc.conf.libvirt lxc.conf.unknown
+
+lxc.conf:
+   cp $(conffile) $@
+
 distclean:
@$(RM) -f compile config.guess config.sub depcomp install-sh ltmain.sh 
missing Makefile.in Makefile
diff --git a/config/lxc.conf.libvirt b/config/lxc.conf.libvirt
new file mode 100644
index 000..7128619
--- /dev/null
+++ b/config/lxc.conf.libvirt
@@ -0,0 +1,3 @@
+lxc.network.type=veth
+lxc.network.link=virbr0
+lxc.network.flags=up
diff --git a/config/lxc.conf.ubuntu b/config/lxc.conf.ubuntu
new file mode 100644
index 000..d2ac167
--- /dev/null
+++ b/config/lxc.conf.ubuntu
@@ -0,0 +1,3 @@
+lxc.network.type=veth
+lxc.network.link=lxcbr0
+lxc.network.flags=up
diff --git a/config/lxc.conf.unknown b/config/lxc.conf.unknown
new file mode 100644
index 000..16fa9d6
--- /dev/null
+++ b/config/lxc.conf.unknown
@@ -0,0 +1 @@
+lxc.network.type=empty
diff --git a/configure.ac b/configure.ac
index b9a0d65..657d4e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,10 +12,45 @@ AM_PROG_CC_C_O
 AC_GNU_SOURCE
 AC_CHECK_PROG(SETCAP, setcap, yes, no, $PATH$PATH_SEPARATOR/sbin)
 
-if test -f /etc/debian_version; then
-osname="debian"
+AC_MSG_CHECKING([host distribution])
+AC_ARG_WITH(distro, AS_HELP_STRING([--with-distro=DISTRO], [Specify the Linux 
distribution to target: One of redhat, oracle, fedora, suse, gentoo, debian, 
arch, slackware, paldo, mandriva or pardus]))
+if test "z$with_distro" = "z"; then
+   with_distro=`lsb_release -is`
 fi
-AM_CONDITIONAL([HAVE_DEBIAN], [test x"$osname" == xdebian])
+if test "z$with_distro" = "z"; then
+   AC_CHECK_FILE(/etc/redhat-release,with_distro="redhat")
+   AC_CHECK_FILE(/etc/oracle-release,with_distro="oracle")
+   AC_CHECK_FILE(/etc/fedora-release,with_distro="fedora")
+   AC_CHECK_FILE(/etc/SuSE-release,with_distro="suse")
+   AC_CHECK_FILE(/etc/gentoo-release,with_distro="gentoo")
+   AC_CHECK_FILE(/etc/debian_version,with_distro="debian")
+   AC_CHECK_FILE(/etc/arch-release,with_distro="arch")
+   AC_CHECK_FILE(/etc/slackware-version,with_distro="slackware")
+   AC_CHECK_FILE(/etc/frugalware-release,with_distro="frugalware")
+   AC_CHECK_FILE(/etc/mandrakelinux-release, with_distro="mandriva")
+   AC_CHECK_FILE(/etc/mandriva-release,with_distro="mandriva")
+   AC_CHECK_FILE(/etc/pardus-release,with_distro="pardus")
+fi
+with_distro=`echo ${with_distro} | tr '[[:upper:]]' '[[:lower:]]'`
+
+if test "z$with_distro" = "z"; then
+   with_distro="unknown"
+fi
+case $with_distro in
+   ubuntu)
+   conffile=lxc.conf.ubuntu
+   ;;
+   redhat|fedora|oracle|oracleserver)
+   conffile=lxc.conf.libvirt
+   ;;
+   *)
+   echo -n "Linux distribution network config unknown, defaulting 
to lxc.network.type = empty"
+   conffile=lxc.conf.unknown
+   ;;
+esac
+AC_MSG_RESULT([$with_distro])
+
+AM_CONDITIONAL([HAVE_DEBIAN], [test x"$with_distro" = "xdebian" -o 
x"$with_distro" = "xubuntu"])
 
 AC_ARG_ENABLE([rpath],
[AC_HELP_STRING([--disable-rpath], [do not set rpath in executables])],
@@ -111,6 +146,7 @@ AC_ARG_WITH([rootfs-path],
[lxc rootfs mount point]
)], [], [with_rootfs_path=['${libdir}/lxc/rootfs']])
 
+AS_AC_EXPAND(LXC_CONFFILE, $conffile)
 AS_AC_EXPAND(LXC_GENERATE_DATE, "$(date)")
 AS_AC_EXPAND(LXCPATH, "${with_config_path}")
 AS_AC_EXPAND(LXCROOTFSMOUNT, "${with_rootfs_path}")
diff --git a/lxc.spec.in b/lxc.spec.in
index e14eff6..24d3ded 100644
--- a/lxc.spe