lib: Add public api to enable atomic listing of guest

This patch adds a new public api that lists domains. The new approach is
different from those used before. There are key points to this:

1) The list is acquired atomically and contains both active and inactive
domains (guests). This eliminates the need to call two different list
APIs, where the state might change in between the calls.

2) The returned list consists of virDomainPtrs instead of names or ID's
that have to be converted to virDomainPtrs anyways using separate calls
for each one of them. This is more convenient and saves hypervisor calls.

3) The returned list is auto-allocated. This saves a lot of hassle for
the users.

4) Built in support for filtering. The API call supports various
filtering flags that modify the output list according to user needs.

Available filter groups:
    Domain status:
    VIR_CONNECT_LIST_DOMAINS_ACTIVE, VIR_CONNECT_LIST_DOMAINS_INACTIVE

    Domain persistence:
    VIR_CONNECT_LIST_DOMAINS_PERSISTENT,
    VIR_CONNECT_LIST_DOMAINS_TRANSIENT

    Domain state:
    VIR_CONNECT_LIST_DOMAINS_RUNNING, VIR_CONNECT_LIST_DOMAINS_PAUSED,
    VIR_CONNECT_LIST_DOMAINS_SHUTOFF, VIR_CONNECT_LIST_DOMAINS_OTHER

    Existence of managed save image:
    VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE,
    VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE

    Auto-start option:
    VIR_CONNECT_LIST_DOMAINS_AUTOSTART,
    VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART

    Existence of snapshot:
    VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT,
    VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT

5) The python binding returns a list of domain objects that is very neat
to work with.

The only problem with this approach is no support from code generators
so both RPC code and python bindings had to be written manually.

*include/libvirt/libvirt.h.in: - add API prototype
                               - clean up whitespace mistakes nearby
*python/generator.py: - inhibit generation of the bindings for the new
                        api
*src/driver.h: - add driver prototype
               - clean up some whitespace mistakes nearby
*src/libvirt.c: - add public implementation
*src/libvirt_public.syms: - export the new symbol
This commit is contained in:
Peter Krempa
2012-05-18 17:22:02 +02:00
parent 72099c5be0
commit 747f64eeaf
5 changed files with 166 additions and 7 deletions

View File

@@ -1760,8 +1760,40 @@ int virDomainUndefineFlags (virDomainPtr domain,
unsigned int flags);
int virConnectNumOfDefinedDomains (virConnectPtr conn);
int virConnectListDefinedDomains (virConnectPtr conn,
char **const names,
int maxnames);
char **const names,
int maxnames);
/**
* virConnectListAllDomainsFlags:
*
* Flags used to tune which domains are listed by virConnectListAllDomains().
* Note that these flags come in groups; if all bits from a group are 0,
* then that group is not used to filter results.
*/
typedef enum {
VIR_CONNECT_LIST_DOMAINS_ACTIVE = 1 << 0,
VIR_CONNECT_LIST_DOMAINS_INACTIVE = 1 << 1,
VIR_CONNECT_LIST_DOMAINS_PERSISTENT = 1 << 2,
VIR_CONNECT_LIST_DOMAINS_TRANSIENT = 1 << 3,
VIR_CONNECT_LIST_DOMAINS_RUNNING = 1 << 4,
VIR_CONNECT_LIST_DOMAINS_PAUSED = 1 << 5,
VIR_CONNECT_LIST_DOMAINS_SHUTOFF = 1 << 6,
VIR_CONNECT_LIST_DOMAINS_OTHER = 1 << 7,
VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE = 1 << 8,
VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE = 1 << 9,
VIR_CONNECT_LIST_DOMAINS_AUTOSTART = 1 << 10,
VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART = 1 << 11,
VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT = 1 << 12,
VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT = 1 << 13,
} virConnectListAllDomainsFlags;
int virConnectListAllDomains (virConnectPtr conn,
virDomainPtr **domains,
unsigned int flags);
int virDomainCreate (virDomainPtr domain);
int virDomainCreateWithFlags (virDomainPtr domain,
unsigned int flags);