Class: VCenterDriver::VirtualMachineFolder

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

Overview

VirtualMachineFolder class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ VirtualMachineFolder

Returns a new instance of VirtualMachineFolder.



24
25
26
27
28
# File 'lib/vm_folder.rb', line 24

def initialize(item)
    @item = item
    check_item(@item, nil)
    @items = {}
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



22
23
24
# File 'lib/vm_folder.rb', line 22

def item
  @item
end

#itemsObject

Returns the value of attribute items.



22
23
24
# File 'lib/vm_folder.rb', line 22

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 }



36
37
38
39
40
41
# File 'lib/vm_folder.rb', line 36

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

#fetch_templates!Object



43
44
45
46
47
48
49
50
# File 'lib/vm_folder.rb', line 43

def fetch_templates!
    VIClient.get_entities(@item, 'VirtualMachine').each do |item|
        if item.config.template
            item_name = item._ref
            @items[item_name.to_sym] = Template.new(item)
        end
    end
end

#get(ref) ⇒ Object

Returns a Datastore. Uses the cache if available.

Parameters:

  • ref (Symbol)

    the vcenter ref

Returns:

  • Datastore



58
59
60
61
62
63
64
65
# File 'lib/vm_folder.rb', line 58

def get(ref)
    if !@items[ref.to_sym]
        rbvmomi_dc = RbVmomi::VIM::Datastore.new(@item._connection, ref)
        @items[ref.to_sym] = Datastore.new(rbvmomi_dc)
    end

    @items[ref.to_sym]
end