zig libvirt: implement most error codes as zig errors
This commit is contained in:
parent
05969155df
commit
8ae3069450
2 changed files with 232 additions and 27 deletions
|
@ -20,29 +20,30 @@ pub fn main() !void {
|
|||
nix.cwd_dir = flake_dir;
|
||||
_ = try nix.spawnAndWait();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#beforeInstall", "-o", "beforeInstall" };
|
||||
_ = try nix.spawnAndWait();
|
||||
// _ = try nix.spawnAndWait();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#afterInstall", "-o", "afterInstall" };
|
||||
_ = try nix.spawnAndWait();
|
||||
// _ = try nix.spawnAndWait();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#beforeBoot", "-o", "beforeBoot" };
|
||||
_ = try nix.spawnAndWait();
|
||||
// _ = try nix.spawnAndWait();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#afterBoot", "-o", "afterBoot" };
|
||||
_ = try nix.spawnAndWait();
|
||||
// _ = try nix.spawnAndWait();
|
||||
|
||||
// const volume_def = try flake_dir.openFile("volume", .{});
|
||||
// defer volume_def.close();
|
||||
// const volume_xml = try volume_def.readToEndAlloc(allocator, 1024 * 1024);
|
||||
// defer allocator.free(volume_xml);
|
||||
const volume_def = try flake_dir.openFile("volume", .{});
|
||||
defer volume_def.close();
|
||||
const volume_xml = try volume_def.readToEndAlloc(allocator, 1024 * 1024);
|
||||
defer allocator.free(volume_xml);
|
||||
// const volume = try connection.defineVolume(volume_xml);
|
||||
|
||||
// --------------
|
||||
|
||||
const uri = try connection.getURI();
|
||||
defer connection.freeURI(uri);
|
||||
std.debug.print("uri: {s}\n", .{uri});
|
||||
// std.debug.print("uri: {s}\n", .{uri});
|
||||
|
||||
const num_active = try connection.numOfDomains();
|
||||
const num_inactive = try connection.numOfDefinedDomains();
|
||||
std.debug.print("active: {d}, inactive: {d}\n", .{ num_active, num_inactive });
|
||||
// std.debug.print("active: {d}, inactive: {d}\n", .{ num_active, num_inactive });
|
||||
_ = .{ num_active, num_inactive };
|
||||
|
||||
var domain_iter = try connection.iterateDomains(&[_]libvirt.Domain.ListFlags{
|
||||
libvirt.Domain.ListFlags.Active,
|
||||
|
@ -53,7 +54,8 @@ pub fn main() !void {
|
|||
while (domain_iter.next()) |domain| {
|
||||
const active = domain.isActive();
|
||||
const name = domain.getName();
|
||||
std.debug.print("name: {s}, active: {any}\n", .{ name, active });
|
||||
// std.debug.print("name: {s}, active: {any}\n", .{ name, active });
|
||||
_ = .{ name, active };
|
||||
}
|
||||
|
||||
var pool_iter = try connection.iteratePools(&[_]libvirt.Pool.ListFlags{
|
||||
|
@ -63,9 +65,24 @@ pub fn main() !void {
|
|||
defer pool_iter.deinit();
|
||||
|
||||
while (pool_iter.next()) |pool| {
|
||||
// const active = pool.isActive();
|
||||
const name = try pool.getName();
|
||||
std.debug.print("name: {s}\n", .{name});
|
||||
// std.debug.print("name: {s}\n", .{name});
|
||||
if (mem.eql(u8, name, "default")) {
|
||||
// std.debug.print("xml: {s}\n\n", .{volume_xml});
|
||||
const xml_str =
|
||||
\\<volume>
|
||||
\\ <name>wintest.qcow2</name>
|
||||
\\ <capacity unit='GB'>16</capacity>
|
||||
\\ <target>
|
||||
\\ <format type='qcow2'/>
|
||||
\\ </target>
|
||||
\\</volume>
|
||||
;
|
||||
const volume = try pool.createVolume(xml_str, &[_]libvirt.Pool.Volume.CreateFlags{
|
||||
libvirt.Pool.Volume.CreateFlags.Validate,
|
||||
});
|
||||
std.debug.print("pool: {any}\n", .{volume});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue