clc-chef-metal-vsphere 0.3.38 → 0.3.39

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47586963a6feb866d9aa8d60c156c7064f0b9e1e
4
- data.tar.gz: fbef1ff90a768e55d9f2fc5afd49951573fbe7d1
3
+ metadata.gz: ffeed2248d274feab53dbbf62adced7b1ecd6d05
4
+ data.tar.gz: 3e6b3f078c8f292fecae21681bd25d420ce62754
5
5
  SHA512:
6
- metadata.gz: b93b258ab67cb89ce5be9954d9d35247cb98b4ff517112c846275bd4b5e16a8f0820033071709bc7912ea981e5de1770fd9ba5fc8dc63f3339baeffb42b01588
7
- data.tar.gz: 595817d3b1199f6230629ce720701039d754e888bd1dbd1b4a70de0c79df9378ab04a0285a882aaaa5614683f20c3d8debe69da904716b6a63b1556dac946cf0
6
+ metadata.gz: 5aa22207d144995dd61205bfbd0e4fe121bc82671ef44643ccc48cf0623efae4feea1e02d478fe40bd0a58426813bfaf6577d34f58f510a6be6ab7e1fb00d745
7
+ data.tar.gz: f409f5497804cbe31725bb60dd3cc444c984867559d672e6e9e756edb828faaf3d21b939cb8908e977f10bba15049ee96e0d69a1fc49ace54c36739c8e57bc84
@@ -1,3 +1,3 @@
1
1
  module ChefMetalVsphere
2
- VERSION = '0.3.38'
2
+ VERSION = '0.3.39'
3
3
  end
@@ -212,6 +212,7 @@ module ChefMetalVsphere
212
212
 
213
213
  until (Time.now.utc - now) > machine_options[:ready_timeout] || (vm.guest.net.map { |net| net.ipAddress}.flatten).include?(vm_ip) do
214
214
  action_handler.report_progress "IP addresses on #{machine_spec.name} are #{vm.guest.net.map { |net| net.ipAddress}.flatten}"
215
+ vm_ip = ip_for(bootstrap_options, vm) if vm_ip.nil?
215
216
  sleep 5
216
217
  end
217
218
  if !(vm.guest.net.map { |net| net.ipAddress}.flatten).include?(vm_ip)
@@ -4,8 +4,12 @@ module ChefMetalVsphere
4
4
  module Helpers
5
5
 
6
6
  def vim(options = connect_options)
7
- # reconnect on every call - connections may silently timeout during long operations (e.g. cloning)
8
- RbVmomi::VIM.connect options
7
+ if @current_connection.nil? or @current_connection.serviceContent.sessionManager.currentSession.nil?
8
+ puts "establishing connection to #{options[:host]}"
9
+ @current_connection = RbVmomi::VIM.connect options
10
+ end
11
+
12
+ @current_connection
9
13
  end
10
14
 
11
15
  def find_vm(dc_name, vm_folder, vm_name)
@@ -426,5 +430,31 @@ module ChefMetalVsphere
426
430
  raise "Customization Spec not found [#{customization_spec}]" if spec.nil?
427
431
  spec
428
432
  end
433
+
434
+ def upload_file_to_vm(vm, username, password, local, remote)
435
+ auth = RbVmomi::VIM::NamePasswordAuthentication({:username => username, :password => password, :interactiveSession => false})
436
+ size = File.size(local)
437
+ endpoint = vim.serviceContent.guestOperationsManager.fileManager.InitiateFileTransferToGuest(
438
+ :vm => vm,
439
+ :auth => auth,
440
+ :guestFilePath => remote,
441
+ :overwrite => true,
442
+ :fileAttributes => RbVmomi::VIM::GuestWindowsFileAttributes.new,
443
+ :fileSize => size)
444
+
445
+ uri = URI.parse(endpoint)
446
+ http = Net::HTTP.new(uri.host, uri.port)
447
+ http.use_ssl = true
448
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
449
+
450
+ req = Net::HTTP::Put.new("#{uri.path}?#{uri.query}")
451
+ req.body_stream = File.open(local)
452
+ req["Content-Type"] = "application/octet-stream"
453
+ req["Content-Length"] = size
454
+ res = http.request(req)
455
+ unless res.kind_of?(Net::HTTPSuccess)
456
+ raise "Error: #{res.inspect} :: #{res.body} :: sending #{local} to #{remote} at #{vm.name} via #{endpoint} with a size of #{size}"
457
+ end
458
+ end
429
459
  end
430
460
  end
@@ -1,4 +1,5 @@
1
1
  require 'kitchen/driver/vsphere_common'
2
+ require 'zip'
2
3
 
