Revision 347968ad src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb

View differences:

src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb
24 24
        return_if_error(rc, item, exit_if_fail)
25 25
    end
26 26

  
27
    def self.new_one_item(the_class)
28
        item = the_class.new(the_class.build_xml, client)
29
        return item
30
    end
31

  
27 32
    def self.one_pool(the_class, exit_if_fail = true)
28 33
        item = the_class.new(client)
29 34
        rc = item.info
30 35
        return_if_error(rc, item, exit_if_fail)
31 36
    end
32 37

  
33
    def self.find_by_name(the_class, name, exit_if_fail = true)
34
        pool = one_pool(the_class)
35
        element = pool.select{|e| e['NAME'] == name }.first rescue nil
36
        if element.nil?
38
    def self.find_by_name(the_class, name, pool = nil, raise_if_fail = true)
39
        pool = one_pool(the_class, raise_if_fail) if pool.nil?
40
        element = pool.select{|e| e['NAME'] == "#{name}" }.first rescue nil
41
        if element.nil? && raise_if_fail
37 42
            raise "Could not find element '#{name}' in pool '#{the_class}'"
38 43
        else
39 44
            element
40 45
        end
41 46
    end
47

  
48
    def self.find_by_ref(the_class, attribute, ref, vcenter_uuid, pool = nil)
49
        pool = one_pool(the_class, false) if pool.nil?
50
        element = pool.select{|e|
51
            e["#{attribute}"] == ref &&
52
            e["TEMPLATE/VCENTER_INSTANCE_ID"] == vcenter_uuid}.first rescue nil
53

  
54
        return element
55
    end
56

  
42 57
end # class VIHelper
43 58

  
44 59
end # module VCenterDriver

Also available in: Unified diff