1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 06:50:22 +03:00

src: add constants for guest info 'if.' parameters

Contrary to most APIs returning typed parameters, there are no constants
defined for the guest info data keys. This is was because many of the
keys needs to be dynamically constructed using one or more array index
values.

It is possible to define constants while still supporting dynamic
array indexes by simply defining the prefixes and suffixes as constants.
The consuming code can then combine the constants with array index
value.

With this approach, it is practical to add constants for the guest info
API keys.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2025-02-27 13:42:08 +00:00
parent d28a49cd6d
commit 9e725c1ccd
3 changed files with 104 additions and 18 deletions

View File

@ -6855,6 +6855,94 @@ int virDomainSetLaunchSecurityState(virDomainPtr domain,
*/
# define VIR_DOMAIN_GUEST_INFO_DISK_SUFFIX_GUEST_BUS ".guest_bus"
/**
* VIR_DOMAIN_GUEST_INFO_IF_COUNT:
*
* The number of interfaces defined on this domain as an unsigned int.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_COUNT "if.count"
/**
* VIR_DOMAIN_GUEST_INFO_IF_PREFIX:
*
* The parameter name prefix to access each interface entry. Concatenate the
* prefix, the entry number formatted as an unsigned integer and one of the
* interface suffix parameters to form a complete parameter name.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_PREFIX "if."
/**
* VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_NAME:
*
* Name in the guest (e.g. ``eth0``) for the interface as a string.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_NAME ".name"
/**
* VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_HWADDR:
*
* Hardware address in the guest of the interface as a string.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_HWADDR ".hwaddr"
/**
* VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_COUNT:
*
* The number of IP addresses of interface as an unsigned int.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_COUNT ".addr.count"
/**
* VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX:
*
* The parameter name prefix to access each address entry. Concatenate the
* interface prefix, the interface entry number formatted as an unsigned
* integer, the address prefix, the address entry number formatted as an
* unsigned integer and one of the address suffix parameters to form a
* complete parameter name.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX ".addr."
/**
* VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_TYPE:
*
* The IP address type (e.g. ipv4) as a string.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_TYPE ".type"
/**
* VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_ADDR:
*
* The IP address as a string.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_ADDR ".addr"
/**
* VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_PREFIX:
*
* The prefix of IP address as an unsigned int.
*
* Since: 11.2.0
*/
# define VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_PREFIX ".prefix"
/**
* virDomainGuestInfoTypes:
*

View File

@ -13233,16 +13233,9 @@ virDomainSetVcpu(virDomainPtr domain,
* keys.
*
* VIR_DOMAIN_GUEST_INFO_INTERFACES:
* Returns information about the interfaces within the domain. The typed
* parameter keys are in this format:
*
* "if.count" - the number of interfaces defined on this domain
* "if.<num>.name" - name in the guest (e.g. ``eth0``) for interface <num>
* "if.<num>.hwaddr" - hardware address in the guest for interface <num>
* "if.<num>.addr.count - the number of IP addresses of interface <num>
* "if.<num>.addr.<num1>.type" - the IP address type of addr <num1> (e.g. ipv4)
* "if.<num>.addr.<num1>.addr" - the IP address of addr <num1>
* "if.<num>.addr.<num1>.prefix" - the prefix of IP address of addr <num1>
* Returns information about the interfaces within the domain.
* The VIR_DOMAIN_GUEST_INFO_IF_* constants define the known typed parameter
* keys.
*
* VIR_DOMAIN_GUEST_INFO_LOAD:
* Returns load (the number of processes in the runqueue or waiting for disk

View File

@ -19325,30 +19325,35 @@ virDomainInterfaceFormatParams(virDomainInterfacePtr *ifaces,
{
size_t i;
virTypedParamListAddUInt(list, nifaces, "if.count");
virTypedParamListAddUInt(list, nifaces, VIR_DOMAIN_GUEST_INFO_IF_COUNT);
for (i = 0; i < nifaces; i++) {
size_t j;
virTypedParamListAddString(list, ifaces[i]->name, "if.%zu.name", i);
virTypedParamListAddString(list, ifaces[i]->hwaddr, "if.%zu.hwaddr", i);
virTypedParamListAddUInt(list, ifaces[i]->naddrs, "if.%zu.addr.count", i);
virTypedParamListAddString(list, ifaces[i]->name,
VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_NAME, i);
virTypedParamListAddString(list, ifaces[i]->hwaddr,
VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_HWADDR, i);
virTypedParamListAddUInt(list, ifaces[i]->naddrs,
VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_COUNT, i);
for (j = 0; j < ifaces[i]->naddrs; j++) {
switch (ifaces[i]->addrs[j].type) {
case VIR_IP_ADDR_TYPE_IPV4:
virTypedParamListAddString(list, "ipv4", "if.%zu.addr.%zu.type", i, j);
virTypedParamListAddString(list, "ipv4",
VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_TYPE, i, j);
break;
case VIR_IP_ADDR_TYPE_IPV6:
virTypedParamListAddString(list, "ipv6", "if.%zu.addr.%zu.type", i, j);
virTypedParamListAddString(list, "ipv6",
VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_TYPE, i, j);
break;
}
virTypedParamListAddString(list, ifaces[i]->addrs[j].addr,
"if.%zu.addr.%zu.addr", i, j);
VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_ADDR, i, j);
virTypedParamListAddUInt(list, ifaces[i]->addrs[j].prefix,
"if.%zu.addr.%zu.prefix", i, j);
VIR_DOMAIN_GUEST_INFO_IF_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_PREFIX "%zu" VIR_DOMAIN_GUEST_INFO_IF_SUFFIX_ADDR_SUFFIX_PREFIX, i, j);
}
}
}