This just adds the four new functions to the public API. Rich. -- Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/ Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 03798903
Index: src/libvirt.c =================================================================== RCS file: /data/cvs/libvirt/src/libvirt.c,v retrieving revision 1.123 diff -u -r1.123 libvirt.c --- src/libvirt.c 20 Feb 2008 16:54:36 -0000 1.123 +++ src/libvirt.c 21 Feb 2008 20:43:11 -0000 @@ -3683,6 +3683,194 @@ return -1; } +/** + * virNetworkNumOfDHCPHostMappings: + * @network: a network object + * + * Returns the number of DHCP host mappings, or -1 in case of error. + */ +int +virNetworkNumOfDHCPHostMappings (virNetworkPtr network) +{ + virConnectPtr conn; + DEBUG("network=%p", network); + + if (!VIR_IS_NETWORK(network)) { + virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + return -1; + } + + conn = network->conn; + + if (conn->networkDriver && + conn->networkDriver->networkNumOfDHCPHostMappings) + return conn->networkDriver->networkNumOfDHCPHostMappings (network); + + virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); + return -1; +} + +/** + * virNetworkListDHCPHostMappings: + * @network: a network object + * @mappings: an array of virNetworkDHCPHostMappingPtr + * @maxmappings: the length of the array + * + * This can be used to return a list of DHCP host mappings for the + * network. + * + * Use virNetworkFreeDHCPHostMappings to free the returned list. + * + * Returns the number of DHCP host mappings, or -1 in case of error. + */ +int +virNetworkListDHCPHostMappings (virNetworkPtr network, + virNetworkDHCPHostMappingPtr *const mappings, + int maxmappings) +{ + virConnectPtr conn; + DEBUG("network=%p, mappings=%p, maxmappings=%d", + network, mappings, maxmappings); + + if (!VIR_IS_NETWORK(network)) { + virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + return -1; + } + + conn = network->conn; + + if (!mappings) { + virLibNetworkError (conn, VIR_ERR_INVALID_ARG, __FUNCTION__); + return -1; + } + + if (maxmappings == 0) return 0; + + memset (mappings, 0, sizeof (virNetworkDHCPHostMappingPtr) * maxmappings); + + if (conn->networkDriver && + conn->networkDriver->networkListDHCPHostMappings) + return conn->networkDriver->networkListDHCPHostMappings (network, + mappings, + maxmappings); + + virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); + return -1; +} + +/** + * virNetworkFreeDHCPHostMappings: + * @mappings: an array of virNetworkDHCPHostMappingPtr + * @maxmappings: the length of the array + * + * Free the array of mappings returned by virNetworkListDHCPHostMappings. + * + * Return -1 on error or 0 on success. + */ +int +virNetworkFreeDHCPHostMappings (virNetworkDHCPHostMappingPtr *const mappings, + int maxmappings) +{ + int i; + + DEBUG("mappings=%p, maxmappings=%d", mappings, maxmappings); + + if (!mappings) { + virLibNetworkError (NULL, VIR_ERR_INVALID_ARG, __FUNCTION__); + return -1; + } + + for (i = 0; i < maxmappings; ++i) { + if (mappings[maxmappings]) { + free (mappings[maxmappings]->hwaddr); + free (mappings[maxmappings]->hostname); + free (mappings[maxmappings]->ipaddr); + free (mappings[maxmappings]); + } + } + + return 0; +} + +/** + * virNetworkAddDHCPHostMapping: + * @network: a network object + * @hwaddr: hardware (MAC) address + * @ipaddr: IP address + * @hostname: hostname + * @flags: unused, pass 0 + * + * Add a DHCP hardware address to IP address mapping, and optionally + * a DHCP hostname for the IP address (if hostname is not NULL). + * + * The mappings are keyed on the hardware (MAC) address. If the hardware + * address already has a mapping, then this call replaces it. + * + * Return -1 on error or 0 on success. + */ +int +virNetworkAddDHCPHostMapping (virNetworkPtr network, + const char *hwaddr, + const char *ipaddr, + const char *hostname, + unsigned int flags) +{ + virConnectPtr conn; + DEBUG("network=%p, hwaddr=%s, hostname=%s, ipaddr=%s, flags=%d", + network, hwaddr, hostname, ipaddr, flags); + + if (!VIR_IS_NETWORK(network)) { + virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + return -1; + } + + conn = network->conn; + + if (flags != 0) { + virLibNetworkError (NULL, VIR_ERR_INVALID_ARG, __FUNCTION__); + return -1; + } + + if (conn->networkDriver && + conn->networkDriver->networkAddDHCPHostMapping) + return conn->networkDriver->networkAddDHCPHostMapping + (network, hwaddr, ipaddr, hostname, flags); + + virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); + return -1; +} + +/** + * virNetworkDeleteDHCPHostMapping: + * @network: a network object + * @hwaddr: hardware (MAC) address + * + * Delete an existing DHCP host mapping. + * + * Return -1 on error or 0 on success. + */ +int +virNetworkDeleteDHCPHostMapping (virNetworkPtr network, + const char *hwaddr) +{ + virConnectPtr conn; + DEBUG("network=%p, hwaddr=%s", network, hwaddr); + + if (!VIR_IS_NETWORK(network)) { + virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + return -1; + } + + conn = network->conn; + + if (conn->networkDriver && + conn->networkDriver->networkDeleteDHCPHostMapping) + return conn->networkDriver->networkDeleteDHCPHostMapping (network, + hwaddr); + + virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); + return -1; +} /** * virStoragePoolGetConnect: Index: src/libvirt_sym.version =================================================================== RCS file: /data/cvs/libvirt/src/libvirt_sym.version,v retrieving revision 1.36 diff -u -r1.36 libvirt_sym.version --- src/libvirt_sym.version 21 Feb 2008 03:53:03 -0000 1.36 +++ src/libvirt_sym.version 21 Feb 2008 20:43:11 -0000 @@ -99,6 +99,11 @@ virNetworkGetBridgeName; virNetworkGetAutostart; virNetworkSetAutostart; + virNetworkNumOfDHCPHostMappings; + virNetworkListDHCPHostMappings; + virNetworkFreeDHCPHostMappings; + virNetworkAddDHCPHostMapping; + virNetworkDeleteDHCPHostMapping; virStoragePoolGetConnect; virConnectNumOfStoragePools; Index: include/libvirt/libvirt.h.in =================================================================== RCS file: /data/cvs/libvirt/include/libvirt/libvirt.h.in,v retrieving revision 1.42 diff -u -r1.42 libvirt.h.in --- include/libvirt/libvirt.h.in 20 Feb 2008 14:57:39 -0000 1.42 +++ include/libvirt/libvirt.h.in 21 Feb 2008 20:43:12 -0000 @@ -684,6 +684,19 @@ */ typedef virNetwork *virNetworkPtr; +/** + * virNetworkDHCPHostMapping: + * + * hostname mappings are returned by virNetworkListDHCPHostMapping. + */ +typedef struct _virNetworkDHCPHostMapping { + char *hwaddr; + char *ipaddr; + char *hostname; +} virNetworkDHCPHostMapping; + +typedef virNetworkDHCPHostMapping *virNetworkDHCPHostMappingPtr; + /* * Get connection from network. */ @@ -760,6 +773,28 @@ int virNetworkSetAutostart (virNetworkPtr network, int autostart); +/* + * DHCP host mappings + */ +int virNetworkNumOfDHCPHostMappings + (virNetworkPtr network); +int virNetworkListDHCPHostMappings + (virNetworkPtr network, + virNetworkDHCPHostMappingPtr *const mappings, + int maxmappings); +int virNetworkFreeDHCPHostMappings + (virNetworkDHCPHostMappingPtr *const mappings, + int maxmappings); + +int virNetworkAddDHCPHostMapping + (virNetworkPtr network, + const char *hwaddr, + const char *hostname, + const char *ipaddr, + unsigned int flags); +int virNetworkDeleteDHCPHostMapping + (virNetworkPtr network, + const char *hwaddr); /** * virStoragePool:
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list