Class: Ironfan::Provider::Vsphere::Keypair

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

Methods inherited from Builder

ui, #ui

Class Method Details

.create_private_key(key, name) ⇒ Object


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

def self.create_private_key(key, name)
  key_filename = "%s/%s.pem" %[key_dir, name]
  File.open(key_filename, "w", 0600){|f| f.print( key.to_s ) }
end

.expected_ids(computer) ⇒ Object


21
22
23
# File 'lib/ironfan/provider/vsphere/keypair.rb', line 21

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

.key_dirObject

Utility


64
65
66
67
68
69
# File 'lib/ironfan/provider/vsphere/keypair.rb', line 64

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

.multiple?Boolean

Returns:

  • (Boolean)

18
# File 'lib/ironfan/provider/vsphere/keypair.rb', line 18

def self.multiple?     ; false    ; end

.prepare!(computers) ⇒ Object

Manipulation


50
51
52
53
54
55
56
57
58
# File 'lib/ironfan/provider/vsphere/keypair.rb', line 50

def self.prepare!(computers)
  return if computers.empty?
  name = computers.values[0].server.cluster_name
  return if recall? name
  return if File.exists?("%s/%s.pem" %[key_dir, name])
  Ironfan.step(name, "creating key pair for #{name}", :blue)
  Dir.mkdir(key_dir) if !FileTest::directory?(key_dir)
  create_private_key(OpenSSL::PKey::RSA.new(2048), name)
end

.public_key(computer) ⇒ Object


30
31
32
33
34
35
# File 'lib/ironfan/provider/vsphere/keypair.rb', line 30

def self.public_key(computer)
  key_filename = "%s/%s.pem" %[key_dir, computer.server.cluster_name]
  key = OpenSSL::PKey::RSA.new(File.open(key_filename, "rb").read)
  data = [ key.to_blob ].pack('m0')
  "#{key.ssh_type} #{data}"
end

.resource_typeObject


19
# File 'lib/ironfan/provider/vsphere/keypair.rb', line 19

def self.resource_type ; :keypair ; end

.shared?Boolean

Returns:

  • (Boolean)

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

def self.shared?       ; true     ; end

Instance Method Details

#private_keyObject


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

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

#to_sObject


42
43
44
# File 'lib/ironfan/provider/vsphere/keypair.rb', line 42

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