Class: VSphereCloud::Resources::Cluster

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

Constant Summary collapse

PROPERTIES =
%w(name datastore resourcePool host)
HOST_PROPERTIES =
%w(hardware.memorySize runtime.inMaintenanceMode)
HOST_COUNTERS =
%w(mem.usage.average)

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(datacenter, cloud_config, cluster_config, properties) ⇒ Cluster

Creates a new Cluster resource from the specified datacenter, cluster configuration, and prefetched properties.

Parameters:

  • VSphereCloud::Config (CloudConfig)
  • config (ClusterConfig)

    cluster configuration as specified by the operator.

  • properties (Hash)

    prefetched vSphere properties for the cluster.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cloud/vsphere/resources/cluster.rb', line 49

def initialize(datacenter, cloud_config, cluster_config, properties)
  @datacenter = datacenter
  @logger = cloud_config.logger
  @client = cloud_config.client
  @properties = properties

  @config = cluster_config
  @cloud_config = cloud_config
  @mob = properties[:obj]
  @resource_pool = ResourcePool.new(cloud_config, cluster_config, properties["resourcePool"])

  @allocated_after_sync = 0
  @ephemeral_datastores = {}
  @persistent_datastores = {}
  @shared_datastores = {}

  setup_datastores

  # Have to use separate mechanisms for fetching utilization depending on
  # whether we're using resource pools or raw clusters.
  if @config.resource_pool.nil?
    fetch_cluster_utilization(properties['host'])
  else
    fetch_resource_pool_utilization
  end
end

Instance Attribute Details

#allocated_after_syncInteger

Returns memory allocated since utilization sync in MB.

Returns:

  • (Integer)

    memory allocated since utilization sync in MB.



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

def allocated_after_sync
  @allocated_after_sync
end

#datacenterObject

Returns the value of attribute datacenter.



16
17
18
# File 'lib/cloud/vsphere/resources/cluster.rb', line 16

def datacenter
  @datacenter
end

#ephemeral_datastoresObject

Returns the value of attribute ephemeral_datastores.



24
25
26
# File 'lib/cloud/vsphere/resources/cluster.rb', line 24

def ephemeral_datastores
  @ephemeral_datastores
end

#mobObject

Returns the value of attribute mob.



12
13
14
# File 'lib/cloud/vsphere/resources/cluster.rb', line 12

def mob
  @mob
end

#persistent_datastoresObject

Returns the value of attribute persistent_datastores.



28
29
30
# File 'lib/cloud/vsphere/resources/cluster.rb', line 28

def persistent_datastores
  @persistent_datastores
end

#resource_poolObject

Returns the value of attribute resource_pool.



20
21
22
# File 'lib/cloud/vsphere/resources/cluster.rb', line 20

def resource_pool
  @resource_pool
end

#shared_datastoresObject

Returns the value of attribute shared_datastores.



32
33
34
# File 'lib/cloud/vsphere/resources/cluster.rb', line 32

def shared_datastores
  @shared_datastores
end

#synced_free_memoryInteger

Returns cached memory utilization in MB.

Returns:

  • (Integer)

    cached memory utilization in MB.



36
37
38
# File 'lib/cloud/vsphere/resources/cluster.rb', line 36

def synced_free_memory
  @synced_free_memory
end

Instance Method Details

#allocate(memory) ⇒ void

This method returns an undefined value.

Marks the memory reservation against the cached utilization data.

Parameters:

  • memory (Integer)

    size of memory reservation.



96
97
98
# File 'lib/cloud/vsphere/resources/cluster.rb', line 96

def allocate(memory)
  @allocated_after_sync += memory
end

#free_memoryInteger

Returns amount of free memory in the cluster.

Returns:

  • (Integer)

    amount of free memory in the cluster



87
88
89
90
# File 'lib/cloud/vsphere/resources/cluster.rb', line 87

def free_memory
  @synced_free_memory -
    (@allocated_after_sync * cloud_config.mem_overcommit).to_i
end

#inspectString

Returns debug cluster information.

Returns:

  • (String)

    debug cluster information.



125
126
127
# File 'lib/cloud/vsphere/resources/cluster.rb', line 125

def inspect
  "<Cluster: #{mob} / #{config.name}>"
end

#nameString

Returns cluster name.

Returns:



120
121
122
# File 'lib/cloud/vsphere/resources/cluster.rb', line 120

def name
  config.name
end

#persistent(datastore_name) ⇒ Datastore?

Returns the persistent datastore by name. This could be either from the exclusive or shared datastore pools.

Parameters:

  • datastore_name (String)

    name of the datastore.

Returns:

  • (Datastore, nil)

    the requested persistent datastore.



81
82
83
84
# File 'lib/cloud/vsphere/resources/cluster.rb', line 81

def persistent(datastore_name)
  @persistent_datastores[datastore_name] ||
    @shared_datastores[datastore_name]
end

#pick_ephemeral(size) ⇒ Datastore?

Picks the best datastore for the specified ephemeral disk.

Parameters:

  • size (Integer)

    ephemeral disk size.

Returns:

  • (Datastore, nil)

    best datastore if available for the requested size.



115
116
117
# File 'lib/cloud/vsphere/resources/cluster.rb', line 115

def pick_ephemeral(size)
  pick_store(size, :ephemeral)
end

#pick_persistent(size) ⇒ Datastore?

Picks the best datastore for the specified persistent disk.

Parameters:

  • size (Integer)

    persistent disk size.

Returns:

  • (Datastore, nil)

    best datastore if available for the requested size.



106
107
108
# File 'lib/cloud/vsphere/resources/cluster.rb', line 106

def pick_persistent(size)
  pick_store(size, :persistent)
end