Revision fc41d302 src/vmm_mad/remotes/lib/vcenter_driver/vi_client.rb

View differences:

src/vmm_mad/remotes/lib/vcenter_driver/vi_client.rb
7 7
    attr_accessor :rp
8 8

  
9 9
    def initialize(opts)
10

  
10 11
        opts = {:insecure => true}.merge(opts)
11 12
        @vim = RbVmomi::VIM.connect(opts)
12 13

  
13
        rp_ref = opts.delete(:rp)
14
        @rp = RbVmomi::VIM::ResourcePool(@vim, rp_ref) if rp_ref
14
        # Get ccr
15
        ccr_ref = opts.delete(:ccr)
16
        ccr = RbVmomi::VIM::ClusterComputeResource.new(@vim, ccr_ref)
17

  
18
        #Get ref for rp
19
        if ccr
20
            rp = opts.delete(:rp)
21
            rp_list = get_resource_pool_list(ccr)
22
            rp_ref = rp_list.select { |r| r[:name] == rp }.first._ref rescue nil
23
            @rp = RbVmomi::VIM::ResourcePool(@vim, rp_ref) if rp_ref
24
        end
15 25
    end
16 26

  
17 27
    def rp_confined?
18 28
        !!@rp
19 29
    end
20 30

  
31
    def get_resource_pool_list(ccr, rp = nil, parent_prefix = "", rp_array = [])
32

  
33
        current_rp = ""
34

  
35
        if rp.nil?
36
            rp = ccr.resourcePool
37
        else
38
            if !parent_prefix.empty?
39
                current_rp << parent_prefix
40
                current_rp << "/"
41
            end
42
            current_rp << rp.name
43
        end
44

  
45
        if rp.resourcePool.size == 0
46
            rp_info = {}
47
            rp_info[:name] = current_rp
48
            rp_info[:ref]  = rp._ref
49
            rp_array << rp_info
50
        else
51
            rp.resourcePool.each do |child_rp|
52
                get_resource_pool_list(ccr, child_rp, current_rp, rp_array)
53
            end
54
            rp_info = {}
55
            rp_info[:name] = current_rp
56
            rp_info[:ref]  = rp._ref
57
            rp_array << rp_info if !current_rp.empty?
58
        end
59

  
60
        rp_array
61
    end
62

  
21 63
    def close_connection
22 64
        @vim.close
23 65
    end
......
66 108
        connection = {
67 109
            :host     => host["TEMPLATE/VCENTER_HOST"],
68 110
            :user     => host["TEMPLATE/VCENTER_USER"],
69
            :rp       => host["TEMPLATE/VCENTER_RP_REF"],
111
            :rp       => host["TEMPLATE/VCENTER_RESOURCE_POOL"],
112
            :ccr      => host["TEMPLATE/VCENTER_CCR_REF"],
70 113
            :password => password
71 114
        }
72 115

  

Also available in: Unified diff