Revision e6a57b0f src/sunstone/routes/vcenter.rb

View differences:

src/sunstone/routes/vcenter.rb
88 88
            error 404, error.to_json
89 89
        end
90 90

  
91
        rs = dc_folder.get_unimported_hosts(hpool)
91
        rs = dc_folder.get_unimported_hosts(hpool,vcenter_client.vim.host)
92 92
        [200, rs.to_json]
93 93
    rescue Exception => e
94 94
        logger.error("[vCenter] " + e.message)
......
110 110
            error 404, error.to_json
111 111
        end
112 112

  
113
        templates = dc_folder.get_unimported_templates(vcenter_client, tpool)
113
        templates = dc_folder.get_unimported_templates(vcenter_client, tpool, vcenter_client.vim.host)
114 114

  
115 115
        if templates.nil?
116 116
            msg = "No datacenter found"
......
131 131
    begin
132 132
        t = {}
133 133
        t[:one] = ""
134
        template_copy_ref = nil
135
        template = nil
136
        append = true
137
        lc_error = nil
134 138

  
135
        template = VCenterDriver::VirtualMachine.new_from_ref(params[:vcenter_ref], vcenter_client)
139
        ref = params[:vcenter_ref]
136 140

  
141
        if !ref || ref.empty?
142
            msg = "No template ref specified"
143
            logger.error("[vCenter] " + msg)
144
            error = Error.new(msg)
145
            error 404, error.to_json
146
        end
147

  
148
        template = VCenterDriver::Template.new_from_ref(ref, vcenter_client)
137 149
        vc_uuid = vcenter_client.vim.serviceContent.about.instanceUuid
138 150
        dpool = VCenterDriver::VIHelper.one_pool(OpenNebula::DatastorePool)
139 151
        ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
140 152
        npool = VCenterDriver::VIHelper.one_pool(OpenNebula::VirtualNetworkPool)
141 153

  
154
        # POST params
155
        if @request_body && !@request_body.empty?
156
            body_hash = JSON.parse(@request_body)
157
            use_linked_clones = body_hash['use_linked_clones'] || false
158
            create_copy = body_hash['create_copy'] || false
159
            template_name = body_hash['template_name'] || ""
160

  
161
            if !use_linked_clones && (create_copy || !template_name.empty?)
162
                msg = "Should not set create template copy or template copy name if not using linked clones"
163
                logger.error("[vCenter] " + msg)
164
                error = Error.new(msg)
165
                error 403, error.to_json
166
            end
167

  
168
            if use_linked_clones && !create_copy && !template_name.empty?
169
                msg = "Should not set template copy name if create template copy hasn't been selected"
170
                logger.error("[vCenter] " + msg)
171
                error = Error.new(msg)
172
                error 403, error.to_json
173
            end
174

  
175
            if create_copy
176

  
177
                lc_error, template_copy_ref = template.create_template_copy(template_name)
178

  
179
                if template_copy_ref
180

  
181
                    template = VCenterDriver::Template.new_from_ref(template_copy_ref, vi_client)
182

  
183
                    one_template = VCenterDriver::Template.get_xml_template(template, vc_uuid, vi_client, vcenter_client.vim.host)
184

  
185
                    if one_template
186

  
187
                        lc_error, use_lc = template.create_delta_disks
188
                        if !lc_error
189
                            one_template[:one] << "\nVCENTER_LINKED_CLONES=\"YES\"\n"
190
                            t = one_template
191
                            append = false # t[:one] replaces the current template
192
                        end
193
                    else
194
                        lc_error = "Could not obtain the info from the template's copy"
195
                        template.delete_template if template_copy_ref
196
                    end
197
                end
198

  
199
            else
200
                lc_error, use_lc = template.create_delta_disks
201
                if !lc_error
202
                    append = true
203
                    t[:one] << "\nVCENTER_LINKED_CLONES=\"YES\"\n" if use_lc
204
                end
205
            end
206
        end
207

  
142 208
        # Create images or get disks information for template
143 209
        error, template_disks = template.import_vcenter_disks(vc_uuid, dpool, ipool)
144 210

  
145 211
        if !error.empty?
212
            append = false
213
            template.delete_template if template_copy_ref
146 214
            msg = error
147 215
            logger.error("[vCenter] " + msg)
148 216
            error = Error.new(msg)
......
155 223
        error, template_nics = template.import_vcenter_nics(vc_uuid, npool)
156 224

  
157 225
        if !error.empty?
226
            append = false
227
            template.delete_template if template_copy_ref
158 228
            msg = error
159 229
            logger.error("[vCenter] " + msg)
160 230
            error = Error.new(msg)
......
163 233

  
164 234
        t[:one] << template_nics
165 235

  
236
        t[:lc_error] = lc_error
237
        t[:append] = append
238

  
166 239
        [200, t.to_json]
167 240
    rescue Exception => e
241
        template.delete_template if template_copy_ref
168 242
        logger.error("[vCenter] " + e.message)
169 243
        error = Error.new(e.message)
170 244
        error 403, error.to_json
......
184 258
            error 404, error.to_json
185 259
        end
186 260

  
187
        networks = dc_folder.get_unimported_networks(npool)
261
        networks = dc_folder.get_unimported_networks(npool,vcenter_client.vim.host)
188 262

  
189 263
        if networks.nil?
190 264
            msg = "No datacenter found"
......
231 305
    begin
232 306
        dc_folder = VCenterDriver::DatacenterFolder.new(vcenter_client)
233 307

  
234
        hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::DatastorePool, false)
308
        dpool = VCenterDriver::VIHelper.one_pool(OpenNebula::DatastorePool, false)
309

  
310
        if dpool.respond_to?(:message)
311
            msg = "Could not get OpenNebula DatastorePool: #{dpool.message}"
312
            logger.error("[vCenter] " + msg)
313
            error = Error.new(msg)
314
            error 404, error.to_json
315
        end
316

  
317

  
318
        hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool, false)
235 319

  
236 320
        if hpool.respond_to?(:message)
237
            msg = "Could not get OpenNebula DatastorePool: #{hpool.message}"
321
            msg = "Could not get OpenNebula HostPool: #{hpool.message}"
238 322
            logger.error("[vCenter] " + msg)
239 323
            error = Error.new(msg)
240 324
            error 404, error.to_json
241 325
        end
242 326

  
243
        datastores = dc_folder.get_unimported_datastores(hpool)
327

  
328
        datastores = dc_folder.get_unimported_datastores(dpool, vcenter_client.vim.host, hpool)
244 329
        if datastores.nil?
245 330
            msg = "No datacenter found"
246 331
            logger.error("[vCenter] " + msg)

Also available in: Unified diff