Class: Houcho::Host

Inherits:
Element show all
Includes:
Attribute
Defined in:
lib/houcho/host.rb

Instance Method Summary collapse

Methods included from Attribute

#attr_id, #del_attr, #get_attr, #get_attr_json, #set_attr, #set_attr!

Methods inherited from Element

#attach, #detach, #detach_from_all, #id, #list

Constructor Details

#initializeHost

Returns a new instance of Host.



10
11
12
13
# File 'lib/houcho/host.rb', line 10

def initialize
  super("host")
  @type_id = 2
end

Instance Method Details

#details(hosts) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/houcho/host.rb', line 15

def details(hosts)
  hosts = hosts.is_a?(Array) ? hosts : [hosts]
  result  = {}

  hosts.each do |host|
    roles = super(host)[host]["role"]
    outerroles = @db.execute("
      SELECT role.name
      FROM outerrole role, outerrole_host oh
      WHERE role.id = oh.outerrole_id
      AND oh.host_id = ?
    ", id(host)).flatten.sort.uniq

    result[host] = {}
    result[host]["role"] = roles if ! roles.empty?
    result[host]["outer role"] = outerroles if ! outerroles.empty?

    result.delete(host) if result[host].keys.empty?
  end

  result
end