UNPKG

@unraid/libvirt

Version:

Libvirt bindings for Node.js® - forked from vmngr/libvirt

121 lines 4.04 kB
/** * Represents a libvirt domain (virtual machine). * This class provides methods to interact with and manage a virtual machine instance. */ export class Domain { /** * Creates a new Domain instance. * @param nativeDomain - The native libvirt domain object * @param hypervisor - The hypervisor instance this domain belongs to */ constructor(nativeDomain, hypervisor) { this.nativeDomain = nativeDomain; this.hypervisor = hypervisor; } /** * Saves the current state of the domain to a file. * This allows the domain to be restored later using the saved state. * @param filename - The path where the domain state should be saved * @throws {LibvirtError} If saving the domain state fails */ async save(filename) { return this.hypervisor.domainSave(this, filename); } /** * Starts the domain. * This operation is only valid for defined but inactive domains. * @throws {LibvirtError} If starting the domain fails */ async create() { return this.hypervisor.domainCreate(this); } /** * Gracefully shuts down the domain. * This sends an ACPI shutdown signal to the domain's operating system. * @throws {LibvirtError} If shutting down the domain fails */ async shutdown() { return this.hypervisor.domainShutdown(this); } /** * Pauses the domain's execution * @throws {LibvirtError} If pausing the domain fails */ async suspend() { return this.hypervisor.domainSuspend(this); } /** * Resumes a paused domain. * This operation restarts execution of a domain that was previously paused. * @throws {LibvirtError} If resuming the domain fails */ async resume() { return this.hypervisor.domainResume(this); } /** * Forcefully terminates the domain. * This is equivalent to pulling the power plug on a physical machine. * @throws {LibvirtError} If destroying the domain fails */ async destroy() { return this.hypervisor.domainDestroy(this); } /** * Removes the domain's configuration from the hypervisor. * This operation is only valid for inactive domains. * @throws {LibvirtError} If undefining the domain fails */ async undefine() { return this.hypervisor.domainUndefine(this); } /** * Gets the XML description of the domain. * @param flags - Optional flags to modify the XML output * @returns The domain's XML configuration * @throws {LibvirtError} If getting the domain XML fails */ async getXMLDesc(flags) { return this.hypervisor.domainGetXMLDesc(this, flags); } /** * Gets information about the domain's current state and resource usage. * @returns Domain information including state, memory usage, CPU time, etc. * @throws {LibvirtError} If getting domain information fails */ async getInfo() { return this.hypervisor.domainGetInfo(this); } /** * Gets the ID of the domain. * @returns The domain ID if the domain is running, null otherwise * @throws {LibvirtError} If getting the domain ID fails */ async getID() { return this.hypervisor.domainGetID(this); } /** * Gets the name of the domain. * @returns The domain name * @throws {LibvirtError} If getting the domain name fails */ async getName() { return this.hypervisor.domainGetName(this); } /** * Gets the UUID of the domain. * @returns The domain UUID as a string * @throws {LibvirtError} If getting the domain UUID fails */ async getUUIDString() { return this.hypervisor.domainGetUUIDString(this); } /** * Gets the native libvirt domain object. * This method is for internal use only. * @returns The native domain object */ getNativeDomain() { return this.nativeDomain; } } //# sourceMappingURL=domain.js.map