Commit 5a3d2e1e by Stéphane Graber

API shouldn't be calling create for already defined containers or destroy for non defined ones

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 avatarS.Çağlar Onur <caglar@10ur.org> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 6b5d5b97
......@@ -523,14 +523,15 @@ static bool lxcapi_create(struct lxc_container *c, char *t, char *const argv[])
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 */
......@@ -767,6 +768,9 @@ static bool lxcapi_save_config(struct lxc_container *c, const char *alt_file)
return false;
}
if (!create_container_dir(c))
return false;
FILE *fout = fopen(alt_file, "w");
if (!fout)
return false;
......@@ -788,6 +792,10 @@ static bool lxcapi_destroy(struct lxc_container *c)
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;
......
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