oslib/server/src/main.zig

72 lines
2.4 KiB
Zig
Raw Normal View History

2024-06-24 12:54:49 -06:00
const std = @import("std");
2024-06-24 13:50:55 -06:00
const process = std.process;
const heap = std.heap;
const mem = std.mem;
2024-06-24 12:54:49 -06:00
const fs = std.fs;
const libvirt = @import("libvirt.zig");
pub fn main() !void {
2024-06-24 13:50:55 -06:00
var gpa = heap.GeneralPurposeAllocator(.{}){};
2024-06-24 12:54:49 -06:00
defer _ = gpa.deinit();
const allocator = gpa.allocator();
2024-06-25 04:24:08 -06:00
const connection = try libvirt.Connection.connect("qemu:///system", allocator);
2024-06-24 12:54:49 -06:00
defer connection.close();
2024-06-25 04:24:08 -06:00
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" };
2024-06-24 13:50:55 -06:00
_ = try nix.spawnAndWait();
2024-06-25 04:24:08 -06:00
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 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);
2024-06-24 12:54:49 -06:00
2024-06-25 04:24:08 -06:00
// --------------
2024-06-24 12:54:49 -06:00
2024-06-25 04:24:08 -06:00
const uri = try connection.getURI();
defer connection.freeURI(uri);
std.debug.print("uri: {s}\n", .{uri});
2024-06-24 12:54:49 -06:00
2024-06-25 04:24:08 -06:00
const num_active = try connection.numOfDomains();
const num_inactive = try connection.numOfDefinedDomains();
std.debug.print("active: {d}, inactive: {d}\n", .{ num_active, num_inactive });
2024-06-24 12:54:49 -06:00
2024-06-25 04:24:08 -06:00
var domain_iter = try connection.iterateDomains(&[_]libvirt.Domain.ListFlags{
libvirt.Domain.ListFlags.Active,
libvirt.Domain.ListFlags.Inactive,
});
defer domain_iter.deinit();
2024-06-24 12:54:49 -06:00
2024-06-25 04:24:08 -06:00
while (domain_iter.next()) |domain| {
const active = domain.isActive();
const name = domain.getName();
std.debug.print("name: {s}, active: {any}\n", .{ name, active });
}
2024-06-24 12:54:49 -06:00
}
pub const DomainSpec = struct {
os: Quad,
preinstalledSoftware: []const []const u8,
modules: []const []const u8,
};
pub const Quad = struct {
name: []const u8,
version: []const u8,
edition: []const u8,
arch: []const u8,
};