clc-chef-metal-vsphere 0.3.53 → 0.3.54

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: f1569eb531cf6e5e16b3ce7b0df3548fb4d62e61
4
- data.tar.gz: 90f2adcfb6746f1608d85319fa39baec0bd5681f
3
+ metadata.gz: 1cdf54d237686265e3ff0e7b24bcc2c64d5f2577
4
+ data.tar.gz: a1aa849d6f42a5af24956b71a29dd315401c645b
5
5
  SHA512:
6
- metadata.gz: ddb6857f682b6a2231bc447d51bfffb8b2f6d744dc23d2e2441fcc5862b8f757dc87b350ca08b05e899542021668184adb9008f6d69371fcba7260837c16b2eb
7
- data.tar.gz: 8cc91c2cde4736008b1ccbdb03349d10170fec2cc38da9215214318128fc3c14bd3e17c62c5299d3ff8220c1bd774e636aee478707a9bb8fdd9849858bf2d433
6
+ metadata.gz: 359d208bb49fb37174e174fc042edaf4cc578120f5b9557536d4128c824dd0662ea163d39821864208d903b4a1f1aabc520f4538d9a531d98efba6325bdbc0a4
7
+ data.tar.gz: a0c97b7093f83345d737c45d18e7ee63b140f5ded43804b70e670ad6cac3ee315fb4f1f442e01517586f6eb3a2fe2762d5e13f295d52ebb60bf785497cc0d67d
@@ -1,3 +1,3 @@
1
1
  module ChefMetalVsphere
2
- VERSION = '0.3.53'
2
+ VERSION = '0.3.54'
3
3
  end
@@ -1,8 +1,10 @@
1
- require 'kitchen/driver/vsphere_common'
1
+ require 'kitchen'
2
+ require 'chef_metal_vsphere/vsphere_driver'
3
+ require 'chef_metal/chef_machine_spec'
2
4
 
3
5
  module Kitchen
4
6
  module Driver
5
- class Vsphere < Kitchen::Driver::SSHBase
7
+ class Vsphere < Kitchen::Driver::Base
6
8
 
7
9
  default_config :machine_options,
8
10
  :start_timeout => 600,
@@ -21,7 +23,44 @@ module Kitchen
21
23
  }
22
24
  }
23
25
 
24
- include Kitchen::Driver::VsphereCommon
26
+ def create(state)
27
+ config[:server_name] ||= "kitchen-#{SecureRandom.hex}-#{instance.name}"
28
+ state[:username] = config[:machine_options][:bootstrap_options][:ssh][:user]
29
+ state[:password] = config[:machine_options][:bootstrap_options][:ssh][:password]
30
+
31
+ machine = with_metal_driver(config[:server_name]) do | action_handler, driver, machine_spec|
32
+ driver.allocate_machine(action_handler, machine_spec, config[:machine_options])
33
+ driver.ready_machine(action_handler, machine_spec, config[:machine_options])
34
+ state[:server_id] = machine_spec.location['server_id']
35
+ state[:hostname] = machine_spec.location['ipaddress']
36
+ state[:vsphere_name] = config[:server_name]
37
+ end
38
+ end
39
+
40
+ def destroy(state)
41
+ return if state[:server_id].nil?
42
+
43
+ with_metal_driver(state[:vsphere_name]) do | action_handler, driver, machine_spec|
44
+ machine_spec.location = { 'driver_url' => driver.driver_url,
45
+ 'server_id' => state[:server_id]}
46
+ driver.destroy_machine(action_handler, machine_spec, config[:machine_options])
47
+ end
48
+
49
+ state.delete(:server_id)
50
+ state.delete(:hostname)
51
+ state.delete(:vsphere_name)
52
+ end
53
+
54
+ def with_metal_driver(name, &block)
55
+ Cheffish.honor_local_mode do
56
+ chef_server = Cheffish.default_chef_server(Cheffish.profiled_config)
57
+ config[:machine_options][:convergence_options] = {:chef_server => chef_server}
58
+ machine_spec = ChefMetal::ChefMachineSpec.new({'name' => name}, chef_server)
59
+ driver = ChefMetal.driver_for_url("vsphere://#{config[:driver_options][:host]}", config)
60
+ action_handler = ChefMetal::ActionHandler.new
61
+ block.call(action_handler, driver, machine_spec)
62
+ end
63
+ end
25
64
 
26
65
  end
27
66
  end
