Class: VCenterDriver::NetworkFolder

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

Overview

Class NetworkFolder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ NetworkFolder

Returns a new instance of NetworkFolder.



31
32
33
34
# File 'lib/network.rb', line 31

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

Instance Attribute Details

#itemObject

Returns the value of attribute item.



29
30
31
# File 'lib/network.rb', line 29

def item
  @item
end

#itemsObject

Returns the value of attribute items.



29
30
31
# File 'lib/network.rb', line 29

def items
  @items
end

Instance Method Details

#fetch!Hash

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

Returns:

  • (Hash)

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/network.rb', line 41

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

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

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

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

#get(ref) ⇒ Object

Returns a Network. Uses the cache if available.

Parameters:

  • ref (Symbol)

    the vcenter ref

Returns:

  • Network



76
77
78
79
80
81
82
83
# File 'lib/network.rb', line 76

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

    @items[ref.to_sym]
end