Class: VSphereCloud::Resources::Datacenter

Inherits:
Object
  • Object
show all
Includes:
VimSdk
Defined in:
lib/cloud/vsphere/resources/datacenter.rb

Constant Summary

Constants included from VimSdk

VimSdk::BASE_VERSION, VimSdk::DYNAMIC_TYPES, VimSdk::SOAP_BODY_END, VimSdk::SOAP_BODY_START, VimSdk::SOAP_BODY_TAG, VimSdk::SOAP_END, VimSdk::SOAP_ENVELOPE_END, VimSdk::SOAP_ENVELOPE_START, VimSdk::SOAP_ENVELOPE_TAG, VimSdk::SOAP_FAULT_TAG, VimSdk::SOAP_HEADER_END, VimSdk::SOAP_HEADER_START, VimSdk::SOAP_HEADER_TAG, VimSdk::SOAP_NAMESPACE_MAP, VimSdk::SOAP_START, VimSdk::VERSION1, VimSdk::XMLNS_SOAPENC, VimSdk::XMLNS_SOAPENV, VimSdk::XMLNS_VMODL_BASE, VimSdk::XMLNS_XSD, VimSdk::XMLNS_XSI, VimSdk::XML_ENCODING, VimSdk::XML_HEADER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Datacenter

Returns a new instance of Datacenter.



8
9
10
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 8

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 6

def config
  @config
end

Instance Method Details

#allow_mixedObject



60
61
62
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 60

def allow_mixed
  @config.datacenter_allow_mixed_datastores
end

#clustersObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 68

def clusters
  client = @config.client
  cluster_mobs = client.cloud_searcher.get_managed_objects(
    Vim::ClusterComputeResource, root: mob, include_name: true)
  cluster_mobs.delete_if { |name, _| !config.datacenter_clusters.has_key?(name) }
  cluster_mobs = Hash[*cluster_mobs.flatten]

  clusters_properties = client.cloud_searcher.get_properties(
    cluster_mobs.values, Vim::ClusterComputeResource,
    Cluster::PROPERTIES, :ensure_all => true)

  clusters = {}
  config.datacenter_clusters.each do |cluster_name, cluster_config|
    cluster_mob = cluster_mobs[cluster_name]
    raise "Can't find cluster: #{cluster_name}" if cluster_mob.nil?

    cluster_properties = clusters_properties[cluster_mob]
    raise "Can't find properties for cluster: #{cluster_name}" if cluster_properties.nil?

    cluster = Cluster.new(self, @config, cluster_config, cluster_properties)
    clusters[cluster.name] = cluster
  end
  clusters
end

#disk_pathObject



48
49
50
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 48

def disk_path
  @config.datacenter_disk_path
end

#ephemeral_patternObject



52
53
54
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 52

def ephemeral_pattern
  @config.datacenter_datastore_pattern
end

#inspectObject



64
65
66
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 64

def inspect
  "<Datacenter: #{mob} / #{name}>"
end

#master_template_folderObject



40
41
42
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 40

def master_template_folder
  Folder.new(@config.datacenter_template_folder, @config)
end

#master_vm_folderObject



27
28
29
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 27

def master_vm_folder
  Folder.new(@config.datacenter_vm_folder, @config)
end

#mobObject



12
13
14
15
16
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 12

def mob
  mob = @config.client.find_by_inventory_path(name)
  raise "Datacenter: #{name} not found" if mob.nil?
  mob
end

#nameObject



44
45
46
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 44

def name
  @config.datacenter_name
end

#persistent_patternObject



56
57
58
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 56

def persistent_pattern
  @config.datacenter_persistent_datastore_pattern
end

#template_folderObject



31
32
33
34
35
36
37
38
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 31

def template_folder
  if @config.datacenter_use_sub_folder
    folder_path = [@config.datacenter_template_folder, Bosh::Clouds::Config.uuid].join('/')
    Folder.new(folder_path, @config)
  else
    master_template_folder
  end
end

#vm_folderObject



18
19
20
21
22
23
24
25
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 18

def vm_folder
  if @config.datacenter_use_sub_folder
    folder_path = [@config.datacenter_vm_folder, Bosh::Clouds::Config.uuid].join('/')
    Folder.new(folder_path, @config)
  else
    master_vm_folder
  end
end