mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-13 20:45:30 +00:00
python3: Allow passing create flags
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
1314b689ec
commit
bb711f3927
@ -694,13 +694,14 @@ static PyObject *
|
||||
Container_create(Container *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
char* template_name = NULL;
|
||||
int flags = 0;
|
||||
char** create_args = {NULL};
|
||||
PyObject *retval = NULL, *vargs = NULL;
|
||||
int i = 0;
|
||||
static char *kwlist[] = {"template", "args", NULL};
|
||||
static char *kwlist[] = {"template", "flags", "args", NULL};
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|O", kwlist,
|
||||
&template_name, &vargs))
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|iO", kwlist,
|
||||
&template_name, &flags, &vargs))
|
||||
return NULL;
|
||||
|
||||
if (vargs) {
|
||||
@ -716,8 +717,8 @@ Container_create(Container *self, PyObject *args, PyObject *kwds)
|
||||
}
|
||||
}
|
||||
|
||||
if (self->container->create(self->container, template_name, NULL, NULL, 0,
|
||||
create_args))
|
||||
if (self->container->create(self->container, template_name, NULL, NULL,
|
||||
flags, create_args))
|
||||
retval = Py_True;
|
||||
else
|
||||
retval = Py_False;
|
||||
@ -1536,6 +1537,9 @@ PyInit__lxc(void)
|
||||
PYLXC_EXPORT_CONST(LXC_CLONE_KEEPNAME);
|
||||
PYLXC_EXPORT_CONST(LXC_CLONE_SNAPSHOT);
|
||||
|
||||
/* create: create flags */
|
||||
PYLXC_EXPORT_CONST(LXC_CREATE_QUIET);
|
||||
|
||||
#undef PYLXC_EXPORT_CONST
|
||||
|
||||
return m;
|
||||
|
@ -229,22 +229,29 @@ class Container(_lxc.Container):
|
||||
|
||||
return _lxc.Container.set_config_item(self, key, value)
|
||||
|
||||
def create(self, template, args={}):
|
||||
def create(self, template, flags=0, args=()):
|
||||
"""
|
||||
Create a new rootfs for the container.
|
||||
|
||||
"template" must be a valid template name.
|
||||
|
||||
"args" (optional) is a dictionary of parameters and values to pass
|
||||
to the template.
|
||||
"flags" (optional) is an integer representing the optional
|
||||
create flags to be passed.
|
||||
|
||||
"args" (optional) is a tuple of arguments to pass to the
|
||||
template. It can also be provided as a dict.
|
||||
"""
|
||||
|
||||
template_args = []
|
||||
for item in args.items():
|
||||
template_args.append("--%s" % item[0])
|
||||
template_args.append("%s" % item[1])
|
||||
if isinstance(args, dict):
|
||||
template_args = []
|
||||
for item in args.items():
|
||||
template_args.append("--%s" % item[0])
|
||||
template_args.append("%s" % item[1])
|
||||
else:
|
||||
template_args = args
|
||||
|
||||
return _lxc.Container.create(self, template, tuple(template_args))
|
||||
return _lxc.Container.create(self, template=template,
|
||||
flags=flags, args=tuple(template_args))
|
||||
|
||||
def clone(self, newname, config_path=None, flags=0, bdevtype=None,
|
||||
bdevdata=None, newsize=0, hookargs=()):
|
||||
|
Loading…
Reference in New Issue
Block a user