[lxc-devel] [PATCH] lxc-create: Allow for empty or unset template name

2012-12-07 Thread Stéphane Graber
This restores an old behaviour where lxc-create can be called without
a template. In such case, only a minimal configuration is built and no
rootfs is created. However the various backingstore code is still used.

Signed-off-by: Stéphane Graber 
---
 src/lxc/lxc-create.in | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
index 3c66bfa..5cd9fdb 100644
--- a/src/lxc/lxc-create.in
+++ b/src/lxc/lxc-create.in
@@ -284,19 +284,19 @@ if [ ! -r "$lxc_config" ]; then
 exit 1
 fi
 
-# Allow for a path to be provided as the template name
-if [ -x "$lxc_template" ]; then
-template_path=$lxc_template
-else
-template_path=${templatedir}/lxc-$lxc_template
-fi
+if [ ! -z "$lxc_template" ]; then
+# Allow for a path to be provided as the template name
+if [ -x "$lxc_template" ]; then
+template_path=$lxc_template
+else
+template_path=${templatedir}/lxc-$lxc_template
+fi
 
-if ! [ -x "$template_path" ]; then
-echo "$(basename $0): unknown template '$lxc_template'" >&2
-cleanup
-fi
+if ! [ -x "$template_path" ]; then
+echo "$(basename $0): unknown template '$lxc_template'" >&2
+cleanup
+fi
 
-if [ ! -z "$lxc_template" ]; then
 sum=$(sha1sum $template_path | cut -d ' ' -f1)
 echo "# Template used to create this container: $lxc_template" >> 
$lxc_path/$lxc_name/config
 if [ -n "$*" ]; then
-- 
1.8.0


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH RFC] Enable use of user namespaces in containers

2012-12-07 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
> > +   if (idmaplist)
> > +   free(idmaplist);
> > +
> > +   if (idmap) {
> > +   free(idmap);
> > +   }
> 
> ^ code style isn't really consistent here :)

:)  fixed in my git branch

--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-create: Allow for empty or unset template name

2012-12-07 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
> This restores an old behaviour where lxc-create can be called without
> a template. In such case, only a minimal configuration is built and no
> rootfs is created. However the various backingstore code is still used.
> 
> Signed-off-by: Stéphane Graber 
> ---
>  src/lxc/lxc-create.in | 22 +++---
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
> index 3c66bfa..5cd9fdb 100644
> --- a/src/lxc/lxc-create.in
> +++ b/src/lxc/lxc-create.in
> @@ -284,19 +284,19 @@ if [ ! -r "$lxc_config" ]; then
>  exit 1
>  fi
>  
> -# Allow for a path to be provided as the template name
> -if [ -x "$lxc_template" ]; then
> -template_path=$lxc_template
> -else
> -template_path=${templatedir}/lxc-$lxc_template
> -fi
> +if [ ! -z "$lxc_template" ]; then

or '-n' ? :)

Acked-by: Serge E. Hallyn 

> +# Allow for a path to be provided as the template name
> +if [ -x "$lxc_template" ]; then
> +template_path=$lxc_template
> +else
> +template_path=${templatedir}/lxc-$lxc_template
> +fi
>  
> -if ! [ -x "$template_path" ]; then
> -echo "$(basename $0): unknown template '$lxc_template'" >&2
> -cleanup
> -fi
> +if ! [ -x "$template_path" ]; then
> +echo "$(basename $0): unknown template '$lxc_template'" >&2
> +cleanup
> +fi
>  
> -if [ ! -z "$lxc_template" ]; then
>  sum=$(sha1sum $template_path | cut -d ' ' -f1)
>  echo "# Template used to create this container: $lxc_template" >> 
> $lxc_path/$lxc_name/config
>  if [ -n "$*" ]; then
> -- 
> 1.8.0
> 
> 
> --
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> ___
> Lxc-devel mailing list
> Lxc-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel

--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] python3-lxc: Fix build prefix/destdir

2012-12-07 Thread Stéphane Graber
Signed-off-by: Stéphane Graber 
---
 src/python-lxc/Makefile.am | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/python-lxc/Makefile.am b/src/python-lxc/Makefile.am
index 15c61ea..9d775c3 100644
--- a/src/python-lxc/Makefile.am
+++ b/src/python-lxc/Makefile.am
@@ -10,7 +10,11 @@ all:
CFLAGS="$(CFLAGS) -I ../../src -L../../src/lxc/" $(PYTHON) setup.py 
build
 
 install:
-   python3 setup.py install --root=$(DESTDIR) --prefix=$(PREFIX) 
--no-compile $(DISTSETUPOPTS)
+   if [ "$(DESTDIR)" = "" ]; then \
+   $(PYTHON) setup.py install --prefix=$(prefix) --no-compile 
$(DISTSETUPOPTS); \
+   else \
+   $(PYTHON) setup.py install --root=$(DESTDIR) --prefix=$(prefix) 
--no-compile $(DISTSETUPOPTS); \
+   fi
 
 clean:
rm -rf build
-- 
1.8.0


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] API wishlist

2012-12-07 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
...
>  - get_version() (not container specific)
>  - get_lxc_path() (not container specific)
>Returns the storage path for the containers.
>Defaults to LXCPATH.
>  - set_lxc_path(path) (not container specific)
> 
> 
> Looking at my todolist for this cycle, the highest priority ones for me
> would be:
>  1) get_lxc_path()
>  2) set_lxc_path()
>  3) get_cgroup_item()
>  4) set_cgroup_item()

How would set_lxc_path() work?  Would all the lxc code be switched to
check /etc/default/lxc.conf for the value, and autoconf would only fill
in the value in that file?

-serge

--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH 1/1] api: add set_cgroup_item and get_cgroup_item (to c api)

2012-12-07 Thread Stéphane Graber
On 12/06/2012 07:41 PM, Serge Hallyn wrote:
> set_cgroup_item takes a pointer to a running container, a cgroup subsystem
> name, and a char *value and it mimicks
>   'lxc-cgroup -n containername subsys value'
> get_cgroup_item takes a pointer to a running container, a a cgroup
> subsystem name, a destination value * and the length of the value being
> sent in, and returns the length of what was read from the cgroup file.
> If a 0 len is passed in, then the length of the file is returned.  So
> you can do
> 
>   len = c->get_cgroup_item(c, "devices.list", NULL, 0);
>   v = malloc(len+1);
>   ret = c->get_cgroup_item(c, "devices.list", v, len);
> 
> to read the whole file.
> 
> This patch also disables the lxc-init part of the startone test, which
> was failing because lxc-init has been moved due to multiarch issues.
> The test is salvagable, but saving it was beyond this effort.
> 
> Signed-off-by: Serge Hallyn 

Looks good. I'll apply it now and test it thoroughly when updating the
python binding later today.

Acked-by: Stéphane Graber 

> ---
>  src/lxc/cgroup.c   |   20 ++-
>  src/lxc/lxccontainer.c |   52 
> 
>  src/lxc/lxccontainer.h |9 +
>  src/tests/startone.c   |   47 +++
>  4 files changed, 127 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
> index 532d638..b6c948b 100644
> --- a/src/lxc/cgroup.c
> +++ b/src/lxc/cgroup.c
> @@ -789,6 +789,13 @@ out:
>   return ret;
>  }
>  
> +/*
> + * If you pass in NULL value or 0 len, then you are asking for the size
> + * of the file.  Note that we can't get the file size quickly through stat
> + * or lseek.  Therefore if you pass in len > 0 but less than the file size,
> + * your only indication will be that the return value will be equal to the
> + * passed-in ret.  We will not return the actual full file size.
> + */
>  int lxc_cgroup_get(const char *name, const char *filename,
>  char *value, size_t len)
>  {
> @@ -813,7 +820,18 @@ int lxc_cgroup_get(const char *name, const char 
> *filename,
>   return -1;
>   }
>  
> - ret = read(fd, value, len);
> +if (!len || !value) {
> +char buf[100];
> +int count = 0;
> +while ((ret = read(fd, buf, 100)) > 0)
> +count += ret;
> +if (ret >= 0)
> +ret = count;
> +} else {
> +memset(value, 0, len);
> +ret = read(fd, value, len);
> +}
> +
>   if (ret < 0)
>   ERROR("read %s : %s", path, strerror(errno));
>  
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index d25b848..1345ab5 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -163,6 +163,13 @@ static const char *lxcapi_state(struct lxc_container *c)
>   return ret;
>  }
>  
> +static bool is_stopped_nolock(struct lxc_container *c)
> +{
> + lxc_state_t s;
> + s = lxc_getstate(c->name);
> + return (s == STOPPED);
> +}
> +
>  static bool lxcapi_is_running(struct lxc_container *c)
>  {
>   const char *s;
> @@ -850,6 +857,49 @@ static char *lxcapi_config_file_name(struct 
> lxc_container *c)
>   return strdup(c->configfile);
>  }
>  
> +static bool lxcapi_set_cgroup_item(struct lxc_container *c, const char 
> *subsys, const char *value)
> +{
> + int ret;
> + bool b = false;
> +
> + if (!c)
> + return false;
> +
> + if (lxclock(c->privlock, 0))
> + return false;
> +
> + if (is_stopped_nolock(c))
> + goto err;
> +
> + ret = lxc_cgroup_set(c->name, subsys, value);
> + if (!ret)
> + b = true;
> +err:
> + lxcunlock(c->privlock);
> + return b;
> +}
> +
> +static int lxcapi_get_cgroup_item(struct lxc_container *c, const char 
> *subsys, char *retv, int inlen)
> +{
> + int ret = -1;
> +
> + if (!c || !c->lxc_conf)
> + return -1;
> +
> + if (lxclock(c->privlock, 0))
> + return -1;
> +
> + if (is_stopped_nolock(c))
> + goto out;
> +
> + ret = lxc_cgroup_get(c->name, subsys, retv, inlen);
> +
> +out:
> + lxcunlock(c->privlock);
> + return ret;
> +}
> +
> +
>  struct lxc_container *lxc_container_new(const char *name)
>  {
>   struct lxc_container *c;
> @@ -920,6 +970,8 @@ struct lxc_container *lxc_container_new(const char *name)
>   c->shutdown = lxcapi_shutdown;
>   c->clear_config_item = lxcapi_clear_config_item;
>   c->get_config_item = lxcapi_get_config_item;
> + c->get_cgroup_item = lxcapi_get_cgroup_item;
> + c->set_cgroup_item = lxcapi_set_cgroup_item;
>  
>   /* we'll allow the caller to update these later */
>   if (lxc_log_init(NULL, NULL, "lxc_container", 0)) {
> diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
> index 9c9296c..a6fdb2b 100644
> --- a/src/lxc/lxccontainer.h
> +++ b/src/lxc/lxccontainer.h
> @@ -48,6 +48,

Re: [lxc-devel] [PATCH] python3-lxc: Fix build prefix/destdir

2012-12-07 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
> Signed-off-by: Stéphane Graber 

Acked-by: Serge E. Hallyn 

> ---
>  src/python-lxc/Makefile.am | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/src/python-lxc/Makefile.am b/src/python-lxc/Makefile.am
> index 15c61ea..9d775c3 100644
> --- a/src/python-lxc/Makefile.am
> +++ b/src/python-lxc/Makefile.am
> @@ -10,7 +10,11 @@ all:
>   CFLAGS="$(CFLAGS) -I ../../src -L../../src/lxc/" $(PYTHON) setup.py 
> build
>  
>  install:
> - python3 setup.py install --root=$(DESTDIR) --prefix=$(PREFIX) 
> --no-compile $(DISTSETUPOPTS)
> + if [ "$(DESTDIR)" = "" ]; then \
> + $(PYTHON) setup.py install --prefix=$(prefix) --no-compile 
> $(DISTSETUPOPTS); \
> + else \
> + $(PYTHON) setup.py install --root=$(DESTDIR) --prefix=$(prefix) 
> --no-compile $(DISTSETUPOPTS); \
> + fi
>  
>  clean:
>   rm -rf build
> -- 
> 1.8.0
> 
> 
> --
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> ___
> Lxc-devel mailing list
> Lxc-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel

--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] API wishlist

2012-12-07 Thread Stéphane Graber
On 12/07/2012 12:25 PM, Serge Hallyn wrote:
> Quoting Stéphane Graber (stgra...@ubuntu.com):
> ...
>>  - get_version() (not container specific)
>>  - get_lxc_path() (not container specific)
>>Returns the storage path for the containers.
>>Defaults to LXCPATH.
>>  - set_lxc_path(path) (not container specific)
>>
>>
>> Looking at my todolist for this cycle, the highest priority ones for me
>> would be:
>>  1) get_lxc_path()
>>  2) set_lxc_path()
>>  3) get_cgroup_item()
>>  4) set_cgroup_item()
> 
> How would set_lxc_path() work?  Would all the lxc code be switched to
> check /etc/default/lxc.conf for the value, and autoconf would only fill
> in the value in that file?

So I think we should split the implementation in two:
1) Stop hardcoding LXCPATH in all the C code, instead make it default to
LXCPATH and overrideable by the set_lxc_path() call.
2) Discuss implementing a system wide, not container specific, lxc
configuration file to be used by all distros in a format that's easily
parsable.

Implementing 1) will make it easy for individual commands like lxc-list
to implement an extra argument letting the user override the lookup
path. It'll also make it much easier to deal with lxc being run as a
user at some point in the future.

Obviously, once we have that, some people will want to change the
default lookup location in one place and have all the commands use that
path. That's where we need 2) so that we can store that kind of settings
in a way that's not distro-specific and have all the tools in all the
different languages to parse that file.

> -serge
> 


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com



signature.asc
Description: OpenPGP digital signature
--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] API wishlist

2012-12-07 Thread Frederic Crozat
Le vendredi 07 décembre 2012 à 12:47 -0500, Stéphane Graber a écrit :
> On 12/07/2012 12:25 PM, Serge Hallyn wrote:
> > Quoting Stéphane Graber (stgra...@ubuntu.com):
> > ...
> >>  - get_version() (not container specific)
> >>  - get_lxc_path() (not container specific)
> >>Returns the storage path for the containers.
> >>Defaults to LXCPATH.
> >>  - set_lxc_path(path) (not container specific)
> >>
> >>
> >> Looking at my todolist for this cycle, the highest priority ones for me
> >> would be:
> >>  1) get_lxc_path()
> >>  2) set_lxc_path()
> >>  3) get_cgroup_item()
> >>  4) set_cgroup_item()
> > 
> > How would set_lxc_path() work?  Would all the lxc code be switched to
> > check /etc/default/lxc.conf for the value, and autoconf would only fill
> > in the value in that file?
> 
> So I think we should split the implementation in two:
> 1) Stop hardcoding LXCPATH in all the C code, instead make it default to
> LXCPATH and overrideable by the set_lxc_path() call.
> 2) Discuss implementing a system wide, not container specific, lxc
> configuration file to be used by all distros in a format that's easily
> parsable.
> 
> Implementing 1) will make it easy for individual commands like lxc-list
> to implement an extra argument letting the user override the lookup
> path. It'll also make it much easier to deal with lxc being run as a
> user at some point in the future.
> 
> Obviously, once we have that, some people will want to change the
> default lookup location in one place and have all the commands use that
> path. That's where we need 2) so that we can store that kind of settings
> in a way that's not distro-specific and have all the tools in all the
> different languages to parse that file.

I have to agree with that proposal (and making configuration path being
optionally a different path than the one used for rootfs would be a
plus, like the patch Alexey has been posting for a long time and we are
using on SLES).

-- 
Frederic Crozat 
SUSE


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 1/3] python: get_keys() doesn't require a path

2012-12-07 Thread Stéphane Graber
The python binding was forcing the user to pass a base path to
get_keys() even though the C binding doesn't require it.

Signed-off-by: Stéphane Graber 
---
 src/python-lxc/lxc/__init__.py.in | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/python-lxc/lxc/__init__.py.in 
b/src/python-lxc/lxc/__init__.py.in
index f42b944..9ef3459 100644
--- a/src/python-lxc/lxc/__init__.py.in
+++ b/src/python-lxc/lxc/__init__.py.in
@@ -400,11 +400,14 @@ class Container(_lxc.Container):
 os.remove(path)
 return ips
 
-def get_keys(self, key):
+def get_keys(self, key=None):
 """
 Returns a list of valid sub-keys.
 """
-value = _lxc.Container.get_keys(self, key)
+if key:
+value = _lxc.Container.get_keys(self, key)
+else:
+value = _lxc.Container.get_keys(self)
 
 if value is False:
 return False
-- 
1.8.0


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 3/3] gitignore: Update for python files

2012-12-07 Thread Stéphane Graber
Signed-off-by: Stéphane Graber 
---
 .gitignore | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitignore b/.gitignore
index 79dd77a..a766716 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,6 +66,9 @@ src/lxc/lxc-version
 src/lxc/lxc-wait
 src/lxc/legacy/lxc-ls
 
+src/python-lxc/build/
+src/python-lxc/examples/api_test.py
+src/python-lxc/lxc/__init__.py
 src/python-lxc/lxc/__pycache__/
 
 src/tests/lxc-test-containertests
-- 
1.8.0


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 2/3] python: Add binding for {get|set}_cgroup_item

2012-12-07 Thread Stéphane Graber
Updates the binding for the two new functions.

This also fixes some problems with the argument checking of
get_config_item that'd otherwise lead to a segfault.

The python binding for set_cgroup_item and get_cgroup_item are pretty
raw as lxc has little control over the cgroup entries.
That means that we don't try to interpret lists as we do for the config
entries.

Signed-off-by: Stéphane Graber 
---
 src/python-lxc/examples/api_test.py.in |  7 +
 src/python-lxc/lxc.c   | 55 +-
 src/python-lxc/lxc/__init__.py.in  | 12 
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/src/python-lxc/examples/api_test.py.in 
b/src/python-lxc/examples/api_test.py.in
index 0b17bd6..7711291 100644
--- a/src/python-lxc/examples/api_test.py.in
+++ b/src/python-lxc/examples/api_test.py.in
@@ -97,6 +97,13 @@ container.attach("NETWORK|UTSNAME", "/sbin/ifconfig", "eth0")
 # A few basic checks of the current state
 assert(len(ips) > 0)
 
