Provides APIs for the management of networks
#define VIR_NETWORK_EVENT_CALLBACK #define VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE #define VIR_NETWORK_PORT_BANDWIDTH_IN_BURST #define VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR #define VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK #define VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE #define VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST #define VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK
typedef enum virConnectListAllNetworksFlags typedef enum virIPAddrType typedef struct _virNetwork virNetwork typedef enum virNetworkCreateFlags typedef struct _virNetworkDHCPLease virNetworkDHCPLease typedef virNetworkDHCPLease * virNetworkDHCPLeasePtr typedef enum virNetworkDefineFlags typedef enum virNetworkEventID typedef enum virNetworkEventLifecycleType typedef enum virNetworkMetadataType typedef struct _virNetworkPort virNetworkPort typedef enum virNetworkPortCreateFlags typedef virNetworkPort * virNetworkPortPtr typedef virNetwork * virNetworkPtr typedef enum virNetworkUpdateCommand typedef enum virNetworkUpdateFlags typedef enum virNetworkUpdateSection typedef enum virNetworkXMLFlags
int virConnectListAllNetworks (virConnectPtr conn,
virNetworkPtr ** nets,
unsigned int flags) int virConnectListDefinedNetworks (virConnectPtr conn,
char ** const names,
int maxnames) int virConnectListNetworks (virConnectPtr conn,
char ** const names,
int maxnames) int virConnectNetworkEventDeregisterAny (virConnectPtr conn,
int callbackID) typedef virConnectNetworkEventGenericCallback void virConnectNetworkEventGenericCallback (virConnectPtr conn,
virNetworkPtr net,
void * opaque) typedef virConnectNetworkEventLifecycleCallback void virConnectNetworkEventLifecycleCallback (virConnectPtr conn,
virNetworkPtr net,
int event,
int detail,
void * opaque) typedef virConnectNetworkEventMetadataChangeCallback void virConnectNetworkEventMetadataChangeCallback (virConnectPtr conn,
virNetworkPtr net,
int type,
const char * nsuri,
void * opaque) int virConnectNetworkEventRegisterAny (virConnectPtr conn,
virNetworkPtr net,
int eventID,
virConnectNetworkEventGenericCallback cb,
void * opaque,
virFreeCallback freecb) int virConnectNumOfDefinedNetworks (virConnectPtr conn) int virConnectNumOfNetworks (virConnectPtr conn) int virNetworkCreate (virNetworkPtr network) virNetworkPtr virNetworkCreateXML (virConnectPtr conn,
const char * xmlDesc) virNetworkPtr virNetworkCreateXMLFlags (virConnectPtr conn,
const char * xmlDesc,
unsigned int flags) void virNetworkDHCPLeaseFree (virNetworkDHCPLeasePtr lease) virNetworkPtr virNetworkDefineXML (virConnectPtr conn,
const char * xml) virNetworkPtr virNetworkDefineXMLFlags (virConnectPtr conn,
const char * xml,
unsigned int flags) int virNetworkDestroy (virNetworkPtr network) int virNetworkFree (virNetworkPtr network) int virNetworkGetAutostart (virNetworkPtr network,
int * autostart) char * virNetworkGetBridgeName (virNetworkPtr network) virConnectPtr virNetworkGetConnect (virNetworkPtr net) int virNetworkGetDHCPLeases (virNetworkPtr network,
const char * mac,
virNetworkDHCPLeasePtr ** leases,
unsigned int flags) char * virNetworkGetMetadata (virNetworkPtr network,
int type,
const char * uri,
unsigned int flags) const char * virNetworkGetName (virNetworkPtr network) int virNetworkGetUUID (virNetworkPtr network,
unsigned char * uuid) int virNetworkGetUUIDString (virNetworkPtr network,
char * buf) char * virNetworkGetXMLDesc (virNetworkPtr network,
unsigned int flags) int virNetworkIsActive (virNetworkPtr net) int virNetworkIsPersistent (virNetworkPtr net) int virNetworkListAllPorts (virNetworkPtr network,
virNetworkPortPtr ** ports,
unsigned int flags) virNetworkPtr virNetworkLookupByName (virConnectPtr conn,
const char * name) virNetworkPtr virNetworkLookupByUUID (virConnectPtr conn,
const unsigned char * uuid) virNetworkPtr virNetworkLookupByUUIDString (virConnectPtr conn,
const char * uuidstr) virNetworkPortPtr virNetworkPortCreateXML (virNetworkPtr net,
const char * xmldesc,
unsigned int flags) int virNetworkPortDelete (virNetworkPortPtr port,
unsigned int flags) int virNetworkPortFree (virNetworkPortPtr port) virNetworkPtr virNetworkPortGetNetwork (virNetworkPortPtr port) int virNetworkPortGetParameters (virNetworkPortPtr port,
virTypedParameterPtr * params,
int * nparams,
unsigned int flags) int virNetworkPortGetUUID (virNetworkPortPtr port,
unsigned char * uuid) int virNetworkPortGetUUIDString (virNetworkPortPtr port,
char * buf) char * virNetworkPortGetXMLDesc (virNetworkPortPtr port,
unsigned int flags) virNetworkPortPtr virNetworkPortLookupByUUID (virNetworkPtr net,
const unsigned char * uuid) virNetworkPortPtr virNetworkPortLookupByUUIDString (virNetworkPtr net,
const char * uuidstr) int virNetworkPortRef (virNetworkPortPtr port) int virNetworkPortSetParameters (virNetworkPortPtr port,
virTypedParameterPtr params,
int nparams,
unsigned int flags) int virNetworkRef (virNetworkPtr network) int virNetworkSetAutostart (virNetworkPtr network,
int autostart) int virNetworkSetMetadata (virNetworkPtr network,
int type,
const char * metadata,
const char * key,
const char * uri,
unsigned int flags) int virNetworkUndefine (virNetworkPtr network) int virNetworkUpdate (virNetworkPtr network,
unsigned int command,
unsigned int section,
int parentIndex,
const char * xml,
unsigned int flags)
VIR_NETWORK_EVENT_CALLBACK
¶#define VIR_NETWORK_EVENT_CALLBACK
Used to cast the event specific callback into the generic one for use for virConnectNetworkEventRegisterAny()
VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE
¶#define VIR_NETWORK_PORT_BANDWIDTH_IN_AVERAGE
Macro represents the inbound average of NIC bandwidth, as a uint.
VIR_NETWORK_PORT_BANDWIDTH_IN_BURST
¶#define VIR_NETWORK_PORT_BANDWIDTH_IN_BURST
Macro represents the inbound burst of NIC bandwidth, as a uint.
VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR
¶#define VIR_NETWORK_PORT_BANDWIDTH_IN_FLOOR
Macro represents the inbound floor of NIC bandwidth, as a uint.
VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK
¶#define VIR_NETWORK_PORT_BANDWIDTH_IN_PEAK
Macro represents the inbound peak of NIC bandwidth, as a uint.
VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE
¶#define VIR_NETWORK_PORT_BANDWIDTH_OUT_AVERAGE
Macro represents the outbound average of NIC bandwidth, as a uint.
VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST
¶#define VIR_NETWORK_PORT_BANDWIDTH_OUT_BURST
Macro represents the outbound burst of NIC bandwidth, as a uint.
VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK
¶#define VIR_NETWORK_PORT_BANDWIDTH_OUT_PEAK
Macro represents the outbound peak of NIC bandwidth, as a uint.
virConnectListAllNetworksFlags
¶Flags used to filter the returned networks. Flags in each group are exclusive attributes of a network.
enum virConnectListAllNetworksFlags {
VIR_CONNECT_LIST_NETWORKS_INACTIVE | = | 1 (0x1; 1 << 0) | |
VIR_CONNECT_LIST_NETWORKS_ACTIVE | = | 2 (0x2; 1 << 1) | |
VIR_CONNECT_LIST_NETWORKS_PERSISTENT | = | 4 (0x4; 1 << 2) | |
VIR_CONNECT_LIST_NETWORKS_TRANSIENT | = | 8 (0x8; 1 << 3) | |
VIR_CONNECT_LIST_NETWORKS_AUTOSTART | = | 16 (0x10; 1 << 4) | |
VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART | = | 32 (0x20; 1 << 5) |
}
virIPAddrType
¶enum virIPAddrType {
VIR_IP_ADDR_TYPE_IPV4 | = | 0 (0x0) | |
VIR_IP_ADDR_TYPE_IPV6 | = | 1 (0x1) | |
VIR_IP_ADDR_TYPE_LAST | = | 2 (0x2) |
}
virNetwork
¶struct virNetwork {
}
virNetworkCreateFlags
¶enum virNetworkCreateFlags {
VIR_NETWORK_CREATE_VALIDATE | = | 1 (0x1; 1 << 0) | Validate the XML document against schema |
}
virNetworkDHCPLease
¶struct virNetworkDHCPLease {
char * | iface | Network interface name |
long long | expirytime | Seconds since epoch |
int | type | |
char * | mac | MAC address |
char * | iaid | IAID |
char * | ipaddr | IP address |
unsigned int | prefix | IP address prefix |
char * | hostname | Hostname |
char * | clientid | Client ID or DUID |
}
virNetworkDHCPLeasePtr
¶typedef virNetworkDHCPLease * virNetworkDHCPLeasePtr;
virNetworkDefineFlags
¶enum virNetworkDefineFlags {
VIR_NETWORK_DEFINE_VALIDATE | = | 1 (0x1; 1 << 0) | Validate the XML document against schema |
}
virNetworkEventID
¶An enumeration of supported eventId parameters for virConnectNetworkEventRegisterAny(). Each event id determines which signature of callback function will be used.
enum virNetworkEventID {
VIR_NETWORK_EVENT_ID_LIFECYCLE | = | 0 (0x0) | |
VIR_NETWORK_EVENT_ID_METADATA_CHANGE | = | 1 (0x1) | |
VIR_NETWORK_EVENT_ID_LAST | = | 2 (0x2) | NB: this enum value will increase over time as new events are added to the libvirt API. It reflects the last event ID supported by this version of the libvirt API. |
}
virNetworkEventLifecycleType
¶a virNetworkEventLifecycleType is emitted during network lifecycle events
enum virNetworkEventLifecycleType {
VIR_NETWORK_EVENT_DEFINED | = | 0 (0x0) | |
VIR_NETWORK_EVENT_UNDEFINED | = | 1 (0x1) | |
VIR_NETWORK_EVENT_STARTED | = | 2 (0x2) | |
VIR_NETWORK_EVENT_STOPPED | = | 3 (0x3) | |
VIR_NETWORK_EVENT_LAST | = | 4 (0x4) |
}
virNetworkMetadataType
¶enum virNetworkMetadataType {
VIR_NETWORK_METADATA_DESCRIPTION | = | 0 (0x0) | Operate on <description> |
VIR_NETWORK_METADATA_TITLE | = | 1 (0x1) | Operate on <title> |
VIR_NETWORK_METADATA_ELEMENT | = | 2 (0x2) | Operate on <metadata> |
VIR_NETWORK_METADATA_LAST | = | 3 (0x3) |
}
virNetworkPort
¶struct virNetworkPort {
}
virNetworkPortCreateFlags
¶enum virNetworkPortCreateFlags {
VIR_NETWORK_PORT_CREATE_RECLAIM | = | 1 (0x1; 1 << 0) | reclaim existing used resources |
VIR_NETWORK_PORT_CREATE_VALIDATE | = | 2 (0x2; 1 << 1) | Validate the XML document against schema |
}
virNetworkPortPtr
¶typedef virNetworkPort * virNetworkPortPtr;
a virNetworkPortPtr is pointer to a virNetworkPort private structure, this is the type used to reference a virtual network port in the API.
virNetworkPtr
¶typedef virNetwork * virNetworkPtr;
a virNetworkPtr is pointer to a virNetwork private structure, this is the type used to reference a virtual network in the API.
virNetworkUpdateCommand
¶describes which type of update to perform on a <network> definition.
enum virNetworkUpdateCommand {
VIR_NETWORK_UPDATE_COMMAND_NONE | = | 0 (0x0) | invalid |
VIR_NETWORK_UPDATE_COMMAND_MODIFY | = | 1 (0x1) | modify an existing element |
VIR_NETWORK_UPDATE_COMMAND_DELETE | = | 2 (0x2) | delete an existing element |
VIR_NETWORK_UPDATE_COMMAND_ADD_LAST | = | 3 (0x3) | add an element at end of list |
VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST | = | 4 (0x4) | add an element at start of list |
VIR_NETWORK_UPDATE_COMMAND_LAST | = | 5 (0x5) |
}
virNetworkUpdateFlags
¶Flags to control options for virNetworkUpdate()
enum virNetworkUpdateFlags {
VIR_NETWORK_UPDATE_AFFECT_CURRENT | = | 0 (0x0) | affect live if network is active, config if it's not active |
VIR_NETWORK_UPDATE_AFFECT_LIVE | = | 1 (0x1; 1 << 0) | affect live state of network only |
VIR_NETWORK_UPDATE_AFFECT_CONFIG | = | 2 (0x2; 1 << 1) | affect persistent config only |
}
virNetworkUpdateSection
¶describes which section of a <network> definition the provided xml should be applied to.
enum virNetworkUpdateSection {
VIR_NETWORK_SECTION_NONE | = | 0 (0x0) | invalid |
VIR_NETWORK_SECTION_BRIDGE | = | 1 (0x1) | <bridge> |
VIR_NETWORK_SECTION_DOMAIN | = | 2 (0x2) | <domain> |
VIR_NETWORK_SECTION_IP | = | 3 (0x3) | <ip> |
VIR_NETWORK_SECTION_IP_DHCP_HOST | = | 4 (0x4) | <ip>/<dhcp>/<host> |
VIR_NETWORK_SECTION_IP_DHCP_RANGE | = | 5 (0x5) | <ip>/<dhcp>/<range> |
VIR_NETWORK_SECTION_FORWARD | = | 6 (0x6) | <forward> |
VIR_NETWORK_SECTION_FORWARD_INTERFACE | = | 7 (0x7) | <forward>/<interface> |
VIR_NETWORK_SECTION_FORWARD_PF | = | 8 (0x8) | <forward>/<pf> |
VIR_NETWORK_SECTION_PORTGROUP | = | 9 (0x9) | <portgroup> |
VIR_NETWORK_SECTION_DNS_HOST | = | 10 (0xa) | <dns>/<host> |
VIR_NETWORK_SECTION_DNS_TXT | = | 11 (0xb) | <dns>/<txt> |
VIR_NETWORK_SECTION_DNS_SRV | = | 12 (0xc) | <dns>/<srv> |
VIR_NETWORK_SECTION_LAST | = | 13 (0xd) |
}
virNetworkXMLFlags
¶enum virNetworkXMLFlags {
VIR_NETWORK_XML_INACTIVE | = | 1 (0x1; 1 << 0) | dump inactive network information |
}
virConnectListAllNetworks
¶int virConnectListAllNetworks (virConnectPtr conn, virNetworkPtr ** nets, unsigned int flags)
Collect the list of networks, and allocate an array to store those objects. This API solves the race inherent between virConnectListNetworks and virConnectListDefinedNetworks.
Normally, all networks are returned; however, flags
can be used to filter the results for a smaller list of targeted networks. The valid flags are divided into groups, where each group contains bits that describe mutually exclusive attributes of a network, and where all bits within a group describe all possible networks.
The first group of flags
is VIR_CONNECT_LIST_NETWORKS_ACTIVE (up) and VIR_CONNECT_LIST_NETWORKS_INACTIVE (down) to filter the networks by state.
The second group of flags
is VIR_CONNECT_LIST_NETWORKS_PERSISTENT (defined) and VIR_CONNECT_LIST_NETWORKS_TRANSIENT (running but not defined), to filter the networks by whether they have persistent config or not.
The third group of flags
is VIR_CONNECT_LIST_NETWORKS_AUTOSTART and VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART, to filter the networks by whether they are marked as autostart or not.
nets
to NULL in case of error. On success, the array stored into nets
is guaranteed to have an extra allocated element set to NULL but not included in the return count, to make iteration easier. The caller is responsible for calling virNetworkFree() on each array element, then calling free() on nets
.Object | Permission | Condition |
---|---|---|
connect | search-networks | - |
Object | Permission |
---|---|
network | getattr |
virConnectListDefinedNetworks
¶int virConnectListDefinedNetworks (virConnectPtr conn, char ** const names, int maxnames)
list the inactive networks, stores the pointers to the names in names
The use of this function is discouraged. Instead, use virConnectListAllNetworks().
maxnames
. The client must call free() on each returned name.Object | Permission | Condition |
---|---|---|
connect | search-networks | - |
Object | Permission |
---|---|
network | getattr |
virConnectListNetworks
¶int virConnectListNetworks (virConnectPtr conn, char ** const names, int maxnames)
Collect the list of active networks, and store their names in names
The use of this function is discouraged. Instead, use virConnectListAllNetworks().
names
maxnames
. The client must call free() on each returned name.Object | Permission | Condition |
---|---|---|
connect | search-networks | - |
Object | Permission |
---|---|
network | getattr |
virConnectNetworkEventDeregisterAny
¶int virConnectNetworkEventDeregisterAny (virConnectPtr conn, int callbackID)
Removes an event callback. The callbackID parameter should be the value obtained from a previous virConnectNetworkEventRegisterAny() method.
virConnectNetworkEventGenericCallback
¶typedef void (*virConnectNetworkEventGenericCallback) (virConnectPtr conn, virNetworkPtr net, void * opaque)
A generic network event callback handler, for use with virConnectNetworkEventRegisterAny(). Specific events usually have a customization with extra parameters, often with opaque
being passed in a different parameter position; use VIR_NETWORK_EVENT_CALLBACK() when registering an appropriate handler.
virConnectNetworkEventLifecycleCallback
¶typedef void (*virConnectNetworkEventLifecycleCallback) (virConnectPtr conn, virNetworkPtr net, int event, int detail, void * opaque)
This callback occurs when the network is started or stopped.
The callback signature to use when registering for an event of type VIR_NETWORK_EVENT_ID_LIFECYCLE with virConnectNetworkEventRegisterAny()
virConnectNetworkEventMetadataChangeCallback
¶typedef void (*virConnectNetworkEventMetadataChangeCallback) (virConnectPtr conn, virNetworkPtr net, int type, const char * nsuri, void * opaque)
This callback is triggered when the Network XML metadata changes
The callback signature to use when registering for an event of type VIR_NETWORK_EVENT_ID_METADATA_CHANGE with virConnectNetworkEventRegisterAny().
virConnectNetworkEventRegisterAny
¶int virConnectNetworkEventRegisterAny (virConnectPtr conn, virNetworkPtr net, int eventID, virConnectNetworkEventGenericCallback cb, void * opaque, virFreeCallback freecb)
Adds a callback to receive notifications of arbitrary network events occurring on a network. This function requires that an event loop has been previously registered with virEventRegisterImpl() or virEventRegisterDefaultImpl().
If net
is NULL, then events will be monitored for any network. If net
is non-NULL, then only the specific network will be monitored.
Most types of event have a callback providing a custom set of parameters for the event. When registering an event, it is thus necessary to use the VIR_NETWORK_EVENT_CALLBACK() macro to cast the supplied function pointer to match the signature of this method.
The virNetworkPtr object handle passed into the callback upon delivery of an event is only valid for the duration of execution of the callback. If the callback wishes to keep the network object after the callback returns, it shall take a reference to it, by calling virNetworkRef(). The reference can be released once the object is no longer required by calling virNetworkFree().
The return value from this method is a positive integer identifier for the callback. To unregister a callback, this callback ID should be passed to the virConnectNetworkEventDeregisterAny() method.
Object | Permission | Condition |
---|---|---|
connect | search-networks | - |
Object | Permission |
---|---|
network | getattr |
virConnectNumOfDefinedNetworks
¶int virConnectNumOfDefinedNetworks (virConnectPtr conn)
Provides the number of inactive networks.
Object | Permission | Condition |
---|---|---|
connect | search-networks | - |
Object | Permission |
---|---|
network | getattr |
virConnectNumOfNetworks
¶int virConnectNumOfNetworks (virConnectPtr conn)
Provides the number of active networks.
Object | Permission | Condition |
---|---|---|
connect | search-networks | - |
Object | Permission |
---|---|
network | getattr |
virNetworkCreate
¶int virNetworkCreate (virNetworkPtr network)
Create and start a defined network. If the call succeed the network moves from the defined to the running networks pools.
virNetworkCreateXML
¶virNetworkPtr virNetworkCreateXML (virConnectPtr conn, const char * xmlDesc)
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.
virNetworkCreateXMLFlags
¶virNetworkPtr virNetworkCreateXMLFlags (virConnectPtr conn, const char * xmlDesc, unsigned int flags)
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.
virNetworkDHCPLeaseFree
¶void virNetworkDHCPLeaseFree (virNetworkDHCPLeasePtr lease)
Frees all the memory occupied by lease
.
virNetworkDefineXML
¶virNetworkPtr virNetworkDefineXML (virConnectPtr conn, const char * xml)
Define an inactive persistent virtual network or modify an existing persistent one from the XML description.
virNetworkFree should be used to free the resources after the network object is no longer needed.
virNetworkDefineXMLFlags
¶virNetworkPtr virNetworkDefineXMLFlags (virConnectPtr conn, const char * xml, unsigned int flags)
Define an inactive persistent virtual network or modify an existing persistent one from the XML description.
virNetworkFree should be used to free the resources after the network object is no longer needed.
virNetworkDestroy
¶int virNetworkDestroy (virNetworkPtr network)
Destroy the network object. The running instance is shutdown if not down already and all resources used by it are given back to the hypervisor. This does not free the associated virNetworkPtr object. This function may require privileged access
virNetworkFree
¶int virNetworkFree (virNetworkPtr network)
Free the network object. The running instance is kept alive. The data structure is freed and should not be used thereafter.
virNetworkGetAutostart
¶int virNetworkGetAutostart (virNetworkPtr network, int * autostart)
Provides a boolean value indicating whether the network configured to be automatically started when the host machine boots.
virNetworkGetBridgeName
¶char * virNetworkGetBridgeName (virNetworkPtr network)
Provides a bridge interface name to which a domain may connect a network interface in order to join the network.
virNetworkGetConnect
¶virConnectPtr virNetworkGetConnect (virNetworkPtr net)
Provides the connection pointer associated with a network. The reference counter on the connection is not increased by this call.
virNetworkGetDHCPLeases
¶int virNetworkGetDHCPLeases (virNetworkPtr network, const char * mac, virNetworkDHCPLeasePtr ** leases, unsigned int flags)
For DHCPv4, the information returned: - Network Interface Name - Expiry Time - MAC address - IAID (NULL) - IPv4 address (with type and prefix) - Hostname (can be NULL) - Client ID (can be NULL)
For DHCPv6, the information returned: - Network Interface Name - Expiry Time - MAC address - IAID (can be NULL, only in rare cases) - IPv6 address (with type and prefix) - Hostname (can be NULL) - Client DUID
Note: mac
, iaid
, ipaddr
, clientid
are in ASCII form, not raw bytes. Note: expirytime
can 0, in case the lease is for infinite time.
The API fetches leases info of guests in the specified network. If the optional parameter mac
is specified, the returned list will contain only lease info about a specific guest interface with mac
. There can be multiple leases for a single mac
because this API supports DHCPv6 too.
On success, the array stored into leases
is guaranteed to have an extra allocated element set to NULL but not included in the return count, to make iteration easier. The caller is responsible for calling virNetworkDHCPLeaseFree() on each array element, then calling free() on leases
.
See also virNetworkGetDHCPLeasesForMAC() as a convenience for filtering the list to a single MAC address.
Example of usage:
virNetworkDHCPLeasePtr *leases = NULL; virNetworkPtr network = ... obtain a network pointer here ...; size_t i; int nleases; unsigned int flags = 0; nleases = virNetworkGetDHCPLeases(network, NULL, &leases, flags); if (nleases < 0) error(); ... do something with returned values, for example: for (i = 0; i < nleases; i++) { virNetworkDHCPLeasePtr lease = leases[i]; printf("Time(epoch): %lu, MAC address: %s, " "IP address: %s, Hostname: %s, ClientID: %s\n", lease->expirytime, lease->mac, lease->ipaddr, lease->hostname, lease->clientid); virNetworkDHCPLeaseFree(leases[i]); } free(leases);
leases
to NULL in case of error.virNetworkGetMetadata
¶char * virNetworkGetMetadata (virNetworkPtr network, int type, const char * uri, unsigned int flags)
Retrieves the appropriate network element given by type
. If VIR_NETWORK_METADATA_ELEMENT is requested parameter uri
must be set to the name of the namespace the requested elements belong to, otherwise must be NULL.
If an element of the network XML is not present, the resulting error will be VIR_ERR_NO_NETWORK_METADATA. This method forms a shortcut for seeing information from virNetworkSetMetadata() without having to go through virNetworkGetXMLDesc().
flags
controls whether the live network state or persistent configuration will be queried.
virNetworkGetName
¶const char * virNetworkGetName (virNetworkPtr network)
Get the public name for that network
virNetworkGetUUID
¶int virNetworkGetUUID (virNetworkPtr network, unsigned char * uuid)
Get the UUID for a network
virNetworkGetUUIDString
¶int virNetworkGetUUIDString (virNetworkPtr network, char * buf)
Get the UUID for a network as string. For more information about UUID see RFC4122.
virNetworkGetXMLDesc
¶char * virNetworkGetXMLDesc (virNetworkPtr network, unsigned int flags)
Provide an XML description of the network. The description may be reused later to relaunch the network with virNetworkCreateXML().
Normally, if a network included a physical function, the output includes all virtual functions tied to that physical interface. If flags
includes VIR_NETWORK_XML_INACTIVE, then the expansion of virtual interfaces is not performed.
virNetworkIsActive
¶int virNetworkIsActive (virNetworkPtr net)
Determine if the network is currently running
virNetworkIsPersistent
¶int virNetworkIsPersistent (virNetworkPtr net)
Determine if the network has a persistent configuration which means it will still exist after shutting down
virNetworkListAllPorts
¶int virNetworkListAllPorts (virNetworkPtr network, virNetworkPortPtr ** ports, unsigned int flags)
Collect the list of network ports, and allocate an array to store those objects.
ports
to NULL in case of error. On success, the array stored into ports
is guaranteed to have an extra allocated element set to NULL but not included in the return count, to make iteration easier. The caller is responsible for calling virNetworkPortFree() on each array element, then calling free() on ports
.Object | Permission | Condition |
---|---|---|
network | search-ports | - |
Object | Permission |
---|---|
network-port | getattr |
virNetworkLookupByName
¶virNetworkPtr virNetworkLookupByName (virConnectPtr conn, const char * name)
Try to lookup a network on the given hypervisor based on its name.
virNetworkFree should be used to free the resources after the network object is no longer needed.
virNetworkLookupByUUID
¶virNetworkPtr virNetworkLookupByUUID (virConnectPtr conn, const unsigned char * uuid)
Try to lookup a network on the given hypervisor based on its UUID.
virNetworkFree should be used to free the resources after the network object is no longer needed.
virNetworkLookupByUUIDString
¶virNetworkPtr virNetworkLookupByUUIDString (virConnectPtr conn, const char * uuidstr)
Try to lookup a network on the given hypervisor based on its UUID.
virNetworkPortCreateXML
¶virNetworkPortPtr virNetworkPortCreateXML (virNetworkPtr net, const char * xmldesc, unsigned int flags)
Create a new network port, based on an XML description similar to the one returned by virNetworkPortGetXMLDesc()
virNetworkPortFree should be used to free the resources after the network port object is no longer needed.
Object | Permission | Condition |
---|---|---|
network-port | create | - |
virNetworkPortDelete
¶int virNetworkPortDelete (virNetworkPortPtr port, unsigned int flags)
Delete the network port. This does not free the associated virNetworkPortPtr object. It is the caller's responsibility to ensure the port is not still in use by a virtual machine before deleting port.
Object | Permission | Condition |
---|---|---|
network-port | delete | - |
virNetworkPortFree
¶int virNetworkPortFree (virNetworkPortPtr port)
Free the network port object. The data structure is freed and should not be used thereafter.
virNetworkPortGetNetwork
¶virNetworkPtr virNetworkPortGetNetwork (virNetworkPortPtr port)
Provides the network pointer associated with a port. The reference counter on the connection is not increased by this call.
virNetworkPortGetParameters
¶int virNetworkPortGetParameters (virNetworkPortPtr port, virTypedParameterPtr * params, int * nparams, unsigned int flags)
Get all interface parameters. On input, params
should be initialized to NULL. On return params
will be allocated with the size large enough to hold all parameters, and nparams
will be updated to say how many parameters are present. params
should be freed by the caller on success.
Object | Permission | Condition |
---|---|---|
network-port | read | - |
virNetworkPortGetUUID
¶int virNetworkPortGetUUID (virNetworkPortPtr port, unsigned char * uuid)
Get the UUID for a network port
virNetworkPortGetUUIDString
¶int virNetworkPortGetUUIDString (virNetworkPortPtr port, char * buf)
Get the UUID for a network as string. For more information about UUID see RFC4122.
virNetworkPortGetXMLDesc
¶char * virNetworkPortGetXMLDesc (virNetworkPortPtr port, unsigned int flags)
Provide an XML description of the network port. The description may be reused later to recreate the port with virNetworkPortCreateXML().
Object | Permission | Condition |
---|---|---|
network-port | read | - |
virNetworkPortLookupByUUID
¶virNetworkPortPtr virNetworkPortLookupByUUID (virNetworkPtr net, const unsigned char * uuid)
Try to lookup a port on the given network based on its UUID.
virNetworkPortFree should be used to free the resources after the network port object is no longer needed.
Object | Permission | Condition |
---|---|---|
network-port | getattr | - |
virNetworkPortLookupByUUIDString
¶virNetworkPortPtr virNetworkPortLookupByUUIDString (virNetworkPtr net, const char * uuidstr)
Try to lookup a port on the given network based on its UUID.
virNetworkPortRef
¶int virNetworkPortRef (virNetworkPortPtr port)
Increment the reference count on the network port. For each additional call to this method, there shall be a corresponding call to virNetworkPortFree to release the reference count, once the caller no longer needs the reference to this object.
This method is typically useful for applications where multiple threads are using a network port, and it is required that the port remain resident until all threads have finished using it. ie, each new thread using a network port would increment the reference count.
virNetworkPortSetParameters
¶int virNetworkPortSetParameters (virNetworkPortPtr port, virTypedParameterPtr params, int nparams, unsigned int flags)
Change a subset or all parameters of the network port; currently this includes bandwidth parameters.
Object | Permission | Condition |
---|---|---|
network-port | write | - |
virNetworkRef
¶int virNetworkRef (virNetworkPtr network)
Increment the reference count on the network. For each additional call to this method, there shall be a corresponding call to virNetworkFree to release the reference count, once the caller no longer needs the reference to this object.
This method is typically useful for applications where multiple threads are using a connection, and it is required that the connection remain open until all threads have finished using it. ie, each new thread using a network would increment the reference count.
virNetworkSetAutostart
¶int virNetworkSetAutostart (virNetworkPtr network, int autostart)
Configure the network to be automatically started when the host machine boots.
virNetworkSetMetadata
¶int virNetworkSetMetadata (virNetworkPtr network, int type, const char * metadata, const char * key, const char * uri, unsigned int flags)
Sets the appropriate network element given by type
to the value of metadata
. A type
of VIR_NETWORK_METADATA_DESCRIPTION is free-form text; VIR_NETWORK_METADATA_TITLE is free-form, but no newlines are permitted, and should be short (although the length is not enforced). For these two options key
and uri
are irrelevant and must be set to NULL.
For type VIR_NETWORK_METADATA_ELEMENT metadata
must be well-formed XML belonging to namespace defined by uri
with local name key
.
Passing NULL for metadata
says to remove that element from the network XML (passing the empty string leaves the element present).
The resulting metadata will be present in virNetworkGetXMLDesc(), as well as quick access through virNetworkGetMetadata().
flags
controls whether the live network state, persistent configuration, or both will be modified.
Object | Permission | Condition |
---|---|---|
network | write | - |
network | save | !VIR_NETWORK_UPDATE_AFFECT_CONFIG|VIR_NETWORK_UPDATE_AFFECT_LIVE |
network | save | VIR_NETWORK_UPDATE_AFFECT_CONFIG |
virNetworkUndefine
¶int virNetworkUndefine (virNetworkPtr network)
Undefine a network but does not stop it if it is running
virNetworkUpdate
¶int virNetworkUpdate (virNetworkPtr network, unsigned int command, unsigned int section, int parentIndex, const char * xml, unsigned int flags)
Update the definition of an existing network, either its live running state, its persistent configuration, or both.