static char * bhyveConnectGetCapabilities(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; virCapsPtr caps; char *xml = NULL; if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL; if (!(caps = bhyveDriverGetCapabilities(privconn))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to get Capabilities")); goto cleanup; } if (!(xml = virCapabilitiesFormatXML(caps))) { virReportOOMError(); goto cleanup; } cleanup: virObjectUnref(caps); return xml; }
static char * bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) { bhyveConnPtr privconn = domain->conn->privateData; virDomainObjPtr vm; virCapsPtr caps = NULL; char *ret = NULL; if (!(vm = bhyveDomObjFromDomain(domain))) goto cleanup; if (virDomainGetXMLDescEnsureACL(domain->conn, vm->def, flags) < 0) goto cleanup; caps = bhyveDriverGetCapabilities(privconn); if (!caps) goto cleanup; ret = virDomainDefFormat(vm->def, caps, virDomainDefFormatConvertXMLFlags(flags)); virObjectUnref(caps); cleanup: if (vm) virObjectUnlock(vm); return ret; }
static char * bhyveConnectDomainXMLToNative(virConnectPtr conn, const char *format, const char *xmlData, unsigned int flags) { virBuffer buf = VIR_BUFFER_INITIALIZER; bhyveConnPtr privconn = conn->privateData; virDomainDefPtr def = NULL; virCommandPtr cmd = NULL, loadcmd = NULL; virCapsPtr caps = NULL; char *ret = NULL; virCheckFlags(0, NULL); if (virConnectDomainXMLToNativeEnsureACL(conn) < 0) goto cleanup; if (STRNEQ(format, BHYVE_CONFIG_FORMAT_ARGV)) { virReportError(VIR_ERR_INVALID_ARG, _("Unsupported config type %s"), format); goto cleanup; } if (!(caps = bhyveDriverGetCapabilities(privconn))) goto cleanup; if (!(def = virDomainDefParseString(xmlData, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; if (bhyveDomainAssignAddresses(def, NULL) < 0) goto cleanup; if (!(loadcmd = virBhyveProcessBuildLoadCmd(privconn, def))) goto cleanup; if (!(cmd = virBhyveProcessBuildBhyveCmd(privconn, def, true))) goto cleanup; virBufferAdd(&buf, virCommandToString(loadcmd), -1); virBufferAddChar(&buf, '\n'); virBufferAdd(&buf, virCommandToString(cmd), -1); if (virBufferError(&buf)) { virReportOOMError(); goto cleanup; } ret = virBufferContentAndReset(&buf); cleanup: virCommandFree(loadcmd); virCommandFree(cmd); virDomainDefFree(def); virObjectUnref(caps); return ret; }
static virDomainPtr bhyveDomainDefineXML(virConnectPtr conn, const char *xml) { bhyveConnPtr privconn = conn->privateData; virDomainPtr dom = NULL; virDomainDefPtr def = NULL; virDomainDefPtr oldDef = NULL; virDomainObjPtr vm = NULL; virCapsPtr caps = NULL; caps = bhyveDriverGetCapabilities(privconn); if (!caps) return NULL; if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if (virDomainDefineXMLEnsureACL(conn, def) < 0) goto cleanup; if (!(vm = virDomainObjListAdd(privconn->domains, def, privconn->xmlopt, 0, &oldDef))) goto cleanup; def = NULL; vm->persistent = 1; dom = virGetDomain(conn, vm->def->name, vm->def->uuid); if (dom) dom->id = vm->def->id; if (virDomainSaveConfig(BHYVE_CONFIG_DIR, vm->def) < 0) goto cleanup; cleanup: virObjectUnref(caps); virDomainDefFree(def); virObjectUnlock(vm); return dom; }
static virDomainPtr bhyveDomainCreateXML(virConnectPtr conn, const char *xml, unsigned int flags) { bhyveConnPtr privconn = conn->privateData; virDomainPtr dom = NULL; virDomainDefPtr def = NULL; virDomainObjPtr vm = NULL; virObjectEventPtr event = NULL; virCapsPtr caps = NULL; unsigned int start_flags = 0; virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL); if (flags & VIR_DOMAIN_START_AUTODESTROY) start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY; caps = bhyveDriverGetCapabilities(privconn); if (!caps) return NULL; if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if (virDomainCreateXMLEnsureACL(conn, def) < 0) goto cleanup; if (bhyveDomainAssignAddresses(def, NULL) < 0) goto cleanup; if (!(vm = virDomainObjListAdd(privconn->domains, def, privconn->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; def = NULL; if (virBhyveProcessStart(conn, privconn, vm, VIR_DOMAIN_RUNNING_BOOTED, start_flags) < 0) { /* If domain is not persistent, remove its data */ if (!vm->persistent) { virDomainObjListRemove(privconn->domains, vm); vm = NULL; } goto cleanup; } event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_BOOTED); dom = virGetDomain(conn, vm->def->name, vm->def->uuid); if (dom) dom->id = vm->def->id; cleanup: virObjectUnref(caps); virDomainDefFree(def); if (vm) virObjectUnlock(vm); if (event) virObjectEventStateQueue(privconn->domainEventState, event); return dom; }
static virDomainPtr bhyveDomainDefineXML(virConnectPtr conn, const char *xml) { bhyveConnPtr privconn = conn->privateData; virDomainPtr dom = NULL; virDomainDefPtr def = NULL; virDomainDefPtr oldDef = NULL; virDomainObjPtr vm = NULL; virObjectEventPtr event = NULL; virCapsPtr caps = NULL; caps = bhyveDriverGetCapabilities(privconn); if (!caps) return NULL; if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if (virDomainDefineXMLEnsureACL(conn, def) < 0) goto cleanup; if (bhyveDomainAssignAddresses(def, NULL) < 0) goto cleanup; if (!(vm = virDomainObjListAdd(privconn->domains, def, privconn->xmlopt, 0, &oldDef))) goto cleanup; def = NULL; vm->persistent = 1; if (virDomainSaveConfig(BHYVE_CONFIG_DIR, vm->newDef ? vm->newDef : vm->def) < 0) { virDomainObjListRemove(privconn->domains, vm); vm = NULL; goto cleanup; } event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_DEFINED, !oldDef ? VIR_DOMAIN_EVENT_DEFINED_ADDED : VIR_DOMAIN_EVENT_DEFINED_UPDATED); dom = virGetDomain(conn, vm->def->name, vm->def->uuid); if (dom) dom->id = vm->def->id; cleanup: virObjectUnref(caps); virDomainDefFree(def); virDomainDefFree(oldDef); if (vm) virObjectUnlock(vm); if (event) virObjectEventStateQueue(privconn->domainEventState, event); return dom; }