libvirt/tests/testutilsxen.c
Peter Krempa 27cf98e2d1 virCaps: conf: start splitting out irrelevat data
The virCaps structure gathered a ton of irrelevant data over time that.
The original reason is that it was propagated to the XML parser
functions.

This patch aims to create a new data structure virDomainXMLConf that
will contain immutable data that are used by the XML parser. This will
allow two things we need:

1) Get rid of the stuff from virCaps

2) Allow us to add callbacks to check and add driver specific stuff
after domain XML is parsed.

This first attempt removes pointers to private data allocation functions
to this new structure and update all callers and function that require
them.
2013-03-13 09:27:14 +01:00

87 lines
2.5 KiB
C

#include <config.h>
#include <sys/utsname.h>
#include <stdlib.h>
#include "testutilsxen.h"
#include "domain_conf.h"
static int testXenDefaultConsoleType(const char *ostype,
virArch arch ATTRIBUTE_UNUSED)
{
if (STREQ(ostype, "hvm"))
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
else
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
}
virDomainXMLConfPtr
testXenXMLConfInit(void)
{
return virDomainXMLConfNew(NULL, NULL);
}
virCapsPtr testXenCapsInit(void) {
struct utsname utsname;
virCapsPtr caps;
virCapsGuestPtr guest;
virCapsGuestMachinePtr *machines;
int nmachines;
static const char *const x86_machines[] = {
"xenfv"
};
static const char *const xen_machines[] = {
"xenpv"
};
uname(&utsname);
if ((caps = virCapabilitiesNew(VIR_ARCH_I686,
0, 0)) == NULL)
return NULL;
caps->defaultConsoleTargetType = testXenDefaultConsoleType;
nmachines = ARRAY_CARDINALITY(x86_machines);
if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686,
"/usr/lib/xen/bin/qemu-dm", NULL,
nmachines, machines)) == NULL)
goto cleanup;
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
"xen",
NULL,
NULL,
0,
NULL) == NULL)
goto cleanup;
nmachines = ARRAY_CARDINALITY(xen_machines);
if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "xen", VIR_ARCH_I686,
"/usr/lib/xen/bin/qemu-dm", NULL,
nmachines, machines)) == NULL)
goto cleanup;
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
"xen",
NULL,
NULL,
0,
NULL) == NULL)
goto cleanup;
return caps;
cleanup:
virCapabilitiesFreeMachines(machines, nmachines);
virObjectUnref(caps);
return NULL;
}