zig libvirt: add String struct for handling null-terminated strings
This commit is contained in:
parent
8ae3069450
commit
30fcde4b5b
2 changed files with 62 additions and 32 deletions
|
@ -6,9 +6,9 @@ const fs = std.fs;
|
|||
const libvirt = @import("libvirt.zig");
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa = heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
var arena = heap.ArenaAllocator.init(heap.raw_c_allocator);
|
||||
defer arena.deinit();
|
||||
const allocator = arena.allocator();
|
||||
|
||||
const connection = try libvirt.Connection.connect("qemu:///system", allocator);
|
||||
defer connection.close();
|
||||
|
@ -20,7 +20,7 @@ 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();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#beforeBoot", "-o", "beforeBoot" };
|
||||
|
@ -32,7 +32,11 @@ pub fn main() !void {
|
|||
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 domain_beforeinstall_def = try flake_dir.openFile("beforeInstall", .{});
|
||||
defer domain_beforeinstall_def.close();
|
||||
const domain_beforeinstall_xml = try domain_beforeinstall_def.readToEndAlloc(allocator, 1024 * 1024 * 1024);
|
||||
defer allocator.free(domain_beforeinstall_xml);
|
||||
|
||||
// --------------
|
||||
|
||||
|
@ -68,22 +72,22 @@ pub fn main() !void {
|
|||
const name = try pool.getName();
|
||||
// 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});
|
||||
const vol_str = try libvirt.String.init(allocator, volume_xml);
|
||||
defer vol_str.deinit();
|
||||
const volume = pool.createVolume(vol_str, &[_]libvirt.Pool.Volume.CreateFlags{}) catch |err| blk: {
|
||||
if (err == libvirt.VirError.StorageVolExist) {
|
||||
break :blk try pool.lookupVolumeByName("wintest.qcow2");
|
||||
} else return err;
|
||||
};
|
||||
_ = volume;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const dom_str = try libvirt.String.init(allocator, domain_beforeinstall_xml);
|
||||
defer dom_str.deinit();
|
||||
const domain = try connection.createDomain(dom_str, &[_]libvirt.Domain.CreateFlags{});
|
||||
_ = domain;
|
||||
}
|
||||
|
||||
pub const DomainSpec = struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue