Class: Ironfan::Provider::Ec2::Keypair

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

Methods inherited from Builder

ui, #ui

Class Method Details

.expected_ids(computer) ⇒ Object


18
19
20
# File 'lib/ironfan/provider/ec2/keypair.rb', line 18

def self.expected_ids(computer)
  [computer.server.cluster_name]
end

.key_dirObject

Utility


67
68
69
70
71
72
# File 'lib/ironfan/provider/ec2/keypair.rb', line 67

def self.key_dir
  return Chef::Config.ec2_key_dir if Chef::Config.ec2_key_dir
  dir = "#{ENV['HOME']}/.chef/credentials/ec2_keys"
  warn "Please set 'ec2_key_dir' in your knife.rb. Will use #{dir} as a default"
  dir
end

.load!(cluster = nil) ⇒ Object

Discovery


37
38
39
40
41
# File 'lib/ironfan/provider/ec2/keypair.rb', line 37

def self.load!(cluster=nil)
  Ec2.connection.key_pairs.each do |keypair|
    register keypair unless keypair.blank?
  end
end

.multiple?Boolean

Returns:

  • (Boolean)

16
# File 'lib/ironfan/provider/ec2/keypair.rb', line 16

def self.multiple?     ; false    ; end

.prepare!(computers) ⇒ Object

Manipulation


52
53
54
55
56
57
58
59
60
61
# File 'lib/ironfan/provider/ec2/keypair.rb', line 52

def self.prepare!(computers)
  return if computers.empty?
  name = computers.values[0].server.keypair_name
  return if recall? name
  Ironfan.step(name, "creating key pair for #{name}", :blue)
  result = Ec2.connection.create_key_pair(name)
  private_key = result.body["keyMaterial"]
  load!  # Reload to get the native object
  recall(name).private_key = private_key
end

.resource_typeObject


17
# File 'lib/ironfan/provider/ec2/keypair.rb', line 17

def self.resource_type ; :keypair ; end

.shared?Boolean

Returns:

  • (Boolean)

15
# File 'lib/ironfan/provider/ec2/keypair.rb', line 15

def self.shared?       ; true     ; end

Instance Method Details

#private_keyObject


22
23
24
# File 'lib/ironfan/provider/ec2/keypair.rb', line 22

def private_key
  File.open(key_filename, "rb").read
end

#private_key=(body = nil) ⇒ Object


26
27
28
# File 'lib/ironfan/provider/ec2/keypair.rb', line 26

def private_key=(body=nil)
  File.open(key_filename, "w", 0600){|f| f.print( body ) }
end

#receive_adaptee(obj) ⇒ Object


43
44
45
46
# File 'lib/ironfan/provider/ec2/keypair.rb', line 43

def receive_adaptee(obj)
  obj = Ec2.connection.key_pairs.new(obj) if obj.is_a?(Hash)
  super
end

#to_sObject


30
31
32
# File 'lib/ironfan/provider/ec2/keypair.rb', line 30

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