Class: Ironfan::Provider::ChefServer::Client

Inherits:
Resource show all
Defined in:
lib/ironfan/headers.rb,
lib/ironfan/provider/chef/client.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, #on_correlate, patiently, prepare!, recall, recall?, receive, register, remember, save!, validate_computer!, validate_resources!

Methods inherited from Builder

ui, #ui

Constructor Details

#initialize(*args) ⇒ Client

Returns a new instance of Client.


16
17
18
19
# File 'lib/ironfan/provider/chef/client.rb', line 16

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

Class Method Details

.create!(computer) ⇒ Object

Manipulation


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ironfan/provider/chef/client.rb', line 62

def self.create!(computer)
  return if computer.client?
  client                = Client.new
  client.name           computer.server.full_name
  client.admin          false

  result                = client.save
  client.private_key    result["private_key"]

  computer[:client]     = client
  remember              client
end

.destroy!(computer) ⇒ Object


75
76
77
78
79
80
81
# File 'lib/ironfan/provider/chef/client.rb', line 75

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

.expected_ids(computer) ⇒ Object


29
# File 'lib/ironfan/provider/chef/client.rb', line 29

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

.key_dirObject


31
32
33
# File 'lib/ironfan/provider/chef/client.rb', line 31

def self.key_dir
  Chef::Config.client_key_dir || "/tmp/#{ENV['USER']}-client_keys"
end

.load!(cluster = nil) ⇒ Object

Discovery


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ironfan/provider/chef/client.rb', line 47

def self.load!(cluster=nil)
  Chef::ApiClient.list(true).each { |name, raw| client = register(raw) }
  return unless cluster

  # Fallback, for when Solr isn't indexing clients fast enough
  cluster.servers.each do |s|
    next if recall? s.full_name             # Already loaded
    begin; register Chef::ApiClient.load(s.full_name)
    rescue Net::HTTPServerException; end    # Doesn't exist
  end
end

.multiple?Boolean

Returns:

  • (Boolean)

27
# File 'lib/ironfan/provider/chef/client.rb', line 27

def self.multiple?()            false;  end

.resource_typeObject


28
# File 'lib/ironfan/provider/chef/client.rb', line 28

def self.resource_type()        :client;                        end

.shared?Boolean

Returns:

  • (Boolean)

26
# File 'lib/ironfan/provider/chef/client.rb', line 26

def self.shared?()              false;  end

Instance Method Details

#private_key(body = nil) ⇒ Object


35
36
37
38
39
40
41
42
# File 'lib/ironfan/provider/chef/client.rb', line 35

def private_key(body=nil)
  if body.nil?
    body = File.open(key_filename, "rb").read
  else
    File.open(key_filename, "w", 0600){|f| f.print( body ) }
  end
  adaptee.private_key(body)
end

#to_sObject


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

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