@@ -12,8 +12,8 @@
12
12
  :bootstrap_options => {
13
13
  :use_linked_clone => true,
14
14
  :datacenter => 'QA1',
15
- #:template_name => 'UBUNTU-12-64-TEMPLATE',
16
- :template_name => 'WINDEVOPS2012R2',
15
+ :template_name => 'UBUNTU-12-64-TEMPLATE',
16
+ #:template_name => 'WINDEVOPS2012R2',
17
17
  :vm_folder => 'DLAB',
18
18
  :datastore => 'QA1-2-SFIRE-01',
19
19
  :num_cpus => 2,
@@ -24,8 +24,8 @@
24
24
  :resource_pool => 'CLSTR02/DLAB',
25
25
  :additional_disk_size_gb => 50,
26
26
  :ssh => {
27
- #:user => 'root',
28
- :user => 'administrator',
27
+ :user => 'root',
28
+ #:user => 'administrator',
29
29
  :password => 'Password123',
30
30
  :paranoid => false,
31
31
  :port => 22
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.53
4
+ version: 0.3.54
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-09-09 00:00:00.000000000 Z
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -110,8 +110,6 @@ files:
110
110
  - lib/chef_metal_vsphere/vsphere_helpers.rb
111
111
  - lib/chef_metal_vsphere/vsphere_url.rb
112
112
  - lib/kitchen/driver/vsphere.rb
113
- - lib/kitchen/driver/vsphere_common.rb
114
- - lib/kitchen/driver/vsphere_windows.rb
115
113
  - spec/integration_tests/.gitignore
116
114
  - spec/integration_tests/config.rb
117
115
  - spec/integration_tests/vsphere_driver_spec.rb
@@ -1,49 +0,0 @@
1
- require 'benchmark'
2
- require 'kitchen'
3
- require 'chef_metal_vsphere/vsphere_driver'
4
- require 'chef_metal/chef_machine_spec'
5
-
6
- module Kitchen
7
- module Driver
8
- module VsphereCommon
9
- def create(state)
10
- config[:server_name] ||= "kitchen-#{SecureRandom.hex}-#{instance.name}"
11
- state[:username] = config[:machine_options][:bootstrap_options][:ssh][:user]
12
- state[:password] = config[:machine_options][:bootstrap_options][:ssh][:password]
13
-
14
- machine = with_metal_driver(config[:server_name]) do | action_handler, driver, machine_spec|
15
- driver.allocate_machine(action_handler, machine_spec, config[:machine_options])
16
- driver.ready_machine(action_handler, machine_spec, config[:machine_options])
17
- state[:server_id] = machine_spec.location['server_id']
18
- state[:hostname] = machine_spec.location['ipaddress']
19
- state[:vsphere_name] = config[:server_name]
20
- end
21
- end
22
-
23
- def destroy(state)
24
- return if state[:server_id].nil?
25
-
26
- with_metal_driver(state[:vsphere_name]) do | action_handler, driver, machine_spec|
27
- machine_spec.location = { 'driver_url' => driver.driver_url,
28
- 'server_id' => state[:server_id]}
29
- driver.destroy_machine(action_handler, machine_spec, config[:machine_options])
30
- end
31
-
32
- state.delete(:server_id)
33
- state.delete(:hostname)
34
- state.delete(:vsphere_name)
35
- end
36
-
37
- def with_metal_driver(name, &block)
38
- Cheffish.honor_local_mode do
39
- chef_server = Cheffish.default_chef_server(Cheffish.profiled_config)
40
- config[:machine_options][:convergence_options] = {:chef_server => chef_server}
41
- machine_spec = ChefMetal::ChefMachineSpec.new({'name' => name}, chef_server)
42
- driver = ChefMetal.driver_for_url("vsphere://#{config[:driver_options][:host]}", config)
43
- action_handler = ChefMetal::ActionHandler.new
44
- block.call(action_handler, driver, machine_spec)
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,129 +0,0 @@
1
- require 'kitchen/driver/vsphere_common'
2
- require 'zip'
3
-
4
- module Kitchen
5
- module Driver
6
- class VsphereWindows < Kitchen::Driver::WinRMBase
7
-
8
- default_config :machine_options,
9
- :start_timeout => 600,
10
- :create_timeout => 600,
11
- :ready_timeout => 90,
12
- :bootstrap_options => {
13
- :use_linked_clone => true,
14
- :ssh => {
15
- :user => 'administrator',
16
- },
17
- :convergence_options => {},
18
- :customization_spec => {
19
- :domain => 'local',
20
- :org_name => 'Tier3',
21
- :product_id => 'W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9',
22
- :win_time_zone => 4
23
- }
24
- }
25
-
26
- attr_reader :connect_options
27
-
28
- include Kitchen::Driver::VsphereCommon
29
- include ChefMetalVsphere::Helpers
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
127
- end
128
- end
129
- end