mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
network: define new API virNetworkUpdate
This patch adds a new public API virNetworkUpdate that will permit updating an existing network configuration without requiring that the network be destroyed/restarted for the changes to take effect.
This commit is contained in:
parent
76345dd43a
commit
574b9bc66b
@ -2347,6 +2347,72 @@ virNetworkPtr virNetworkDefineXML (virConnectPtr conn,
|
||||
*/
|
||||
int virNetworkUndefine (virNetworkPtr network);
|
||||
|
||||
/**
|
||||
* virNetworkUpdateCommand:
|
||||
*
|
||||
* describes which type of update to perform on a <network>
|
||||
* definition.
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
VIR_NETWORK_UPDATE_COMMAND_NONE = 0, /* (invalid) */
|
||||
VIR_NETWORK_UPDATE_COMMAND_MODIFY = 2, /* modify an existing element */
|
||||
VIR_NETWORK_UPDATE_COMMAND_DELETE = 3, /* delete an existing element */
|
||||
VIR_NETWORK_UPDATE_COMMAND_ADD_LAST = 4, /* add an element at end of list */
|
||||
VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST = 5, /* add an element at start of list */
|
||||
#ifdef VIR_ENUM_SENTINELS
|
||||
VIR_NETWORK_UPDATE_COMMAND_LAST
|
||||
#endif
|
||||
} virNetworkUpdateCommand;
|
||||
|
||||
/**
|
||||
* virNetworkUpdateSection:
|
||||
*
|
||||
* describes which section of a <network> definition the provided
|
||||
* xml should be applied to.
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
VIR_NETWORK_SECTION_NONE = 0, /* (invalid) */
|
||||
VIR_NETWORK_SECTION_BRIDGE = 1, /* <bridge> */
|
||||
VIR_NETWORK_SECTION_DOMAIN = 2, /* <domain> */
|
||||
VIR_NETWORK_SECTION_IP = 3, /* <ip> */
|
||||
VIR_NETWORK_SECTION_IP_DHCP_HOST = 4, /* <ip>/<dhcp>/<host> */
|
||||
VIR_NETWORK_SECTION_IP_DHCP_RANGE = 5, /* <ip>/<dhcp>/<range> */
|
||||
VIR_NETWORK_SECTION_FORWARD = 6, /* <forward> */
|
||||
VIR_NETWORK_SECTION_FORWARD_INTERFACE = 7, /* <forward>/<interface> */
|
||||
VIR_NETWORK_SECTION_FORWARD_PF = 8, /* <forward>/<pf> */
|
||||
VIR_NETWORK_SECTION_PORTGROUP = 9, /* <portgroup> */
|
||||
VIR_NETWORK_SECTION_DNS_HOST = 10, /* <dns>/<host> */
|
||||
VIR_NETWORK_SECTION_DNS_TXT = 11, /* <dns>/<txt> */
|
||||
VIR_NETWORK_SECTION_DNS_SRV = 12, /* <dns>/<srv> */
|
||||
#ifdef VIR_ENUM_SENTINELS
|
||||
VIR_NETWORK_SECTION_LAST
|
||||
#endif
|
||||
} virNetworkUpdateSection;
|
||||
|
||||
/**
|
||||
* virNetworkUpdateFlags:
|
||||
*
|
||||
* Flags to control options for virNetworkUpdate()
|
||||
*/
|
||||
typedef enum {
|
||||
VIR_NETWORK_UPDATE_AFFECT_CURRENT = 0, /* affect live if network is active,
|
||||
config if it's not active */
|
||||
VIR_NETWORK_UPDATE_AFFECT_LIVE = 1 << 0, /* affect live state of network only */
|
||||
VIR_NETWORK_UPDATE_AFFECT_CONFIG = 1 << 1, /* affect persistent config only */
|
||||
} virNetworkUpdateFlags;
|
||||
|
||||
/*
|
||||
* Update an existing network definition
|
||||
*/
|
||||
int virNetworkUpdate(virNetworkPtr network,
|
||||
unsigned int command, /* virNetworkUpdateCommand */
|
||||
unsigned int section, /* virNetworkUpdateSection */
|
||||
int parentIndex,
|
||||
const char *xml,
|
||||
unsigned int flags);
|
||||
|
||||
/*
|
||||
* Activate persistent network
|
||||
*/
|
||||
|
@ -1119,6 +1119,13 @@ typedef virNetworkPtr
|
||||
const char *xml);
|
||||
typedef int
|
||||
(*virDrvNetworkUndefine) (virNetworkPtr network);
|
||||
typedef int
|
||||
(*virDrvNetworkUpdate) (virNetworkPtr network,
|
||||
unsigned int command, /* virNetworkUpdateCommand */
|
||||
unsigned int section, /* virNetworkUpdateSection */
|
||||
int parentIndex,
|
||||
const char *xml,
|
||||
unsigned int flags);
|
||||
typedef int
|
||||
(*virDrvNetworkCreate) (virNetworkPtr network);
|
||||
typedef int
|
||||
@ -1169,6 +1176,7 @@ struct _virNetworkDriver {
|
||||
virDrvNetworkCreateXML networkCreateXML;
|
||||
virDrvNetworkDefineXML networkDefineXML;
|
||||
virDrvNetworkUndefine networkUndefine;
|
||||
virDrvNetworkUpdate networkUpdate;
|
||||
virDrvNetworkCreate networkCreate;
|
||||
virDrvNetworkDestroy networkDestroy;
|
||||
virDrvNetworkGetXMLDesc networkGetXMLDesc;
|
||||
|
@ -10406,6 +10406,68 @@ error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNetworkUpdate:
|
||||
* @network: pointer to a defined network
|
||||
* @section: which section of the network to update
|
||||
* (see virNetworkUpdateSection for descriptions)
|
||||
* @command: what action to perform (add/delete/modify)
|
||||
* (see virNetworkUpdateCommand for descriptions)
|
||||
* @parentIndex: which parent element, if there are multiple parents
|
||||
* of the same type (e.g. which <ip> element when modifying
|
||||
* a <dhcp>/<host> element), or "-1" for "don't care" or
|
||||
* "automatically find appropriate one".
|
||||
* @xml: the XML description for the network, preferably in UTF-8
|
||||
* @flags: bitwise OR of virNetworkUpdateFlags.
|
||||
*
|
||||
* Update the definition of an existing network, either its live
|
||||
* running state, its persistent configuration, or both.
|
||||
*
|
||||
* Returns 0 in case of success, -1 in case of error
|
||||
*/
|
||||
int
|
||||
virNetworkUpdate(virNetworkPtr network,
|
||||
unsigned int command, /* virNetworkUpdateCommand */
|
||||
unsigned int section, /* virNetworkUpdateSection */
|
||||
int parentIndex,
|
||||
const char *xml,
|
||||
unsigned int flags)
|
||||
{
|
||||
virConnectPtr conn;
|
||||
VIR_DEBUG("network=%p, section=%d, parentIndex=%d, xml=%s, flags=0x%x",
|
||||
network, section, parentIndex, xml, flags);
|
||||
|
||||
virResetLastError();
|
||||
|
||||
if (!VIR_IS_CONNECTED_NETWORK(network)) {
|
||||
virLibNetworkError(VIR_ERR_INVALID_NETWORK, __FUNCTION__);
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
conn = network->conn;
|
||||
if (conn->flags & VIR_CONNECT_RO) {
|
||||
virLibNetworkError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
|
||||
goto error;
|
||||
}
|
||||
|
||||
virCheckNonNullArgGoto(xml, error);
|
||||
|
||||
if (conn->networkDriver && conn->networkDriver->networkUpdate) {
|
||||
int ret;
|
||||
ret = conn->networkDriver->networkUpdate(network, section, command,
|
||||
parentIndex, xml, flags);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
return ret;
|
||||
}
|
||||
|
||||
virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
|
||||
|
||||
error:
|
||||
virDispatchError(network->conn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNetworkCreate:
|
||||
* @network: pointer to a defined network
|
||||
|
@ -563,6 +563,7 @@ LIBVIRT_0.10.2 {
|
||||
virConnectListAllSecrets;
|
||||
virConnectListAllStoragePools;
|
||||
virDomainBlockCommit;
|
||||
virNetworkUpdate;
|
||||
virNodeGetMemoryParameters;
|
||||
virNodeSetMemoryParameters;
|
||||
virStoragePoolListAllVolumes;
|
||||
|
Loading…
x
Reference in New Issue
Block a user