Class: VCenterDriver::DatastoreFolder

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

Overview

Class DatastoreFolder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ DatastoreFolder

Returns a new instance of DatastoreFolder.



45
46
47
48
# File 'lib/datastore.rb', line 45

def initialize(item)
    @item = item
    @items = {}
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



43
44
45
# File 'lib/datastore.rb', line 43

def item
  @item
end

#itemsObject

Returns the value of attribute items.



43
44
45
# File 'lib/datastore.rb', line 43

def items
  @items
end

Instance Method Details

#fetch!Hash

Builds a hash with Datastore-Ref / Datastore to be used as a cache

Returns:

  • (Hash)

    in the form { ds_ref [Symbol] => Datastore object }



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/datastore.rb', line 55

def fetch!
    VIClient.get_entities(@item, 'Datastore').each do |item|
        item_name = item._ref
        @items[item_name.to_sym] = Datastore.new(item)
    end

    VIClient.get_entities(@item, 'StoragePod').each do |sp|
        @items[sp._ref.to_sym] = StoragePod.new(sp)
        VIClient.get_entities(sp, 'Datastore').each do |item|
            item_name = item._ref
            @items[item_name.to_sym] = Datastore.new(item)
        end
    end
    @items
end

#get(ref) ⇒ Object

Returns a Datastore or StoragePod. Uses the cache if available.

Parameters:

  • ref (Symbol)

    the vcenter ref

Returns:

  • Datastore



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/datastore.rb', line 76

def get(ref)
    if !@items[ref.to_sym]
        if ref.start_with?('group-')
            rbvmomi_spod = RbVmomi::VIM::StoragePod
                           .new(
                               @item._connection,
                               ref
                           ) rescue nil
            @items[ref.to_sym] = StoragePod.new(rbvmomi_spod)
        else
            rbvmomi_ds = RbVmomi::VIM::Datastore
                         .new(
                             @item._connection,
                             ref
                         ) rescue nil
            @items[ref.to_sym] = Datastore.new(rbvmomi_ds)
        end
    end
    @items[ref.to_sym]
end