require 'libvirt' require 'enum' require 'uuidtools' class Enum class <" end end class Domain class CloseReason < Enum enum_fields :comment start_at 0 enum do Error 'misc I/O Error' EOF 'end-of-file from server' KeepAlive 'keepalive timer triggered' Client 'client requested it' Last '--' end end class BlockedReason < Enum enum_fields :comment start_at 0 enum do Unkown 'unknown reason' Last '--' end end class CrashedReason < Enum enum_fields :comment start_at 0 enum do Unkown 'unknown reason' Last '--' end end class NostateReason < Enum enum_fields :comment start_at 0 enum do Unkown 'unknown reason' Last '--' end end class PMSuspendedReason < Enum enum_fields :comment start_at 0 enum do Unkown 'unknown reason' Last '--' end end class PMSuspendedDiskReason < Enum enum_fields :comment start_at 0 enum do Unkown 'unknown reason' Last '--' end end class PausedReason < Enum enum_fields :comment start_at 0 enum do Unkown 'unknown reason' User 'paused on user request' Migration 'paused for offline migration' Save 'paused for save' Dump 'paused for offline core dump' IOError 'paused due to a disk I/O error' Watchdog 'paused due to a watchdog event' FromSnapshot 'paused after restoring from snapshot' ShuttingDown 'paused during shutdown process' Snapshot 'paused while creating a snapshot' Last '--' end end class RunningReason < Enum enum_fields :comment start_at 0 enum do Unknown 'unknown reason' Booted 'normal startup from boot' Migrated 'migrated from another host' Restored 'restored from a state file' FromSnapshot 'restored from snapshot' Unpaused 'returned from paused state' MigrationCanceled 'returned from migration' SaveCaneled 'returned from failed save process' Wakeup 'returned from pmsuspended due to wakeup event' Last '--' end end class ShutdownReason < Enum enum_fields :comment start_at 0 enum do Unkown 'unknown reason' User 'shutting down on user request' Last '--' end end class ShutoffReason < Enum enum_fields :comment start_at 0 enum do Unkown 'unknown reason' Shutdown 'normal shutdown' Destroyed 'forced poweroff' Crashed 'domain crashed' Migrated 'migrated to another host' Saved 'saved to a file' Failed 'domain failed to start' FromSnapshot 'restored from a snapshot which was taken while domain was shutoff' Last '--' end end class State < Enum enum_fields :comment, :reasons start_at 0 enum do Nostate 'No state', NostateReason Running 'The domain is running', RunningReason Blocked 'The domain is blocked on resource', BlockedReason Paused 'The domain is paused by user', PausedReason Shutdown 'The domain is being shut down', ShutdownReason Shutoff 'The domain is shut off', ShutoffReason Crashed 'The domain is crashed', CrashedReason PMSuspended 'The domain is suspended by guest power management', PMSuspendedReason Last '--' end def self.[] *s state, reason = s.flatten state = find state if reason [state, state.reasons.find( reason)] else state end end end def state_reason State[self.state] end def inspect state, reason = state_reason "#<#{self.class.name}: #{uuid} #{name} #{state.title}[#{reason.title}]>" end end end