Class: VSphereCloud::Resources::Datacenter
- Inherits:
-
Object
- Object
- VSphereCloud::Resources::Datacenter
show all
- Includes:
- ObjectStringifier, 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
included
Constructor Details
#initialize(attrs) ⇒ Datacenter
Returns a new instance of Datacenter.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 12
def initialize(attrs)
@client = attrs.fetch(:client)
@use_sub_folder = attrs.fetch(:use_sub_folder)
@vm_folder = attrs.fetch(:vm_folder)
@template_folder = attrs.fetch(:template_folder)
@name = attrs.fetch(:name)
@disk_path = attrs.fetch(:disk_path)
@ephemeral_pattern = attrs.fetch(:ephemeral_pattern)
@persistent_pattern = attrs.fetch(:persistent_pattern)
@clusters = attrs.fetch(:clusters)
@logger = attrs.fetch(:logger)
@mem_overcommit = attrs.fetch(:mem_overcommit)
@cluster_provider = ClusterProvider.new(self, @client, @logger)
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10
11
12
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 10
def config
@config
end
|
#disk_path ⇒ Object
Returns the value of attribute disk_path.
28
29
30
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 28
def disk_path
@disk_path
end
|
#ephemeral_pattern ⇒ Object
Returns the value of attribute ephemeral_pattern.
28
29
30
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 28
def ephemeral_pattern
@ephemeral_pattern
end
|
#mem_overcommit ⇒ Object
Returns the value of attribute mem_overcommit.
28
29
30
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 28
def mem_overcommit
@mem_overcommit
end
|
#name ⇒ Object
Returns the value of attribute name.
28
29
30
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 28
def name
@name
end
|
#persistent_pattern ⇒ Object
Returns the value of attribute persistent_pattern.
28
29
30
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 28
def persistent_pattern
@persistent_pattern
end
|
Instance Method Details
#all_datastores ⇒ Object
90
91
92
93
94
95
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 90
def all_datastores
clusters.values.inject({}) do |acc, cluster|
acc.merge!(cluster.all_datastores)
acc
end
end
|
#clusters ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 70
def clusters
@logger.debug("All clusters provided: #{@clusters}")
@clusters.keys.inject({}) do |acc, cluster_name|
acc[cluster_name] = find_cluster(cluster_name)
acc
end
end
|
#find_cluster(cluster_name) ⇒ Object
78
79
80
81
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 78
def find_cluster(cluster_name)
cluster_config = @clusters[cluster_name]
@cluster_provider.find(cluster_name, cluster_config)
end
|
#inspect ⇒ Object
66
67
68
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 66
def inspect
"<Datacenter: #{mob} / #{name}>"
end
|
#master_template_folder ⇒ Object
62
63
64
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 62
def master_template_folder
Folder.new(@template_folder, @logger, @client, name)
end
|
#master_vm_folder ⇒ Object
49
50
51
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 49
def master_vm_folder
Folder.new(@vm_folder, @logger, @client, name)
end
|
#mob ⇒ Object
30
31
32
33
34
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 30
def mob
mob = @client.find_by_inventory_path(name)
raise "Datacenter '#{name}' not found" if mob.nil?
mob
end
|
#persistent_datastores ⇒ Object
83
84
85
86
87
88
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 83
def persistent_datastores
clusters.values.inject({}) do |acc, cluster|
acc.merge!(cluster.persistent_datastores)
acc
end
end
|
#pick_persistent_datastore(size) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 97
def pick_persistent_datastore(size)
weighted_datastores = []
persistent_datastores.each_value do |datastore|
if datastore.free_space - size >= DISK_HEADROOM
weighted_datastores << [datastore, datastore.free_space]
end
end
type = :persistent
datastores = persistent_datastores.values
available_datastores = datastores.reject { |datastore| datastore.free_space - size < DISK_HEADROOM }
@logger.debug("Looking for a '#{type}' datastore with #{size}MB free space.")
@logger.debug("All datastores within datacenter #{self.name}: #{datastores.map(&:debug_info)}")
@logger.debug("Datastores with enough space: #{available_datastores.map(&:debug_info)}")
selected_datastore = Util.weighted_random(available_datastores.map { |datastore| [datastore, datastore.free_space] })
if selected_datastore.nil?
raise Bosh::Clouds::NoDiskSpace.new(true), "Couldn't find a '#{type}' datastore with #{size}MB of free space. Found:\n #{datastores.map(&:debug_info).join("\n ")}\n"
end
selected_datastore
end
|
#template_folder ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 53
def template_folder
if @use_sub_folder
folder_path = [@template_folder, Bosh::Clouds::Config.uuid].join('/')
Folder.new(folder_path, @logger, @client, name)
else
master_template_folder
end
end
|
#vm_folder ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 36
def vm_folder
if @use_sub_folder
folder_path = [@vm_folder, Bosh::Clouds::Config.uuid].join('/')
Folder.new(folder_path, @logger, @client, name)
else
master_vm_folder
end
end
|
#vm_path(vm_cid) ⇒ Object
45
46
47
|
# File 'lib/cloud/vsphere/resources/datacenter.rb', line 45
def vm_path(vm_cid)
[name, 'vm', vm_folder.path_components, vm_cid].join('/')
end
|