basic zig libvirt structure
This commit is contained in:
parent
bb3c001b00
commit
de395d47b1
5 changed files with 210 additions and 74 deletions
|
@ -10,44 +10,51 @@ pub fn main() !void {
|
|||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
const connection = try libvirt.Connection.connect("qemu+ssh://jeeves@evil.lan/system", allocator);
|
||||
const connection = try libvirt.Connection.connect("qemu:///system", allocator);
|
||||
defer connection.close();
|
||||
|
||||
var nix = process.Child.init(&[_][]const u8{ "nix", "build", ".#volume" }, allocator);
|
||||
nix.cwd_dir = try fs.cwd().openDir("flakes/windows/test", .{});
|
||||
var flake_dir = try fs.cwd().openDir("flakes/windows/test", .{});
|
||||
defer flake_dir.close();
|
||||
|
||||
var nix = process.Child.init(&[_][]const u8{ "nix", "build", ".#volume", "-o", "volume" }, allocator);
|
||||
nix.cwd_dir = flake_dir;
|
||||
_ = try nix.spawnAndWait();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#beforeInstall", "-o", "beforeInstall" };
|
||||
_ = try nix.spawnAndWait();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#afterInstall", "-o", "afterInstall" };
|
||||
_ = try nix.spawnAndWait();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#beforeBoot", "-o", "beforeBoot" };
|
||||
_ = try nix.spawnAndWait();
|
||||
nix.argv = &[_][]const u8{ "nix", "build", ".#afterBoot", "-o", "afterBoot" };
|
||||
_ = try nix.spawnAndWait();
|
||||
|
||||
// const uri = try connection.getURI();
|
||||
// defer connection.freeURI(uri);
|
||||
// std.debug.print("uri: {s}\n", .{uri});
|
||||
// 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 num_active = try connection.numOfDomains();
|
||||
// const num_inactive = try connection.numOfDefinedDomains();
|
||||
// std.debug.print("active: {d}, inactive: {d}\n", .{ num_active, num_inactive });
|
||||
// --------------
|
||||
|
||||
// var domain_iter = connection.iterateDomains(&[_]libvirt.Domain.Flags{
|
||||
// libvirt.Domain.Flags.ListDomainsActive,
|
||||
// libvirt.Domain.Flags.ListDomainsInactive,
|
||||
// });
|
||||
// defer domain_iter.deinit();
|
||||
const uri = try connection.getURI();
|
||||
defer connection.freeURI(uri);
|
||||
std.debug.print("uri: {s}\n", .{uri});
|
||||
|
||||
// while (domain_iter.next()) |domain| {
|
||||
// const active = domain.isActive();
|
||||
// const name = domain.getName();
|
||||
// std.debug.print("name: {s}, active: {any}\n", .{ name, active });
|
||||
// }
|
||||
const num_active = try connection.numOfDomains();
|
||||
const num_inactive = try connection.numOfDefinedDomains();
|
||||
std.debug.print("active: {d}, inactive: {d}\n", .{ num_active, num_inactive });
|
||||
|
||||
// var flake = try fs.cwd().createFile("flake.nix", .{});
|
||||
// defer flake.close();
|
||||
// try flake.writeAll(
|
||||
// \\{
|
||||
// \\ description = "vm-flake";
|
||||
// \\ inputs.oslib.url = "git+https://git.jeevio.xyz/jeeves/oslib";
|
||||
// \\ outputs = { self, oslib }: oslib.vmFlake {
|
||||
// \\
|
||||
// \\ };
|
||||
// \\}
|
||||
// );
|
||||
var domain_iter = try connection.iterateDomains(&[_]libvirt.Domain.ListFlags{
|
||||
libvirt.Domain.ListFlags.Active,
|
||||
libvirt.Domain.ListFlags.Inactive,
|
||||
});
|
||||
defer domain_iter.deinit();
|
||||
|
||||
while (domain_iter.next()) |domain| {
|
||||
const active = domain.isActive();
|
||||
const name = domain.getName();
|
||||
std.debug.print("name: {s}, active: {any}\n", .{ name, active });
|
||||
}
|
||||
}
|
||||
|
||||
pub const DomainSpec = struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue