Class: Ironfan::Provider::Vsphere

Inherits:
IaasProvider show all
Defined in:
lib/ironfan/headers.rb,
lib/ironfan/provider/vsphere.rb,
lib/ironfan/provider/vsphere/keypair.rb,
lib/ironfan/provider/vsphere/machine.rb

Defined Under Namespace

Classes: Keypair, Machine

Class Method Summary collapse

Methods inherited from IaasProvider

#ensure_prerequisites!, machine_class, #save!

Methods inherited from Ironfan::Provider

aggregate!, forget!, load, prepare!, receive, #resources, validate

Methods inherited from Builder

ui, #ui

Class Method Details

.connectionObject

Some methods cribbed and modified from github.com/ezrapagel/knife-vsphere, Ezra Pagel, Jesse Campbell


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

def self.connection
  @@connection ||=  RbVmomi::VIM.connect(self.vsphere_credentials)
end

.find_all_in_folder(folder, type) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ironfan/provider/vsphere.rb', line 43

def self.find_all_in_folder(folder, type)
  if folder.instance_of?(RbVmomi::VIM::ClusterComputeResource)
    folder = folder.resourcePool
  end
   
  if folder.instance_of?(RbVmomi::VIM::ResourcePool)
    folder.resourcePool.grep(type)
  elsif folder.instance_of?(RbVmomi::VIM::Folder)
    folder.childEntity.grep(type)
  else
    puts "Unknown type #{folder.class}, not enumerating"
    nil
  end
end

.find_dc(vsphere_dc) ⇒ Object


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

def self.find_dc(vsphere_dc)
  connection.serviceInstance.find_datacenter(vsphere_dc)
end

.find_ds(vsphere_dc, name = nil) ⇒ Object


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

def self.find_ds(vsphere_dc, name = nil)
  ds = vsphere_dc.datastore
  return ds.grep(RbVmomi::VIM::Datastore).find { |d| d.name == name } if !name.nil?
end

.find_in_folder(folder, type, name) ⇒ Object


29
30
31
# File 'lib/ironfan/provider/vsphere.rb', line 29

def self.find_in_folder(folder, type, name)
  folder.childEntity.grep(type).find { |o| o.name == name }
end

.find_network(network, dc) ⇒ Object


58
59
60
61
# File 'lib/ironfan/provider/vsphere.rb', line 58

def self.find_network(network, dc)
  baseEntity = dc.network
  baseEntity.find { |f| f.name == network }
end

.get_pub_key(cluster) ⇒ Object


63
64
65
# File 'lib/ironfan/provider/vsphere.rb', line 63

def self.get_pub_key(cluster)
  puts Keypair.private_key
end

.get_rspec(dc, cluster) ⇒ Object


33
34
35
36
37
38
39
40
41
# File 'lib/ironfan/provider/vsphere.rb', line 33

def self.get_rspec(dc, cluster)
  if cluster
    resource_pool = cluster.resourcePool
  else
    hosts = find_all_in_folder(dc.hostFolder, RbVmomi::VIM::ComputeResource).find { |o| o.class == RbVmomi::VIM::ComputeResource }
    resource_pool = hosts.resourcePool || hosts.first.resourcePool
  end
  RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => resource_pool)
end

.resourcesObject


7
8
9
# File 'lib/ironfan/provider/vsphere.rb', line 7

def self.resources()
  [ Machine, Keypair]
end