Class: RbVmomi::VIM::OvfManager
- Inherits:
-
Object
- Object
- RbVmomi::VIM::OvfManager
- Defined in:
- lib/rbvmomi/extensions.rb
Instance Method Summary collapse
-
#deployOVF(opts = {}) ⇒ Object
Parameters: uri vmName vmFolder host resourcePool datastore networkMappings = {} propertyMappings = {} diskProvisioning = :thin.
Instance Method Details
#deployOVF(opts = {}) ⇒ Object
Parameters: uri vmName vmFolder host resourcePool datastore networkMappings = {} propertyMappings = {} diskProvisioning = :thin
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/rbvmomi/extensions.rb', line 370 def deployOVF opts={} opts = { networkMappings: {}, propertyMappings: {}, diskProvisioning: :thin }.merge opts %w(uri vmName vmFolder host resourcePool datastore).each do |k| fail "parameter #{k} required" unless opts[k.to_sym] end ovfImportSpec = VIM::OvfCreateImportSpecParams( hostSystem: opts[:host], locale: "US", entityName: opts[:vmName], deploymentOption: "", networkMapping: opts[:networkMappings].map{|from, to| VIM::OvfNetworkMapping(name: from, network: to)}, propertyMapping: opts[:propertyMappings].map{|key, value| VIM::KeyValue(key: key, value: value)}, diskProvisioning: opts[:diskProvisioning] ) result = CreateImportSpec( ovfDescriptor: open(opts[:uri]).read, resourcePool: opts[:resourcePool], datastore: opts[:datastore], cisp: ovfImportSpec ) raise result.error[0].localizedMessage if result.error && !result.error.empty? if result.warning result.warning.each{|x| puts "OVF Warning: #{x.localizedMessage.chomp}" } end nfcLease = opts[:resourcePool].ImportVApp(spec: result.importSpec, folder: opts[:vmFolder], host: opts[:host]) nfcLease.wait_until(:state) { nfcLease.state != "initializing" } raise nfcLease.error if nfcLease.state == "error" begin nfcLease.HttpNfcLeaseProgress(percent: 5) progress = 0.0 result.fileItem.each do |fileItem| deviceUrl = nfcLease.info.deviceUrl.find{|x| x.importKey == fileItem.deviceId} if !deviceUrl raise "Couldn't find deviceURL for device '#{fileItem.deviceId}'" end # XXX handle file:// URIs ovfFilename = opts[:uri].to_s tmp = ovfFilename.split(/\//) tmp.pop tmp << fileItem.path filename = tmp.join("/") method = fileItem.create ? "PUT" : "POST" href = deviceUrl.url.gsub("*", opts[:host].config.network.vnic[0].spec.ip.ipAddress) downloadCmd = "#{CURLBIN} -L '#{filename}'" uploadCmd = "#{CURLBIN} -X #{method} --insecure -T - -H 'Content-Type: application/x-vnd.vmware-streamVmdk' -H 'Content-Length: #{fileItem.size}' '#{href}'" system("#{downloadCmd} | #{uploadCmd}") progress += (95.0 / result.fileItem.length) nfcLease.HttpNfcLeaseProgress(percent: progress.to_i) end nfcLease.HttpNfcLeaseProgress(percent: 100) vm = nfcLease.info.entity nfcLease.HttpNfcLeaseComplete vm end rescue Exception nfcLease.HttpNfcLeaseAbort raise end |