zig libvirt: define almost everything in Snapshot

This commit is contained in:
Jeeves 2024-06-25 14:24:43 -06:00
parent 2362114b60
commit b22a7fde94

View file

@ -2,8 +2,11 @@ const std = @import("std");
const mem = std.mem; const mem = std.mem;
const heap = std.heap; const heap = std.heap;
const h = @import("libvirt-helper.zig");
const c = @import("libvirt-c.zig").c; const c = @import("libvirt-c.zig").c;
const err = @import("libvirt-error.zig"); const err = @import("libvirt-error.zig");
const Connection = @import("libvirt-connection.zig");
const Domain = @import("libvirt-domain.zig");
const VirError = err.VirError; const VirError = err.VirError;
const Snapshot = @This(); const Snapshot = @This();
@ -21,31 +24,71 @@ pub fn deinit(self: *const Snapshot) void {
self.arena.deinit(); self.arena.deinit();
} }
pub fn hasCurrentSnapshot() void {} pub fn hasCurrentSnapshot(domain: *const Domain) VirError!bool {
pub fn listAllSnapshots() void {} return switch (c.virDomainHasCurrentSnapshot(domain.ptr, 0)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
// pub fn listAllSnapshots(domain: *const Domain) VirError!void {} // TODO
pub fn revertToSnapshot() void {} pub fn revertToSnapshot() void {}
pub fn createXML() void {} pub fn createXML(domain: *const Domain, xml: []const u8, flags: []const CreateFlags) VirError!Snapshot {
pub fn current() void {} return if (c.virDomainSnapshotCreateXML(domain.ptr, @ptrCast(xml), h.intFromFlags(CreateFlags, flags))) |s| s else err.handleError();
}
pub fn current(domain: *const Domain) VirError!Snapshot {
return if (c.virDomainSnapshotCurrent(domain.ptr, 0)) |s| s else err.handleError();
}
pub fn delete() void {} pub fn delete(self: *const Snapshot, flags: []const DeleteFlags) VirError!void {
if (c.virDomainSnapshotDelete(self.ptr, h.intFromFlags(DeleteFlags, flags)) < 0) return err.handleError();
}
pub fn free(self: *const Snapshot) VirError!void { pub fn free(self: *const Snapshot) VirError!void {
if (c.virDomainSnapshotFree(self.ptr) < 0) return err.handleError(); if (c.virDomainSnapshotFree(self.ptr) < 0) return err.handleError();
} }
pub fn getConnect() void {} pub fn getConnect(self: *const Snapshot) VirError!Connection {
pub fn getDomain() void {} return if (c.virDomainSnapshotGetConnect(self.ptr)) |v| v else err.handleError();
pub fn getName() void {} }
pub fn getParent() void {} pub fn getDomain(self: *const Snapshot) VirError!Domain {
pub fn getXMLDesc() void {} return if (c.virDomainSnapshotGetDomain(self.ptr)) |v| v else err.handleError();
pub fn hasMetadata() void {} }
pub fn isCurrent() void {} pub fn getName(self: *const Snapshot) VirError![]const u8 {
return if (c.virDomainSnapshotGetName(self.ptr)) |v| v else err.handleError();
}
pub fn getParent(self: *const Snapshot) VirError!Snapshot {
return if (c.virDomainSnapshotGetParent(self.ptr, 0)) |v| v else err.handleError();
}
// pub fn getXMLDesc(self: *const Snapshot) VirError!void {} // TODO
pub fn hasMetadata(self: *const Snapshot) VirError!bool {
return switch (c.virDomainSnapshotHasMetadata(self.ptr, 0)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
pub fn isCurrent(self: *const Snapshot) VirError!bool {
return switch (c.virDomainSnapshotIsCurrent(self.ptr, 0)) {
0 => false,
1 => true,
else => err.handleError(),
};
}
pub fn listAllChildren() void {} pub fn listAllChildren() void {} // TODO
pub fn listChildrenNames() void {} pub fn listChildrenNames() void {} // TODO
pub fn listNames() void {} // pub fn listNames(domain: *const Domain) VirError!void {} // TODO
pub fn lookupByName() void {} pub fn lookupByName(domain: *const Domain, name: []const u8) VirError!Snapshot {
pub fn num() void {} return if (c.virDomainSnapshotLookupByName(domain.ptr, @ptrCast(name), 0)) |s| s else err.handleError();
pub fn numChildren() void {} }
pub fn num(domain: *const Domain, flags: []const ListFlags) VirError!u32 {
const n = c.virDomainSnapshotNum(domain.ptr, h.intFromFlags(ListFlags, flags));
return if (n < 0) err.handleError() else @intCast(n);
}
pub fn numChildren(self: *const Snapshot, flags: []const ListFlags) VirError!u32 {
const n = c.virDomainSnapshotNumChildred(self.ptr, h.intFromFlags(ListFlags, flags));
return if (n < 0) err.handleError() else @intCast(n);
}
pub fn ref(self: *const Snapshot) VirError!void { pub fn ref(self: *const Snapshot) VirError!void {
if (c.virDomainSnapshotRef(self.ptr) < 0) return err.handleError(); if (c.virDomainSnapshotRef(self.ptr) < 0) return err.handleError();
} }