1880
1783
virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
1883
conn = domain->conn;
1886
* Go though the driver registered entry points
1787
conn = domain->conn;
1789
if (conn->driver->domainGetVcpus)
1790
return conn->driver->domainGetVcpus (domain, info, maxinfo,
1793
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1798
* virDomainGetMaxVcpus:
1799
* @domain: pointer to domain object
1801
* Provides the maximum number of virtual CPUs supported for
1802
* the guest VM. If the guest is inactive, this is basically
1803
* the same as virConnectGetMaxVcpus. If the guest is running
1804
* this will reflect the maximum number of virtual CPUs the
1805
* guest was booted with.
1807
* Returns the maximum of virtual CPU or -1 in case of error.
1810
virDomainGetMaxVcpus(virDomainPtr domain)
1814
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
1815
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1819
conn = domain->conn;
1821
if (conn->driver->domainGetMaxVcpus)
1822
return conn->driver->domainGetMaxVcpus (domain);
1824
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1830
* virDomainAttachDevice:
1831
* @domain: pointer to domain object
1832
* @xml: pointer to XML description of one device
1834
* Create a virtual device attachment to backend.
1836
* Returns 0 in case of success, -1 in case of failure.
1839
virDomainAttachDevice(virDomainPtr domain, char *xml)
1843
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
1844
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1847
if (domain->conn->flags & VIR_CONNECT_RO) {
1848
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
1851
conn = domain->conn;
1853
if (conn->driver->domainAttachDevice)
1854
return conn->driver->domainAttachDevice (domain, xml);
1856
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1861
* virDomainDetachDevice:
1862
* @domain: pointer to domain object
1863
* @xml: pointer to XML description of one device
1865
* Destroy a virtual device attachment to backend.
1867
* Returns 0 in case of success, -1 in case of failure.
1870
virDomainDetachDevice(virDomainPtr domain, char *xml)
1874
if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
1875
virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
1878
if (domain->conn->flags & VIR_CONNECT_RO) {
1879
virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
1882
conn = domain->conn;
1884
if (conn->driver->domainDetachDevice)
1885
return conn->driver->domainDetachDevice (domain, xml);
1887
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1892
* virConnectNumOfNetworks:
1893
* @conn: pointer to the hypervisor connection
1895
* Provides the number of active networks.
1897
* Returns the number of network found or -1 in case of error
1900
virConnectNumOfNetworks(virConnectPtr conn)
1902
if (!VIR_IS_CONNECT(conn)) {
1903
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
1907
if (conn->networkDriver && conn->networkDriver->numOfNetworks)
1908
return conn->networkDriver->numOfNetworks (conn);
1910
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1915
* virConnectListNetworks:
1916
* @conn: pointer to the hypervisor connection
1917
* @names: array to collect the list of names of active networks
1918
* @maxnames: size of @names
1920
* Collect the list of active networks, and store their names in @names
1922
* Returns the number of networks found or -1 in case of error
1925
virConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
1927
if (!VIR_IS_CONNECT(conn)) {
1928
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
1932
if ((names == NULL) || (maxnames <= 0)) {
1933
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
1937
if (conn->networkDriver && conn->networkDriver->listNetworks)
1938
return conn->networkDriver->listNetworks (conn, names, maxnames);
1940
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1945
* virConnectNumOfDefinedNetworks:
1946
* @conn: pointer to the hypervisor connection
1948
* Provides the number of inactive networks.
1950
* Returns the number of networks found or -1 in case of error
1953
virConnectNumOfDefinedNetworks(virConnectPtr conn)
1955
if (!VIR_IS_CONNECT(conn)) {
1956
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
1960
if (conn->networkDriver && conn->networkDriver->numOfDefinedNetworks)
1961
return conn->networkDriver->numOfDefinedNetworks (conn);
1963
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
1968
* virConnectListDefinedNetworks:
1969
* @conn: pointer to the hypervisor connection
1970
* @names: pointer to an array to store the names
1971
* @maxnames: size of the array
1973
* list the inactive networks, stores the pointers to the names in @names
1975
* Returns the number of names provided in the array or -1 in case of error
1978
virConnectListDefinedNetworks(virConnectPtr conn, char **const names,
1981
if (!VIR_IS_CONNECT(conn)) {
1982
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
1986
if ((names == NULL) || (maxnames <= 0)) {
1987
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
1991
if (conn->networkDriver && conn->networkDriver->listDefinedNetworks)
1992
return conn->networkDriver->listDefinedNetworks (conn,
1995
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2000
* virNetworkLookupByName:
2001
* @conn: pointer to the hypervisor connection
2002
* @name: name for the network
2004
* Try to lookup a network on the given hypervisor based on its name.
2006
* Returns a new network object or NULL in case of failure
2009
virNetworkLookupByName(virConnectPtr conn, const char *name)
2011
if (!VIR_IS_CONNECT(conn)) {
2012
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
2016
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
2020
if (conn->networkDriver && conn->networkDriver->networkLookupByName)
2021
return conn->networkDriver->networkLookupByName (conn, name);
2023
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2028
* virNetworkLookupByUUID:
2029
* @conn: pointer to the hypervisor connection
2030
* @uuid: the raw UUID for the network
2032
* Try to lookup a network on the given hypervisor based on its UUID.
2034
* Returns a new network object or NULL in case of failure
2037
virNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
2039
if (!VIR_IS_CONNECT(conn)) {
2040
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
2044
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
2048
if (conn->networkDriver && conn->networkDriver->networkLookupByUUID)
2049
return conn->networkDriver->networkLookupByUUID (conn, uuid);
2051
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2056
* virNetworkLookupByUUIDString:
2057
* @conn: pointer to the hypervisor connection
2058
* @uuidstr: the string UUID for the network
2060
* Try to lookup a network on the given hypervisor based on its UUID.
2062
* Returns a new network object or NULL in case of failure
2065
virNetworkLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
2067
int raw[VIR_UUID_BUFLEN], i;
2068
unsigned char uuid[VIR_UUID_BUFLEN];
2071
if (!VIR_IS_CONNECT(conn)) {
2072
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
2075
if (uuidstr == NULL) {
2076
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
2080
/* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format.
2081
* We needn't it here. Right?
1888
for (i = 0;i < conn->nb_drivers;i++) {
1889
if ((conn->drivers[i] != NULL) &&
1890
(conn->drivers[i]->domainGetVcpus != NULL)) {
1891
ret = conn->drivers[i]->domainGetVcpus(domain, info, maxinfo,
1897
virLibConnError(conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2083
ret = sscanf(uuidstr,
2088
"%02x%02x%02x%02x%02x%02x",
2089
raw + 0, raw + 1, raw + 2, raw + 3,
2090
raw + 4, raw + 5, raw + 6, raw + 7,
2091
raw + 8, raw + 9, raw + 10, raw + 11,
2092
raw + 12, raw + 13, raw + 14, raw + 15);
2094
if (ret!=VIR_UUID_BUFLEN) {
2095
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
2098
for (i = 0; i < VIR_UUID_BUFLEN; i++)
2099
uuid[i] = raw[i] & 0xFF;
2101
return virNetworkLookupByUUID(conn, &uuid[0]);
2105
* virNetworkCreateXML:
2106
* @conn: pointer to the hypervisor connection
2107
* @xmlDesc: an XML description of the network
2109
* Create and start a new virtual network, based on an XML description
2110
* similar to the one returned by virNetworkGetXMLDesc()
2112
* Returns a new network object or NULL in case of failure
2115
virNetworkCreateXML(virConnectPtr conn, const char *xmlDesc)
2117
if (!VIR_IS_CONNECT(conn)) {
2118
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
2121
if (xmlDesc == NULL) {
2122
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
2125
if (conn->flags & VIR_CONNECT_RO) {
2126
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
2130
if (conn->networkDriver && conn->networkDriver->networkCreateXML)
2131
return conn->networkDriver->networkCreateXML (conn, xmlDesc);
2133
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2138
* virNetworkDefineXML:
2139
* @conn: pointer to the hypervisor connection
2140
* @xml: the XML description for the network, preferably in UTF-8
2142
* Define a network, but does not create it
2144
* Returns NULL in case of error, a pointer to the network otherwise
2147
virNetworkDefineXML(virConnectPtr conn, const char *xml)
2149
if (!VIR_IS_CONNECT(conn)) {
2150
virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
2153
if (conn->flags & VIR_CONNECT_RO) {
2154
virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
2158
virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
2162
if (conn->networkDriver && conn->networkDriver->networkDefineXML)
2163
return conn->networkDriver->networkDefineXML (conn, xml);
2165
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2170
* virNetworkUndefine:
2171
* @network: pointer to a defined network
2173
* Undefine a network but does not stop it if it is running
2175
* Returns 0 in case of success, -1 in case of error
2178
virNetworkUndefine(virNetworkPtr network) {
2181
if (!VIR_IS_CONNECTED_NETWORK(network)) {
2182
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2185
conn = network->conn;
2186
if (conn->flags & VIR_CONNECT_RO) {
2187
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
2191
if (conn->networkDriver && conn->networkDriver->networkUndefine)
2192
return conn->networkDriver->networkUndefine (network);
2194
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2200
* @network: pointer to a defined network
2202
* Create and start a defined network. If the call succeed the network
2203
* moves from the defined to the running networks pools.
2205
* Returns 0 in case of success, -1 in case of error
2208
virNetworkCreate(virNetworkPtr network)
2211
if (network == NULL) {
2215
if (!VIR_IS_CONNECTED_NETWORK(network)) {
2216
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2219
conn = network->conn;
2220
if (conn->flags & VIR_CONNECT_RO) {
2221
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
2225
if (conn->networkDriver && conn->networkDriver->networkCreate)
2226
return conn->networkDriver->networkCreate (network);
2228
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2233
* virNetworkDestroy:
2234
* @network: a network object
2236
* Destroy the network object. The running instance is shutdown if not down
2237
* already and all resources used by it are given back to the hypervisor.
2238
* The data structure is freed and should not be used thereafter if the
2239
* call does not return an error.
2240
* This function may requires priviledged access
2242
* Returns 0 in case of success and -1 in case of failure.
2245
virNetworkDestroy(virNetworkPtr network)
2249
if (!VIR_IS_CONNECTED_NETWORK(network)) {
2250
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2254
conn = network->conn;
2255
if (conn->flags & VIR_CONNECT_RO) {
2256
virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
2260
if (conn->networkDriver && conn->networkDriver->networkDestroy)
2261
return conn->networkDriver->networkDestroy (network);
2263
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2269
* @network: a network object
2271
* Free the network object. The running instance is kept alive.
2272
* The data structure is freed and should not be used thereafter.
2274
* Returns 0 in case of success and -1 in case of failure.
2277
virNetworkFree(virNetworkPtr network)
2279
if (!VIR_IS_NETWORK(network)) {
2280
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2283
if (virFreeNetwork(network->conn, network) < 0)
2289
* virNetworkGetName:
2290
* @network: a network object
2292
* Get the public name for that network
2294
* Returns a pointer to the name or NULL, the string need not be deallocated
2295
* its lifetime will be the same as the network object.
2298
virNetworkGetName(virNetworkPtr network)
2300
if (!VIR_IS_NETWORK(network)) {
2301
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2304
return (network->name);
2308
* virNetworkGetUUID:
2309
* @network: a network object
2310
* @uuid: pointer to a VIR_UUID_BUFLEN bytes array
2312
* Get the UUID for a network
2314
* Returns -1 in case of error, 0 in case of success
2317
virNetworkGetUUID(virNetworkPtr network, unsigned char *uuid)
2319
if (!VIR_IS_NETWORK(network)) {
2320
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2324
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
2328
memcpy(uuid, &network->uuid[0], VIR_UUID_BUFLEN);
2334
* virNetworkGetUUIDString:
2335
* @network: a network object
2336
* @buf: pointer to a VIR_UUID_STRING_BUFLEN bytes array
2338
* Get the UUID for a network as string. For more information about
2341
* Returns -1 in case of error, 0 in case of success
2344
virNetworkGetUUIDString(virNetworkPtr network, char *buf)
2346
unsigned char uuid[VIR_UUID_BUFLEN];
2348
if (!VIR_IS_NETWORK(network)) {
2349
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2353
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
2357
if (virNetworkGetUUID(network, &uuid[0]))
2360
snprintf(buf, VIR_UUID_STRING_BUFLEN,
2361
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2362
uuid[0], uuid[1], uuid[2], uuid[3],
2363
uuid[4], uuid[5], uuid[6], uuid[7],
2364
uuid[8], uuid[9], uuid[10], uuid[11],
2365
uuid[12], uuid[13], uuid[14], uuid[15]);
2370
* virNetworkGetXMLDesc:
2371
* @network: a network object
2372
* @flags: and OR'ed set of extraction flags, not used yet
2374
* Provide an XML description of the network. The description may be reused
2375
* later to relaunch the network with virNetworkCreateXML().
2377
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
2378
* the caller must free() the returned value.
2381
virNetworkGetXMLDesc(virNetworkPtr network, int flags)
2385
if (!VIR_IS_NETWORK(network)) {
2386
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2390
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
2394
conn = network->conn;
2396
if (conn->networkDriver && conn->networkDriver->networkDumpXML)
2397
return conn->networkDriver->networkDumpXML (network, flags);
2399
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2404
* virNetworkGetBridgeName:
2405
* @network: a network object
2407
* Provides a bridge interface name to which a domain may connect
2408
* a network interface in order to join the network.
2410
* Returns a 0 terminated interface name, or NULL in case of error.
2411
* the caller must free() the returned value.
2414
virNetworkGetBridgeName(virNetworkPtr network)
2418
if (!VIR_IS_NETWORK(network)) {
2419
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2423
conn = network->conn;
2425
if (conn->networkDriver && conn->networkDriver->networkGetBridgeName)
2426
return conn->networkDriver->networkGetBridgeName (network);
2428
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2433
* virNetworkGetAutostart:
2434
* @network: a network object
2435
* @autostart: the value returned
2437
* Provides a boolean value indicating whether the network
2438
* configured to be automatically started when the host
2441
* Returns -1 in case of error, 0 in case of success
2444
virNetworkGetAutostart(virNetworkPtr network,
2449
if (!VIR_IS_NETWORK(network)) {
2450
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2454
virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__);
2458
conn = network->conn;
2460
if (conn->networkDriver && conn->networkDriver->networkGetAutostart)
2461
return conn->networkDriver->networkGetAutostart (network, autostart);
2463
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2468
* virNetworkSetAutostart:
2469
* @network: a network object
2470
* @autostart: whether the network should be automatically started 0 or 1
2472
* Configure the network to be automatically started
2473
* when the host machine boots.
2475
* Returns -1 in case of error, 0 in case of success
2478
virNetworkSetAutostart(virNetworkPtr network,
2483
if (!VIR_IS_NETWORK(network)) {
2484
virLibNetworkError(network, VIR_ERR_INVALID_NETWORK, __FUNCTION__);
2488
conn = network->conn;
2490
if (conn->networkDriver && conn->networkDriver->networkSetAutostart)
2491
return conn->networkDriver->networkSetAutostart (network, autostart);
2493
virLibConnError (conn, VIR_ERR_CALL_FAILED, __FUNCTION__);
2498
* vim: set tabstop=4:
2499
* vim: set shiftwidth=4:
2500
* vim: set expandtab:
2504
* indent-tabs-mode: nil