3
4
  module Kitchen
4
5
  module Driver
@@ -21,9 +22,108 @@ module Kitchen
21
22
  :win_time_zone => 4
22
23
  }
23
24
  }
25
+
26
+ attr_reader :connect_options
24
27
 
25
28
  include Kitchen::Driver::VsphereCommon
29
+ include ChefMetalVsphere::Helpers
26
30
 
31
+ def initialize(config = {})
32
+ super
33
+
34
+ @connect_options = config[:driver_options]
35
+ end
36
+
37
+ # We are overriding the stock test-kitchen winrm implementation
38
+ # and leveraging vsphere's ability to upload files to the guest.
39
+ # We zip, then send through vsphere and unzip over winrm
40
+ def upload!(local, remote, winrm_connection)
41
+ debug("Upload: #{local} -> #{remote}")
42
+ if File.directory?(local)
43
+ upload_directory(local, remote, winrm_connection)
44
+ else
45
+ upload_file(local, File.join(remote, File.basename(local)), winrm_connection)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def sanitize_path(path, connection)
52
+ command = <<-EOH
53
+ $dest_file_path = [System.IO.Path]::GetFullPath('#{path}')
54
+
55
+ if (!(Test-Path $dest_file_path)) {
56
+ $dest_dir = ([System.IO.Path]::GetDirectoryName($dest_file_path))
57
+ New-Item -ItemType directory -Force -Path $dest_dir | Out-Null
58
+ }
59
+
60
+ $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("#{path}")
61
+ EOH
62
+
63
+ send_winrm(connection, command)
64
+ end
65
+
66
+ def upload_file(local, remote, connection)
67
+ if connection.should_upload_file?(local, remote)
68
+ remote = sanitize_path(remote, connection).strip
69
+ vm = vim.searchIndex.FindByIp(:ip => connection.hostname, :vmSearch => true)
70
+ upload_file_to_vm(vm,connection.username, connection.options[:password], local, remote)
71
+ end
72
+ end
73
+
74
+ def upload_directory(local, remote, connection)
75
+ zipped = zip_path(local)
76
+ return if !File.exist?(zipped)
77
+ remote_zip = File.join(remote, File.basename(zipped))
78
+ debug "uploading #{zipped} to #{remote_zip}"
79
+ upload_file(zipped, remote_zip, connection)
80
+ extract_zip(remote_zip, connection)
81
+ end
82
+
83
+ def extract_zip(remote_zip, connection)
84
+ debug "extracting #{remote_zip} to #{remote_zip.gsub('/','\\').gsub('.zip','')}"
85
+ command = <<-EOH
86
+ $shellApplication = new-object -com shell.application
87
+ $zip_path = "$($env:systemDrive)#{remote_zip.gsub('/','\\')}"
88
+ $zipPackage = $shellApplication.NameSpace($zip_path)
89
+ $dest_path = "$($env:systemDrive)#{remote_zip.gsub('/','\\').gsub('.zip','')}"
90
+ mkdir $dest_path -ErrorAction SilentlyContinue
91
+ $destinationFolder = $shellApplication.NameSpace($dest_path)
92
+ $destinationFolder.CopyHere($zipPackage.Items(),0x10)
93
+ Remove-Item $zip_path
94
+ EOH
95
+
96
+ send_winrm(connection, command)
97
+ end
98
+
99
+ def zip_path(path)
100
+ path.sub!(%r[/$],'')
101
+ archive = File.join(path,File.basename(path))+'.zip'
102
+ FileUtils.rm archive, :force=>true
103
+
104
+ Zip::File.open(archive, 'w') do |zipfile|
105
+ Dir["#{path}/**/**"].reject{|f|f==archive}.each do |file|
106
+ zipfile.add(file.sub(path+'/',''),file)
107
+ end
108
+ end
109
+
110
+ archive
111
+ end
112
+
113
+ def send_winrm(connection, command)
114
+ cmd = connection.powershell("$ProgressPreference='SilentlyContinue';" + command)
115
+ stdout = (cmd[:data].map {|out| out[:stdout]}).join
116
+ stderr = (cmd[:data].map {|out| out[:stderr]}).join
117
+
118
+ if cmd[:exitcode] != 0 || ! stderr.empty?
119
+ raise WinRMFailed,
120
+ "WinRM exited (#{cmd[:exitcode]}) for
121
+ command: [#{command}]\nREMOTE ERROR:\n" +
122
+ stderr
123
+ end
124
+
125
+ stdout
126
+ end
27
127
  end
28
128
  end
29
129
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clc-chef-metal-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.38
4
+ version: 0.3.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-25 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubyzip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.6
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.6
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement