86 lines
3.1 KiB
Zig
86 lines
3.1 KiB
Zig
|
const std = @import("std");
|
||
|
const fs = std.fs;
|
||
|
const libvirt = @import("libvirt.zig");
|
||
|
|
||
|
pub fn main() !void {
|
||
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||
|
defer _ = gpa.deinit();
|
||
|
const allocator = gpa.allocator();
|
||
|
|
||
|
// std.debug.print("{any}\n", .{libvirt.c.virConnectAuthPtr});
|
||
|
|
||
|
const connection = try libvirt.Connection.connect("qemu+ssh://jeeves@evil.lan/system", allocator);
|
||
|
defer connection.close();
|
||
|
|
||
|
const uri = try connection.getURI();
|
||
|
defer connection.freeURI(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 });
|
||
|
|
||
|
var domain_iter = connection.iterateDomains(&[_]libvirt.Domain.Flags{
|
||
|
libvirt.Domain.Flags.ListDomainsActive,
|
||
|
libvirt.Domain.Flags.ListDomainsInactive,
|
||
|
});
|
||
|
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 });
|
||
|
}
|
||
|
|
||
|
// const connection = libvirt.c.virConnectOpenAuth("qemu+ssh://jeeves@evil.lan/system", libvirt.c.virConnectAuthPtrDefault, 0);
|
||
|
// if (connection) |conn| {
|
||
|
// const conn_uri = libvirt.c.virConnectGetURI(conn);
|
||
|
// defer std.c.free(@ptrCast(conn_uri));
|
||
|
// if (conn_uri) |uri| {
|
||
|
// std.debug.print("conn uri: {s}\n", .{uri});
|
||
|
// }
|
||
|
|
||
|
// const num_active_domains = libvirt.c.virConnectNumOfDomains(conn);
|
||
|
// const num_inactive_domains = libvirt.c.virConnectNumOfDefinedDomains(conn);
|
||
|
|
||
|
// std.debug.print("there are {d} active and {d} inactive domains\n", .{ num_active_domains, num_inactive_domains });
|
||
|
|
||
|
// var domain_list: [*]libvirt.c.virDomainPtr = undefined;
|
||
|
// const flags = libvirt.c.VIR_CONNECT_LIST_DOMAINS_ACTIVE | libvirt.c.VIR_CONNECT_LIST_DOMAINS_INACTIVE;
|
||
|
// const num_domains = libvirt.c.virConnectListAllDomains(conn, @ptrCast(&domain_list), flags);
|
||
|
|
||
|
// var i: usize = 0;
|
||
|
// while (i < num_domains) : (i += 1) {
|
||
|
// const active = libvirt.c.virDomainIsActive(domain_list[i]);
|
||
|
// const name = libvirt.c.virDomainGetName(domain_list[i]);
|
||
|
// std.debug.print("name: {s}, active: {any}\n", .{ name, active });
|
||
|
// _ = libvirt.c.virDomainFree(domain_list[i]);
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// 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 {
|
||
|
// \\
|
||
|
// \\ };
|
||
|
// \\}
|
||
|
// );
|
||
|
}
|
||
|
|
||
|
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,
|
||
|
};
|