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 'the reason is unknown' Last '--' end end class CrashedReason < Enum enum_fields :comment start_at 0 enum do Unkown 'the reason is unknown' Last '--' end end class NostateReason < Enum enum_fields :comment start_at 0 enum do Unkown 'the reason is unknown' Last '--' end end class PMSuspendedReason < Enum enum_fields :comment start_at 0 enum do Unkown 'the reason is unknown' Last '--' end end class PMSuspendedDiskReason < Enum enum_fields :comment start_at 0 enum do Unkown 'the reason is unknown' Last '--' end end class PausedReason < Enum enum_fields :comment start_at 0 enum do Unkown 'the reason is unknown' 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 'the reason is unknown' 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 'the reason is unknown' User 'shutting down on user request' Last '--' end end class ShutoffReason < Enum enum_fields :comment start_at 0 enum do Unkown 'the reason is unknown' 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 'restoed from a snapshot which was taken while domain was shutoff' Last '--' end end class State < Enum enum_fields :commend, :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 inspect state, reason = State[self.state] "#<#{self.class.name}: #{uuid} #{name} #{state.title}[#{reason.title}]>" end end end