Class: Ironfan::Provider::ChefServer::Node

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

Instance Attribute Summary

Attributes inherited from Resource

#owner, #users

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

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

Methods inherited from Builder

ui, #ui

Constructor Details

#initialize(*args) ⇒ Node

Returns a new instance of Node.


28
29
30
31
# File 'lib/ironfan/provider/chef/node.rb', line 28

def initialize(*args)
  super
  self.adaptee ||= Chef::Node.new
end

Class Method Details

.create!(computer) ⇒ Object

Manipulation


113
114
115
116
117
118
119
120
# File 'lib/ironfan/provider/chef/node.rb', line 113

def self.create!(computer)
  return if computer.node?
  node = Node.new
  node.name           computer.server.full_name
  node.create!        computer
  computer.node =     node
  remember            node
end

.destroy!(computer) ⇒ Object


122
123
124
125
126
127
# File 'lib/ironfan/provider/chef/node.rb', line 122

def self.destroy!(computer)
  return unless computer.node?
  forget computer.node.name
  computer.node.destroy
  computer.delete(:node)
end

.expected_ids(computer) ⇒ Object


42
# File 'lib/ironfan/provider/chef/node.rb', line 42

def self.expected_ids(computer) [computer.server.full_name];   end

.load!(cluster = nil) ⇒ Object

Discovery


90
91
92
93
94
95
96
# File 'lib/ironfan/provider/chef/node.rb', line 90

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

.multiple?Boolean

Returns:

  • (Boolean)

39
# File 'lib/ironfan/provider/chef/node.rb', line 39

def self.multiple?()            false;  end

.resource_typeObject

def self.resource_type() self; end


41
# File 'lib/ironfan/provider/chef/node.rb', line 41

def self.resource_type()        :node;   end

.save!(computer) ⇒ Object


129
130
131
132
# File 'lib/ironfan/provider/chef/node.rb', line 129

def self.save!(computer)
  return unless computer.node?
  computer.node.save! computer
end

.shared?Boolean

Returns:

  • (Boolean)

38
# File 'lib/ironfan/provider/chef/node.rb', line 38

def self.shared?()              false;  end

.validate_computer!(computer) ⇒ Object


105
106
107
108
# File 'lib/ironfan/provider/chef/node.rb', line 105

def self.validate_computer!(computer)
  return unless computer.node and not computer[:client]
  computer.node.bogus << :node_without_client
end

Instance Method Details

#announce_state(state) ⇒ Object


78
79
80
81
# File 'lib/ironfan/provider/chef/node.rb', line 78

def announce_state state
  set[:state] = state
  save
end

#conterminous_with_machine?Boolean

Returns:

  • (Boolean)

83
84
85
# File 'lib/ironfan/provider/chef/node.rb', line 83

def conterminous_with_machine?
  true
end

#create!(computer) ⇒ Object


54
55
56
57
58
59
60
61
62
# File 'lib/ironfan/provider/chef/node.rb', line 54

def create!(computer)
  prepare_from computer

  client = computer[:client]
  unless File.exists?(client.key_filename)
    raise("Cannot create chef node #{name} -- client #{@chef_client} exists but no client key found in #{client.key_filename}.")
  end
  ChefServer.post_rest("nodes", adaptee, :client => client)
end

#on_correlate(computer) ⇒ Object


98
99
100
101
102
103
# File 'lib/ironfan/provider/chef/node.rb', line 98

def on_correlate(computer)
  return unless self['volumes']
  self['volumes'].each do |name,volume|
    computer.drive(name).node.merge! volume
  end
end

#prepare_from(computer) ⇒ Object


64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ironfan/provider/chef/node.rb', line 64

def prepare_from(computer)
  organization =                Chef::Config.organization
  normal[:organization] =       organization unless organization.nil?
  server =                      computer.server
  chef_environment(server.environment.to_s)
  run_list.instance_eval        { @run_list_items = server.run_list }
  normal[:realm_name] =         server.realm_name
  normal[:cluster_name] =       server.cluster_name
  normal[:facet_name] =         server.facet_name
  normal[:permanent] =          computer.permanent?
  normal[:volumes] =            {}
  computer.drives.each {|d| normal[:volumes][d.name] = d.node}
end

#save!(computer) ⇒ Object


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

def save!(computer)
  prepare_from computer
  save
end

#to_display(style, values = {}) ⇒ Object


44
45
46
47
# File 'lib/ironfan/provider/chef/node.rb', line 44

def to_display(style,values={})
  values["Chef?"] =     adaptee.nil? ? "no" : "yes"
  values
end

#to_sObject


33
34
35
36
# File 'lib/ironfan/provider/chef/node.rb', line 33

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