Class: Ironfan::Provider::ChefServer::Role

Inherits:
Resource show all
Defined in:
lib/ironfan/headers.rb,
lib/ironfan/provider/chef/role.rb

Instance Attribute Summary

Attributes inherited from Resource

#owner, #users

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

aggregate!, #bogus?, create!, destroy!, forget, forget!, handle, known, #on_correlate, patiently, prepare!, recall, recall?, receive, register, remember, validate_computer!, validate_resources!

Methods inherited from Builder

ui, #ui

Constructor Details

#initialize(config = {}) ⇒ Role

Returns a new instance of Role.


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ironfan/provider/chef/role.rb', line 26

def initialize(config={})
  super
  if self.adaptee.nil? and not config[:expected].nil?
    expected = config[:expected]
    desc = "Ironfan generated role for #{expected.name}"
    self.adaptee = Chef::Role.new
    self.name                   expected.name
    self.override_attributes    expected.override_attributes
    self.default_attributes     expected.default_attributes
    self.description            desc
  end
  raise "Missing adaptee" if self.adaptee.nil?
  self
end

Class Method Details

.expected_ids(computer) ⇒ Object


21
22
23
24
# File 'lib/ironfan/provider/chef/role.rb', line 21

def self.expected_ids(computer)
  [ computer.server.cluster_role.name.to_s,
    computer.server.facet_role.name.to_s ]
end

.load!(cluster = nil) ⇒ Object

Discovery


49
50
51
52
53
54
# File 'lib/ironfan/provider/chef/role.rb', line 49

def self.load!(cluster=nil)
  query = cluster && "name:#{cluster.name}-*"
  ChefServer.search(:role,query) do |raw|
    register raw if raw.present?
  end
end

.multiple?Boolean

Returns:

  • (Boolean)

18
# File 'lib/ironfan/provider/chef/role.rb', line 18

def self.multiple?()    true;   end

.resource_typeObject

def self.resource_type() self; end


20
# File 'lib/ironfan/provider/chef/role.rb', line 20

def self.resource_type()        :role;   end

.save!(computer) ⇒ Object

Manipulation


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ironfan/provider/chef/role.rb', line 59

def self.save!(computer)
  dsl_roles = []
  dsl_roles << computer.server.cluster_role
  dsl_roles << computer.server.facet_role

  dsl_roles.each do |dsl_role|
    next if recall? dsl_role.name       # Handle each role only once
    role = remember new(:expected => dsl_role)
    role.save
  end
end

.shared?Boolean

Returns:

  • (Boolean)

17
# File 'lib/ironfan/provider/chef/role.rb', line 17

def self.shared?()      true;   end

Instance Method Details

#to_sObject


41
42
43
44
# File 'lib/ironfan/provider/chef/role.rb', line 41

def to_s
  "<%-15s %-23s %s>" % [
    self.class.handle, name, run_list]
end