This will be the entry point to JSON-based APIs for all non-internal users. Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- include/libvirt/libvirt-domain.h | 3 +++ src/driver-hypervisor.h | 6 +++++ src/libvirt-domain.c | 45 ++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 4 files changed, 55 insertions(+) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 7d36820b5a..193c9ef24f 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1777,6 +1777,9 @@ virDomainPtr virDomainDefineXML (virConnectPtr conn, virDomainPtr virDomainDefineXMLFlags (virConnectPtr conn, const char *xml, unsigned int flags); +virDomainPtr virDomainDefineJSONFlags (virConnectPtr conn, + const char *json, + unsigned int flags); int virDomainUndefine (virDomainPtr domain); typedef enum { diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 5315e33dde..4b2a0ca443 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1328,6 +1328,11 @@ typedef int int *nparams, unsigned int flags); +typedef virDomainPtr +(*virDrvDomainDefineJSONFlags)(virConnectPtr conn, + const char *json, + unsigned int flags); + typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1580,6 +1585,7 @@ struct _virHypervisorDriver { virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU; virDrvNodeGetSEVInfo nodeGetSEVInfo; virDrvDomainGetLaunchSecurityInfo domainGetLaunchSecurityInfo; + virDrvDomainDefineJSONFlags domainDefineJSONFlags; }; diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index be5b1f6740..7c2fcd9f09 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -6217,6 +6217,51 @@ virDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) } +/** + * virDomainDefineJSONFlags: + * @conn: pointer to the hypervisor connection + * @json: the JSON description for the domain, preferably in UTF-8 + * @flags: bitwise OR of the virDomainDefineFlags constants + * + * Defines a domain, but does not start it. + * This definition is persistent, until explicitly undefined with + * virDomainUndefine(). A previous definition for this domain would be + * overridden if it already exists. + * + * virDomainFree should be used to free the resources after the + * domain object is no longer needed. + * + * Returns NULL in case of error, a pointer to the domain otherwise + */ +virDomainPtr +virDomainDefineJSONFlags(virConnectPtr conn, + const char *json, + unsigned int flags) +{ + VIR_DEBUG("conn=%p, json=%s flags=0x%x", conn, NULLSTR(json), flags); + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckReadOnlyGoto(conn->flags, error); + virCheckNonNullArgGoto(json, error); + + if (conn->driver->domainDefineJSONFlags) { + virDomainPtr ret; + ret = conn->driver->domainDefineJSONFlags(conn, json, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + /** * virDomainUndefine: * @domain: pointer to a defined domain diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index dbce3336d5..fe63b51cdb 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -817,6 +817,7 @@ LIBVIRT_4.10.0 { LIBVIRT_5.2.0 { global: virConnectGetStoragePoolCapabilities; + virDomainDefineJSONFlags; } LIBVIRT_4.10.0; # .... define new API here using predicted next version number .... -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list