kitchen-vra 2.7.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/ci.yml +22 -0
- data/.rubocop.yml +1 -31
- data/CHANGELOG.md +29 -2
- data/Gemfile +2 -2
- data/README.md +3 -92
- data/Rakefile +5 -15
- data/kitchen-vra.gemspec +21 -22
- data/lib/kitchen/driver/vra.rb +70 -65
- data/lib/kitchen/driver/vra_version.rb +2 -2
- data/spec/spec_helper.rb +6 -6
- data/spec/vra_spec.rb +175 -187
- metadata +44 -31
- data/.travis.yml +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42841b378dc1efcd266d40f01990f7dedc82e8e3d49e742d3268e0cca5c21049
|
4
|
+
data.tar.gz: fdd7dfe3c395a460cb92414617a990006508007230aa25c4995af63edadc6a0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8742b99fef04d72bd9cd87357ff1d6e30971e5afa70ed3ecadec371a705e7505aafbb38cc655a75e6fab47b2089c61a2323fa1bf084e468913aa852d23c4601
|
7
|
+
data.tar.gz: 76d046c6da25ef7c78379bf0c64bb49c3c438cf7f62a05b3a5da49a1c2057b7a5a4d7fbae6b00aac1db2adaa6bf8cd2d1ac84d28f67bc27ab04dea1b139ec6b7
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby: [ '2.7', '3.0']
|
15
|
+
name: Lint & Test with Ruby ${{ matrix.ruby }}
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby }}
|
21
|
+
bundler-cache: true
|
22
|
+
- run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,32 +1,2 @@
|
|
1
1
|
AllCops:
|
2
|
-
|
3
|
-
Metrics/AbcSize:
|
4
|
-
Max: 100
|
5
|
-
Metrics/ClassLength:
|
6
|
-
Max: 125
|
7
|
-
Metrics/CyclomaticComplexity:
|
8
|
-
Max: 20
|
9
|
-
Metrics/MethodLength:
|
10
|
-
Exclude:
|
11
|
-
- '**/*.rb'
|
12
|
-
Enabled: false
|
13
|
-
Metrics/PerceivedComplexity:
|
14
|
-
Max: 30
|
15
|
-
Metrics/LineLength:
|
16
|
-
Max: 200
|
17
|
-
Metrics/MethodLength:
|
18
|
-
Max: 25
|
19
|
-
Style/Documentation:
|
20
|
-
Enabled: false
|
21
|
-
Style/EndOfLine:
|
22
|
-
EnforcedStyle: lf
|
23
|
-
Style/SignalException:
|
24
|
-
Enabled: false
|
25
|
-
Layout/SpaceInsideBrackets:
|
26
|
-
Enabled: false
|
27
|
-
Style/MutableConstant:
|
28
|
-
Enabled: false
|
29
|
-
Metrics/BlockLength:
|
30
|
-
Exclude:
|
31
|
-
- "**/*_spec.rb"
|
32
|
-
|
2
|
+
TargetRubyVersion: 2.7
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,35 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [v3.1.0](https://github.com/chef-partners/kitchen-vra/tree/v3.1.0)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/
|
5
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v3.0.1...v3.1.0)
|
6
|
+
|
7
|
+
- Move usage documentation from the readme to the kitchen.ci website
|
8
|
+
- Make the version configuration optional
|
9
|
+
- Remove the bundler dev dep
|
10
|
+
- Update the gemspec for the new maintainer of this project
|
11
|
+
|
12
|
+
## [v3.0.1](https://github.com/chef-partners/kitchen-vra/tree/v3.0.1)
|
13
|
+
|
14
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v3.0.0...v3.0.1)
|
15
|
+
|
16
|
+
- Updated the rack gem dependency to allow for modern releases of rack.
|
17
|
+
|
18
|
+
## [v3.0.0](https://github.com/chef-partners/kitchen-vra/tree/v3.0.0)
|
19
|
+
|
20
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.7.1...v3.0.0)
|
21
|
+
|
22
|
+
- kitchen-vra now supports VMware vRealize Automation 8. See the readme of kitchen.ci driver documentation for new configuration options necessary for use with vRA 8. If you need support for vRA 7 make sure to pin to an earlier release.
|
23
|
+
|
24
|
+
## [v2.7.1](https://github.com/chef-partners/kitchen-vra/tree/v2.7.1)
|
25
|
+
|
26
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.7.0...v2.7.1)
|
27
|
+
|
28
|
+
- Pin vmware-vra gem dep to < 3 to prevent pulling in the new release
|
29
|
+
|
30
|
+
## [v2.7.0](https://github.com/chef-partners/kitchen-vra/tree/v2.7.0)
|
31
|
+
|
32
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.6.0...v2.7.0)
|
6
33
|
|
7
34
|
- Accept shirt size option available in blueprint as input in kitchen.yml
|
8
35
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -22,104 +22,15 @@ Or even better, install it via ChefDK:
|
|
22
22
|
|
23
23
|
$ chef gem install kitchen-vra
|
24
24
|
|
25
|
-
##
|
26
|
-
|
27
|
-
After installing the gem as described above, edit your .kitchen.yml file to set the driver to 'vra' and supply your login credentials:
|
28
|
-
|
29
|
-
```yaml
|
30
|
-
driver:
|
31
|
-
name: vra
|
32
|
-
username: myuser@corp.local
|
33
|
-
password: mypassword
|
34
|
-
tenant: mytenant
|
35
|
-
base_url: https://vra.corp.local
|
36
|
-
verify_ssl: true
|
37
|
-
```
|
38
|
-
|
39
|
-
If you want username and password to be prompted, remove usename and password in your .kitchen.yml as shown below:
|
40
|
-
|
41
|
-
```yaml
|
42
|
-
driver:
|
43
|
-
name: vra
|
44
|
-
tenant: mytenant
|
45
|
-
base_url: https://vra.corp.local
|
46
|
-
verify_ssl: true
|
47
|
-
```
|
48
|
-
If you don't want to explicitly specify username and password in the kitchen.yml, you have an option to set it in the environment variable as
|
49
|
-
|
50
|
-
$ export VRA_USER_NAME='myuser@corp.local'
|
51
|
-
$ export VRA_USER_PASSWORD='mypassword'
|
52
|
-
|
53
|
-
Then configure your platforms. Either a catalog_id or a catalog_name is required for each platform. If both catalog_id and catalog_name are mentioned in .kitchen.yml then catalog_name would be used to derive the catalog_id and this catalog_id would override the catalog_id being passed in .kitchen.yml. In the below example as can be seen we are using catalog_id for centos6 driver while catalog_name for the centos7 driver just to demonstrate that we can use either of the two.
|
25
|
+
## Configuration
|
54
26
|
|
55
|
-
|
56
|
-
```yaml
|
57
|
-
platforms:
|
58
|
-
- name: centos6
|
59
|
-
driver:
|
60
|
-
catalog_id: e9db1084-d1c6-4c1f-8e3c-eb8f3dc574f9
|
61
|
-
- name: centos7
|
62
|
-
driver:
|
63
|
-
catalog_name: my_catalog_name
|
64
|
-
```
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
Other options that you can set include:
|
69
|
-
|
70
|
-
* **lease_days**: number of days to request for a lease, if your catalog item / blueprint requires it
|
71
|
-
* **request_timeout**: amount of time, in seconds, to wait for a vRA request to complete. Default is 600 seconds.
|
72
|
-
* **server_ready_retries**: Number of times to retry the "waiting for server to be ready" check. In some cases, this will error out immediately due to DNS propagation issues, etc. Setting this to a number greater than 0 will retry the `wait_until_ready` method with a growing sleep in between each attempt. Defaults to 1. Set to 0 to disable any retrying of the `wait_until_ready` method.
|
73
|
-
* **cpus**: number of CPUs the host should have
|
74
|
-
* **memory**: amount of RAM, in MB, the host should have
|
75
|
-
* **shirt_size**: This parameter corresponds to shirt size option of vRA available on blueprint like ValueSet.Large, ValueSet.Small etc. As shirt size is a combination of memory and RAM, hence while using this no need to use cpus and memory parameter. This shirt size option helps in standardizing the sizing available for end users
|
76
|
-
* **requested_for**: the vRA login ID to list as the owner of this resource. Defaults to the vRA username configured in the `driver` section.
|
77
|
-
* **subtenant_id**: the Business Group ID to list as the owner. This is required if the catalog item is a shared/global item; we are unable to determine the subtenant_id from the catalog, and vRA requires it to be set on every request.
|
78
|
-
* **subtenant_name**: the Business Group Name as the owner. This can be passed instead of subtenant_id and would act as a more friendly name. subtenant_id would be internally retrieved based on the provided subtenant_name. In case both subtenant_id and subtenant_name are passed, subtenant_name would take the precendence and would try to retrieve subtenant_id based on subtenant_name passed.
|
79
|
-
* **private_key_path**: path to the SSH private key to use when logging in. Defaults to '~/.ssh/id_rsa' or '~/.ssh/id_dsa', preferring the RSA key. Only applies to instances where SSH transport is used; i.e., does not apply to Windows hosts with the WinRM transport configured.
|
80
|
-
* **use_dns**: Defaults to `false`. Set to `true` if vRA doesn't manage vm ip addresses. This will cause kitchen to attempt to connect via hostname.
|
81
|
-
* **dns_suffix**: Defaults to `nil`. Set to your domain suffix, for example 'mydomain.com'. This only takes effect when `use_dns` == true and is appended to the hostname returned by vRA.
|
82
|
-
* **extra_parameters**: a hash of other data to set on a catalog request, most notably custom properties. Allows updates to existing properties on the blueprint as well as the addition of new properties. Each key in the hash is the property name, and the value is a another hash containing the value data type and the value itself. It is possible to use a `~` to add nested parameters.
|
83
|
-
|
84
|
-
These settings can be set globally under the top-level `driver` section, or they can be set on each platform, which allows you to set globals and then override them. For example, this configuration would set the CPU count to 1 except on the "large" platform:
|
85
|
-
|
86
|
-
```yaml
|
87
|
-
driver:
|
88
|
-
name: vra
|
89
|
-
cpus: 1
|
90
|
-
|
91
|
-
platforms:
|
92
|
-
- name: small
|
93
|
-
driver:
|
94
|
-
catalog_name: my_catalog_name_small
|
95
|
-
catalog_id: 8a189191-fea6-43eb-981e-ee0fa40f8f57
|
96
|
-
extra_parameters:
|
97
|
-
mycustompropname:
|
98
|
-
type: string
|
99
|
-
value: smallvalue
|
100
|
-
Vrm.DataCenter.Location:
|
101
|
-
type: string
|
102
|
-
value: Non-Prod
|
103
|
-
- name: large
|
104
|
-
driver:
|
105
|
-
catalog_name: my_catalog_name_large
|
106
|
-
catalog_id: 1d7c6122-18fa-4ed6-bd13-8a33b6c6ed50
|
107
|
-
cpus: 2
|
108
|
-
subtenant_name: my_subtenant_name
|
109
|
-
extra_parameters:
|
110
|
-
mycustompropname:
|
111
|
-
type: string
|
112
|
-
value: largevalue
|
113
|
-
Vrm.DataCenter.Location:
|
114
|
-
type: string
|
115
|
-
value: Prod
|
116
|
-
```
|
27
|
+
See the [kitchen.ci kitchen-vra docs](https://kitchen.ci/docs/drivers/vra/) for a complete list of configuration options.
|
117
28
|
|
118
29
|
## License and Authors
|
119
30
|
|
120
31
|
Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
121
32
|
|
122
|
-
Copyright:: Copyright (c)
|
33
|
+
Copyright:: Copyright (c) 2022 Chef Software, Inc.
|
123
34
|
|
124
35
|
License:: Apache License, Version 2.0
|
125
36
|
|
data/Rakefile
CHANGED
@@ -1,21 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require "chefstyle"
|
6
|
+
require "rubocop/rake_task"
|
6
7
|
|
7
8
|
RSpec::Core::RakeTask.new(:spec)
|
8
9
|
RuboCop::RakeTask.new(:style)
|
9
10
|
|
10
|
-
|
11
|
-
require 'github_changelog_generator/task'
|
12
|
-
|
13
|
-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
14
|
-
config.future_release = Kitchen::Driver::VRA_VERSION
|
15
|
-
config.issues = true
|
16
|
-
end
|
17
|
-
rescue LoadError
|
18
|
-
puts 'github_changelog_generator is not available. gem install github_changelog_generator to generate changelogs'
|
19
|
-
end
|
20
|
-
|
21
|
-
task default: %i[spec style]
|
11
|
+
task default: %i{spec style}
|
data/kitchen-vra.gemspec
CHANGED
@@ -1,35 +1,34 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
5
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
-
require
|
5
|
+
require "kitchen/driver/vra_version"
|
7
6
|
|
8
7
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name =
|
8
|
+
spec.name = "kitchen-vra"
|
10
9
|
spec.version = Kitchen::Driver::VRA_VERSION
|
11
|
-
spec.authors = [
|
12
|
-
spec.email = [
|
13
|
-
spec.summary =
|
10
|
+
spec.authors = ["Chef Commmunity Tools Team"]
|
11
|
+
spec.email = ["oss@chef.io"]
|
12
|
+
spec.summary = "A Test Kitchen driver for VMware vRealize Automation (vRA)"
|
14
13
|
spec.description = spec.summary
|
15
|
-
spec.homepage =
|
16
|
-
spec.license =
|
14
|
+
spec.homepage = "https://github.com/test-kitchen/kitchen-vra"
|
15
|
+
spec.license = "Apache-2.0"
|
17
16
|
|
18
17
|
spec.files = `git ls-files -z`.split("\x0")
|
19
18
|
spec.executables = []
|
20
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ["lib"]
|
22
21
|
|
23
|
-
spec.
|
24
|
-
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
27
|
-
spec.add_dependency
|
28
|
-
spec.
|
29
|
-
spec.
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
22
|
+
spec.required_ruby_version = ">= 2.7"
|
23
|
+
|
24
|
+
spec.add_dependency "test-kitchen"
|
25
|
+
spec.add_dependency "vmware-vra", ">= 3.1.0" # 3.0 required for vRA 8.x
|
26
|
+
spec.add_dependency "highline"
|
27
|
+
spec.add_dependency "rack", ">= 1.6", "< 3.0"
|
28
|
+
spec.add_dependency "ffi-yajl", ">= 2.2.3", "< 2.5.0"
|
29
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
31
|
+
spec.add_development_dependency "simplecov", "~> 0.10"
|
32
|
+
spec.add_development_dependency "webmock", "~> 3.14"
|
33
|
+
spec.add_development_dependency "chefstyle", "~> 2.2.1"
|
35
34
|
end
|
data/lib/kitchen/driver/vra.rb
CHANGED
@@ -18,13 +18,13 @@
|
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
20
|
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require_relative
|
21
|
+
require "kitchen"
|
22
|
+
require "highline/import"
|
23
|
+
require "openssl" unless defined?(OpenSSL)
|
24
|
+
require "base64" unless defined?(Base64)
|
25
|
+
require "digest/sha1" unless defined?(Digest::SHA1)
|
26
|
+
require "vra"
|
27
|
+
require_relative "vra_version"
|
28
28
|
|
29
29
|
module Kitchen
|
30
30
|
module Driver
|
@@ -36,6 +36,11 @@ module Kitchen
|
|
36
36
|
default_config :password, nil
|
37
37
|
required_config :base_url
|
38
38
|
required_config :tenant
|
39
|
+
required_config :project_id
|
40
|
+
required_config :image_mapping
|
41
|
+
required_config :flavor_mapping
|
42
|
+
|
43
|
+
default_config :version, nil
|
39
44
|
default_config :catalog_id, nil
|
40
45
|
default_config :catalog_name, nil
|
41
46
|
|
@@ -45,18 +50,13 @@ module Kitchen
|
|
45
50
|
default_config :request_timeout, 600
|
46
51
|
default_config :request_refresh_rate, 2
|
47
52
|
default_config :server_ready_retries, 1
|
48
|
-
default_config :
|
49
|
-
|
50
|
-
default_config :shirt_size, nil
|
51
|
-
default_config :requested_for do |driver|
|
52
|
-
driver[:username]
|
53
|
+
default_config :deployment_name do |driver|
|
54
|
+
driver&.instance&.platform&.name
|
53
55
|
end
|
54
|
-
default_config :lease_days, nil
|
55
|
-
default_config :notes, nil
|
56
56
|
default_config :cache_credentials, false
|
57
57
|
default_config :extra_parameters, {}
|
58
58
|
default_config :private_key_path do
|
59
|
-
%w
|
59
|
+
%w{id_rsa id_dsa}.map do |key|
|
60
60
|
file = File.expand_path("~/.ssh/#{key}")
|
61
61
|
file if File.exist?(file)
|
62
62
|
end.compact.first
|
@@ -65,21 +65,21 @@ module Kitchen
|
|
65
65
|
default_config :dns_suffix, nil
|
66
66
|
|
67
67
|
def name
|
68
|
-
|
68
|
+
"vRA"
|
69
69
|
end
|
70
70
|
|
71
71
|
def check_config(force_change = false)
|
72
|
-
config[:username] = config[:username] || ENV[
|
73
|
-
config[:password] = config[:password] || ENV[
|
72
|
+
config[:username] = config[:username] || ENV["VRA_USER_NAME"]
|
73
|
+
config[:password] = config[:password] || ENV["VRA_USER_PASSWORD"]
|
74
74
|
c_load if config[:username].nil? && config[:password].nil?
|
75
75
|
|
76
|
-
config[:username] = ask(
|
77
|
-
config[:password] = ask(
|
76
|
+
config[:username] = ask("Enter Username: e.g. username@domain") if config[:username].nil? || force_change
|
77
|
+
config[:password] = ask("Enter password: ") { |q| q.echo = "*" } if config[:password].nil? || force_change
|
78
78
|
c_save if config[:cache_credentials]
|
79
79
|
end
|
80
80
|
|
81
81
|
def c_save
|
82
|
-
cipher = OpenSSL::Cipher
|
82
|
+
cipher = OpenSSL::Cipher.new("cip-her-aes")
|
83
83
|
cipher.encrypt
|
84
84
|
cipher.key = Digest::SHA1.hexdigest(config[:base_url])
|
85
85
|
iv_user = cipher.random_iv
|
@@ -89,21 +89,21 @@ module Kitchen
|
|
89
89
|
cipher.iv = iv_pwd
|
90
90
|
password = cipher.update(config[:password]) + cipher.final
|
91
91
|
output = "#{Base64.encode64(iv_user).strip!}:#{Base64.encode64(username).strip!}:#{Base64.encode64(iv_pwd).strip!}:#{Base64.encode64(password).strip!}"
|
92
|
-
file = File.open(
|
92
|
+
file = File.open(".kitchen/cached_vra", "w")
|
93
93
|
file.write(output)
|
94
94
|
file.close
|
95
95
|
rescue
|
96
|
-
puts
|
96
|
+
puts "Unable to save credentials"
|
97
97
|
end
|
98
98
|
|
99
99
|
def c_load
|
100
|
-
if File.exist?
|
101
|
-
encrypted = File.read(
|
102
|
-
iv_user = Base64.decode64(encrypted.split(
|
103
|
-
username = Base64.decode64(encrypted.split(
|
104
|
-
iv_pwd = Base64.decode64(encrypted.split(
|
105
|
-
password = Base64.decode64(encrypted.split(
|
106
|
-
cipher = OpenSSL::Cipher
|
100
|
+
if File.exist? ".kitchen/cached_vra"
|
101
|
+
encrypted = File.read(".kitchen/cached_vra")
|
102
|
+
iv_user = Base64.decode64(encrypted.split(":")[0] + '\n')
|
103
|
+
username = Base64.decode64(encrypted.split(":")[1] + "\n")
|
104
|
+
iv_pwd = Base64.decode64(encrypted.split(":")[2] + "\n")
|
105
|
+
password = Base64.decode64(encrypted.split(":")[3] + "\n")
|
106
|
+
cipher = OpenSSL::Cipher.new("cip-her-aes")
|
107
107
|
cipher.decrypt
|
108
108
|
cipher.key = Digest::SHA1.hexdigest(config[:base_url])
|
109
109
|
cipher.iv = iv_user
|
@@ -112,30 +112,31 @@ module Kitchen
|
|
112
112
|
config[:password] = cipher.update(password) + cipher.final
|
113
113
|
end
|
114
114
|
rescue
|
115
|
-
puts
|
115
|
+
puts "Failed to load cached credentials"
|
116
116
|
end
|
117
117
|
|
118
118
|
def create(state)
|
119
|
-
return if state[:
|
119
|
+
return if state[:deployment_id]
|
120
120
|
|
121
121
|
server = request_server
|
122
|
-
state[:
|
122
|
+
state[:deployment_id] = server.deployment_id
|
123
123
|
state[:hostname] = hostname_for(server)
|
124
124
|
state[:ssh_key] = config[:private_key_path] unless config[:private_key_path].nil?
|
125
125
|
|
126
126
|
wait_for_server(state, server)
|
127
|
-
info("Server #{server.
|
127
|
+
info("Server #{server.deployment_id} (#{server.name}) ready.")
|
128
128
|
end
|
129
129
|
|
130
130
|
def hostname_for(server)
|
131
131
|
if config[:use_dns]
|
132
|
-
raise
|
132
|
+
raise "No server name returned for the vRA request" if server.name.nil?
|
133
|
+
|
133
134
|
return config[:dns_suffix] ? "#{server.name}.#{config[:dns_suffix]}" : server.name
|
134
135
|
end
|
135
136
|
|
136
|
-
ip_address = server.
|
137
|
+
ip_address = server.ip_address
|
137
138
|
if ip_address.nil?
|
138
|
-
warn("Server #{server.
|
139
|
+
warn("Server #{server.deployment_id} has no IP address. Falling back to server name (#{server.name})...")
|
139
140
|
server.name
|
140
141
|
else
|
141
142
|
ip_address
|
@@ -143,16 +144,18 @@ module Kitchen
|
|
143
144
|
end
|
144
145
|
|
145
146
|
def request_server
|
146
|
-
info(
|
147
|
-
|
148
|
-
|
147
|
+
info("Building vRA catalog request...")
|
148
|
+
|
149
|
+
deployment_request = catalog_request.submit
|
149
150
|
|
150
|
-
|
151
|
-
raise "The vRA request failed: #{submitted_request.completion_details}" if submitted_request.failed?
|
151
|
+
info("Catalog request #{deployment_request.id} submitted.")
|
152
152
|
|
153
|
-
|
154
|
-
raise
|
155
|
-
|
153
|
+
wait_for_request(deployment_request)
|
154
|
+
raise "The vRA request failed: #{deployment_request.completion_details}" if deployment_request.failed?
|
155
|
+
|
156
|
+
servers = deployment_request.resources.select(&:vm?)
|
157
|
+
raise "The vRA request created more than one server. The catalog blueprint should only return one." if servers.size > 1
|
158
|
+
raise "the vRA request did not create any servers." if servers.size == 0
|
156
159
|
|
157
160
|
servers.first
|
158
161
|
end
|
@@ -172,7 +175,7 @@ module Kitchen
|
|
172
175
|
sleep_time += 5 if sleep_time < 30
|
173
176
|
|
174
177
|
if try > config[:server_ready_retries]
|
175
|
-
error(
|
178
|
+
error("Retries exceeded. Destroying server...")
|
176
179
|
destroy(state)
|
177
180
|
raise
|
178
181
|
else
|
@@ -184,56 +187,57 @@ module Kitchen
|
|
184
187
|
end
|
185
188
|
|
186
189
|
def destroy(state)
|
187
|
-
return if state[:
|
190
|
+
return if state[:deployment_id].nil?
|
188
191
|
|
189
192
|
begin
|
190
|
-
server = vra_client.
|
193
|
+
server = vra_client.deployments.by_id(state[:deployment_id])
|
191
194
|
rescue ::Vra::Exception::NotFound
|
192
|
-
warn("No server found with ID #{state[:
|
195
|
+
warn("No server found with ID #{state[:deployment_id]}, assuming it has been destroyed already.")
|
193
196
|
return
|
194
197
|
end
|
195
198
|
|
196
199
|
begin
|
197
200
|
destroy_request = server.destroy
|
198
201
|
rescue ::Vra::Exception::NotFound
|
199
|
-
info(
|
202
|
+
info("Server not found, or no destroy action available, perhaps because it is already destroyed.")
|
200
203
|
return
|
201
204
|
end
|
202
205
|
info("Destroy request #{destroy_request.id} submitted.")
|
203
206
|
wait_for_request(destroy_request)
|
204
|
-
info(
|
207
|
+
info("Destroy request complete.")
|
205
208
|
|
206
|
-
File.delete(
|
207
|
-
info(
|
209
|
+
File.delete(".kitchen/cached_vra") if File.exist?(".kitchen/cached_vra")
|
210
|
+
info("Removed cached file")
|
208
211
|
end
|
209
212
|
|
210
213
|
def catalog_request # rubocop:disable Metrics/MethodLength
|
211
214
|
unless config[:catalog_name].nil?
|
212
|
-
info(
|
215
|
+
info("Fetching Catalog ID by Catalog Name")
|
213
216
|
response = vra_client.catalog.fetch_catalog_items(config[:catalog_name])
|
214
217
|
parsed_json = JSON.parse(response.body)
|
215
218
|
begin
|
216
|
-
config[:catalog_id] = parsed_json[
|
219
|
+
config[:catalog_id] = parsed_json["content"][0]["catalogItemId"]
|
217
220
|
rescue
|
218
221
|
puts "Unable to retrieve Catalog ID from Catalog Name: #{config[:catalog_name]}"
|
219
222
|
end
|
220
223
|
end
|
221
224
|
|
222
|
-
|
225
|
+
deployment_params = {
|
226
|
+
image_mapping: config[:image_mapping],
|
227
|
+
flavor_mapping: config[:flavor_mapping],
|
228
|
+
name: config[:deployment_name],
|
229
|
+
project_id: config[:project_id],
|
230
|
+
version: config[:version],
|
231
|
+
}
|
223
232
|
|
224
|
-
catalog_request
|
225
|
-
catalog_request.memory = config[:memory]
|
226
|
-
catalog_request.shirt_size = config[:shirt_size] unless config[:shirt_size].nil?
|
227
|
-
catalog_request.requested_for = config[:requested_for]
|
228
|
-
catalog_request.lease_days = config[:lease_days] unless config[:lease_days].nil?
|
229
|
-
catalog_request.notes = config[:notes] unless config[:notes].nil?
|
233
|
+
catalog_request = vra_client.catalog.request(config[:catalog_id], deployment_params)
|
230
234
|
|
231
235
|
unless config[:subtenant_name].nil?
|
232
|
-
info(
|
236
|
+
info("Fetching Subtenant ID by Subtenant Name")
|
233
237
|
response = vra_client.fetch_subtenant_items(config[:tenant], config[:subtenant_name])
|
234
238
|
parsed_json = JSON.parse(response.body)
|
235
239
|
begin
|
236
|
-
config[:subtenant_id] = parsed_json[
|
240
|
+
config[:subtenant_id] = parsed_json["content"][0]["id"]
|
237
241
|
rescue
|
238
242
|
puts "Unable to retrieve Subtenant ID from Subtenant Name: #{config[:subtenant_name]}"
|
239
243
|
end
|
@@ -263,9 +267,10 @@ module Kitchen
|
|
263
267
|
def wait_for_request(request)
|
264
268
|
# config = check_config config
|
265
269
|
|
266
|
-
last_status =
|
270
|
+
last_status = ""
|
267
271
|
wait_time = config[:request_timeout]
|
268
272
|
sleep_time = config[:request_refresh_rate]
|
273
|
+
|
269
274
|
Timeout.timeout(wait_time) do
|
270
275
|
loop do
|
271
276
|
request.refresh
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#
|
4
4
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
5
|
-
# Copyright:: Copyright (c)
|
5
|
+
# Copyright:: Copyright (c) Chef Software, Inc.
|
6
6
|
# License:: Apache License, Version 2.0
|
7
7
|
#
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -20,6 +20,6 @@
|
|
20
20
|
|
21
21
|
module Kitchen
|
22
22
|
module Driver
|
23
|
-
VRA_VERSION =
|
23
|
+
VRA_VERSION = "3.1.0"
|
24
24
|
end
|
25
25
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,14 +18,14 @@
|
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
20
|
|
21
|
-
require
|
21
|
+
require "webmock/rspec"
|
22
22
|
|
23
23
|
WebMock.disable_net_connect!(allow_localhost: true)
|
24
24
|
|
25
|
-
if ENV[
|
26
|
-
require
|
27
|
-
SimpleCov.profiles.define
|
28
|
-
command_name
|
25
|
+
if ENV["COVERAGE"]
|
26
|
+
require "simplecov"
|
27
|
+
SimpleCov.profiles.define "gem" do
|
28
|
+
command_name "Specs"
|
29
29
|
end
|
30
|
-
SimpleCov.start
|
30
|
+
SimpleCov.start "gem"
|
31
31
|
end
|