Class: VSphereCloud::Resources::Datastore

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/vsphere/resources/datastore.rb

Overview

Datastore resource.

Constant Summary collapse

PROPERTIES =
%w(summary.freeSpace summary.capacity name)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties) ⇒ Datastore

Creates a Datastore resource from the prefetched vSphere properties.

Parameters:

  • properties (Hash)

    prefetched vSphere properties to build the model.



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

def initialize(properties)
  @mob = properties[:obj]
  @name = properties["name"]
  @total_space = properties["summary.capacity"].to_i / BYTES_IN_MB
  @synced_free_space = properties["summary.freeSpace"].to_i / BYTES_IN_MB
  @allocated_after_sync = 0
end

Instance Attribute Details

#allocated_after_syncInteger

Returns allocated space since vSphere fetch.

Returns:

  • (Integer)

    allocated space since vSphere fetch.



26
27
28
# File 'lib/cloud/vsphere/resources/datastore.rb', line 26

def allocated_after_sync
  @allocated_after_sync
end

#mobVim::Datastore

Returns datastore vSphere MOB.

Returns:

  • (Vim::Datastore)

    datastore vSphere MOB.



10
11
12
# File 'lib/cloud/vsphere/resources/datastore.rb', line 10

def mob
  @mob
end

#nameString

Returns datastore name.

Returns:

  • (String)

    datastore name.



14
15
16
# File 'lib/cloud/vsphere/resources/datastore.rb', line 14

def name
  @name
end

#synced_free_spaceInteger

Returns datastore free space when fetched from vSphere.

Returns:

  • (Integer)

    datastore free space when fetched from vSphere.



22
23
24
# File 'lib/cloud/vsphere/resources/datastore.rb', line 22

def synced_free_space
  @synced_free_space
end

#total_spaceInteger

Returns datastore capacity.

Returns:

  • (Integer)

    datastore capacity.



18
19
20
# File 'lib/cloud/vsphere/resources/datastore.rb', line 18

def total_space
  @total_space
end

Instance Method Details

#allocate(space) ⇒ void

This method returns an undefined value.

Marks the disk space against the cached utilization data.

Parameters:

  • space (Integer)

    requested disk space.



49
50
51
# File 'lib/cloud/vsphere/resources/datastore.rb', line 49

def allocate(space)
  @allocated_after_sync += space
end

#free_spaceInteger

Returns free disk space available for allocation.

Returns:

  • (Integer)

    free disk space available for allocation



41
42
43
# File 'lib/cloud/vsphere/resources/datastore.rb', line 41

def free_space
  @synced_free_space - @allocated_after_sync
end

#inspectString

Returns debug datastore information.

Returns:

  • (String)

    debug datastore information.



54
55
56
# File 'lib/cloud/vsphere/resources/datastore.rb', line 54

def inspect
  "<Datastore: #@mob / #@name>"
end