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

View differences:

src/vmm_mad/remotes/lib/vcenter_driver/host.rb
1 1
module VCenterDriver
2 2

  
3 3
class HostFolder
4
    attr_accessor :item, :clusters
4
    attr_accessor :item, :items
5 5

  
6 6
    def initialize(item)
7 7
        @item = item
8
        @clusters = {}
8
        @items = {}
9 9
    end
10 10

  
11 11
    def fetch_clusters!
12 12
        VIClient.get_entities(@item, 'ClusterComputeResource').each do |item|
13 13
            item_name = item._ref
14
            @clusters[item_name.to_sym] = ClusterComputeResource.new(item)
14
            @items[item_name.to_sym] = ClusterComputeResource.new(item)
15 15
        end
16 16
    end
17 17

  
18 18
    def get_cluster(ref)
19
        if !@clusters[ref.to_sym]
19
        if !@items[ref.to_sym]
20 20
            rbvmomi_dc = RbVmomi::VIM::ClusterComputeResource.new(@item._connection, ref)
21
            @clusters[ref.to_sym] = ClusterComputeResource.new(rbvmomi_dc)
21
            @items[ref.to_sym] = ClusterComputeResource.new(rbvmomi_dc)
22 22
        end
23 23

  
24
        @clusters[ref.to_sym]
24
        @items[ref.to_sym]
25 25
    end
26 26
end # class HostFolder
27 27

  
......
53 53
        @resource_pools
54 54
    end
55 55

  
56
    def get_resource_pool_list(rp = nil, parent_prefix = "", rp_array = [])
57

  
58
        current_rp = ""
59

  
60
        if rp.nil?
61
            rp = @item.resourcePool
62
        else
63
            if !parent_prefix.empty?
64
                current_rp << parent_prefix
65
                current_rp << "/"
66
            end
67
            current_rp << rp.name
68
        end
69

  
70
        if rp.resourcePool.size == 0
71
            rp_info = {}
72
            rp_info[:name] = current_rp
73
            rp_info[:ref]  = rp._ref
74
            rp_array << rp_info
75
        else
76
            rp.resourcePool.each do |child_rp|
77
                get_resource_pool_list(child_rp, current_rp, rp_array)
78
            end
79
            rp_info = {}
80
            rp_info[:name] = current_rp
81
            rp_info[:ref]  = rp._ref
82
            rp_array << rp_info if !current_rp.empty?
83
        end
84

  
85
        rp_array
86
    end
87

  
56 88
    def monitor
57 89
        #Load the host systems
58 90
        summary = @item.summary
......
236 268
                }
237 269

  
238 270
                if number == -1
239
                    vm_template_64 = Base64.encode64(vm.to_one(ccr_host)).gsub("\n","")
271
                    vm_template_64 = Base64.encode64(vm.to_one).gsub("\n","")
240 272

  
241 273
                    str_info << "IMPORT_TEMPLATE=\"#{vm_template_64}\","
242 274
                end
......
281 313
        Datacenter.new(item)
282 314
    end
283 315

  
316
    def self.to_one(name, host, user, pass, ref, vc_uuid)
317

  
318
        one_host = VCenterDriver::VIHelper.one_item(OpenNebula::Host)
319

  
320
        if OpenNebula.is_error?(one_host)
321
            raise "Could not create host: #{one_host.message}"
322
        end
323

  
324
        rc = one_host.allocate(name, 'vcenter', 'vcenter',
325
                ::OpenNebula::ClusterPool::NONE_CLUSTER_ID)
326

  
327
        if OpenNebula.is_error?(rc)
328
            raise "Could not allocate host: #{rc.message}"
329
        end
330

  
331
        template = "VCENTER_HOST=\"#{host}\"\n"\
332
                   "VCENTER_PASSWORD=\"#{pass}\"\n"\
333
                   "VCENTER_USER=\"#{user}\"\n"\
334
                   "VCENTER_CCR_REF=\"#{ref}\"\n"\
335
                   "VCENTER_INSTANCE_ID=\"#{vc_uuid}\"\n"
336

  
337
        rc = one_host.update(template, false)
338

  
339
        if OpenNebula.is_error?(rc)
340
            update_error = rc.message
341
            rc = one_host.delete
342
            if OpenNebula.is_error?(rc)
343
                raise "Could not update host: #{update_error} "\
344
                      "and could not delete host: #{rc.message}"
345
            else
346
                raise "Could not update host: #{rc.message}"
347
            end
348
        end
349

  
350
        return one_host
351
    end
352

  
284 353
    def self.new_from_ref(ref, vi_client)
285 354
        self.new(RbVmomi::VIM::ClusterComputeResource.new(vi_client.vim, ref), vi_client)
286 355
    end

Also available in: Unified diff