api: add public virNetworkCreateXMLFlags() and remote protocol

This new API creates network with given flags.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-09-15 13:07:27 +02:00 committed by Michal Privoznik
parent ddba9f1dc9
commit 6a0a2840cf
7 changed files with 77 additions and 1 deletions

View File

@ -118,6 +118,9 @@ virNetworkPtr virNetworkLookupByUUIDString (virConnectPtr conn,
*/
virNetworkPtr virNetworkCreateXML (virConnectPtr conn,
const char *xmlDesc);
virNetworkPtr virNetworkCreateXMLFlags(virConnectPtr conn,
const char *xmlDesc,
unsigned int flags);
typedef enum {
VIR_NETWORK_DEFINE_VALIDATE = 1 << 0, /* Validate the XML document against schema */

View File

@ -69,6 +69,11 @@ typedef virNetworkPtr
(*virDrvNetworkCreateXML)(virConnectPtr conn,
const char *xmlDesc);
typedef virNetworkPtr
(*virDrvNetworkCreateXMLFlags)(virConnectPtr conn,
const char *xmlDesc,
unsigned int flags);
typedef virNetworkPtr
(*virDrvNetworkDefineXML)(virConnectPtr conn,
const char *xml);
@ -176,6 +181,7 @@ struct _virNetworkDriver {
virDrvNetworkLookupByUUID networkLookupByUUID;
virDrvNetworkLookupByName networkLookupByName;
virDrvNetworkCreateXML networkCreateXML;
virDrvNetworkCreateXMLFlags networkCreateXMLFlags;
virDrvNetworkDefineXML networkDefineXML;
virDrvNetworkDefineXMLFlags networkDefineXMLFlags;
virDrvNetworkUndefine networkUndefine;

View File

@ -427,6 +427,47 @@ virNetworkCreateXML(virConnectPtr conn, const char *xmlDesc)
}
/**
* virNetworkCreateXMLFlags:
* @conn: pointer to the hypervisor connection
* @xmlDesc: an XML description of the network
* @flags: extra flags; not used yet, so callers should always pass 0
*
* Create and start a new virtual network, based on an XML description
* similar to the one returned by virNetworkGetXMLDesc()
*
* virNetworkFree should be used to free the resources after the
* network object is no longer needed.
*
* Returns a new network object or NULL in case of failure
*/
virNetworkPtr
virNetworkCreateXMLFlags(virConnectPtr conn, const char *xmlDesc, unsigned int flags)
{
VIR_DEBUG("conn=%p, xmlDesc=%s, flags=0x%x", conn, NULLSTR(xmlDesc), flags);
virResetLastError();
virCheckConnectReturn(conn, NULL);
virCheckNonNullArgGoto(xmlDesc, error);
virCheckReadOnlyGoto(conn->flags, error);
if (conn->networkDriver && conn->networkDriver->networkCreateXMLFlags) {
virNetworkPtr ret;
ret = conn->networkDriver->networkCreateXMLFlags(conn, xmlDesc, flags);
if (!ret)
goto error;
return ret;
}
virReportUnsupportedError();
error:
virDispatchError(conn);
return NULL;
}
/**
* virNetworkDefineXML:
* @conn: pointer to the hypervisor connection

View File

@ -908,6 +908,7 @@ LIBVIRT_7.8.0 {
virNodeDeviceGetAutostart;
virNodeDeviceIsPersistent;
virNodeDeviceIsActive;
virNetworkCreateXMLFlags;
} LIBVIRT_7.7.0;
# .... define new API here using predicted next version number ....

View File

@ -8552,6 +8552,7 @@ static virNetworkDriver network_driver = {
.networkLookupByUUID = remoteNetworkLookupByUUID, /* 0.3.0 */
.networkLookupByName = remoteNetworkLookupByName, /* 0.3.0 */
.networkCreateXML = remoteNetworkCreateXML, /* 0.3.0 */
.networkCreateXMLFlags = remoteNetworkCreateXMLFlags, /* 7.8.0 */
.networkDefineXML = remoteNetworkDefineXML, /* 0.3.0 */
.networkDefineXMLFlags = remoteNetworkDefineXMLFlags, /* 7.7.0 */
.networkUndefine = remoteNetworkUndefine, /* 0.3.0 */

View File

@ -1530,6 +1530,15 @@ struct remote_network_create_xml_ret {
remote_nonnull_network net;
};
struct remote_network_create_xml_flags_args {
remote_nonnull_string xml;
unsigned int flags;
};
struct remote_network_create_xml_flags_ret {
remote_nonnull_network net;
};
struct remote_network_define_xml_args {
remote_nonnull_string xml;
};
@ -6875,6 +6884,13 @@ enum remote_procedure {
* @priority: high
* @acl: node_device:read
*/
REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 436
REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 436,
/**
* @generate: both
* @priority: high
* @acl: network:write
* @acl: network:start
*/
REMOTE_PROC_NETWORK_CREATE_XML_FLAGS = 437
};

View File

@ -1098,6 +1098,13 @@ struct remote_network_create_xml_args {
struct remote_network_create_xml_ret {
remote_nonnull_network net;
};
struct remote_network_create_xml_flags_args {
remote_nonnull_string xml;
u_int flags;
};
struct remote_network_create_xml_flags_ret {
remote_nonnull_network net;
};
struct remote_network_define_xml_args {
remote_nonnull_string xml;
};
@ -3665,4 +3672,5 @@ enum remote_procedure {
REMOTE_PROC_NODE_DEVICE_SET_AUTOSTART = 434,
REMOTE_PROC_NODE_DEVICE_IS_PERSISTENT = 435,
REMOTE_PROC_NODE_DEVICE_IS_ACTIVE = 436,
REMOTE_PROC_NETWORK_CREATE_XML_FLAGS = 437,
};