Module: Libvirt::FFI::Domain
- Extended by:
- FFI::Library, Helpers
- Defined in:
- lib/libvirt/ffi/domain.rb
Constant Summary collapse
- EVENT_ID_TO_CALLBACK =
{ LIFECYCLE: :virConnectDomainEventCallback, REBOOT: :virConnectDomainEventGenericCallback, RTC_CHANGE: :virConnectDomainEventRTCChangeCallback, WATCHDOG: :virConnectDomainEventWatchdogCallback, IO_ERROR: :virConnectDomainEventIOErrorCallback, GRAPHICS: :virConnectDomainEventGraphicsCallback, IO_ERROR_REASON: :virConnectDomainEventIOErrorReasonCallback, CONTROL_ERROR: :virConnectDomainEventGenericCallback, BLOCK_JOB: :virConnectDomainEventBlockJobCallback, DISK_CHANGE: :virConnectDomainEventDiskChangeCallback, TRAY_CHANGE: :virConnectDomainEventTrayChangeCallback, PMWAKEUP: :virConnectDomainEventPMWakeupCallback, PMSUSPEND: :virConnectDomainEventPMSuspendCallback, BALLOON_CHANGE: :virConnectDomainEventBalloonChangeCallback, PMSUSPEND_DISK: :virConnectDomainEventPMSuspendDiskCallback, DEVICE_REMOVED: :virConnectDomainEventDeviceRemovedCallback, BLOCK_JOB_2: :virConnectDomainEventBlockJobCallback, TUNABLE: :virConnectDomainEventTunableCallback, AGENT_LIFECYCLE: :virConnectDomainEventAgentLifecycleCallback, DEVICE_ADDED: :virConnectDomainEventDeviceAddedCallback, MIGRATION_ITERATION: :virConnectDomainEventMigrationIterationCallback, JOB_COMPLETED: :virConnectDomainEventJobCompletedCallback, DEVICE_REMOVAL_FAILED: :virConnectDomainEventDeviceRemovalFailedCallback, METADATA_CHANGE: :virConnectDomainEventMetadataChangeCallback, BLOCK_THRESHOLD: :virConnectDomainEventBlockThresholdCallback }.freeze
Class Method Summary collapse
-
.event_callback { ... } ⇒ FFI::Function
Creates event callback function for lifecycle event_id.
-
.event_callback_base(event_id_sym) { ... } ⇒ FFI::Function
Creates generic event callback function for provided event_id_sym.
-
.event_callback_for(event_id) { ... } ⇒ FFI::Function
Creates event callback function for provided event_id.
-
.event_detail_type(event, detail) ⇒ Symbol
Converts detail from lifecycle callback from integer to symbol name.
-
.state_reason(state, reason) ⇒ Symbol
Converts state reason of domain from integer to symbol name.
Methods included from Helpers
Class Method Details
.event_callback { ... } ⇒ FFI::Function
Creates event callback function for lifecycle event_id
865 866 867 868 869 870 871 872 |
# File 'lib/libvirt/ffi/domain.rb', line 865 def self.event_callback(&block) callback_function(:virConnectDomainEventCallback) do |conn, dom, event, detail, opaque| detail_sym = event_detail_type(event, detail) Util.log(:debug) { "Libvirt::Domain LIFECYCLE CALLBACK #{conn}, #{dom}, #{event}, #{detail_sym}, #{opaque}," } block.call(conn, dom, event, detail_sym, opaque) 0 end end |
.event_callback_base(event_id_sym) { ... } ⇒ FFI::Function
Creates generic event callback function for provided event_id_sym
853 854 855 856 857 858 859 |
# File 'lib/libvirt/ffi/domain.rb', line 853 def self.event_callback_base(event_id_sym, &block) callback_name = EVENT_ID_TO_CALLBACK.fetch(event_id_sym) callback_function(callback_name) do |*args| Util.log(:debug) { "Libvirt::Domain #{event_id_sym} CALLBACK #{args.map(&:to_s).join(', ')}," } block.call(*args) end end |
.event_callback_for(event_id) { ... } ⇒ FFI::Function
Creates event callback function for provided event_id
838 839 840 841 842 843 844 845 846 847 |
# File 'lib/libvirt/ffi/domain.rb', line 838 def self.event_callback_for(event_id, &block) event_id_sym = event_id.is_a?(Symbol) ? event_id : enum_type(:event_id)[event_id] case event_id_sym when :LIFECYCLE event_callback(&block) else event_callback_base(event_id_sym, &block) end end |
.event_detail_type(event, detail) ⇒ Symbol
Converts detail from lifecycle callback from integer to symbol name.
820 821 822 823 |
# File 'lib/libvirt/ffi/domain.rb', line 820 def self.event_detail_type(event, detail) detail_enum = enum_type(:"event_#{event.to_s.downcase}_detail_type") detail_enum[detail] end |
.state_reason(state, reason) ⇒ Symbol
Converts state reason of domain from integer to symbol name.
829 830 831 832 |
# File 'lib/libvirt/ffi/domain.rb', line 829 def self.state_reason(state, reason) reason_enum = enum_type(:"#{state.to_s.downcase}_reason") reason_enum[reason] end |