Class: Berta::EntityHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/berta/entity_handler.rb

Overview

Class for handeling entities in OpenNebula

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handle) ⇒ EntityHandler

Returns a new instance of EntityHandler.



6
7
8
9
10
11
12
# File 'lib/berta/entity_handler.rb', line 6

def initialize(handle)
  @handle = handle
  @type = handle.class.name.split('::').last
  @name = handle['NAME']
  @email = handle['TEMPLATE/EMAIL']
  @id = handle['ID']
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'lib/berta/entity_handler.rb', line 4

def email
  @email
end

#handleObject (readonly)

Returns the value of attribute handle.



4
5
6
# File 'lib/berta/entity_handler.rb', line 4

def handle
  @handle
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/berta/entity_handler.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/berta/entity_handler.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/berta/entity_handler.rb', line 4

def type
  @type
end

Instance Method Details

#notify(vms) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/berta/entity_handler.rb', line 14

def notify(vms)
  notification = Berta::Notification.new(name, email, type)
  to_notify = vms.keep_if(&:should_notify?)
  if to_notify.empty?
    logger.debug { "No notifications for #{type} #{name} with id #{id}" }
    return
  end
  notification.notify(to_notify)
  to_notify.each(&:update_notified)
rescue Berta::Errors::Entities::NoEmailError
  logger.debug { "#{type} #{id} has no email, skipping" }
end