Revision 400f5126

View differences:

src/sunstone/public/app/utils/vcenter/clusters.js
100 100
            var newdiv = $(content).appendTo($(".vcenter_datacenter_list", context));
101 101
            var tbody = $('#' + tableId + ' tbody', context);
102 102

  
103
            $.each(elements, function(id, cluster_name) {
103
            $.each(elements, function(id, cluster) {
104
              var cluster_name = cluster.cluster_name;
104 105
              var opts = { name: cluster_name };
105 106
              var trow = $(RowTemplate(opts)).appendTo(tbody);
106 107

  
107
              $(".check_item", trow).data("cluster_name", cluster_name);
108
              $(".check_item", trow).data("cluster", cluster);
108 109
            });
109 110

  
110 111
            var elementsTable = new DomDataTable(
......
165 166

  
166 167
        var host_json = {
167 168
          "host": {
168
            "name": $(this).data("cluster_name"),
169
            "name": $(this).data("cluster").cluster_name,
169 170
            "vm_mad": "vcenter",
170 171
            "vnm_mad": "dummy",
171 172
            "im_mad": "vcenter",
......
173 174
          }
174 175
        };
175 176

  
177
        var cluster_ref = $(this).data("cluster").cluster_ref;
178
        var vcenter_uuid = $(this).data("cluster").vcenter_uuid;
179
        var vcenter_version = $(this).data("cluster").vcenter_version;
180

  
176 181
        OpenNebulaHost.create({
177 182
          timeout: true,
178 183
          data: host_json,
......
185 190
            var template_raw =
186 191
              "VCENTER_USER=\"" + that.opts.vcenter_user + "\"\n" +
187 192
              "VCENTER_PASSWORD=\"" + that.opts.vcenter_password + "\"\n" +
188
              "VCENTER_HOST=\"" + that.opts.vcenter_host + "\"\n";
193
              "VCENTER_HOST=\"" + that.opts.vcenter_host + "\"\n" +
194
              "VCENTER_INSTANCE_ID=\"" + vcenter_uuid + "\"\n" +
195
              "VCENTER_CCR_REF=\"" + cluster_ref + "\"\n" +
196
              "VCENTER_VERSION=\"" + vcenter_version + "\"\n";
189 197

  
190 198
            Sunstone.runAction("Host.update_template", response.HOST.ID, template_raw);
191 199
          },
src/sunstone/routes/vcenter.rb
56 56
            error 404, error.to_json
57 57
        end
58 58

  
59
        return VCenterDriver::VIClient.new_connection({
59
        return VCenterDriver::VIClient.new({
60 60
            :user     => vuser,
61 61
            :password => vpass,
62
            :host     => vhost},
63
            ::OpenNebula::Client.new(nil,$conf[:one_xmlrpc]))
62
            :host     => vhost})
63

  
64 64
    end
65 65

  
66 66
#    def af_format_response(resp)
......
77 77

  
78 78
get '/vcenter' do
79 79
    begin
80
        rs = vcenter_client.hierarchy
80
        dc_folder = VCenterDriver::DatacenterFolder.new(vcenter_client)
81
        rs = dc_folder.get_unimported_hosts
81 82
        [200, rs.to_json]
82 83
    rescue Exception => e
83 84
        logger.error("[vCenter] " + e.message)
src/vmm_mad/remotes/lib/vcenter_driver/datacenter.rb
38 38
        @vi_client.vim.serviceContent.about.instanceUuid
39 39
    end
40 40

  
41
    def get_vcenter_api_version
42
        @vi_client.vim.serviceContent.about.apiVersion
43
    end
44

  
41 45
    def get_clusters
42 46

  
43 47
        clusters = {}
......
85 89

  
86 90
        vcenter_uuid = get_vcenter_instance_uuid
87 91

  
92
        vcenter_version = get_vcenter_api_version
93

  
88 94
        hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool, false)
89 95

  
90 96
        if hpool.respond_to?(:message)
......
108 114
                                                               hpool)
109 115
                next if one_host #If the host has been already imported
110 116

  
111
                host_objects[dc_name] << host
117
                host_info = {}
118
                host_info[:cluster_name]     = host['name']
119
                host_info[:cluster_ref]      = host['_ref']
120
                host_info[:vcenter_uuid]     = vcenter_uuid
121
                host_info[:vcenter_version]  = vcenter_version
122

  
123
                host_objects[dc_name] << host_info
112 124
            end
113 125
        end
114 126

  
src/vmm_mad/remotes/lib/vcenter_driver/host.rb
313 313
        Datacenter.new(item)
314 314
    end
315 315

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

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

  
......
321 321
            raise "Could not create host: #{one_host.message}"
322 322
        end
323 323

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

  
327 327
        if OpenNebula.is_error?(rc)
328 328
            raise "Could not allocate host: #{rc.message}"
329 329
        end
330 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
                   "VCENTER_VERSION=\"#{vc_version}\"\n"\
331
        template = "VCENTER_HOST=\"#{con_ops[:host]}\"\n"\
332
                   "VCENTER_PASSWORD=\"#{con_ops[:password]}\"\n"\
333
                   "VCENTER_USER=\"#{con_ops[:user]}\"\n"\
334
                   "VCENTER_CCR_REF=\"#{cluster[:cluster_ref]}\"\n"\
335
                   "VCENTER_INSTANCE_ID=\"#{cluster[:vcenter_uuid]}\"\n"\
336
                   "VCENTER_VERSION=\"#{cluster[:vcenter_version]}\"\n"\
337 337

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

  
src/vmm_mad/remotes/lib/vcenter_driver/importer.rb
34 34
                next
35 35
            end
36 36

  
37
            clusters.each{ |c|
38
                imported_name = "#{c["name"]}"
39
                STDOUT.print "  * Import cluster #{imported_name} (y/[n])? "
37
            clusters.each{ |cluster|
38
                STDOUT.print "  * Import cluster #{cluster[:cluster_name]} (y/[n])? "
40 39

  
41 40
                next if STDIN.gets.strip.downcase != 'y'
42 41

  
43
                one_host = VCenterDriver::ClusterComputeResource.to_one(imported_name,
44
                                                                        con_ops[:host],
45
                                                                        con_ops[:user],
46
                                                                        con_ops[:password],
47
                                                                        c['_ref'],
48
                                                                        vc_uuid,
49
                                                                        vc_version)
42
                one_host = VCenterDriver::ClusterComputeResource.to_one(cluster,
43
                                                                        con_ops)
50 44

  
51
                STDOUT.puts "    OpenNebula host #{imported_name} with "\
45
                STDOUT.puts "    OpenNebula host #{cluster[:cluster_name]} with "\
52 46
                            " id #{one_host.id} successfully created."
53 47
                STDOUT.puts
54 48
            }

Also available in: Unified diff