Commit 84ac80ef authored by Antoine Catton's avatar Antoine Catton

Merge branch 'lxc-capabilities-experiment' into lxc

Conflicts:
	component/libcap/buildout.cfg
	component/lxc/buildout.cfg
parents 9e57d543 7cc4e9db
# CA certificates
[buildout]
extends =
../patch/buildout.cfg
parts =
ca-certificates
......@@ -16,6 +20,7 @@ download-only = true
recipe = hexagonit.recipe.cmmi
version = 20120623
url = ftp://ftp.free.fr/mirrors/ftp.debian.org/pool/main/c/ca-certificates/ca-certificates_${:version}.tar.gz
patch-binary = ${patch:location}/bin/patch
patches =
${ca-certificates-sbin-dir.patch:location}/${ca-certificates-sbin-dir.patch:filename}
patch-options = -p0
......
......@@ -5,6 +5,12 @@ extends =
parts = libcap
# /\
# / \ Compiled with SlapOS node
# / ! \
# / ! \
# / \ Can't be compiled as normal user
# /____°_____\
[libcap2]
recipe = slapos.recipe.build
format = no
......
[buildout]
extends =
../attr/buildout.cfg
../libcap/buildout.cfg
../patch/buildout.cfg
parts = lxc
......@@ -17,6 +15,13 @@ filename = libexecdir-fix.patch
download-only = true
md5sum = d674463ccb3a7c205c2326fb4ab5436b
[lxc-0.8.0-rc2-lxc-ls-patch]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
filename = lxc-ls-fix.patch
download-only = true
md5sum = 28c155a554d4f4856351085494585c73
[lxc-0.8]
recipe = hexagonit.recipe.cmmi
url = http://lxc.sourceforge.net/download/lxc/lxc-0.8.0-rc2.tar.gz
......@@ -25,6 +30,7 @@ patch-binary = ${patch:location}/bin/patch
patch-options = -p1
patches =
${lxc-0.8.0-rc2-libexecdir-patch:location}/${lxc-0.8.0-rc2-libexecdir-patch:filename}
${lxc-0.8.0-rc2-lxc-ls-patch:location}/${lxc-0.8.0-rc2-lxc-ls-patch:filename}
environment =
PATH=%(PATH)s:${attr:location}/bin/:${libcap:location}/sbin/
CFLAGS=-I${libcap:location}/usr/include
......
commit 7ef0141356454503ab81460290b5dffa32c1f441
Author: David Ward <david.ward@ll.mit.edu>
Date: Fri May 4 00:50:15 2012 +0200
refresh lxc-ls
Add an '--active' option that lists active containers by searching
cgroups. (Otherwise, the directories in /var/lib/lxc are listed.)
Modify the cgroup search to only use hierarchies that contain one
or more subsystems. When searching, if a hierarchy contains the
'ns' subsystem, do not append '/lxc' to the parent cgroup.
Add a '--help' option that prints the command syntax.
Print error messages and help information to stderr.
Update the documentation.
Signed-off-by: David Ward <david.ward@ll.mit.edu>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
diff --git a/doc/lxc-ls.sgml.in b/doc/lxc-ls.sgml.in
index 3ffd4f8..d33e9b3 100644
--- a/doc/lxc-ls.sgml.in
+++ b/doc/lxc-ls.sgml.in
@@ -48,7 +48,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<refsynopsisdiv>
<cmdsynopsis>
- <command>lxc-ls <optional>ls option</optional>
+ <command>lxc-ls <optional>--active</optional> <optional>ls option</optional>
</command>
</cmdsynopsis>
</refsynopsisdiv>
@@ -67,6 +67,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
<varlistentry>
<term>
+ <option><optional>--active</optional></option>
+ </term>
+ <listitem>
+ <para>
+ List active containers.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
<option><optional>ls options</optional></option>
</term>
<listitem>
@@ -94,10 +105,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</varlistentry>
<varlistentry>
- <term>lxc-ls -1</term>
+ <term>lxc-ls --active -1</term>
<listitem>
<para>
- list all the containers and display the list in one column.
+ list active containers and display the list in one column.
</para>
</listitem>
</varlistentry>
diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in
index a1ad642..11a3b45 100644
--- a/src/lxc/lxc-ls.in
+++ b/src/lxc/lxc-ls.in
@@ -1,43 +1,100 @@
#!/bin/bash
-localstatedir=@LOCALSTATEDIR@
-lxcpath=@LXCPATH@
+#
+# lxc: linux Container library
-if [ ! -r $lxcpath ]; then
- exit 0
-fi
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+localstatedir=@LOCALSTATEDIR@
+lxc_path=@LXCPATH@
-function get_cgroup()
+usage()
{
- local mount_string
- mount_string=$(mount -t cgroup |grep -E -e '^lxc ')
- if test -n "$mount_string"; then
- mount_point=$(echo $mount_string |cut -d' ' -f3)
- return
- fi
- mount_string=`grep -m1 -E '^[^ \t]+[ \t]+[^ \t]+[ \t]+cgroup' /proc/self/mounts`;
- if test -z "$mount_string"; then
- echo "failed to find mounted cgroup"
- exit 1
- fi
- mount_point=`echo "$mount_string" |cut -d' ' -f2`;
+ echo "usage: $(basename $0) [--active] [--] [LS_OPTIONS...]" >&2
}
-ls "$@" $lxcpath
+help() {
+ usage
+ echo >&2
+ echo "List containers existing on the system." >&2
+ echo >&2
+ echo " --active list active containers" >&2
+ echo " LS_OPTIONS ls command options (see \`ls --help')" >&2
+}
+
+get_parent_cgroup()
+{
+ local hierarchies hierarchy fields subsystems init_cgroup mountpoint
+
+ parent_cgroup=""
+
+ # Obtain a list of hierarchies that contain one or more subsystems
+ hierarchies=$(tail -n +2 /proc/cgroups | cut -f 2)
-active=$(netstat -xl 2>/dev/null | grep $lxcpath | \
- sed -e 's#.*'"$lxcpath/"'\(.*\)/command#\1#');
+ # Iterate through the list until a suitable hierarchy is found
+ for hierarchy in $hierarchies; do
+ # Obtain information about the init process in the hierarchy
+ fields=$(grep -E "^$hierarchy:" /proc/1/cgroup | head -n 1)
+ if [ -z "$fields" ]; then continue; fi
+ fields=${fields#*:}
-if test -n "$active"; then
- get_cgroup
- if test -n "$mount_point"; then
- # get cgroup for init
- init_cgroup=`cat /proc/1/cgroup | awk -F: '{ print $3 }' | head -1`
- if [ ! -d $mount_point/$init_cgroup/lxc ]; then
- cd $mount_point/$init_cgroup
+ # Get a comma-separated list of the hierarchy's subsystems
+ subsystems=${fields%:*}
+
+ # Get the cgroup of the init process in the hierarchy
+ init_cgroup=${fields#*:}
+
+ # Get the filesystem mountpoint of the hierarchy
+ mountpoint=$(grep -E "^cgroup [^ ]+ [^ ]+ ([^ ]+,)?$subsystems(,[^ ]+)? " /proc/self/mounts | cut -d ' ' -f 2)
+ if [ -z "$mountpoint" ]; then continue; fi
+
+ # Return the absolute path to the containers' parent cgroup
+ # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem)
+ if [[ ",$subsystems," == *,ns,* ]]; then
+ parent_cgroup="${mountpoint}${init_cgroup%/}"
else
- cd $mount_point/$init_cgroup/lxc
+ parent_cgroup="${mountpoint}${init_cgroup%/}/lxc"
fi
- ls "$@" -d $active
- fi
+ break
+ done
+}
+
+directory="$lxc_path"
+
+for i in "$@"; do
+ case $i in
+ --help)
+ help; exit 1;;
+ --active)
+ get_parent_cgroup; directory="$parent_cgroup"; shift;;
+ --)
+ shift; break;;
+ *)
+ break;;
+ esac
+done
+
+containers=""
+if [ ! -z "$directory" ]; then
+ containers=$(find $directory -mindepth 1 -maxdepth 1 -type d -printf "%f\n" 2>/dev/null)
fi
+
+if [ -z "$containers" ]; then
+ echo "$(basename $0): no containers found" >&2
+ exit 1
+fi
+
+cd "$directory"
+ls -d $@ $containers
......@@ -7,6 +7,7 @@
extends =
../ca-certificates/buildout.cfg
../zlib/buildout.cfg
../patch/buildout.cfg
parts =
openssl
......@@ -30,6 +31,7 @@ download-only = true
recipe = hexagonit.recipe.cmmi
url = https://www.openssl.org/source/openssl-1.0.1.tar.gz
md5sum = 134f168bc2a8333f19f81d684841710b
patch-binary = ${patch:location}/bin/patch
patches =
${openssl-nodoc.patch:location}/${openssl-nodoc.patch:filename}
${openssl-exlibs.patch:location}/${openssl-exlibs.patch:filename}
......
......@@ -19,6 +19,8 @@ extends =
../sqlite3/buildout.cfg
../swig/buildout.cfg
../zlib/buildout.cfg
../patch/buildout.cfg
../libcap/buildout.cfg
parts =
slapos
......@@ -48,7 +50,7 @@ allowed-eggs-from-site-packages =
[environment]
# Note: For now original PATH is appeneded to the end, as not all tools are
# provided by SlapOS
PATH=${bison:location}/bin:${bzip2:location}/bin:${gettext:location}/bin:${glib:location}/bin:${libxml2:location}/bin:${libxslt:location}/bin:${m4:location}/bin:${ncurses:location}/bin:${openssl:location}/bin:${pkgconfig:location}/bin:${python2.7:location}/bin:${readline:location}/bin:${sqlite3:location}/bin:${swig:location}/bin:${buildout:bin-directory}:$PATH
PATH=${bison:location}/bin:${bzip2:location}/bin:${gettext:location}/bin:${glib:location}/bin:${libxml2:location}/bin:${libxslt:location}/bin:${m4:location}/bin:${ncurses:location}/bin:${openssl:location}/bin:${pkgconfig:location}/bin:${python2.7:location}/bin:${readline:location}/bin:${sqlite3:location}/bin:${swig:location}/bin:${buildout:bin-directory}:${buildout:bin-directory}:${attr:location}/bin/:$PATH
CFLAGS=-I${bzip2:location}/include -I${gdbm:location}/include -I${gettext:location}/include -I${glib:location}/include -I${libxml2:location}/include -I${libxslt:location}/include -I${ncurses:location}/include -I${openssl:location}/include -I${popt:location}/include -I${readline:location}/include -I${sqlite3:location}/include -I${zlib:location}/include
CPPFLAGS=${:CFLAGS}
LDFLAGS=-L${bzip2:location}/lib -Wl,-rpath=${bzip2:location}/lib -L${gdbm:location}/lib -Wl,-rpath=${gdbm:location}/lib -L${gettext:location}/lib -Wl,-rpath=${gettext:location}/lib -L${glib:location}/lib -Wl,-rpath=${glib:location}/lib -L${libxml2:location}/lib -Wl,-rpath=${libxml2:location}/lib -L${libxslt:location}/lib -Wl,-rpath=${libxslt:location}/lib -L${ncurses:location}/lib -Wl,-rpath=${ncurses:location}/lib -L${openssl:location}/lib -Wl,-rpath=${openssl:location}/lib -L${popt:location}/lib -Wl,-rpath=${popt:location}/lib -L${readline:location}/lib -Wl,-rpath=${readline:location}/lib -L${sqlite3:location}/lib -Wl,-rpath=${sqlite3:location}/lib -L${zlib:location}/lib -Wl,-rpath=${zlib:location}/lib
......@@ -96,6 +98,8 @@ eggs =
initialization =
import os
os.environ['PATH'] = os.path.expandvars('${environment:PATH}')
os.environ['LIBCAP_LOCATION'] = '${libcap:location}'
os.environ['ATTR_LOCATION'] = '${attr:location}'
# control scripts generation in order to avoid reinstalling bin/buildout
scripts =
......
[buildout]
parts = tar
[tar]
recipe = hexagonit.recipe.cmmi
url = http://ftp.gnu.org/gnu/tar/tar-1.26.tar.gz
md5sum = 00d1e769c6af702c542cca54b728920d
environment =
FORCE_UNSAFE_CONFIGURE=1
[buidout]
parts =
xz-utils
[xz-utils]
recipe = hexagonit.recipe.cmmi
url = http://tukaani.org/xz/xz-5.0.4.tar.gz
md5sum = df3df690aef18384e1e031be7ec3a964
......@@ -100,6 +100,7 @@ setup(name=name,
'pwgen = slapos.recipe.pwgen:Recipe',
'proactive = slapos.recipe.proactive:Recipe',
'request = slapos.recipe.request:Recipe',
'rootfs = slapos.recipe.rootfs:Recipe',
'seleniumrunner = slapos.recipe.seleniumrunner:Recipe',
'sheepdogtestbed = slapos.recipe.sheepdogtestbed:SheepDogTestBed',
'shell = slapos.recipe.shell:Recipe',
......@@ -108,6 +109,8 @@ setup(name=name,
'softwaretype = slapos.recipe.softwaretype:Recipe',
'siptester = slapos.recipe.siptester:SipTesterRecipe',
'simplelogger = slapos.recipe.simplelogger:Recipe',
'slapcontainer = slapos.recipe.container:Recipe',
'slapcontainer.promise = slapos.recipe.container:Promise',
'slaprunner = slapos.recipe.slaprunner:Recipe',
'slapmonitor = slapos.recipe.slapmonitor:Recipe',
'slapreport = slapos.recipe.slapreport:Recipe',
......
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import ConfigParser
import uuid
import os
import subprocess
# XXX : This is in order to get the computer_partition object
# which exposes the state of the current partition.
#
# XXX : We could have modify slapgrid in order to put the
# state of the current partition offline. But this is
# written to have the most minimal impact.
from slapos.recipe.librecipe import GenericSlapRecipe
from slapos.recipe.librecipe import GenericBaseRecipe
def promise_func(args):
output = subprocess.check_output(
[args['lxc-info'], '-n', args['name']]
)
if 'RUNNING' in output:
return 0
else:
return 127
class Promise(GenericBaseRecipe):
def install(self):
return [
self.createPythonScript(
self.options['promise'],
'slapos.recipe.container.promise_func',
{
'lxc-info': self.options['lxc-info'],
'name': self.options['slapcontainer-name']
}
)
]
class Recipe(GenericSlapRecipe):
def _options(self, options):
config_filename = self.options['config']
container_uuid = None
if os.path.exists(config_filename):
config = ConfigParser.ConfigParser()
config.read(config_filename)
if config.has_option('requested', 'name'):
container_uuid = uuid.UUID(hex=config.get('requested', 'name'))
if container_uuid is None:
# uuid wasn't generated at first in order to avoid
# wasting entropy
container_uuid = uuid.uuid4()
options['slapcontainer-name'] = container_uuid.hex
return options
def _install(self):
path_list = []
self.logger.info("Putting slapcontainer configuration file...")
config = ConfigParser.ConfigParser()
config.add_section('requested')
config.set('requested', 'status',
self.computer_partition.getState())
config.set('requested', 'name', self.options['slapcontainer-name'])
config.add_section('rootfs')
config.set('rootfs', 'image', self.options['image'])
config.set('rootfs', 'complete', self.options['image-complete'])
config.add_section('network')
config.set('network', 'interface', self.options['interface'])
config.add_section('config')
config.set('config', 'file', self.options['lxc-config'])
# Just a touch
open(self.options['lxc-config'], 'a').close()
config_filename = self.options['config']
with open(config_filename, 'w') as config_file:
config.write(config_file)
path_list.append(config_filename)
return path_list
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import os
import subprocess
from slapos.recipe.librecipe import GenericBaseRecipe
def service(args):
if not os.path.exists(args['confirm']):
subprocess.check_call([args['wget'], args['image'],
'-O', args['output']])
open(args['confirm'], 'w').close()
class Recipe(GenericBaseRecipe):
def install(self):
path_list = []
path_list.append(
self.createPythonScript(
self.options['binary'],
'slapos.recipe.rootfs.service',
{
'wget': self.options['wget-binary'],
'image': self.options['image-url'],
'output': self.options['downloaded-image'],
'confirm': self.options['downloaded-image-complete']
}
)
)
return path_list
[buildout]
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
parts =
slapcontainer
rootfs
slapcontainer-promise
[rootdirectory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc
tmp = $${buildout:directory}/tmp
srv = $${buildout:directory}/srv
[basedirectory]
recipe = slapos.cookbook:mkdirectory
services = $${rootdirectory:etc}/run
promises = $${rootdirectory:etc}/promise
[slapcontainer]
recipe = slapos.cookbook:slapcontainer
interface = $${slap-network-information:network-interface}
config = $${buildout:directory}/.slapcontainer
lxc-config = $${rootdirectory:etc}/lxc.conf
image = $${rootfs:downloaded-image}
image-complete = $${rootfs:downloaded-image-complete}
tmp-dir = $${rootdirectory:tmp}/slapcontainer/
[slapcontainer-promise]
recipe = slapos.cookbook:slapcontainer.promise
promise = $${basedirectory:promises}/slapcontainer
lxc-info = ${lxc:location}/bin/lxc-info
slapcontainer-name = $${slapcontainer:slapcontainer-name}
[rootfs]
recipe = slapos.cookbook:rootfs
image-url = $${slap-parameter:rootfs}
downloaded-image = $${rootdirectory:srv}/rootfs.img
downloaded-image-complete = $${:downloaded-image}.complete
binary = $${basedirectory:services}/rootfsdownload
wget-binary = ${wget:location}/bin/wget
[buildout]
parts =
switch-softwaretype
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
[switch-softwaretype]
recipe = slapos.cookbook:softwaretype
default = ${template-lxc:output}
[slap-connection]
# part to migrate to new - separated words
computer-id = $${slap_connection:computer_id}
partition-id = $${slap_connection:partition_id}
server-url = $${slap_connection:server_url}
software-release-url = $${slap_connection:software_release_url}
key-file = $${slap_connection:key_file}
cert-file = $${slap_connection:cert_file}
[buildout]
extends =
../../stack/slapos.cfg
../../component/lxc/buildout.cfg
../../component/lxml-python/buildout.cfg
../../component/curl/buildout.cfg
../../component/wget/buildout.cfg
../../component/gzip/buildout.cfg
../../component/bzip2/buildout.cfg
../../component/xz-utils/buildout.cfg
parts =
lxml-python
template
template-lxc
slapos-cookbook
slapos-toolbox
lxc
[template]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance.cfg
md5sum = c722ba58b06d3105f64fdeccbbd689bb
output = ${buildout:directory}/template.cfg
mode = 0644
[template-lxc]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-lxc.cfg
md5sum = 901fd10e1404d10aa399b3dffcf68845
output = ${buildout:directory}/template-lxc.cfg
mode = 0644
[slapos-toolbox]
recipe = zc.recipe.egg
scripts = slapcontainer
eggs =
slapos.toolbox
[versions]
slapos.core =
slapos.cookbook =
slapos.toolbox =
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment