[lxc-devel] [PATCH 1/2] python3: Don't require a template name

Stéphane Graber stgraber at ubuntu.com
Tue Jun 3 15:13:44 UTC 2014


On Tue, Jun 03, 2014 at 03:11:02PM +0000, Serge Hallyn wrote:
> Quoting Stéphane Graber (stgraber at ubuntu.com):
> > The template name isn't required, if it's not passed, then create will
> > simply be asked to create a container without a rootfs.
> 
> With the command line lxc-create, we decided that this was too dangerous
> and too easy for ppl to do wrong, so we required 'none' for this case.
> 
> Do you feel that API users are different and won't just start typeing
> 'create()' and get confused?

The binding is meant to follow the C API and in the C API we don't have
the special string, so that's why I did it that way.

While it may be reasonable for shell users to try and guess parameters,
I'd expect API users to actually read the function help before using it,
so I think that's fine.

> 
> > Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
> > ---
> >  src/python-lxc/lxc.c           |  2 +-
> >  src/python-lxc/lxc/__init__.py | 13 +++++++++----
> >  2 files changed, 10 insertions(+), 5 deletions(-)
> > 
> > diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
> > index f7ab092..d436c28 100644
> > --- a/src/python-lxc/lxc.c
> > +++ b/src/python-lxc/lxc.c
> > @@ -733,7 +733,7 @@ Container_create(Container *self, PyObject *args, PyObject *kwds)
> >      int i = 0;
> >      static char *kwlist[] = {"template", "flags", "args", NULL};
> >  
> > -    if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|iO", kwlist,
> > +    if (! PyArg_ParseTupleAndKeywords(args, kwds, "|siO", kwlist,
> >                                        &template_name, &flags, &vargs))
> >          return NULL;
> >  
> > diff --git a/src/python-lxc/lxc/__init__.py b/src/python-lxc/lxc/__init__.py
> > index 45d139d..47b25b8 100644
> > --- a/src/python-lxc/lxc/__init__.py
> > +++ b/src/python-lxc/lxc/__init__.py
> > @@ -201,11 +201,11 @@ class Container(_lxc.Container):
> >  
> >          return _lxc.Container.set_config_item(self, key, value)
> >  
> > -    def create(self, template, flags=0, args=()):
> > +    def create(self, template=None, flags=0, args=()):
> >          """
> >              Create a new rootfs for the container.
> >  
> > -            "template" must be a valid template name.
> > +            "template" if passed must be a valid template name.
> >  
> >              "flags" (optional) is an integer representing the optional
> >              create flags to be passed.
> > @@ -222,8 +222,13 @@ class Container(_lxc.Container):
> >          else:
> >              template_args = args
> >  
> > -        return _lxc.Container.create(self, template=template,
> > -                                     flags=flags, args=tuple(template_args))
> > +        if template:
> > +            return _lxc.Container.create(self, template=template,
> > +                                         flags=flags,
> > +                                         args=tuple(template_args))
> > +        else:
> > +            return _lxc.Container.create(self, flags=flags,
> > +                                         args=tuple(template_args))
> >  
> >      def clone(self, newname, config_path=None, flags=0, bdevtype=None,
> >                bdevdata=None, newsize=0, hookargs=()):
> > -- 
> > 1.9.1
> > 
> > _______________________________________________
> > lxc-devel mailing list
> > lxc-devel at lists.linuxcontainers.org
> > http://lists.linuxcontainers.org/listinfo/lxc-devel
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140603/ccb22bcd/attachment.sig>


More information about the lxc-devel mailing list