class VCenterDriver::DatastoreFolder

Class DatastoreFolder

Attributes

item[RW]
items[RW]

Public Class Methods

new(item) click to toggle source
# File lib/datastore.rb, line 32
def initialize(item)
    @item = item
    @items = {}
end

Public Instance Methods

fetch!() click to toggle source

Builds a hash with Datastore-Ref / Datastore to be used as a cache @return [Hash] in the form

{ ds_ref [Symbol] => Datastore object }
# File lib/datastore.rb, line 42
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) click to toggle source

Returns a Datastore or StoragePod. Uses the cache if available. @param ref [Symbol] the vcenter ref @return Datastore

# File lib/datastore.rb, line 63
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