Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for storagepool

  • Loading branch information...
commit c67329b0f1a29d1bf3564d8399a5cd4392951bac 1 parent ea29cdf
@msantos authored
View
132 bin/vert
@@ -310,6 +310,117 @@ call(["nwfilter-undefine", Name | Arg]) ->
{ok, Filter} = nwfilter(Connect, Name),
rp(vert:virNWFilterUndefine(Filter));
+call(["find-storage-pool-sources", Type, File | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ Res = case file:read_file(File) of
+ {ok, Spec} ->
+ vert:virConnectFindStoragePoolSources(Connect, Type, Spec);
+ Error ->
+ Error
+ end,
+ rp(Res);
+
+call(["pool-autostart", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+
+ Autostart = case proplists:get_value("disable", Opt) of
+ undefined -> 1;
+ _ -> 0
+ end,
+
+ rp(vert:virStoragePoolSetAutostart(Pool, Autostart));
+
+call(["pool-build", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolBuild(Pool));
+
+call(["pool-create", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = case file:read_file(Name) of
+ {ok, XML} ->
+ vert:virStoragePoolDefineXML(Connect, XML);
+ {error, enoent} ->
+ storagepool(Connect, Name)
+ end,
+ rp(vert:virStoragePoolCreate(Pool));
+
+call(["pool-define", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ Res = case file:read_file(Name) of
+ {ok, XML} ->
+ vert:virStoragePoolDefineXML(Connect, XML);
+ Error ->
+ Error
+ end,
+ rp(Res);
+
+call(["pool-delete", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolDelete(Pool));
+
+call(["pool-destroy", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolDestroy(Pool));
+
+call(["pool-dumpxml", Name | Arg]) ->
+ Opt = getopt(Arg),
+ Flags = proplists:get_value("flags", Opt, 0),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolGetXMLDesc(Pool, Flags));
+
+call(["pool-info", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolGetInfo(Pool));
+
+call(["pool-list" | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pools} = vert:virConnectListStoragePools(Connect),
+ rp({ok, [ begin
+ {ok, Pool} = storagepool(Connect, Name),
+ {ok, Active} = vert:virStoragePoolIsActive(Pool),
+ Autostart = vert:virStoragePoolGetAutostart(Pool),
+ {Name, [{state, bool(Active)}, {autostart, Autostart}]}
+ end || Name <- Pools ]});
+
+call(["pool-name", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolGetName(Pool));
+
+call(["pool-refresh", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolRefresh(Pool));
+
+call(["pool-undefine", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolUndefine(Pool));
+
+call(["pool-uuid", Name | Arg]) ->
+ Opt = getopt(Arg),
+ {ok, Connect} = connect(Opt),
+ {ok, Pool} = storagepool(Connect, Name),
+ rp(vert:virStoragePoolGetUUIDString(Pool));
+
call(_) ->
Help = [
"autostart",
@@ -347,6 +458,22 @@ call(_) ->
"nwfilter-dumpxml",
"nwfilter-list",
"nwfilter-undefine"
+
+ "find-storage-pool-sources",
+ "pool-autostart",
+ "pool-build",
+ "pool-create",
+ "pool-define",
+ "pool-delete",
+ "pool-destroy",
+ "pool-dumpxml",
+ "pool-info",
+ "pool-list",
+ "pool-name",
+ "pool-refresh",
+ "pool-undefine",
+ "pool-uuid"
+
],
rp(Help),
halt(1).
@@ -394,6 +521,11 @@ nwfilter(Connect, Name) ->
fun() -> vert:virNWFilterLookupByName(Connect, Name) end ],
lookup(Fun).
+storagepool(Connect, Name) ->
+ Fun = [ fun() -> vert:virStoragePoolLookupByUUIDString(Connect, Name) end,
+ fun() -> vert:virStoragePoolLookupByName(Connect, Name) end ],
+ lookup(Fun).
+
lookup(Fun) ->
lookup(Fun, []).
lookup([], [{error, Error}|_]) ->
View
1  c_src/vert.c
@@ -86,6 +86,7 @@ load(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM load_info)
atom_interface = enif_make_atom(env, "interface");
atom_network = enif_make_atom(env, "network");
atom_nwfilter = enif_make_atom(env, "nwfilter");
+ atom_storagepool = enif_make_atom(env, "storagepool");
atom_stream = enif_make_atom(env, "stream");
atom_true = enif_make_atom(env, "true");
atom_false = enif_make_atom(env, "false");
View
35 c_src/vert.h
@@ -51,6 +51,7 @@ ERL_NIF_TERM atom_domain;
ERL_NIF_TERM atom_interface;
ERL_NIF_TERM atom_network;
ERL_NIF_TERM atom_nwfilter;
+ERL_NIF_TERM atom_storagepool;
ERL_NIF_TERM atom_stream;
ERL_NIF_TERM atom_true;
ERL_NIF_TERM atom_false;
@@ -86,13 +87,13 @@ typedef struct _vert_resource {
enum {
VERT_RES_CONNECT = 0,
VERT_RES_DOMAIN,
+ VERT_RES_FILTER,
VERT_RES_INTERFACE,
VERT_RES_NETWORK,
VERT_RES_NWFILTER,
- VERT_RES_STORAGEPOOL,
- VERT_RES_FILTER,
VERT_RES_SECRET,
- VERT_RES_STREAM,
+ VERT_RES_STORAGEPOOL,
+ VERT_RES_STREAM
};
#define VERT_RES_ALLOC(var,vtype,initial) do { \
@@ -267,6 +268,34 @@ vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
return vert_make_resource(env, rp, tag); \
}
+#define VERT_FUN_CREATEXML(fun, type, tag) \
+ ERL_NIF_TERM \
+vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
+{ \
+ VERT_RESOURCE *vp = NULL; \
+ ErlNifBinary xml = {0}; \
+ u_int32_t flags = 0; \
+ \
+ VERT_RESOURCE *rp = NULL; \
+ \
+ VERT_GET_RESOURCE(0, vp, VERT_RES_CONNECT); \
+ VERT_GET_IOLIST(1, xml); \
+ VERT_GET_UINT(2, flags); \
+ \
+ VERT_BIN_APPEND_NULL(xml); \
+ \
+ VERT_RES_ALLOC(rp, type, vp->res); \
+ \
+ rp->res = fun(vp->res, (const char *)xml.data, flags); \
+ \
+ if (rp->res == NULL) { \
+ enif_release_resource(rp); \
+ return verterr(env); \
+ } \
+ \
+ return vert_make_resource(env, rp, tag); \
+}
+
#define VERT_FUN_GETNAME(fun, type) \
ERL_NIF_TERM \
vert_##fun(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) \
View
30 c_src/vert_connect.c
@@ -226,6 +226,36 @@ vert_virConnectListDomains(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
list);
}
+ ERL_NIF_TERM
+vert_virConnectFindStoragePoolSources(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
+{
+ VERT_RESOURCE *vp = NULL;
+ ErlNifBinary type = {0};
+ ErlNifBinary srcSpec = {0};
+ u_int32_t flags = 0;
+
+ char *buf = NULL;
+
+
+ VERT_GET_RESOURCE(0, vp, VERT_RES_CONNECT);
+ VERT_GET_IOLIST(1, type);
+ VERT_GET_IOLIST(2, srcSpec);
+
+ VERT_BIN_APPEND_NULL(type);
+ VERT_BIN_APPEND_NULL(srcSpec);
+
+ buf = virConnectFindStoragePoolSources(vp->res,
+ type.size == 0 ? NULL : (char *)type.data,
+ srcSpec.size == 0 ? NULL : (char *)srcSpec.data,
+ flags);
+
+ VERTERR(buf == NULL);
+
+ return enif_make_tuple2(env,
+ atom_ok,
+ enif_make_string(env, buf, ERL_NIF_LATIN1));
+}
+
/*
* Internal functions
View
25 c_src/vert_func.h
@@ -32,6 +32,7 @@
ErlNifFunc vert_funcs[] = {
/* connect */
+ {"virConnectFindStoragePoolSources", 3, vert_virConnectFindStoragePoolSources},
{"virConnectGetCapabilities", 1, vert_virConnectGetCapabilities},
{"virConnectGetHostname", 1, vert_virConnectGetHostname},
{"virConnectGetLibVersion", 1, vert_virConnectGetLibVersion},
@@ -143,6 +144,30 @@ ErlNifFunc vert_funcs[] = {
{"virNWFilterLookupByUUIDString", 2, vert_virNWFilterLookupByUUIDString},
{"virNWFilterUndefine", 1, vert_virNWFilterUndefine},
+ /* storagepool */
+ {"virStoragePoolBuild", 2, vert_virStoragePoolBuild},
+ {"virStoragePoolCreate", 2, vert_virStoragePoolCreate},
+ {"virStoragePoolCreateXML", 3, vert_virStoragePoolCreateXML},
+ {"virStoragePoolDefineXML", 3, vert_virStoragePoolDefineXML},
+ {"virStoragePoolDelete", 2, vert_virStoragePoolDelete},
+ {"virStoragePoolDestroy", 1, vert_virStoragePoolDestroy},
+ {"virStoragePoolGetAutostart", 1, vert_virStoragePoolGetAutostart},
+ {"virStoragePoolGetInfo", 1, vert_virStoragePoolGetInfo},
+ {"virStoragePoolGetName", 1, vert_virStoragePoolGetName},
+ {"virStoragePoolGetUUID", 1, vert_virStoragePoolGetUUID},
+ {"virStoragePoolGetUUIDString", 1, vert_virStoragePoolGetUUIDString},
+ {"virStoragePoolGetXMLDesc", 2, vert_virStoragePoolGetXMLDesc},
+ {"virStoragePoolIsActive", 1, vert_virStoragePoolIsActive},
+ {"virStoragePoolIsPersistent", 1, vert_virStoragePoolIsPersistent},
+ {"virStoragePoolListVolumes", 2, vert_virStoragePoolListVolumes},
+ {"virStoragePoolLookupByName", 2, vert_virStoragePoolLookupByName},
+ {"virStoragePoolLookupByUUID", 2, vert_virStoragePoolLookupByUUID},
+ {"virStoragePoolLookupByUUIDString", 2, vert_virStoragePoolLookupByUUIDString},
+ {"virStoragePoolNumOfVolumes", 1, vert_virStoragePoolNumOfVolumes},
+ {"virStoragePoolRefresh", 2, vert_virStoragePoolRefresh},
+ {"virStoragePoolSetAutostart", 2, vert_virStoragePoolSetAutostart},
+ {"virStoragePoolUndefine", 1, vert_virStoragePoolUndefine},
+
/* stream */
{"virStreamAbort", 1, vert_virStreamAbort},
{"virStreamFinish", 1, vert_virStreamFinish},
View
77 c_src/vert_storagepool.c
@@ -0,0 +1,77 @@
+/* Copyright (c) 2012, Michael Santos <michael.santos@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of the author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "vert.h"
+#include "vert_util.h"
+
+VERT_FUN_SETFLAG(virStoragePoolBuild, VERT_RES_STORAGEPOOL)
+VERT_FUN_SETFLAG(virStoragePoolCreate, VERT_RES_STORAGEPOOL)
+VERT_FUN_SETFLAG(virStoragePoolDelete, VERT_RES_STORAGEPOOL)
+
+VERT_FUN_CREATEXML(virStoragePoolCreateXML, VERT_RES_STORAGEPOOL, atom_storagepool)
+VERT_FUN_CREATEXML(virStoragePoolDefineXML, VERT_RES_STORAGEPOOL, atom_storagepool)
+
+VERT_FUN_INT_RES(virStoragePoolDestroy, VERT_RES_STORAGEPOOL)
+VERT_FUN_GETAUTOSTART(virStoragePoolGetAutostart, VERT_RES_STORAGEPOOL)
+VERT_FUN_GETNAME(virStoragePoolGetName, VERT_RES_STORAGEPOOL)
+VERT_FUN_GETUUID(virStoragePoolGetUUID, VERT_RES_STORAGEPOOL)
+VERT_FUN_GETUUIDSTRING(virStoragePoolGetUUIDString, VERT_RES_STORAGEPOOL)
+VERT_FUN_GETXMLDESC(virStoragePoolGetXMLDesc, VERT_RES_STORAGEPOOL)
+VERT_FUN_INT_RES(virStoragePoolIsActive, VERT_RES_STORAGEPOOL)
+VERT_FUN_INT_RES(virStoragePoolIsPersistent, VERT_RES_STORAGEPOOL)
+
+VERT_FUN_INT_RES_CHARPP_INT(virStoragePoolListVolumes, VERT_RES_STORAGEPOOL)
+VERT_FUN_INT_RES(virStoragePoolNumOfVolumes, VERT_RES_STORAGEPOOL)
+VERT_FUN_LOOKUPBYNAME(virStoragePoolLookupByName, VERT_RES_STORAGEPOOL, atom_storagepool)
+VERT_FUN_LOOKUPBYNAME(virStoragePoolLookupByUUIDString, VERT_RES_STORAGEPOOL, atom_storagepool)
+VERT_FUN_LOOKUPBYUUID(virStoragePoolLookupByUUID, VERT_RES_STORAGEPOOL, atom_storagepool)
+VERT_FUN_SETFLAG(virStoragePoolRefresh, VERT_RES_STORAGEPOOL)
+VERT_FUN_SETFLAG(virStoragePoolSetAutostart, VERT_RES_STORAGEPOOL)
+VERT_FUN_INT_RES(virStoragePoolUndefine, VERT_RES_STORAGEPOOL)
+
+ ERL_NIF_TERM
+vert_virStoragePoolGetInfo(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
+{
+ VERT_RESOURCE *sp = NULL;
+ ErlNifBinary info = {0};
+
+
+ VERT_GET_RESOURCE(0, sp, VERT_RES_STORAGEPOOL);
+
+ if (!enif_alloc_binary(sizeof(virStoragePoolInfo), &info))
+ return error_tuple(env, atom_enomem);
+
+ VERTERR(virStoragePoolGetInfo(sp->res, (virStoragePoolInfoPtr)info.data) < 0);
+
+ return enif_make_tuple2(env,
+ atom_ok,
+ enif_make_binary(env, &info));
+}
View
6 c_src/vert_util.c
@@ -133,9 +133,6 @@ vert_cleanup(ErlNifEnv *env, void *obj)
case VERT_RES_NETWORK:
(void)virNetworkFree(vp->res);
break;
- case VERT_RES_STORAGEPOOL:
- (void)virStoragePoolFree(vp->res);
- break;
#if HAVE_NWFILTER
case VERT_RES_NWFILTER:
(void)virNWFilterFree(vp->res);
@@ -144,6 +141,9 @@ vert_cleanup(ErlNifEnv *env, void *obj)
case VERT_RES_SECRET:
(void)virSecretFree(vp->res);
break;
+ case VERT_RES_STORAGEPOOL:
+ (void)virStoragePoolFree(vp->res);
+ break;
case VERT_RES_STREAM:
(void)virStreamFree(vp->res);
break;
View
8 include/vert.hrl
@@ -90,6 +90,14 @@
threads = 0
}).
+%% virStoragePoolInfo
+-record(storagepool_info, {
+ state = 0,
+ capacity = 0,
+ allocation = 0,
+ available = 0
+ }).
+
%% virSecurityModel
-define(VIR_SECURITY_MODEL_BUFLEN, (256 + 1)).
-define(VIR_SECURITY_DOI_BUFLEN, (256 + 1)).
View
160 src/vert.erl
@@ -31,6 +31,14 @@
-module(vert).
-include("vert.hrl").
+-define(UINT16(N), N:2/native-unsigned-integer-unit:8).
+-define(UINT32(N), N:4/native-unsigned-integer-unit:8).
+-define(UINT64(N), N:8/native-unsigned-integer-unit:8).
+
+-define(INT16(N), N:2/native-integer-unit:8).
+-define(INT32(N), N:4/native-integer-unit:8).
+-define(INT64(N), N:8/native-integer-unit:8).
+
-export([
virNodeGetCellsFreeMemory/2,
virNodeGetFreeMemory/1,
@@ -107,6 +115,7 @@
virDomainSuspend/1,
virDomainUndefine/1,
+ virConnectFindStoragePoolSources/3, virConnectFindStoragePoolSources/4,
virConnectGetCapabilities/1,
virConnectGetHostname/1,
virConnectGetLibVersion/1,
@@ -139,6 +148,29 @@
virConnectOpen/1,
virConnectOpenReadOnly/1,
+ virStoragePoolBuild/1, virStoragePoolBuild/2,
+ virStoragePoolCreate/1, virStoragePoolCreate/2,
+ virStoragePoolCreateXML/3,
+ virStoragePoolDefineXML/2, virStoragePoolDefineXML/3,
+ virStoragePoolDelete/2,
+ virStoragePoolDestroy/1,
+ virStoragePoolGetAutostart/1,
+ virStoragePoolGetInfo/1,
+ virStoragePoolGetName/1,
+ virStoragePoolGetUUID/1,
+ virStoragePoolGetUUIDString/1,
+ virStoragePoolGetXMLDesc/2,
+ virStoragePoolIsActive/1,
+ virStoragePoolIsPersistent/1,
+ virStoragePoolListVolumes/1, virStoragePoolListVolumes/2,
+ virStoragePoolNumOfVolumes/1,
+ virStoragePoolLookupByName/2,
+ virStoragePoolLookupByUUID/2,
+ virStoragePoolLookupByUUIDString/2,
+ virStoragePoolRefresh/1, virStoragePoolRefresh/2,
+ virStoragePoolSetAutostart/2,
+ virStoragePoolUndefine/1,
+
virStreamAbort/1,
virStreamFinish/1,
virStreamNew/1, virStreamNew/2,
@@ -212,31 +244,100 @@ virStreamAbort(#resource{type = stream, res = Res}) ->
%%% Storage Pool
%%-------------------------------------------------------------------------
-%virStoragePoolUndefine(Pool) ->
-%virStoragePoolSetAutostart(Pool, Autostart) ->
-%virStoragePoolRefresh(Pool, Flags) ->
-%virStoragePoolNumOfVolumes(Pool) ->
+virStoragePoolUndefine(#resource{type = storagepool, res = Res}) ->
+ ok(call(virStoragePoolUndefine, [Res])).
+
+virStoragePoolSetAutostart(#resource{type = storagepool, res = Res}, Autostart) ->
+ call(virStoragePoolSetAutostart, [Res, Autostart]).
+
+virStoragePoolRefresh(Res) ->
+ virStoragePoolRefresh(Res, 0).
+virStoragePoolRefresh(#resource{type = storagepool, res = Res}, Flags) ->
+ call(virStoragePoolRefresh, [Res, Flags]).
+
+virStoragePoolNumOfVolumes(#resource{type = storagepool, res = Res}) ->
+ call(virStoragePoolNumOfVolumes, [Res]).
+
%virStoragePoolLookupByVolume(Vol) ->
-%virStoragePoolLookupByUUIDString(Conn, Uuidstr) ->
-%virStoragePoolLookupByUUID(Conn, Uuid) ->
-%virStoragePoolLookupByName(Conn, Name) ->
-%virStoragePoolListVolumes(Pool, Names, Maxnames) ->
-%virStoragePoolIsPersistent(Pool) ->
-%virStoragePoolIsActive(Pool) ->
-%virStoragePoolGetXMLDesc(Pool, Flags) ->
-%virStoragePoolGetUUIDString(Pool, Buf) ->
-%virStoragePoolGetUUID(Pool, Uuid) ->
-%virStoragePoolGetName(Pool) ->
-%virStoragePoolGetInfo(Pool, Info) ->
-%virStoragePoolGetConnect(Pool) ->
-%virStoragePoolGetAutostart(Pool, Autostart) ->
-%virStoragePoolFree(Pool) ->
-%virStoragePoolDestroy(Pool) ->
-%virStoragePoolDelete(Pool, Flags) ->
-%virStoragePoolDefineXML(Conn, Xml, Flags) ->
-%virStoragePoolCreateXML(Conn, XmlDesc, Flags) ->
-%virStoragePoolCreate(Pool, Flags) ->
-%virStoragePoolBuild(Pool, Flags) ->
+
+virStoragePoolLookupByUUIDString(#resource{type = connect, res = Res}, UUID) ->
+ call(virStoragePoolLookupByUUIDString, [Res, UUID]).
+virStoragePoolLookupByUUID(#resource{type = connect, res = Res}, UUID) ->
+ call(virStoragePoolLookupByUUID, [Res, UUID]).
+virStoragePoolLookupByName(#resource{type = connect, res = Res}, Name) ->
+ call(virStoragePoolLookupByName, [Res, Name]).
+
+virStoragePoolListVolumes(Res) ->
+ {ok, Maxnames} = virStoragePoolNumOfVolumes(Res),
+ virStoragePoolListVolumes(Res, Maxnames).
+virStoragePoolListVolumes(#resource{type = storagepool}, 0) ->
+ {ok, []};
+virStoragePoolListVolumes(#resource{type = storagepool, res = Res}, Maxnames) ->
+ call(virStoragePoolListVolumes, [Res, Maxnames]).
+
+virStoragePoolIsPersistent(#resource{type = storagepool, res = Res}) ->
+ call(virStoragePoolIsPersistent, [Res]).
+
+virStoragePoolIsActive(#resource{type = storagepool, res = Res}) ->
+ call(virStoragePoolIsActive, [Res]).
+
+virStoragePoolGetXMLDesc(#resource{type = storagepool, res = Res}, Flags) ->
+ call(virStoragePoolGetXMLDesc, [Res, Flags]).
+
+virStoragePoolGetUUIDString(#resource{type = storagepool, res = Res}) ->
+ call(virStoragePoolGetUUIDString, [Res]).
+
+virStoragePoolGetUUID(#resource{type = storagepool, res = Res}) ->
+ call(virStoragePoolGetUUID, [Res]).
+
+virStoragePoolGetName(#resource{type = storagepool, res = Res}) ->
+ call(virStoragePoolGetName, [Res]).
+
+virStoragePoolGetInfo(#resource{type = storagepool, res = Res}) ->
+ Pad = wordalign(4)*8,
+ case call(virStoragePoolGetInfo, [Res]) of
+ {ok, <<?INT32(State), % virStoragePoolState flags
+ 0:Pad,
+ ?UINT64(Capacity), % Logical size bytes
+ ?UINT64(Allocation), % Current allocation bytes
+ ?UINT64(Available) % Remaining free space bytes
+ >>} ->
+ {ok, #storagepool_info{
+ state = State,
+ capacity = Capacity,
+ allocation = Allocation,
+ available = Available
+ }};
+ {error, _} = Error ->
+ Error
+ end.
+
+virStoragePoolGetAutostart(#resource{type = storagepool, res = Res}) ->
+ call(virStoragePoolGetAutostart, [Res]).
+
+virStoragePoolDestroy(#resource{type = storagepool, res = Res}) ->
+ ok(call(virStoragePoolDestroy, [Res])).
+
+virStoragePoolDelete(#resource{type = storagepool, res = Res}, Flags) ->
+ call(virStoragePoolDelete, [Res, Flags]).
+
+virStoragePoolDefineXML(Res, XML) ->
+ virStoragePoolDefineXML(Res, XML, 0).
+virStoragePoolDefineXML(#resource{type = connect, res = Res}, XML, Flags) ->
+ call(virStoragePoolDefineXML, [Res, XML, Flags]).
+
+virStoragePoolCreateXML(#resource{type = storagepool, res = Res}, XML, Flags) ->
+ call(virStoragePoolCreateXML, [Res, XML, Flags]).
+
+virStoragePoolCreate(Res) ->
+ virStoragePoolCreate(Res, 0).
+virStoragePoolCreate(#resource{type = storagepool, res = Res}, Flags) ->
+ call(virStoragePoolCreate, [Res, Flags]).
+
+virStoragePoolBuild(Res) ->
+ virStoragePoolBuild(Res, 0).
+virStoragePoolBuild(#resource{type = storagepool, res = Res}, Flags) ->
+ call(virStoragePoolBuild, [Res, Flags]).
%%-------------------------------------------------------------------------
@@ -834,7 +935,11 @@ virConnectGetHostname(#resource{type = connect, res = Res}) ->
virConnectGetCapabilities(#resource{type = connect, res = Res}) ->
call(virConnectGetCapabilities, [Res]).
-%virConnectFindStoragePoolSources(Conn, Type, SrcSpec, Flags) ->
+virConnectFindStoragePoolSources(Conn, Type, SrcSpec) ->
+ virConnectFindStoragePoolSources(Conn, Type, SrcSpec, 0).
+virConnectFindStoragePoolSources(#resource{type = connect, res = Res}, Type, SrcSpec, Flags) ->
+ call(virConnectFindStoragePoolSources, [Res, Type, SrcSpec, Flags]).
+
%virConnectDomainXMLToNative(Conn, NativeFormat, DomainXml, Flags) ->
%virConnectDomainXMLFromNative(Conn, NativeFormat, NativeConfig, Flags) ->
@@ -993,3 +1098,8 @@ niflib() ->
{error, bad_name} -> progname_ebin();
_ -> progname_priv()
end.
+
+wordalign(Offset) ->
+ wordalign(Offset, erlang:system_info({wordsize, external})).
+wordalign(Offset, Align) ->
+ (Align - (Offset rem Align)) rem Align.
Please sign in to comment.
Something went wrong with that request. Please try again.