Currently it always calls create/destroy which might be confusing for the code
that checks the return value of those calls to determine whether operation
completed successfully or not.
>>> c = lxc.Container("r")
>>> c.create("ubuntu")
True
>>> c.create("ubuntu")
True
>>> c.create("ubuntu")
True
>>> c.create("ubuntu")
True
>>> c.create("ubuntu")
>>> c.destroy()
True
>>> c.destroy()
lxc-destroy: 'r' does not exist
False
>>> c.destroy()
lxc-destroy: 'r' does not exist
False
New behaviour
>>> c = lxc.Container("r")
>>> c.create('ubuntu')
True
>>> c.create('ubuntu')
False
>>> c.destroy()
True
>>> c.destroy()
False
>>>
Tested with following script;
import lxc
c = lxc.Container("abcdef")
print ("set", c.set_config_item("lxc.utsname", "abcdef"))
print ("save", c.save_config())
print ("create", c.create("ubuntu"))
print ("create", c.create("ubuntu"))
print ("destroy", c.destroy())
print ("destroy", c.destroy())
print ("set", c.set_config_item("lxc.utsname", "abcdef"))
print ("save", c.save_config())
print ("destroy", c.destroy())
print ("destroy", c.destroy())
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
goto out;
}
- if (!create_container_dir(c))
- goto out;
-
if (!c->save_config(c, NULL)) {
ERROR("failed to save starting configuration for %s\n", c->name);
goto out;
}
+ /* container is already created if we have a config and rootfs.path is accessible */
+ if (lxcapi_is_defined(c) && c->lxc_conf && c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) == 0)
+ return false;
+
/* we're going to fork. but since we'll wait for our child, we
don't need to lxc_container_get */
return false;
}
+ if (!create_container_dir(c))
+ return false;
+
FILE *fout = fopen(alt_file, "w");
if (!fout)
return false;
if (!c)
return false;
+ /* container is already destroyed if we don't have a config and rootfs.path is not accessible */
+ if (!lxcapi_is_defined(c) && (!c->lxc_conf || !c->lxc_conf->rootfs.path || access(c->lxc_conf->rootfs.path, F_OK) != 0))
+ return false;
+
pid = fork();
if (pid < 0)
return false;