+## Testing cgroups a bit
+print("Testing cgroup API")
+max_mem = container.get_cgroup_item("memory.max_usage_in_bytes")
+current_limit = container.get_cgroup_item("memory.limit_in_bytes")
+assert(container.set_cgroup_item("memory.limit_in_bytes", max_mem))
+assert(container.get_cgroup_item("memory.limit_in_bytes") != current_limit)
+
 ## Freezing the container
 print("Freezing the container")
 container.freeze()
diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
index b489079..83e2659 100644
--- a/src/python-lxc/lxc.c
+++ b/src/python-lxc/lxc.c
@@ -204,13 +204,38 @@ Container_freeze(Container *self, PyObject *args, 
PyObject *kwds)
 }
 
 static PyObject *
+Container_get_cgroup_item(Container *self, PyObject *args, PyObject *kwds)
+{
+static char *kwlist[] = {"key", NULL};
+char* key = NULL;
+int len = 0;
+
+if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist,
+  &key))
+Py_RETURN_FALSE;
+
+len = self->container->get_cgroup_item(self->container, key, NULL, 0);
+
+if (len <= 0) {
+Py_RETURN_FALSE;
+}
+
+char* value = (char*) malloc(sizeof(char)*len + 1);
+if (self->container->get_cgroup_item(self->container, key, value, len + 1) 
!= len) {
+Py_RETURN_FALSE;
+}
+
+return PyUnicode_FromString(value);
+}
+
+static PyObject *
 Container_get_config_item(Container *self, PyObject *args, PyObject *kwds)
 {
 static char *kwlist[] = {"key", NULL};
 char* key = NULL;
 int len = 0;
 
-if (! PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist,
+if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist,
   &key))
 Py_RETURN_FALSE;
 
@@ -288,6 +313,24 @@ Container_save_config(Container *self, PyObject *args, 
PyObject *kwds)
 }
 
 static PyObject *
+Container_set_cgroup_item(Container *self, PyObject *args, PyObject *kwds)
+{
+static char *kwlist[] = {"key", "value", NULL};
+char *key = NULL;
+char *value = NULL;
+
+if (! PyArg_ParseTupleAndKeywords(args, kwds, "ss|", kwlist,
+  &key, &value))
+Py_RETURN_FALSE;
+
+if (self->container->set_cgroup_item(self->container, key, value)) {
+Py_RETURN_TRUE;
+}
+
+Py_RETURN_FALSE;
+}
+
+static PyObject *
 Container_set_config_item(Container *self, PyObject *args, PyObject *kwds)
 {
 static char *kwlist[] = {"key", "value", NULL};
@@ -441,6 +484,11 @@ static PyMethodDef Container_methods[] = {
  "\n"
  "Freezes the container and returns its return code."
 },
+{"get_cgroup_item", (PyCFunction)Container_get_cgroup_item, METH_VARARGS | 
METH_KEYWORDS,
+ "get_cgroup_item(key) -> string\n"
+ "\n"
+ "Get the current value of a cgroup entry."
+},
 {"get_config_item", (PyCFunction)Container_get_config_item, METH_VARARGS | 
METH_KEYWORDS,
  "get_config_item(key) -> string\n"
  "\n"
@@ -463,6 +511,11 @@ static PyMethodDef Container_methods[] = {
  "Save the container configuration to its default "
  "location or to an alternative location if provided."
 },
+{"set_cgroup_item", (PyCFunction)Container_set_cgroup_item, METH_VARARGS | 
METH_KEYWORDS,
+ "set_cgroup_item(key, value) -> boolean\n"
+ "\n"
+ "Set a cgroup entry to the provided value."
+},
 {"set_config_item", (PyCFunction)Container_set_config_item, METH_VARARGS | 
METH_KEYWORDS,
  "set_config_item(key, value) -> boolean\n"
  "\n"
diff --git a/src/python-lxc/lxc/__init__.py.in 
b/src/python-lxc/lxc/__init__.py.in
index 9ef3459..91a59ed 100644
--- a/src/python-lxc/lxc/__init__.py.in
+++ b/src/python-lxc/lxc/__init__.py.in
@@ -318,6 +318,18 @@ class Container(_lxc.Container):
 return False
 return True
 
+def get_cgroup_item(self, key):
+"""
+Returns the value for a given cgroup entry.
+A list is returned when multiple values are set.
+"""
+