2007-07-17 13:27:26 +00:00
|
|
|
/*
|
|
|
|
* openvz_conf.c: config functions for managing OpenVZ VEs
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, 2007 Binary Karma
|
|
|
|
* Copyright (C) 2006 Shuveb Hussain
|
2007-09-03 15:37:07 +00:00
|
|
|
* Copyright (C) 2007 Anoop Joe Cyriac
|
2007-07-17 13:27:26 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* Authors:
|
2007-09-03 15:37:07 +00:00
|
|
|
* Shuveb Hussain <shuveb@binarykarma.com>
|
|
|
|
* Anoop Joe Cyriac <anoop@binarykarma.com>
|
|
|
|
*
|
2007-07-17 13:27:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WITH_OPENVZ
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-12-05 21:40:15 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <time.h>
|
2007-09-03 15:37:07 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
#include <libxml/xpath.h>
|
|
|
|
#include <libxml/uri.h>
|
|
|
|
|
Wed Dec 5 13:48:00 UTC 2007 Richard W.M. Jones <rjones@redhat.com>
* python/libvir.c, python/libvirt_wrap.h, qemud/qemud.c,
qemud/remote.c, src/internal.h, src/openvz_conf.c,
src/openvz_driver.c, src/proxy_internal.h, src/qemu_conf.c,
src/qemu_driver.c, src/remote_internal.h, src/test.h, src/util.c,
src/xen_unified.c, src/xen_unified.h, tests/nodeinfotest.c,
tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c, tests/reconnect.c,
tests/sexpr2xmltest.c, tests/virshtest.c, tests/xencapstest.c,
tests/xmconfigtest.c, tests/xml2sexprtest.c:
Change #include <> to #include "" for local includes.
Removed many includes from src/internal.h and put them in
the C files which actually use them.
Removed <ansidecl.h> - unused.
Added a comment around __func__.
Removed a clashing redefinition of VERSION symbol.
All limits (PATH_MAX etc) now done in src/internal.h, so we
don't need to include those headers in other files.
2007-12-05 13:56:22 +00:00
|
|
|
#include "libvirt/virterror.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
#include "openvz_driver.h"
|
2007-09-03 15:37:07 +00:00
|
|
|
#include "openvz_conf.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
#include "uuid.h"
|
|
|
|
#include "buf.h"
|
2008-06-06 11:09:57 +00:00
|
|
|
#include "memory.h"
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static char *openvzLocateConfDir(void);
|
|
|
|
static void error (virConnectPtr conn, virErrorNumber code, const char *info);
|
|
|
|
static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml);
|
|
|
|
static int openvzGetVPSUUID(int vpsid, char *uuidstr);
|
|
|
|
static int openvzSetUUID(int vpsid);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
/* For errors internal to this library. */
|
|
|
|
static void
|
|
|
|
error (virConnectPtr conn, virErrorNumber code, const char *info)
|
|
|
|
{
|
|
|
|
const char *errmsg;
|
|
|
|
|
|
|
|
errmsg = __virErrorMsg (code, info);
|
2007-11-20 10:15:38 +00:00
|
|
|
__virRaiseError (conn, NULL, NULL, VIR_FROM_OPENVZ,
|
2007-07-17 13:27:26 +00:00
|
|
|
code, VIR_ERR_ERROR, errmsg, info, NULL, 0, 0,
|
|
|
|
errmsg, info);
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
struct openvz_vm
|
2007-07-19 16:22:40 +00:00
|
|
|
*openvzFindVMByID(const struct openvz_driver *driver, int id) {
|
2007-07-17 13:27:26 +00:00
|
|
|
struct openvz_vm *vm = driver->vms;
|
|
|
|
|
|
|
|
while (vm) {
|
|
|
|
if (vm->vpsid == id)
|
|
|
|
return vm;
|
|
|
|
vm = vm->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
struct openvz_vm
|
2007-07-19 16:22:40 +00:00
|
|
|
*openvzFindVMByUUID(const struct openvz_driver *driver,
|
2007-07-17 13:27:26 +00:00
|
|
|
const unsigned char *uuid) {
|
|
|
|
struct openvz_vm *vm = driver->vms;
|
|
|
|
|
|
|
|
while (vm) {
|
2007-08-09 20:19:12 +00:00
|
|
|
if (!memcmp(vm->vmdef->uuid, uuid, VIR_UUID_BUFLEN))
|
2007-07-17 13:27:26 +00:00
|
|
|
return vm;
|
|
|
|
vm = vm->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
struct openvz_vm
|
2007-07-19 16:22:40 +00:00
|
|
|
*openvzFindVMByName(const struct openvz_driver *driver,
|
2007-07-17 13:27:26 +00:00
|
|
|
const char *name) {
|
|
|
|
struct openvz_vm *vm = driver->vms;
|
|
|
|
|
|
|
|
while (vm) {
|
2008-05-14 19:51:24 +00:00
|
|
|
if (STREQ(vm->vmdef->name, name))
|
2007-07-17 13:27:26 +00:00
|
|
|
return vm;
|
|
|
|
vm = vm->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
int
|
2007-09-03 16:30:00 +00:00
|
|
|
strtoI(const char *str)
|
2007-09-03 15:37:07 +00:00
|
|
|
{
|
|
|
|
int base = 10;
|
|
|
|
char *endptr;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = (int) strtol(str, &endptr, base);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
/* Check for various possible errors */
|
|
|
|
if ((endptr == str) /* "No digits were found" */
|
2008-02-05 19:27:37 +00:00
|
|
|
||((*endptr != '\0')
|
2007-09-03 15:37:07 +00:00
|
|
|
&& (*endptr != ' ')) /*"Name contain characters other than integers" */ )
|
|
|
|
return 0;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
openvzRemoveInactiveVM(struct openvz_driver *driver, struct openvz_vm *vm)
|
|
|
|
{
|
|
|
|
driver->num_inactive--;
|
|
|
|
openvzFreeVM(driver, vm, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free all memory associated with a openvz_vm_def structure */
|
|
|
|
void
|
|
|
|
openvzFreeVMDef(struct openvz_vm_def *def)
|
|
|
|
{
|
|
|
|
if (def) {
|
|
|
|
struct ovz_quota *quota = def->fs.quota;
|
|
|
|
struct ovz_ip *ip = def->net.ips;
|
|
|
|
struct ovz_ns *ns = def->net.ns;
|
|
|
|
|
|
|
|
while (quota) {
|
|
|
|
struct ovz_quota *prev = quota;
|
|
|
|
|
|
|
|
quota = quota->next;
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(prev);
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
while (ip) {
|
|
|
|
struct ovz_ip *prev = ip;
|
|
|
|
|
|
|
|
ip = ip->next;
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(prev);
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
while (ns) {
|
|
|
|
struct ovz_ns *prev = ns;
|
|
|
|
|
|
|
|
ns = ns->next;
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(prev);
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(def);
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
/* Free all memory associated with a openvz_vm structure
|
2007-09-03 15:37:07 +00:00
|
|
|
* @checkCallee == 0 then openvzFreeDriver() is callee else some other function
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
openvzFreeVM(struct openvz_driver *driver, struct openvz_vm *vm,
|
|
|
|
int checkCallee)
|
|
|
|
{
|
|
|
|
struct openvz_vm *vms;
|
|
|
|
|
|
|
|
if (!vm && !driver)
|
|
|
|
return;
|
|
|
|
vms = driver->vms;
|
|
|
|
if (checkCallee) {
|
|
|
|
if (vms == vm)
|
|
|
|
driver->vms = vm->next;
|
|
|
|
else {
|
|
|
|
while (vms) {
|
|
|
|
struct openvz_vm *prev = vms;
|
|
|
|
|
|
|
|
vms = vms->next;
|
|
|
|
if (vms == vm) {
|
|
|
|
prev->next = vms->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2007-09-03 15:37:07 +00:00
|
|
|
if (vms) {
|
|
|
|
openvzFreeVMDef(vm->vmdef);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(vm);
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
/* Free all memory associated with a openvz_driver structure */
|
|
|
|
void
|
|
|
|
openvzFreeDriver(struct openvz_driver *driver)
|
|
|
|
{
|
|
|
|
struct openvz_vm *next;
|
|
|
|
|
|
|
|
if (!driver)
|
|
|
|
return;
|
|
|
|
if (driver->vms)
|
|
|
|
for(next = driver->vms->next; driver->vms; driver->vms = next)
|
|
|
|
openvzFreeVM(driver, driver->vms, 0);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(driver);
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct openvz_vm *
|
|
|
|
openvzAssignVMDef(virConnectPtr conn,
|
|
|
|
struct openvz_driver *driver, struct openvz_vm_def *def)
|
|
|
|
{
|
|
|
|
struct openvz_vm *vm = NULL;
|
|
|
|
|
|
|
|
if (!driver || !def)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((vm = openvzFindVMByName(driver, def->name))) {
|
|
|
|
if (!openvzIsActiveVM(vm)) {
|
|
|
|
openvzFreeVMDef(vm->vmdef);
|
|
|
|
vm->vmdef = def;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-27 14:00:28 +00:00
|
|
|
openvzLog(OPENVZ_ERR,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("Error already an active OPENVZ VM having id '%s'"),
|
|
|
|
def->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
openvzFreeVMDef(def);
|
|
|
|
return NULL; /* can't redefine an active domain */
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(vm) < 0) {
|
2008-02-05 19:27:37 +00:00
|
|
|
openvzFreeVMDef(def);
|
2007-09-03 15:37:07 +00:00
|
|
|
error(conn, VIR_ERR_NO_MEMORY, "vm");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm->vpsid = -1; /* -1 needed for to represent inactiveness of domain before 'start' */
|
|
|
|
vm->status = VIR_DOMAIN_SHUTOFF;
|
|
|
|
vm->vmdef = def;
|
|
|
|
vm->next = driver->vms;
|
|
|
|
|
|
|
|
driver->vms = vm;
|
|
|
|
driver->num_inactive++;
|
|
|
|
|
|
|
|
return vm;
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
struct openvz_vm_def
|
2007-09-03 15:37:07 +00:00
|
|
|
*openvzParseVMDef(virConnectPtr conn,
|
|
|
|
const char *xmlStr, const char *displayName)
|
|
|
|
{
|
|
|
|
xmlDocPtr xml;
|
|
|
|
struct openvz_vm_def *def = NULL;
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : "domain.xml", NULL,
|
2007-09-03 15:37:07 +00:00
|
|
|
XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
|
|
|
|
if (!xml) {
|
|
|
|
error(conn, VIR_ERR_XML_ERROR, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
def = openvzParseXML(conn, xml);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
|
|
|
|
return def;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parses a libvirt XML definition of a guest, and populates the
|
|
|
|
* the openvz_vm struct with matching data about the guests config
|
|
|
|
*/
|
2008-02-05 19:27:37 +00:00
|
|
|
static struct openvz_vm_def
|
2007-07-19 16:22:40 +00:00
|
|
|
*openvzParseXML(virConnectPtr conn,
|
|
|
|
xmlDocPtr xml) {
|
2007-07-17 13:27:26 +00:00
|
|
|
xmlNodePtr root = NULL;
|
|
|
|
xmlChar *prop = NULL;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
xmlXPathObjectPtr obj = NULL;
|
|
|
|
struct openvz_vm_def *def;
|
2007-09-03 15:37:07 +00:00
|
|
|
struct ovz_ip *ovzIp;
|
|
|
|
struct ovz_ns *ovzNs;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(def) < 0) {
|
2007-07-17 13:27:26 +00:00
|
|
|
error(conn, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare parser / xpath context */
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
root = xmlDocGetRootElement(xml);
|
|
|
|
if ((root == NULL) || (!xmlStrEqual(root->name, BAD_CAST "domain"))) {
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("incorrect root element"));
|
2007-07-17 13:27:26 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt = xmlXPathNewContext(xml);
|
|
|
|
if (ctxt == NULL) {
|
|
|
|
error(conn, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
/* Find out what type of OPENVZ virtualization to use */
|
2007-07-17 13:27:26 +00:00
|
|
|
if (!(prop = xmlGetProp(root, BAD_CAST "type"))) {
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("missing domain type attribute"));
|
2007-07-17 13:27:26 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
|
2008-05-14 19:51:24 +00:00
|
|
|
if (STRNEQ((char *)prop, "openvz")){
|
2008-04-09 13:50:27 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("invalid domain type attribute"));
|
2007-07-17 13:27:26 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(prop);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
/* Extract domain name */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
|
2007-09-03 15:37:07 +00:00
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
2007-07-17 13:27:26 +00:00
|
|
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("invalid domain name"));
|
2007-07-17 13:27:26 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
/* rejecting VPS ID <= OPENVZ_RSRV_VM_LIMIT for they are reserved */
|
2007-09-03 16:30:00 +00:00
|
|
|
if (strtoI((const char *) obj->stringval) <= OPENVZ_RSRV_VM_LIMIT) {
|
2008-02-05 19:27:37 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("VPS ID Error (must be an integer greater than 100"));
|
2007-07-17 13:27:26 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
2007-09-03 15:37:07 +00:00
|
|
|
strncpy(def->name, (const char *) obj->stringval, OPENVZ_NAME_MAX);
|
2007-07-17 13:27:26 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
/* Extract domain uuid */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/uuid[1])", ctxt);
|
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
|
|
|
|
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
|
|
|
|
int err;
|
2007-09-03 15:37:07 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if ((err = virUUIDGenerate(def->uuid))) {
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("Failed to generate UUID"));
|
2007-07-17 13:27:26 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
} else if (virUUIDParse((const char *)obj->stringval, def->uuid) < 0) {
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("malformed uuid element"));
|
2007-07-17 13:27:26 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
/* Extract filesystem info */
|
2007-09-03 15:37:07 +00:00
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/container/filesystem/template[1])", ctxt);
|
2008-02-05 19:27:37 +00:00
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) || (obj->stringval == NULL)
|
2007-09-03 15:37:07 +00:00
|
|
|
|| (obj->stringval[0] == 0)) {
|
2007-07-17 13:27:26 +00:00
|
|
|
error(conn, VIR_ERR_OS_TYPE, NULL);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
2007-09-03 15:37:07 +00:00
|
|
|
strncpy(def->fs.tmpl, (const char *) obj->stringval, OPENVZ_TMPL_MAX);
|
2007-07-17 13:27:26 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
/* TODO Add quota processing here */
|
|
|
|
|
|
|
|
/* TODO analysis of the network devices */
|
|
|
|
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
/* Extract network */
|
|
|
|
/* Extract ipaddress */
|
|
|
|
obj = xmlXPathEval(BAD_CAST"string(/domain/container/network/ipaddress[1])", ctxt);
|
2008-02-05 19:27:37 +00:00
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) || (obj->stringval == NULL)
|
2007-09-03 15:37:07 +00:00
|
|
|
|| (obj->stringval[0] == 0)) {
|
2008-03-27 14:00:28 +00:00
|
|
|
openvzLog(OPENVZ_WARN,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("No IP address in the given xml config file '%s'"),
|
|
|
|
xml->name);
|
2007-09-03 15:37:07 +00:00
|
|
|
}
|
|
|
|
if (xmlStrlen(obj->stringval) >= (OPENVZ_IP_MAX)) {
|
|
|
|
char errorMessage[OPENVZ_MAX_ERROR_LEN];
|
|
|
|
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
snprintf(errorMessage, OPENVZ_MAX_ERROR_LEN - 1, "%s",
|
2008-04-10 16:54:54 +00:00
|
|
|
_("ipaddress length too long"));
|
2007-09-03 15:37:07 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(ovzIp) < 0) {
|
2008-03-27 14:00:28 +00:00
|
|
|
openvzLog(OPENVZ_ERR,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("Failed to Create Memory for 'ovz_ip' structure"));
|
2007-09-03 15:37:07 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
strncpy(ovzIp->ip, (const char *) obj->stringval, OPENVZ_IP_MAX);
|
|
|
|
def->net.ips = ovzIp;
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
/* Extract netmask */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/container/network/netmask[1])", ctxt);
|
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING)
|
|
|
|
|| (obj->stringval == NULL) || (obj->stringval[0] == 0))
|
2008-03-27 14:00:28 +00:00
|
|
|
openvzLog(OPENVZ_WARN,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("No Netmask address in the given xml config file '%s'"),
|
|
|
|
xml->name);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
if (strlen((const char *) obj->stringval) >= (OPENVZ_IP_MAX)) {
|
|
|
|
char errorMessage[OPENVZ_MAX_ERROR_LEN];
|
|
|
|
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
snprintf(errorMessage, OPENVZ_MAX_ERROR_LEN - 1, "%s",
|
2008-04-10 16:54:54 +00:00
|
|
|
_("netmask length too long"));
|
2007-09-03 15:37:07 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
strncpy(def->net.ips->netmask, (const char *) obj->stringval, OPENVZ_IP_MAX);
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
/* Extract hostname */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/container/network/hostname[1])", ctxt);
|
2008-02-05 19:27:37 +00:00
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) || (obj->stringval == NULL)
|
2007-09-03 15:37:07 +00:00
|
|
|
|| (obj->stringval[0] == 0))
|
2008-03-27 14:00:28 +00:00
|
|
|
openvzLog(OPENVZ_WARN,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("No hostname in the given xml config file '%s'"),
|
|
|
|
xml->name);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
if (strlen((const char *) obj->stringval) >= (OPENVZ_HOSTNAME_MAX - 1)) {
|
|
|
|
char errorMessage[OPENVZ_MAX_ERROR_LEN];
|
|
|
|
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
snprintf(errorMessage, OPENVZ_MAX_ERROR_LEN - 1,
|
2008-04-10 16:54:54 +00:00
|
|
|
"%s", _("hostname length too long"));
|
2007-09-03 15:37:07 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
strncpy(def->net.hostname, (const char *) obj->stringval, OPENVZ_HOSTNAME_MAX - 1);
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
/* Extract gateway */
|
|
|
|
obj = xmlXPathEval(BAD_CAST"string(/domain/container/network/gateway[1])", ctxt);
|
2008-02-05 19:27:37 +00:00
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) || (obj->stringval == NULL)
|
2007-09-03 15:37:07 +00:00
|
|
|
|| (obj->stringval[0] == 0))
|
2008-03-27 14:00:28 +00:00
|
|
|
openvzLog(OPENVZ_WARN,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("No Gateway address in the given xml config file '%s'"),
|
|
|
|
xml->name);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
if (strlen((const char *) obj->stringval) >= (OPENVZ_IP_MAX)) {
|
|
|
|
char errorMessage[OPENVZ_MAX_ERROR_LEN];
|
|
|
|
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
snprintf(errorMessage, OPENVZ_MAX_ERROR_LEN - 1,
|
|
|
|
"%s", _("gateway length too long"));
|
2007-09-03 15:37:07 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
strncpy(def->net.def_gw, (const char *) obj->stringval, OPENVZ_IP_MAX);
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
/* Extract nameserver */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/container/network/nameserver[1])", ctxt);
|
2008-02-05 19:27:37 +00:00
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) || (obj->stringval == NULL)
|
2007-09-03 15:37:07 +00:00
|
|
|
|| (obj->stringval[0] == 0))
|
2008-03-27 14:00:28 +00:00
|
|
|
openvzLog(OPENVZ_WARN,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("No Nameserver address inthe given xml config file '%s'"),
|
|
|
|
xml->name);
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
if (strlen((const char *) obj->stringval) >= (OPENVZ_IP_MAX)) {
|
|
|
|
char errorMessage[OPENVZ_MAX_ERROR_LEN];
|
|
|
|
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
snprintf(errorMessage, OPENVZ_MAX_ERROR_LEN - 1,
|
|
|
|
"%s", _("nameserver length too long"));
|
2007-09-03 15:37:07 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(ovzNs) < 0) {
|
2008-03-27 14:00:28 +00:00
|
|
|
openvzLog(OPENVZ_ERR,
|
|
|
|
_("Failed to Create Memory for 'ovz_ns' structure"));
|
2007-09-03 15:37:07 +00:00
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
strncpy(ovzNs->ip, (const char *) obj->stringval, OPENVZ_IP_MAX);
|
|
|
|
def->net.ns = ovzNs;
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
/* Extract profile */
|
|
|
|
obj = xmlXPathEval(BAD_CAST "string(/domain/container/profile[1])", ctxt);
|
2008-02-05 19:27:37 +00:00
|
|
|
if ((obj == NULL) || (obj->type != XPATH_STRING) || (obj->stringval == NULL)
|
2007-09-03 15:37:07 +00:00
|
|
|
|| (obj->stringval[0] == 0)) {
|
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, NULL);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
if (strlen((const char *) obj->stringval) >= (OPENVZ_PROFILE_MAX - 1)) {
|
|
|
|
char errorMessage[OPENVZ_MAX_ERROR_LEN];
|
|
|
|
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
snprintf(errorMessage, OPENVZ_MAX_ERROR_LEN - 1,
|
|
|
|
"%s", _("profile length too long"));
|
2007-09-03 15:37:07 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
strncpy(def->profile, (const char *) obj->stringval, OPENVZ_PROFILE_MAX - 1);
|
|
|
|
xmlXPathFreeObject(obj);
|
|
|
|
|
|
|
|
xmlXPathFreeContext(ctxt);
|
2007-07-17 13:27:26 +00:00
|
|
|
return def;
|
|
|
|
|
|
|
|
bail_out:
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(prop);
|
2008-02-07 16:49:29 +00:00
|
|
|
xmlXPathFreeObject(obj);
|
2008-01-29 18:23:43 +00:00
|
|
|
xmlXPathFreeContext(ctxt);
|
2007-07-17 13:27:26 +00:00
|
|
|
openvzFreeVMDef(def);
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
return NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct openvz_vm *
|
|
|
|
openvzGetVPSInfo(virConnectPtr conn) {
|
|
|
|
FILE *fp;
|
|
|
|
int veid, ret;
|
|
|
|
char status[16];
|
2007-07-19 16:22:40 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
2007-07-17 13:27:26 +00:00
|
|
|
struct openvz_vm *vm;
|
|
|
|
struct openvz_vm **pnext;
|
|
|
|
struct openvz_driver *driver;
|
|
|
|
struct openvz_vm_def *vmdef;
|
|
|
|
|
|
|
|
vm = NULL;
|
|
|
|
driver = conn->privateData;
|
|
|
|
driver->num_active = 0;
|
|
|
|
driver->num_inactive = 0;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if((fp = popen(VZLIST " -a -ovpsid,status -H 2>/dev/null", "r")) == NULL) {
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("popen failed"));
|
2007-07-17 13:27:26 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
pnext = &vm;
|
|
|
|
while(!feof(fp)) {
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(*pnext) < 0) {
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("calloc failed"));
|
2007-09-03 16:30:00 +00:00
|
|
|
goto error;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
if(!vm)
|
|
|
|
vm = *pnext;
|
|
|
|
|
2007-09-03 16:30:00 +00:00
|
|
|
if (fscanf(fp, "%d %s\n", &veid, status) != 2) {
|
2008-04-10 16:54:54 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to parse vzlist output"));
|
|
|
|
goto error;
|
|
|
|
}
|
2008-05-14 19:51:24 +00:00
|
|
|
if(STRNEQ(status, "stopped")) {
|
2007-07-17 13:27:26 +00:00
|
|
|
(*pnext)->status = VIR_DOMAIN_RUNNING;
|
|
|
|
driver->num_active ++;
|
|
|
|
(*pnext)->vpsid = veid;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(*pnext)->status = VIR_DOMAIN_SHUTOFF;
|
|
|
|
driver->num_inactive ++;
|
2008-04-10 16:54:54 +00:00
|
|
|
/*
|
|
|
|
* inactive domains don't have their ID set in libvirt,
|
|
|
|
* thought this doesn't make sense for OpenVZ
|
|
|
|
*/
|
2008-02-05 19:27:37 +00:00
|
|
|
(*pnext)->vpsid = -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_ALLOC(vmdef) < 0) {
|
error: mark most string arguments for translation
Also mark some arguments to __virRaiseError.
* Makefile.maint (msg_gen_function): Add error.
* po/POTFILES.in: Add src/openvz_conf.c and src/openvz_driver.c.
* src/openvz_conf.c (openvzParseXML, openvzGetVPSInfo): Mark strings.
* src/openvz_driver.c (openvzDomainLookupByID): Likewise.
(openvzDomainLookupByUUID, openvzDomainLookupByName): Likewise.
(openvzDomainGetInfo, openvzDomainShutdown, openvzDomainReboot)
(openvzDomainCreate, openvzDomainUndefine): Likewise.
* src/remote_internal.c (check_cert_file): Likewise.
(negotiate_gnutls_on_connection, verify_certificate): Likewise.
(remoteAuthenticate, addrToString, remoteAuthSASL): Likewise.
(remoteAuthPolkit, call, really_read_buf): Likewise.
2008-03-27 13:58:56 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("calloc failed"));
|
2008-04-10 16:54:54 +00:00
|
|
|
goto error;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2007-07-17 13:27:26 +00:00
|
|
|
snprintf(vmdef->name, OPENVZ_NAME_MAX, "%i", veid);
|
|
|
|
openvzGetVPSUUID(veid, uuidstr);
|
2007-07-19 16:22:40 +00:00
|
|
|
ret = virUUIDParse(uuidstr, vmdef->uuid);
|
|
|
|
|
|
|
|
if(ret == -1) {
|
2007-09-03 16:30:00 +00:00
|
|
|
error(conn, VIR_ERR_INTERNAL_ERROR,
|
2008-04-10 16:54:54 +00:00
|
|
|
_("UUID in config file malformed"));
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(vmdef);
|
2007-09-03 16:30:00 +00:00
|
|
|
goto error;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(*pnext)->vmdef = vmdef;
|
|
|
|
pnext = &(*pnext)->next;
|
|
|
|
}
|
|
|
|
return vm;
|
2007-09-03 16:30:00 +00:00
|
|
|
error:
|
|
|
|
while (vm != NULL) {
|
|
|
|
struct openvz_vm *next;
|
|
|
|
|
2008-04-10 16:54:54 +00:00
|
|
|
next = vm->next;
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(vm->vmdef);
|
|
|
|
VIR_FREE(vm);
|
2008-04-10 16:54:54 +00:00
|
|
|
vm = next;
|
2007-09-03 16:30:00 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
static char
|
2007-07-19 16:22:40 +00:00
|
|
|
*openvzLocateConfDir(void)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL};
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
while(conf_dir_list[i]) {
|
|
|
|
if(!access(conf_dir_list[i], F_OK))
|
2008-04-10 16:54:54 +00:00
|
|
|
return strdup(conf_dir_list[i]);
|
2007-07-17 13:27:26 +00:00
|
|
|
i ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Richard Steven's classic readline() function */
|
2008-02-05 19:27:37 +00:00
|
|
|
int
|
2007-07-19 16:22:40 +00:00
|
|
|
openvz_readline(int fd, char *ptr, int maxlen)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
int n, rc;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
for(n = 1; n < maxlen; n ++) {
|
|
|
|
if( (rc = read(fd, &c, 1)) == 1) {
|
|
|
|
*ptr++ = c;
|
|
|
|
if(c == '\n')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(rc == 0) {
|
|
|
|
if(n == 1)
|
|
|
|
return 0; /* EOF condition */
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1; /* error */
|
|
|
|
}
|
|
|
|
*ptr = 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
static int
|
2007-09-03 15:37:07 +00:00
|
|
|
openvzGetVPSUUID(int vpsid, char *uuidstr)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
char conf_file[PATH_MAX];
|
|
|
|
char line[1024];
|
2007-09-03 15:37:07 +00:00
|
|
|
char uuidbuf[1024];
|
2007-07-17 13:27:26 +00:00
|
|
|
char iden[1024];
|
|
|
|
char *conf_dir;
|
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
conf_dir = openvzLocateConfDir();
|
2008-02-21 18:22:45 +00:00
|
|
|
if (conf_dir == NULL)
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(conf_dir);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
fd = open(conf_file, O_RDWR);
|
|
|
|
if(fd == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
ret = openvz_readline(fd, line, sizeof(line));
|
|
|
|
if(ret == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if(ret == 0) { /* EoF, UUID was not found */
|
2007-09-03 15:37:07 +00:00
|
|
|
uuidstr[0] = 0;
|
2007-07-17 13:27:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-09-03 15:37:07 +00:00
|
|
|
sscanf(line, "%s %s\n", iden, uuidbuf);
|
2008-05-14 19:51:24 +00:00
|
|
|
if(STREQ(iden, "#UUID:")) {
|
2007-09-03 15:37:07 +00:00
|
|
|
strncpy(uuidstr, uuidbuf, VIR_UUID_STRING_BUFLEN);
|
2007-07-17 13:27:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do actual checking for UUID presence in conf file,
|
|
|
|
* assign if not present.
|
|
|
|
*/
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
static int
|
2007-07-19 16:22:40 +00:00
|
|
|
openvzSetUUID(int vpsid)
|
2007-07-17 13:27:26 +00:00
|
|
|
{
|
|
|
|
char conf_file[PATH_MAX];
|
2007-08-09 20:19:12 +00:00
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
2007-07-17 13:27:26 +00:00
|
|
|
char *conf_dir;
|
|
|
|
|
|
|
|
conf_dir = openvzLocateConfDir();
|
2008-02-21 18:22:45 +00:00
|
|
|
if (conf_dir == NULL)
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(conf_dir);
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2008-02-21 18:48:06 +00:00
|
|
|
if (openvzGetVPSUUID(vpsid, uuidstr))
|
2007-07-17 13:27:26 +00:00
|
|
|
return -1;
|
|
|
|
|
2008-02-21 18:48:06 +00:00
|
|
|
if (uuidstr[0] == 0) {
|
2008-04-10 16:54:54 +00:00
|
|
|
FILE *fp = fopen(conf_file, "a"); /* append */
|
|
|
|
if (fp == NULL)
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
2007-08-09 20:19:12 +00:00
|
|
|
virUUIDGenerate(uuid);
|
|
|
|
virUUIDFormat(uuid, uuidstr);
|
|
|
|
|
2008-04-10 16:54:54 +00:00
|
|
|
/* Record failure if fprintf or fclose fails,
|
|
|
|
and be careful always to close the stream. */
|
|
|
|
if ((fprintf(fp, "\n#UUID: %s\n", uuidstr) < 0)
|
|
|
|
+ (fclose(fp) == EOF))
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan VPS config files and see if they have a UUID.
|
|
|
|
* If not, assign one. Just append one to the config
|
|
|
|
* file as comment so that the OpenVZ tools ignore it.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
int openvzAssignUUIDs(void)
|
|
|
|
{
|
|
|
|
DIR *dp;
|
|
|
|
struct dirent *dent;
|
|
|
|
char *conf_dir;
|
|
|
|
int vpsid, res;
|
|
|
|
char ext[8];
|
|
|
|
|
|
|
|
conf_dir = openvzLocateConfDir();
|
2008-02-21 18:22:45 +00:00
|
|
|
if (conf_dir == NULL)
|
|
|
|
return -1;
|
2007-07-17 13:27:26 +00:00
|
|
|
|
|
|
|
dp = opendir(conf_dir);
|
|
|
|
if(dp == NULL) {
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(conf_dir);
|
2007-07-17 13:27:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while((dent = readdir(dp))) {
|
|
|
|
res = sscanf(dent->d_name, "%d.%5s", &vpsid, ext);
|
2008-05-14 19:51:24 +00:00
|
|
|
if(!(res == 2 && STREQ(ext, "conf")))
|
2007-07-17 13:27:26 +00:00
|
|
|
continue;
|
|
|
|
if(vpsid > 0) /* '0.conf' belongs to the host, ignore it */
|
|
|
|
openvzSetUUID(vpsid);
|
|
|
|
}
|
|
|
|
closedir(dp);
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(conf_dir);
|
2007-07-17 13:27:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|