Class: OsCtld::Eventd
- Inherits:
-
Object
- Object
- OsCtld::Eventd
- Defined in:
- lib/osctld/eventd.rb
Overview
Singleton event daemon
This class aggregates events from osctld and announces them to subscribed clients.
Subscribing
Clients can subscribe by calling #subscribe, which returns a queue over which the events will be sent. To unsubscribe, call ##unsubscribe with the queue as an argument. An instance of Event is sent over the queue for every reported event.
Announcing events
Events are announced using method #report. Events are classified by a `type` and described by `opts`. For possible event types, see below.
Event types
`:management`
Used for management commands received over the command socket. Options:
{
id: unique internal command identifier,
cmd: management command,
opts: command options,
state: :run | :done | :failed
}
`:state`
Used to report changes of container states. Options:
{
pool: pool name,
id: container id,
state: new state
}
`:db`
Reports about changes in osctld database. Options:
{
object: pool/user/group/container,
pool: object's pool name,
id: object identificator,
action: add/remove
}
`:ct_netif`
Reports about container networking interfaces being added, deleted or coming up and down.
Options:
{
pool: container's pool name,
id: container id,
action: add/remove/rename/up/down,
name: interface name inside the container,
new_name: net interface name when action is rename,
veth: interface name on the host
}
Constant Summary collapse
- @@instance =
nil
Class Method Summary collapse
Instance Method Summary collapse
-
#report(type, opts) ⇒ Object
Report an event that should be announced to all subscribers.
- #start ⇒ Object
- #stop ⇒ Object
-
#subscribe ⇒ Queue
Subscribe a client to all events.
-
#unsubscribe(queue) ⇒ Object
Unsubscribe client represented by `queue`.
Class Method Details
.instance ⇒ Object
72 73 74 75 |
# File 'lib/osctld/eventd.rb', line 72 def instance return @@instance if @@instance @@instance = new end |
Instance Method Details
#report(type, opts) ⇒ Object
Report an event that should be announced to all subscribers
128 129 130 |
# File 'lib/osctld/eventd.rb', line 128 def report(type, opts) @queue << Event.new(type, opts) end |
#start ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/osctld/eventd.rb', line 91 def start @thread = Thread.new do loop do event = @queue.pop break if event == :stop @subscribers.each do |queue| queue << event end end @subscribers.clear end end |
#stop ⇒ Object
106 107 108 109 |
# File 'lib/osctld/eventd.rb', line 106 def stop @queue << :stop @thread.join end |
#subscribe ⇒ Queue
Subscribe a client to all events
113 114 115 116 117 |
# File 'lib/osctld/eventd.rb', line 113 def subscribe q = OsCtl::Lib::Queue.new @subscribers << q q end |
#unsubscribe(queue) ⇒ Object
Unsubscribe client represented by `queue`
121 122 123 |
# File 'lib/osctld/eventd.rb', line 121 def unsubscribe(queue) @subscribers.delete(queue) end |