1
0
mirror of https://github.com/lxc/go-lxc.git synced 2026-02-05 06:46:38 +01:00

pass ConfigPath via CloneOptions

This commit is contained in:
S.Çağlar Onur
2014-10-12 10:50:46 -04:00
parent 74c95a9509
commit c56cbb7cd4
4 changed files with 27 additions and 18 deletions

View File

@@ -303,11 +303,7 @@ func (c *Container) Unfreeze() error {
// Create creates the container using given TemplateOptions
func (c *Container) Create(options TemplateOptions) error {
// FIXME: Support bdevtype and bdev_specs
// bdevtypes:
// "btrfs", "zfs", "lvm", "dir"
//
// best tries to find the best backing store type
// FIXME: Support bdev_specs
//
// bdev_specs:
// zfs requires zfsroot
@@ -518,10 +514,7 @@ func (c *Container) Destroy() error {
// Clone clones the container using given arguments with specified backend.
func (c *Container) Clone(name string, options CloneOptions) error {
// FIXME: support lxcpath, bdevtype, bdevdata, newsize and hookargs
//
// bdevtypes:
// "btrfs", "zfs", "lvm", "dir" "overlayfs"
// FIXME: bdevdata, newsize and hookargs
//
// bdevdata:
// zfs requires zfsroot
@@ -561,8 +554,17 @@ func (c *Container) Clone(name string, options CloneOptions) error {
cbackend := C.CString(options.Backend.String())
defer C.free(unsafe.Pointer(cbackend))
if !bool(C.go_lxc_clone(c.container, cname, C.int(flags), cbackend)) {
return ErrCloneFailed
if options.ConfigPath != "" {
clxcpath := C.CString(options.ConfigPath)
defer C.free(unsafe.Pointer(clxcpath))
if !bool(C.go_lxc_clone(c.container, cname, clxcpath, C.int(flags), cbackend)) {
return ErrCloneFailed
}
} else {
if !bool(C.go_lxc_clone(c.container, cname, nil, C.int(flags), cbackend)) {
return ErrCloneFailed
}
}
return nil
}

4
lxc.c
View File

@@ -148,8 +148,8 @@ bool go_lxc_save_config(struct lxc_container *c, const char *alt_file) {
return c->save_config(c, alt_file);
}
bool go_lxc_clone(struct lxc_container *c, const char *newname, int flags, const char *bdevtype) {
return c->clone(c, newname, NULL, flags, bdevtype, NULL, 0, NULL) != NULL;
bool go_lxc_clone(struct lxc_container *c, const char *newname, const char *lxcpath, int flags, const char *bdevtype) {
return c->clone(c, newname, lxcpath, flags, bdevtype, NULL, 0, NULL) != NULL;
}
int go_lxc_console_getfd(struct lxc_container *c, int ttynum) {

2
lxc.h
View File

@@ -5,7 +5,7 @@
extern bool go_lxc_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path);
extern void go_lxc_clear_config(struct lxc_container *c);
extern bool go_lxc_clear_config_item(struct lxc_container *c, const char *key);
extern bool go_lxc_clone(struct lxc_container *c, const char *newname, int flags, const char *bdevtype);
extern bool go_lxc_clone(struct lxc_container *c, const char *newname, const char *lxcpath, int flags, const char *bdevtype);
extern bool go_lxc_console(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape);
extern bool go_lxc_create(struct lxc_container *c, const char *t, const char *bdevtype, int flags, char * const argv[]);
extern bool go_lxc_defined(struct lxc_container *c);

View File

@@ -64,6 +64,7 @@ var DefaultAttachOptions = AttachOptions{
// TemplateOptions type is used for defining various template options.
type TemplateOptions struct {
// Template specifies the name of the template.
Template string
@@ -152,18 +153,24 @@ var DefaultConsoleOptions = ConsoleOptions{
// CloneOptions type is used for defining various clone options.
type CloneOptions struct {
// Backend specifies the type of the backend.
Backend BackendStore
// do not change the container name
// lxcpath in which to create the new container. If not set the original container's lxcpath will be used.
ConfigPath string
// Do not change the hostname of the container (in the root filesystem).
KeepName bool
// do not choose a random new mac address
// Use the same MAC address as the original container, rather than generating a new random one.
KeepMAC bool
// snapshot rather than copy
// Create a snapshot rather than copy.
Snapshot bool
}
// DownloadTemplateOptions is a convenient set of options for "download" template.
// DefaultCloneOptions is a convenient set of options to be used.
var DefaultCloneOptions = CloneOptions{
Backend: Directory,
}