mirror of
https://github.com/lxc/go-lxc.git
synced 2026-02-05 06:46:38 +01:00
rename internal function from lxc_container_ to lxc_ and MayControl to Controllable
This commit is contained in:
7
const.go
7
const.go
@@ -16,6 +16,13 @@ const (
|
||||
DontWait
|
||||
)
|
||||
|
||||
const (
|
||||
isDefined = 1 << iota
|
||||
isNotDefined
|
||||
isRunning
|
||||
isNotRunning
|
||||
)
|
||||
|
||||
const (
|
||||
errAddDeviceNodeFailed = "adding device %s to container %q failed"
|
||||
errAlreadyDefined = "container %q already defined"
|
||||
|
||||
776
container.go
776
container.go
File diff suppressed because it is too large
Load Diff
82
lxc.c
82
lxc.c
@@ -12,71 +12,71 @@
|
||||
#include <lxc/lxccontainer.h>
|
||||
#include <lxc/attach_options.h>
|
||||
|
||||
bool lxc_container_defined(struct lxc_container *c) {
|
||||
bool lxc_defined(struct lxc_container *c) {
|
||||
return c->is_defined(c);
|
||||
}
|
||||
|
||||
const char* lxc_container_state(struct lxc_container *c) {
|
||||
const char* lxc_state(struct lxc_container *c) {
|
||||
return c->state(c);
|
||||
}
|
||||
|
||||
bool lxc_container_running(struct lxc_container *c) {
|
||||
bool lxc_running(struct lxc_container *c) {
|
||||
return c->is_running(c);
|
||||
}
|
||||
|
||||
bool lxc_container_freeze(struct lxc_container *c) {
|
||||
bool lxc_freeze(struct lxc_container *c) {
|
||||
return c->freeze(c);
|
||||
}
|
||||
|
||||
bool lxc_container_unfreeze(struct lxc_container *c) {
|
||||
bool lxc_unfreeze(struct lxc_container *c) {
|
||||
return c->unfreeze(c);
|
||||
}
|
||||
|
||||
pid_t lxc_container_init_pid(struct lxc_container *c) {
|
||||
pid_t lxc_init_pid(struct lxc_container *c) {
|
||||
return c->init_pid(c);
|
||||
}
|
||||
|
||||
bool lxc_container_want_daemonize(struct lxc_container *c, bool state) {
|
||||
bool lxc_want_daemonize(struct lxc_container *c, bool state) {
|
||||
return c->want_daemonize(c, state);
|
||||
}
|
||||
|
||||
bool lxc_container_want_close_all_fds(struct lxc_container *c, bool state) {
|
||||
bool lxc_want_close_all_fds(struct lxc_container *c, bool state) {
|
||||
return c->want_close_all_fds(c, state);
|
||||
}
|
||||
|
||||
bool lxc_container_create(struct lxc_container *c, const char *t, const char *bdevtype, int flags, char * const argv[]) {
|
||||
bool lxc_create(struct lxc_container *c, const char *t, const char *bdevtype, int flags, char * const argv[]) {
|
||||
return c->create(c, t, bdevtype, NULL, !!(flags & LXC_CREATE_QUIET), argv);
|
||||
}
|
||||
|
||||
bool lxc_container_start(struct lxc_container *c, int useinit, char * const argv[]) {
|
||||
bool lxc_start(struct lxc_container *c, int useinit, char * const argv[]) {
|
||||
return c->start(c, useinit, argv);
|
||||
}
|
||||
|
||||
bool lxc_container_stop(struct lxc_container *c) {
|
||||
bool lxc_stop(struct lxc_container *c) {
|
||||
return c->stop(c);
|
||||
}
|
||||
|
||||
bool lxc_container_reboot(struct lxc_container *c) {
|
||||
bool lxc_reboot(struct lxc_container *c) {
|
||||
return c->reboot(c);
|
||||
}
|
||||
|
||||
bool lxc_container_shutdown(struct lxc_container *c, int timeout) {
|
||||
bool lxc_shutdown(struct lxc_container *c, int timeout) {
|
||||
return c->shutdown(c, timeout);
|
||||
}
|
||||
|
||||
char* lxc_container_config_file_name(struct lxc_container *c) {
|
||||
char* lxc_config_file_name(struct lxc_container *c) {
|
||||
return c->config_file_name(c);
|
||||
}
|
||||
|
||||
bool lxc_container_destroy(struct lxc_container *c) {
|
||||
bool lxc_destroy(struct lxc_container *c) {
|
||||
return c->destroy(c);
|
||||
}
|
||||
|
||||
bool lxc_container_wait(struct lxc_container *c, const char *state, int timeout) {
|
||||
bool lxc_wait(struct lxc_container *c, const char *state, int timeout) {
|
||||
return c->wait(c, state, timeout);
|
||||
}
|
||||
|
||||
char* lxc_container_get_config_item(struct lxc_container *c, const char *key) {
|
||||
char* lxc_get_config_item(struct lxc_container *c, const char *key) {
|
||||
int len = c->get_config_item(c, key, NULL, 0);
|
||||
if (len <= 0) {
|
||||
return NULL;
|
||||
@@ -89,15 +89,15 @@ char* lxc_container_get_config_item(struct lxc_container *c, const char *key) {
|
||||
return value;
|
||||
}
|
||||
|
||||
bool lxc_container_set_config_item(struct lxc_container *c, const char *key, const char *value) {
|
||||
bool lxc_set_config_item(struct lxc_container *c, const char *key, const char *value) {
|
||||
return c->set_config_item(c, key, value);
|
||||
}
|
||||
|
||||
bool lxc_container_clear_config_item(struct lxc_container *c, const char *key) {
|
||||
bool lxc_clear_config_item(struct lxc_container *c, const char *key) {
|
||||
return c->clear_config_item(c, key);
|
||||
}
|
||||
|
||||
char* lxc_container_get_keys(struct lxc_container *c, const char *key) {
|
||||
char* lxc_get_keys(struct lxc_container *c, const char *key) {
|
||||
int len = c->get_keys(c, key, NULL, 0);
|
||||
if (len <= 0) {
|
||||
return NULL;
|
||||
@@ -110,7 +110,7 @@ char* lxc_container_get_keys(struct lxc_container *c, const char *key) {
|
||||
return value;
|
||||
}
|
||||
|
||||
char* lxc_container_get_cgroup_item(struct lxc_container *c, const char *key) {
|
||||
char* lxc_get_cgroup_item(struct lxc_container *c, const char *key) {
|
||||
int len = c->get_cgroup_item(c, key, NULL, 0);
|
||||
if (len <= 0) {
|
||||
return NULL;
|
||||
@@ -123,31 +123,31 @@ char* lxc_container_get_cgroup_item(struct lxc_container *c, const char *key) {
|
||||
return value;
|
||||
}
|
||||
|
||||
bool lxc_container_set_cgroup_item(struct lxc_container *c, const char *key, const char *value) {
|
||||
bool lxc_set_cgroup_item(struct lxc_container *c, const char *key, const char *value) {
|
||||
return c->set_cgroup_item(c, key, value);
|
||||
}
|
||||
|
||||
const char* lxc_container_get_config_path(struct lxc_container *c) {
|
||||
const char* lxc_get_config_path(struct lxc_container *c) {
|
||||
return c->get_config_path(c);
|
||||
}
|
||||
|
||||
bool lxc_container_set_config_path(struct lxc_container *c, const char *path) {
|
||||
bool lxc_set_config_path(struct lxc_container *c, const char *path) {
|
||||
return c->set_config_path(c, path);
|
||||
}
|
||||
|
||||
bool lxc_container_load_config(struct lxc_container *c, const char *alt_file) {
|
||||
bool lxc_load_config(struct lxc_container *c, const char *alt_file) {
|
||||
return c->load_config(c, alt_file);
|
||||
}
|
||||
|
||||
bool lxc_container_save_config(struct lxc_container *c, const char *alt_file) {
|
||||
bool lxc_save_config(struct lxc_container *c, const char *alt_file) {
|
||||
return c->save_config(c, alt_file);
|
||||
}
|
||||
|
||||
bool lxc_container_clone(struct lxc_container *c, const char *newname, int flags, const char *bdevtype) {
|
||||
bool 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;
|
||||
}
|
||||
|
||||
int lxc_container_console_getfd(struct lxc_container *c, int ttynum) {
|
||||
int lxc_console_getfd(struct lxc_container *c, int ttynum) {
|
||||
int masterfd;
|
||||
|
||||
if (c->console_getfd(c, &ttynum, &masterfd) < 0) {
|
||||
@@ -156,7 +156,7 @@ int lxc_container_console_getfd(struct lxc_container *c, int ttynum) {
|
||||
return masterfd;
|
||||
}
|
||||
|
||||
bool lxc_container_console(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape) {
|
||||
bool lxc_console(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape) {
|
||||
|
||||
if (c->console(c, ttynum, stdinfd, stdoutfd, stderrfd, escape) == 0) {
|
||||
return true;
|
||||
@@ -164,15 +164,15 @@ bool lxc_container_console(struct lxc_container *c, int ttynum, int stdinfd, int
|
||||
return false;
|
||||
}
|
||||
|
||||
char** lxc_container_get_interfaces(struct lxc_container *c) {
|
||||
char** lxc_get_interfaces(struct lxc_container *c) {
|
||||
return c->get_interfaces(c);
|
||||
}
|
||||
|
||||
char** lxc_container_get_ips(struct lxc_container *c, const char *interface, const char *family, int scope) {
|
||||
char** lxc_get_ips(struct lxc_container *c, const char *interface, const char *family, int scope) {
|
||||
return c->get_ips(c, interface, family, scope);
|
||||
}
|
||||
|
||||
int lxc_container_attach(struct lxc_container *c, bool clear_env) {
|
||||
int lxc_attach(struct lxc_container *c, bool clear_env) {
|
||||
int ret;
|
||||
pid_t pid;
|
||||
lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT;
|
||||
@@ -220,7 +220,7 @@ int lxc_container_attach(struct lxc_container *c, bool clear_env) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int lxc_container_attach_run_wait(struct lxc_container *c, bool clear_env, const char * const argv[]) {
|
||||
int lxc_attach_run_wait(struct lxc_container *c, bool clear_env, const char * const argv[]) {
|
||||
int ret;
|
||||
lxc_attach_options_t attach_options = LXC_ATTACH_OPTIONS_DEFAULT;
|
||||
|
||||
@@ -235,34 +235,34 @@ int lxc_container_attach_run_wait(struct lxc_container *c, bool clear_env, const
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool lxc_container_may_control(struct lxc_container *c) {
|
||||
bool lxc_may_control(struct lxc_container *c) {
|
||||
return c->may_control(c);
|
||||
}
|
||||
|
||||
int lxc_container_snapshot(struct lxc_container *c) {
|
||||
int lxc_snapshot(struct lxc_container *c) {
|
||||
return c->snapshot(c, NULL);
|
||||
}
|
||||
|
||||
int lxc_container_snapshot_list(struct lxc_container *c, struct lxc_snapshot **ret) {
|
||||
int lxc_snapshot_list(struct lxc_container *c, struct lxc_snapshot **ret) {
|
||||
return c->snapshot_list(c, ret);
|
||||
}
|
||||
|
||||
bool lxc_container_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname) {
|
||||
bool lxc_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname) {
|
||||
return c->snapshot_restore(c, snapname, newname);
|
||||
}
|
||||
|
||||
bool lxc_container_snapshot_destroy(struct lxc_container *c, const char *snapname) {
|
||||
bool lxc_snapshot_destroy(struct lxc_container *c, const char *snapname) {
|
||||
return c->snapshot_destroy(c, snapname);
|
||||
}
|
||||
|
||||
bool lxc_container_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path) {
|
||||
bool lxc_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path) {
|
||||
return c->add_device_node(c, src_path, dest_path);
|
||||
}
|
||||
|
||||
bool lxc_container_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path) {
|
||||
bool lxc_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path) {
|
||||
return c->remove_device_node(c, src_path, dest_path);
|
||||
}
|
||||
|
||||
bool lxc_container_rename(struct lxc_container *c, const char *newname) {
|
||||
bool lxc_rename(struct lxc_container *c, const char *newname) {
|
||||
return c->rename(c, newname);
|
||||
}
|
||||
|
||||
7
lxc.go
7
lxc.go
@@ -17,16 +17,9 @@ import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if os.Geteuid() != 0 {
|
||||
fmt.Printf("You are using LXC as an unprivileged user. Some functionality may not work.\n\n")
|
||||
}
|
||||
}
|
||||
|
||||
// NewContainer returns a new container struct
|
||||
func NewContainer(name string, lxcpath ...string) (*Container, error) {
|
||||
var container *C.struct_lxc_container
|
||||
|
||||
82
lxc.h
82
lxc.h
@@ -5,44 +5,44 @@
|
||||
// Authors:
|
||||
// S.Çağlar Onur <caglar@10ur.org>
|
||||
|
||||
extern bool lxc_container_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path);
|
||||
extern bool lxc_container_clear_config_item(struct lxc_container *c, const char *key);
|
||||
extern bool lxc_container_clone(struct lxc_container *c, const char *newname, int flags, const char *bdevtype);
|
||||
extern bool lxc_container_console(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape);
|
||||
extern bool lxc_container_create(struct lxc_container *c, const char *t, const char *bdevtype, int flags, char * const argv[]);
|
||||
extern bool lxc_container_defined(struct lxc_container *c);
|
||||
extern bool lxc_container_destroy(struct lxc_container *c);
|
||||
extern bool lxc_container_freeze(struct lxc_container *c);
|
||||
extern bool lxc_container_load_config(struct lxc_container *c, const char *alt_file);
|
||||
extern bool lxc_container_may_control(struct lxc_container *c);
|
||||
extern bool lxc_container_reboot(struct lxc_container *c);
|
||||
extern bool lxc_container_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path);
|
||||
extern bool lxc_container_rename(struct lxc_container *c, const char *newname);
|
||||
extern bool lxc_container_running(struct lxc_container *c);
|
||||
extern bool lxc_container_save_config(struct lxc_container *c, const char *alt_file);
|
||||
extern bool lxc_container_set_cgroup_item(struct lxc_container *c, const char *key, const char *value);
|
||||
extern bool lxc_container_set_config_item(struct lxc_container *c, const char *key, const char *value);
|
||||
extern bool lxc_container_set_config_path(struct lxc_container *c, const char *path);
|
||||
extern bool lxc_container_shutdown(struct lxc_container *c, int timeout);
|
||||
extern bool lxc_container_snapshot_destroy(struct lxc_container *c, const char *snapname);
|
||||
extern bool lxc_container_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname);
|
||||
extern bool lxc_container_start(struct lxc_container *c, int useinit, char * const argv[]);
|
||||
extern bool lxc_container_stop(struct lxc_container *c);
|
||||
extern bool lxc_container_unfreeze(struct lxc_container *c);
|
||||
extern bool lxc_container_wait(struct lxc_container *c, const char *state, int timeout);
|
||||
extern bool lxc_container_want_close_all_fds(struct lxc_container *c, bool state);
|
||||
extern bool lxc_container_want_daemonize(struct lxc_container *c, bool state);
|
||||
extern char* lxc_container_config_file_name(struct lxc_container *c);
|
||||
extern char* lxc_container_get_cgroup_item(struct lxc_container *c, const char *key);
|
||||
extern char* lxc_container_get_config_item(struct lxc_container *c, const char *key);
|
||||
extern char** lxc_container_get_interfaces(struct lxc_container *c);
|
||||
extern char** lxc_container_get_ips(struct lxc_container *c, const char *interface, const char *family, int scope);
|
||||
extern char* lxc_container_get_keys(struct lxc_container *c, const char *key);
|
||||
extern const char* lxc_container_get_config_path(struct lxc_container *c);
|
||||
extern const char* lxc_container_state(struct lxc_container *c);
|
||||
extern int lxc_container_attach_run_wait(struct lxc_container *c, bool clear_env, const char * const argv[]);
|
||||
extern int lxc_container_attach(struct lxc_container *c, bool clear_env);
|
||||
extern int lxc_container_console_getfd(struct lxc_container *c, int ttynum);
|
||||
extern int lxc_container_snapshot_list(struct lxc_container *c, struct lxc_snapshot **ret);
|
||||
extern int lxc_container_snapshot(struct lxc_container *c);
|
||||
extern pid_t lxc_container_init_pid(struct lxc_container *c);
|
||||
extern bool lxc_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path);
|
||||
extern bool lxc_clear_config_item(struct lxc_container *c, const char *key);
|
||||
extern bool lxc_clone(struct lxc_container *c, const char *newname, int flags, const char *bdevtype);
|
||||
extern bool lxc_console(struct lxc_container *c, int ttynum, int stdinfd, int stdoutfd, int stderrfd, int escape);
|
||||
extern bool lxc_create(struct lxc_container *c, const char *t, const char *bdevtype, int flags, char * const argv[]);
|
||||
extern bool lxc_defined(struct lxc_container *c);
|
||||
extern bool lxc_destroy(struct lxc_container *c);
|
||||
extern bool lxc_freeze(struct lxc_container *c);
|
||||
extern bool lxc_load_config(struct lxc_container *c, const char *alt_file);
|
||||
extern bool lxc_may_control(struct lxc_container *c);
|
||||
extern bool lxc_reboot(struct lxc_container *c);
|
||||
extern bool lxc_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path);
|
||||
extern bool lxc_rename(struct lxc_container *c, const char *newname);
|
||||
extern bool lxc_running(struct lxc_container *c);
|
||||
extern bool lxc_save_config(struct lxc_container *c, const char *alt_file);
|
||||
extern bool lxc_set_cgroup_item(struct lxc_container *c, const char *key, const char *value);
|
||||
extern bool lxc_set_config_item(struct lxc_container *c, const char *key, const char *value);
|
||||
extern bool lxc_set_config_path(struct lxc_container *c, const char *path);
|
||||
extern bool lxc_shutdown(struct lxc_container *c, int timeout);
|
||||
extern bool lxc_snapshot_destroy(struct lxc_container *c, const char *snapname);
|
||||
extern bool lxc_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname);
|
||||
extern bool lxc_start(struct lxc_container *c, int useinit, char * const argv[]);
|
||||
extern bool lxc_stop(struct lxc_container *c);
|
||||
extern bool lxc_unfreeze(struct lxc_container *c);
|
||||
extern bool lxc_wait(struct lxc_container *c, const char *state, int timeout);
|
||||
extern bool lxc_want_close_all_fds(struct lxc_container *c, bool state);
|
||||
extern bool lxc_want_daemonize(struct lxc_container *c, bool state);
|
||||
extern char* lxc_config_file_name(struct lxc_container *c);
|
||||
extern char* lxc_get_cgroup_item(struct lxc_container *c, const char *key);
|
||||
extern char* lxc_get_config_item(struct lxc_container *c, const char *key);
|
||||
extern char* lxc_get_keys(struct lxc_container *c, const char *key);
|
||||
extern char** lxc_get_interfaces(struct lxc_container *c);
|
||||
extern char** lxc_get_ips(struct lxc_container *c, const char *interface, const char *family, int scope);
|
||||
extern const char* lxc_get_config_path(struct lxc_container *c);
|
||||
extern const char* lxc_state(struct lxc_container *c);
|
||||
extern int lxc_attach(struct lxc_container *c, bool clear_env);
|
||||
extern int lxc_attach_run_wait(struct lxc_container *c, bool clear_env, const char * const argv[]);
|
||||
extern int lxc_console_getfd(struct lxc_container *c, int ttynum);
|
||||
extern int lxc_snapshot(struct lxc_container *c);
|
||||
extern int lxc_snapshot_list(struct lxc_container *c, struct lxc_snapshot **ret);
|
||||
extern pid_t lxc_init_pid(struct lxc_container *c);
|
||||
@@ -359,14 +359,14 @@ func TestStart(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMayControl(t *testing.T) {
|
||||
func TestControllable(t *testing.T) {
|
||||
z, err := lxc.NewContainer(ContainerName)
|
||||
if err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
defer lxc.PutContainer(z)
|
||||
|
||||
if !z.MayControl() {
|
||||
if !z.Controllable() {
|
||||
t.Errorf("Controling the container failed...")
|
||||
}
|
||||
}
|
||||
@@ -1032,7 +1032,7 @@ func TestDestroy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
z, err := lxc.NewContainer(ContainerCloneName)
|
||||
z, err := lxc.NewContainer(ContainerCloneName)
|
||||
if err != nil {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user