static int testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion) { char *xmlData = NULL; char *xmcfgData = NULL; char *gotxml = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn; struct _xenUnifiedPrivate priv; virDomainDefPtr def = NULL; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xml, &xmlData) < 0) goto fail; if (virtTestLoadFile(xmcfg, &xmcfgData) < 0) goto fail; /* Many puppies died to bring you this code. */ priv.xendConfigVersion = xendConfigVersion; priv.caps = caps; conn->privateData = &priv; if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0))) goto fail; if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps))) goto fail; if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE))) goto fail; if (STRNEQ(xmlData, gotxml)) { virtTestDifference(stderr, xmlData, gotxml); goto fail; } ret = 0; fail: if (conf) virConfFree(conf); VIR_FREE(xmlData); VIR_FREE(xmcfgData); VIR_FREE(gotxml); virDomainDefFree(def); virObjectUnref(conn); return ret; }
int daemonConfigLoadData(struct daemonConfig *data, const char *filename, const char *filedata) { virConfPtr conf; int ret; conf = virConfReadMem(filedata, strlen(filedata), 0); if (!conf) return -1; ret = daemonConfigLoadOptions(data, filename, conf); virConfFree(conf); return ret; }
static int testCompareFormatXML(const char *xmcfg, const char *xml) { char *xmcfgData = NULL; char *gotxml = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn; struct _xenUnifiedPrivate priv; virDomainDefPtr def = NULL; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xmcfg, &xmcfgData) < 0) goto fail; /* Many puppies died to bring you this code. */ priv.caps = caps; conn->privateData = &priv; if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0))) goto fail; if (!(def = xenParseXM(conf, caps, xmlopt))) goto fail; if (!(gotxml = virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto fail; if (virtTestCompareToFile(gotxml, xml) < 0) goto fail; ret = 0; fail: if (conf) virConfFree(conf); VIR_FREE(xmcfgData); VIR_FREE(gotxml); virDomainDefFree(def); virObjectUnref(conn); return ret; }
/* * Parses xl.cfg(5) config to virDomainDef object, which is then converted to * domXML and compared to expected XML. */ static int testCompareFormatXML(const char *xlcfg, const char *xml) { char *xlcfgData = NULL; char *gotxml = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn; virDomainDefPtr def = NULL; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xlcfg, &xlcfgData) < 0) goto fail; if (!(conf = virConfReadMem(xlcfgData, strlen(xlcfgData), 0))) goto fail; if (!(def = xenParseXL(conf, caps, xmlopt))) goto fail; if (!(gotxml = virDomainDefFormat(def, caps, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE))) goto fail; if (virtTestCompareToFile(gotxml, xml) < 0) goto fail; ret = 0; fail: if (conf) virConfFree(conf); VIR_FREE(xlcfgData); VIR_FREE(gotxml); virDomainDefFree(def); virObjectUnref(conn); return ret; }
virDomainDefPtr lxcParseConfigString(const char *config, virCapsPtr caps, virDomainXMLOptionPtr xmlopt) { virDomainDefPtr vmdef = NULL; virConfPtr properties = NULL; virConfValuePtr value; if (!(properties = virConfReadMem(config, 0, VIR_CONF_FLAG_LXC_FORMAT))) return NULL; if (!(vmdef = virDomainDefNew())) goto error; if (virUUIDGenerate(vmdef->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to generate uuid")); goto error; } vmdef->id = -1; virDomainDefSetMemoryTotal(vmdef, 64 * 1024); vmdef->onReboot = VIR_DOMAIN_LIFECYCLE_RESTART; vmdef->onCrash = VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY; vmdef->onPoweroff = VIR_DOMAIN_LIFECYCLE_DESTROY; vmdef->virtType = VIR_DOMAIN_VIRT_LXC; /* Value not handled by the LXC driver, setting to * minimum required to make XML parsing pass */ if (virDomainDefSetVcpusMax(vmdef, 1) < 0) goto error; if (virDomainDefSetVcpus(vmdef, 1) < 0) goto error; vmdef->nfss = 0; vmdef->os.type = VIR_DOMAIN_OSTYPE_EXE; if ((value = virConfGetValue(properties, "lxc.arch")) && value->str) { virArch arch = virArchFromString(value->str); if (arch == VIR_ARCH_NONE && STREQ(value->str, "x86")) arch = VIR_ARCH_I686; else if (arch == VIR_ARCH_NONE && STREQ(value->str, "amd64")) arch = VIR_ARCH_X86_64; vmdef->os.arch = arch; } if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0) goto error; if (!(value = virConfGetValue(properties, "lxc.utsname")) || !value->str || (VIR_STRDUP(vmdef->name, value->str) < 0)) goto error; if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") < 0)) goto error; if (lxcSetRootfs(vmdef, properties) < 0) goto error; /* Look for fstab: we shouldn't have it */ if (virConfGetValue(properties, "lxc.mount")) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("lxc.mount found, use lxc.mount.entry lines instead")); goto error; } /* Loop over lxc.mount.entry to add filesystem devices for them */ if (virConfWalk(properties, lxcFstabWalkCallback, vmdef) < 0) goto error; /* Network configuration */ if (lxcConvertNetworkSettings(vmdef, properties) < 0) goto error; /* Consoles */ if (lxcCreateConsoles(vmdef, properties) < 0) goto error; /* lxc.id_map */ if (virConfWalk(properties, lxcIdmapWalkCallback, vmdef) < 0) goto error; /* lxc.cgroup.memory.* */ if (lxcSetMemTune(vmdef, properties) < 0) goto error; /* lxc.cgroup.cpu.* */ if (lxcSetCpuTune(vmdef, properties) < 0) goto error; /* lxc.cgroup.cpuset.* */ if (lxcSetCpusetTune(vmdef, properties) < 0) goto error; /* lxc.cgroup.blkio.* */ if (lxcSetBlkioTune(vmdef, properties) < 0) goto error; /* lxc.cap.drop */ lxcSetCapDrop(vmdef, properties); if (virDomainDefPostParse(vmdef, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, xmlopt) < 0) goto cleanup; goto cleanup; error: virDomainDefFree(vmdef); vmdef = NULL; cleanup: virConfFree(properties); return vmdef; }