diff --git a/server/src/libvirt-snapshot.zig b/server/src/libvirt-snapshot.zig index 1d48944..19a4bc7 100644 --- a/server/src/libvirt-snapshot.zig +++ b/server/src/libvirt-snapshot.zig @@ -2,8 +2,11 @@ const std = @import("std"); const mem = std.mem; const heap = std.heap; +const h = @import("libvirt-helper.zig"); const c = @import("libvirt-c.zig").c; const err = @import("libvirt-error.zig"); +const Connection = @import("libvirt-connection.zig"); +const Domain = @import("libvirt-domain.zig"); const VirError = err.VirError; const Snapshot = @This(); @@ -21,31 +24,71 @@ pub fn deinit(self: *const Snapshot) void { self.arena.deinit(); } -pub fn hasCurrentSnapshot() void {} -pub fn listAllSnapshots() void {} +pub fn hasCurrentSnapshot(domain: *const Domain) VirError!bool { + 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 createXML() void {} -pub fn current() void {} +pub fn createXML(domain: *const Domain, xml: []const u8, flags: []const CreateFlags) VirError!Snapshot { + 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 { if (c.virDomainSnapshotFree(self.ptr) < 0) return err.handleError(); } -pub fn getConnect() void {} -pub fn getDomain() void {} -pub fn getName() void {} -pub fn getParent() void {} -pub fn getXMLDesc() void {} -pub fn hasMetadata() void {} -pub fn isCurrent() void {} +pub fn getConnect(self: *const Snapshot) VirError!Connection { + return if (c.virDomainSnapshotGetConnect(self.ptr)) |v| v else err.handleError(); +} +pub fn getDomain(self: *const Snapshot) VirError!Domain { + return if (c.virDomainSnapshotGetDomain(self.ptr)) |v| v else err.handleError(); +} +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 listChildrenNames() void {} -pub fn listNames() void {} +pub fn listAllChildren() void {} // TODO +pub fn listChildrenNames() void {} // TODO +// pub fn listNames(domain: *const Domain) VirError!void {} // TODO -pub fn lookupByName() void {} -pub fn num() void {} -pub fn numChildren() void {} +pub fn lookupByName(domain: *const Domain, name: []const u8) VirError!Snapshot { + return if (c.virDomainSnapshotLookupByName(domain.ptr, @ptrCast(name), 0)) |s| s else err.handleError(); +} +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 { if (c.virDomainSnapshotRef(self.ptr) < 0) return err.handleError(); }