#include "../../lib/types.h"
void
-_vsc_mgmt_data_init (struct VscError *error);
+_vsc_mgmt_data_init (struct VscError *error,
+ const char *config_file_path);
void
_vsc_mgmt_data_cleanup (void);
void
-_vsc_mgmt_data_init (struct VscError *error)
+_vsc_mgmt_data_init (struct VscError *error, const char *config_file_path)
{
+ (void) config_file_path;
+
VSC__ASSERT (error != NULL);
VSC__ASSERT (! error->occured);
VSC__ASSERT (! _data_initialized);
- _data_initialized = 1;
+ if (_data_initialized) {
+ VSC__ERROR1 (error, VSC__ERROR_CODE__INVALID_CALL,
+ "Already initialized");
+ return;
+ }
_host_by_ip_tree = g_tree_new (_ip_compare);
if (! _host_by_ip_tree) {
g_tree_foreach (_host_by_ip_tree, _host_tree_traverse_free, NULL);
g_tree_destroy (_host_by_ip_tree);
}
+
+ _data_initialized = 0;
}
void
-_vsc_mgmt_network_common_init (struct VscError *error)
+_vsc_mgmt_network_common_init (struct VscError *error, const char *config_file_path)
{
+ (void) config_file_path;
+
const char *mac_base_str = MAC_BASE;
unsigned char octet = 0;
char i = 1;
VSC__ASSERT (! error->occured);
VSC__ASSERT (! _network_initialized);
+ if (_network_initialized == TRUE) {
+ VSC__ERROR1 (error, VSC__ERROR_CODE__INVALID_CALL,
+ "Already initialized");
+ return;
+ }
+
_mac_base = 0;
/* Cut MAC_BASE into octets and compute numerical value */
#include "../../../lib/network.h"
void
-_vsc_mgmt_network_common_init (struct VscError *error);
+_vsc_mgmt_network_common_init (struct VscError *error, const char *config_file_path);
void
_vsc_mgmt_network_common_cleanup (void);
void
-_vsc_mgmt_network_init (struct VscError *error)
+_vsc_mgmt_network_init (struct VscError *error, const char *config_file_path)
{
+ (void) config_file_path;
+
VSC__ASSERT (error != NULL);
VSC__ASSERT (! error->occured);
VSC__ASSERT (! _network_initialized);
if (_network_initialized) {
- VSC__ERROR0 (error, VSC__ERROR_CODE__INVALID_CALL);
+ VSC__ERROR1 (error, VSC__ERROR_CODE__INVALID_CALL,
+ "Already initialized");
return;
}
- _vsc_mgmt_network_common_init (error);
+ _vsc_mgmt_network_common_init (error, config_file_path);
if (error->occured) {
VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
return;
#include "../../include/libvscmgmt/network.h"
void
-_vsc_mgmt_network_init (struct VscError *error);
+_vsc_mgmt_network_init (struct VscError *error, const char *config_file_path);
void
_vsc_mgmt_network_cleanup (void);
#endif
void
-vsc_mgmt_init (struct VscError *error);
+vsc_mgmt_init (struct VscError *error,
+ const char *image_dir_path, const char *image_suffix,
+ const char *data_backend_config_file,
+ const char *network_backend_config_file);
void
vsc_mgmt_cleanup (void);
/*!
* @file
*/
+#include <errno.h>
+#include <string.h>
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <libvscmisc/assert.h>
#include <libvscmisc/error.h>
+#include <libvscmisc/memory.h>
#include "../include/libvscmgmt/core.h"
#include "../backend/data/data.h"
static int _initialized = FALSE;
static struct VscMgmtMutex *_mutex = NULL;
+/* Path information for vsc_mgmt_image_{deploy,retract} in vm.c */
+char *_image_basedir = NULL;
+int _image_basedir_length = 0;
+char *_image_file_suffix = NULL;
+int _image_file_suffix_length = 0;
+
+
void
_vsc_mgmt_lock (void)
{
* @note Function is not threadsafe.
*/
void
-vsc_mgmt_init (struct VscError *error)
+vsc_mgmt_init (struct VscError *error,
+ const char *image_dir_path, const char *image_suffix,
+ const char *data_backend_config_file,
+ const char *network_backend_config_file)
{
VSC__ASSERT (error != NULL);
VSC__ASSERT (! error->occured);
+ VSC__ASSERT (image_dir_path != NULL);
+ VSC__ASSERT (image_suffix != NULL);
+ /*
+ * Don't check if the backend config files are given as they might be
+ * optional for the used backend. Just pass them to the backend.
+ */
if (_initialized) {
VSC__ERROR1 (error, VSC__ERROR_CODE__INVALID_CALL,
return;
}
- _mutex = _vsc_mgmt_mutex_new_recursive (error);
+ /* Check if one of the paths is NULL which would break strdup() */
+ if (! image_dir_path || ! image_suffix) {
+ VSC__ERROR1 (error, VSC__ERROR_CODE__INVALID_ARGUMENT,
+ "image_dir_path or image_suffix is NULL");
+ return;
+ }
+
+ _image_basedir = strdup (image_dir_path);
+ if (! _image_basedir) {
+ VSC__ERROR2 (error, VSC__ERROR_CODE__ERRNO,
+ "Could not copy image_dir_path string: %s",
+ strerror (errno));
+ return;
+ }
+ _image_file_suffix = strdup (image_suffix);
+ if (! _image_file_suffix) {
+ VSC__ERROR2 (error, VSC__ERROR_CODE__ERRNO,
+ "Could not copy image_suffix string: %s",
+ strerror (errno));
+ vsc_free (&_image_basedir);
+ return;
+ }
+
+ _image_basedir_length = strlen (_image_basedir);
+ _image_file_suffix_length = strlen (_image_file_suffix);
+
+
+ /* Initialize mutex */
+ _mutex = _vsc_mgmt_mutex_new_recursive (error);
if (error->occured) {
VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
return;
}
- _vsc_mgmt_network_init (error);
+ /* Initialize network backend */
+ _vsc_mgmt_network_init (error,network_backend_config_file);
if (error->occured) {
VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
return;
}
- _vsc_mgmt_data_init (error);
+
+ /* Initialize data backend */
+ _vsc_mgmt_data_init (error, data_backend_config_file);
if (error->occured) {
VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
return;
}
+
+ /* Initialize libVirt */
if (virInitialize() < 0) {
VSC__ERROR1 (error, VSC__ERROR_CODE__LIBVIRT_ERROR,
"Could not initialize libvirt");
#define BUFFER_SIZE 4096
-static const char *image_basedir = "/srv/vsc/images";
-static unsigned int image_basedir_length = 0;
+/* Import global config options from core.c */
+extern char *_image_basedir;
+extern int _image_basedir_length;
-static const char *image_file_suffix = "image";
-static unsigned int image_file_suffix_length;
+extern char *_image_file_suffix;
+extern int _image_file_suffix_length;
/*******************************************************************************
* internal functions *
return;
}
- /* Compute the string lengths of the static strings */
- if (! image_basedir_length) {
- image_basedir_length = strlen (image_basedir);
- image_file_suffix_length = strlen (image_file_suffix);
- }
-
/* Allocate memory for the VM image dir and file */
- dest_filename = vsc_alloc (error, image_basedir_length + 1 + /* <basedir>/ */
+ dest_filename = vsc_alloc (error, _image_basedir_length + 1 + /* <basedir>/ */
VSC_MGMT__UUID__STRING_SIZE + 1 + /* <uuid>/ */
- VSC_MGMT__UUID__STRING_SIZE + 1 + image_file_suffix_length + 1); /* <uuid>.<suffix>\0 */
+ VSC_MGMT__UUID__STRING_SIZE + 1 + _image_file_suffix_length + 1); /* <uuid>.<suffix>\0 */
if (error->occured) {
VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
goto cleanup;
}
- dest_file_dirname = vsc_alloc (error, image_basedir_length + 1 + /* <basedir>/ */
+ dest_file_dirname = vsc_alloc (error, _image_basedir_length + 1 + /* <basedir>/ */
VSC_MGMT__UUID__STRING_SIZE + 1); /* <uuid>\0 */
if (error->occured) {
VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
* At first only print the path to the VM image directory so we can
* create it.
*/
- sprintf (dest_file_dirname, "%s/%s", image_basedir, vm->info.uuid_string);
+ sprintf (dest_file_dirname, "%s/%s", _image_basedir, vm->info.uuid_string);
if (mkdir (dest_file_dirname, S_IRUSR|S_IWUSR|S_IXUSR | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) != 0) {
VSC__ERROR2 (error, VSC__ERROR_CODE__ERRNO,
cleanup_flag = 1;
/* Concatenate all elements of the whole path */
- sprintf (dest_filename, "%s/%s/%s.%s", image_basedir, vm->info.uuid_string,
- vm->info.uuid_string, image_file_suffix);
+ sprintf (dest_filename, "%s/%s/%s.%s", _image_basedir, vm->info.uuid_string,
+ vm->info.uuid_string, _image_file_suffix);
cleanup_flag = 2;
* Check if there is enough space left on the FS to store the images
* for num_hosts * imagesize
*/
- if (statvfs (image_basedir, &image_fs_stat) != 0) {
+ if (statvfs (_image_basedir, &image_fs_stat) != 0) {
VSC__ERROR2 (error, VSC__ERROR_CODE__ERRNO,
"Failed to get information about image dir filesystem '%s': %s",
- image_basedir, strerror (errno));
+ _image_basedir, strerror (errno));
return NULL;
}
VSC__ERROR2 (error, VSC__ERROR_CODE__INVALID_ARGUMENT,
"Not enought space on image filesystem '%s' "
"to save %u copies of image '%s'",
- image_basedir, num_hosts, image_filename);
+ _image_basedir, num_hosts, image_filename);
return NULL;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Core: init
+ */
+
+PyDoc_STRVAR (_init__doc__,
+"init(image_dir_path, image_suffix, data_backend_config_file, network_backend_config_file)\n\n"
+"Initialize the library");
+
+static PyObject *
+_init (PyObject *self VSC__ATTR__UNUSED, PyObject *args)
+{
+ struct VscError error;
+ PyObject *result = Py_None;
+ const char *image_dir_path;
+ const char *image_suffix;
+ const char *data_backend_config_file;
+ const char *network_backend_config_file;
+
+ if (! PyArg_ParseTuple (args, "ssss:init", &image_dir_path,
+ &image_suffix, &data_backend_config_file,
+ &network_backend_config_file)) {
+ return NULL;
+ }
+
+ vsc_error_init (&error);
+
+ vsc_mgmt_init (&error, image_dir_path, image_suffix,
+ data_backend_config_file,
+ network_backend_config_file);
+
+ if (error.occured) {
+ _format_error (&error);
+ goto failure;
+ }
+
+cleanup:
+ vsc_error_cleanup (&error);
+
+ return result;
+
+failure:
+ result = NULL;
+
+ goto cleanup;
+}
+
+
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Core: backup
*/
static PyMethodDef _methods[] = {
/* Core */
+ _METHOD_DEFINITION (init),
_METHOD_DEFINITION (backup),
_METHOD_DEFINITION (recover),
_METHOD_DEFINITION (get_version),
initlibvscmgmtmodule (void)
{
PyObject *module;
- struct VscError error;
static int initialized = FALSE;
if (initialized) {
Py_INCREF (_error_type);
PyModule_AddObject (module, "Error", _error_type);
- /* Initialize libvscmgmt */
- vsc_error_init (&error);
-
- vsc_mgmt_init (&error);
-
- if (error.occured) {
- goto failure;
- }
-
initialized = TRUE;
-
- return;
-
-failure:
- _format_error (&error);
-
- vsc_error_cleanup (&error);
}
vsc_error_init (&error);
- vsc_mgmt_init (&error);
+ vsc_mgmt_init (&error, "/srv/vsc/images", "image", NULL, NULL);
if (error.occured) {
vsc_error_fprint (&error, stderr);
vsc_error_init (&error);
- vsc_mgmt_init (&error);
+ vsc_mgmt_init (&error, "/srv/vsc/images", "image", NULL, NULL);
if (error.occured) {
vsc_error_fprint (&error, stderr);
return 1;
vsc_error_init (&error);
- vsc_mgmt_init (&error);
+ vsc_mgmt_init (&error, "/srv/vsc/images", "image", NULL, NULL);
if (error.occured) {
vsc_error_fprint (&error, stderr);
return 1;