kitchen-vra 2.4.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/ci.yml +22 -0
- data/CHANGELOG.md +35 -10
- data/Gemfile +3 -2
- data/README.md +25 -13
- data/Rakefile +6 -15
- data/kitchen-vra.gemspec +23 -22
- data/lib/kitchen/driver/vra.rb +93 -73
- data/lib/kitchen/driver/vra_version.rb +2 -1
- data/spec/spec_helper.rb +7 -6
- data/spec/vra_spec.rb +179 -187
- metadata +46 -27
- data/.rubocop.yml +0 -19
- data/.travis.yml +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2dd5eb1c44307d885cafca15ead2050b18cc44339d1ee0ef2cae0729c02b1fb0
|
4
|
+
data.tar.gz: 406983722267fe198f460fb24e38726b7534d6ab722b5a7b9fda96028c4df3c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1258498bd2583ffa37232dd4b2a0f47e6f37e035edd597947b887a32ce74c830b450893c7d6489b70dd5666b893a4f3ccf94fd58c842ac0676341774ee5d174
|
7
|
+
data.tar.gz: ef96e597cf8289935c79491951c0aba5c6156c3d8e0e0aa5b73e6aadbe996db6fd7ed8dc2d6e973390fc374e7b91896445558f6928288158c912204f6ae29e1b
|
@@ -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/CHANGELOG.md
CHANGED
@@ -1,19 +1,44 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [
|
4
|
-
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.3.0...2.4.0)
|
3
|
+
## [v3.0.0](https://github.com/chef-partners/kitchen-vra/tree/v3.0.0)
|
5
4
|
|
6
|
-
|
5
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.7.1...v3.0.0)
|
7
6
|
|
8
|
-
-
|
9
|
-
- Ability of vRA Kitchen driver to accept credentials from environment variable even if they are not being mentioned in the `.kitchen.yml` file
|
10
|
-
- Ability of vRA kitchen driver to prompt for credentials if it’s not able retrieve from `.kitchen.yml` or from environment variable.
|
11
|
-
- An option to not save credentials based on the usage of an existing flag.
|
12
|
-
- Fixed a bug in the encryption/decryption logic.
|
7
|
+
- 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.
|
13
8
|
|
9
|
+
## [v2.7.1](https://github.com/chef-partners/kitchen-vra/tree/v2.7.1)
|
14
10
|
|
15
|
-
|
16
|
-
|
11
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.7.0...v2.7.1)
|
12
|
+
|
13
|
+
- Pin vmware-vra gem dep to < 3 to prevent pulling in the new release
|
14
|
+
|
15
|
+
## [v2.7.0](https://github.com/chef-partners/kitchen-vra/tree/v2.7.0)
|
16
|
+
|
17
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.6.0...v2.7.0)
|
18
|
+
|
19
|
+
- Accept shirt size option available in blueprint as input in kitchen.yml
|
20
|
+
|
21
|
+
## [v2.5.0](https://github.com/chef-partners/kitchen-vra/tree/v2.5.0)
|
22
|
+
|
23
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.4.0...v2.5.0)
|
24
|
+
|
25
|
+
**Closed issues:**
|
26
|
+
|
27
|
+
- Feature Query: Support for Capture Snapshot & Restore Snapshot [\#27](https://github.com/chef-partners/kitchen-vra/issues/27)
|
28
|
+
|
29
|
+
**Merged pull requests:**
|
30
|
+
|
31
|
+
- Accept subtenant name as input in kitchen.yml [\#28](https://github.com/chef-partners/kitchen-vra/pull/28) ([vinuphilip](https://github.com/vinuphilip))
|
32
|
+
|
33
|
+
## [v2.4.0](https://github.com/chef-partners/kitchen-vra/tree/v2.4.0) (2018-01-22)
|
34
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.3.0...v2.4.0)
|
35
|
+
|
36
|
+
**Merged pull requests:**
|
37
|
+
|
38
|
+
- Kitchen vRA enahancements [\#26](https://github.com/chef-partners/kitchen-vra/pull/26) ([rupeshpatel88](https://github.com/rupeshpatel88))
|
39
|
+
|
40
|
+
## [v2.3.0](https://github.com/chef-partners/kitchen-vra/tree/v2.3.0) (2017-07-14)
|
41
|
+
[Full Changelog](https://github.com/chef-partners/kitchen-vra/compare/v2.2.0...v2.3.0)
|
17
42
|
|
18
43
|
**Merged pull requests:**
|
19
44
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -50,7 +50,7 @@ If you don't want to explicitly specify username and password in the kitchen.yml
|
|
50
50
|
$ export VRA_USER_NAME='myuser@corp.local'
|
51
51
|
$ export VRA_USER_PASSWORD='mypassword'
|
52
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.
|
53
|
+
Then configure your platforms. You will need to specify project_id, image_mapping, flavor_mapping and version for the platform. image_mapping specifies the OS image for a machine and the flavor_mapping specifies the CPU count and RAM of the machine. 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.
|
54
54
|
|
55
55
|
|
56
56
|
```yaml
|
@@ -58,56 +58,68 @@ platforms:
|
|
58
58
|
- name: centos6
|
59
59
|
driver:
|
60
60
|
catalog_id: e9db1084-d1c6-4c1f-8e3c-eb8f3dc574f9
|
61
|
+
project_id: 6ba69375-79d5-42c3-a099-7d32739f71a9
|
62
|
+
image_mapping: SQL 2016
|
63
|
+
flavor_mapping: Small
|
64
|
+
version: 1
|
61
65
|
- name: centos7
|
62
66
|
driver:
|
63
67
|
catalog_name: my_catalog_name
|
68
|
+
project_id: 6ba69375-79d5-42c3-a099-7d32739f71a9
|
69
|
+
image_mapping: VRA-nc-lnx-ce8.4-Docker
|
70
|
+
flavor_mapping: Small
|
71
|
+
version: 1
|
64
72
|
```
|
65
73
|
|
66
74
|
|
67
75
|
|
68
76
|
Other options that you can set include:
|
69
77
|
|
70
|
-
* **lease_days**: number of days to request for a lease, if your catalog item / blueprint requires it
|
71
78
|
* **request_timeout**: amount of time, in seconds, to wait for a vRA request to complete. Default is 600 seconds.
|
72
79
|
* **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
|
-
* **requested_for**: the vRA login ID to list as the owner of this resource. Defaults to the vRA username configured in the `driver` section.
|
76
80
|
* **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.
|
81
|
+
* **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.
|
77
82
|
* **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.
|
78
83
|
* **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.
|
79
84
|
* **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.
|
80
|
-
* **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.
|
85
|
+
* **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.
|
81
86
|
|
82
87
|
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:
|
83
88
|
|
84
89
|
```yaml
|
85
90
|
driver:
|
86
91
|
name: vra
|
87
|
-
cpus: 1
|
88
92
|
|
89
93
|
platforms:
|
90
94
|
- name: small
|
91
95
|
driver:
|
92
96
|
catalog_name: my_catalog_name_small
|
93
97
|
catalog_id: 8a189191-fea6-43eb-981e-ee0fa40f8f57
|
98
|
+
project_id: 6ba69375-79d5-42c3-a099-7d32739f71a9
|
99
|
+
image_mapping: SQL 2016
|
100
|
+
flavor_mapping: Small
|
101
|
+
version: 1
|
94
102
|
extra_parameters:
|
95
|
-
|
103
|
+
mycustompropname:
|
96
104
|
type: string
|
97
105
|
value: smallvalue
|
98
|
-
|
106
|
+
Vrm.DataCenter.Location:
|
99
107
|
type: string
|
100
108
|
value: Non-Prod
|
101
109
|
- name: large
|
102
110
|
driver:
|
103
111
|
catalog_name: my_catalog_name_large
|
104
112
|
catalog_id: 1d7c6122-18fa-4ed6-bd13-8a33b6c6ed50
|
105
|
-
|
113
|
+
project_id: 6ba69375-79d5-42c3-a099-7d32739f71a9
|
114
|
+
image_mapping: VRA-nc-lnx-ce8.4-Docker
|
115
|
+
flavor_mapping: Large
|
116
|
+
version: 1
|
117
|
+
subtenant_name: my_subtenant_name
|
106
118
|
extra_parameters:
|
107
|
-
|
119
|
+
mycustompropname:
|
108
120
|
type: string
|
109
121
|
value: largevalue
|
110
|
-
|
122
|
+
Vrm.DataCenter.Location:
|
111
123
|
type: string
|
112
124
|
value: Prod
|
113
125
|
```
|
@@ -116,7 +128,7 @@ platforms:
|
|
116
128
|
|
117
129
|
Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
118
130
|
|
119
|
-
Copyright:: Copyright (c)
|
131
|
+
Copyright:: Copyright (c) 2022 Chef Software, Inc.
|
120
132
|
|
121
133
|
License:: Apache License, Version 2.0
|
122
134
|
|
data/Rakefile
CHANGED
@@ -1,20 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require "chefstyle"
|
6
|
+
require "rubocop/rake_task"
|
5
7
|
|
6
8
|
RSpec::Core::RakeTask.new(:spec)
|
7
9
|
RuboCop::RakeTask.new(:style)
|
8
10
|
|
9
|
-
|
10
|
-
require 'github_changelog_generator/task'
|
11
|
-
|
12
|
-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
13
|
-
config.future_release = Kitchen::Driver::VRA_VERSION
|
14
|
-
config.issues = true
|
15
|
-
end
|
16
|
-
rescue LoadError
|
17
|
-
puts 'github_changelog_generator is not available. gem install github_changelog_generator to generate changelogs'
|
18
|
-
end
|
19
|
-
|
20
|
-
task default: [ :spec, :style ]
|
11
|
+
task default: %i{spec style}
|
data/kitchen-vra.gemspec
CHANGED
@@ -1,34 +1,35 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "kitchen/driver/vra_version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = "kitchen-vra"
|
9
9
|
spec.version = Kitchen::Driver::VRA_VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
12
|
-
spec.summary =
|
10
|
+
spec.authors = ["Chef Partner Engineering"]
|
11
|
+
spec.email = ["partnereng@chef.io"]
|
12
|
+
spec.summary = "A Test Kitchen driver for VMware vRealize Automation (vRA)"
|
13
13
|
spec.description = spec.summary
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = "https://github.com/chef-partners/kitchen-vra"
|
15
|
+
spec.license = "Apache-2.0"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
18
18
|
spec.executables = []
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.required_ruby_version = ">= 2.7"
|
21
23
|
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
24
|
-
spec.add_dependency
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency 'rubocop', '~> 0.35'
|
24
|
+
spec.add_dependency "test-kitchen"
|
25
|
+
spec.add_dependency "vmware-vra", "~> 3.0" # 3.0 required for vRA 8.x
|
26
|
+
spec.add_dependency "highline"
|
27
|
+
spec.add_dependency "rack", "~> 1.6"
|
28
|
+
spec.add_dependency "ffi-yajl", ">= 2.2.3", "< 2.5.0"
|
29
|
+
spec.add_development_dependency "bundler", ">= 1.7"
|
30
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
32
|
+
spec.add_development_dependency "simplecov", "~> 0.10"
|
33
|
+
spec.add_development_dependency "webmock", "~> 3.14"
|
34
|
+
spec.add_development_dependency "chefstyle", "~> 2.2.1"
|
34
35
|
end
|
data/lib/kitchen/driver/vra.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
5
|
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
@@ -17,13 +18,13 @@
|
|
17
18
|
# limitations under the License.
|
18
19
|
#
|
19
20
|
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
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"
|
27
28
|
|
28
29
|
module Kitchen
|
29
30
|
module Driver
|
@@ -35,25 +36,27 @@ module Kitchen
|
|
35
36
|
default_config :password, nil
|
36
37
|
required_config :base_url
|
37
38
|
required_config :tenant
|
39
|
+
required_config :project_id
|
40
|
+
required_config :image_mapping
|
41
|
+
required_config :flavor_mapping
|
42
|
+
required_config :version
|
43
|
+
|
38
44
|
default_config :catalog_id, nil
|
39
45
|
default_config :catalog_name, nil
|
40
46
|
|
41
|
-
default_config :
|
47
|
+
default_config :subtenant_id, nil
|
48
|
+
default_config :subtenant_name, nil
|
42
49
|
default_config :verify_ssl, true
|
43
50
|
default_config :request_timeout, 600
|
44
51
|
default_config :request_refresh_rate, 2
|
45
52
|
default_config :server_ready_retries, 1
|
46
|
-
default_config :
|
47
|
-
|
48
|
-
default_config :requested_for do |driver|
|
49
|
-
driver[:username]
|
53
|
+
default_config :deployment_name do |driver|
|
54
|
+
driver&.instance&.platform&.name
|
50
55
|
end
|
51
|
-
default_config :lease_days, nil
|
52
|
-
default_config :notes, nil
|
53
56
|
default_config :cache_credentials, false
|
54
57
|
default_config :extra_parameters, {}
|
55
58
|
default_config :private_key_path do
|
56
|
-
%w
|
59
|
+
%w{id_rsa id_dsa}.map do |key|
|
57
60
|
file = File.expand_path("~/.ssh/#{key}")
|
58
61
|
file if File.exist?(file)
|
59
62
|
end.compact.first
|
@@ -62,21 +65,21 @@ module Kitchen
|
|
62
65
|
default_config :dns_suffix, nil
|
63
66
|
|
64
67
|
def name
|
65
|
-
|
68
|
+
"vRA"
|
66
69
|
end
|
67
70
|
|
68
71
|
def check_config(force_change = false)
|
69
|
-
config[:username] = config[:username] || ENV[
|
70
|
-
config[:password] = config[:password] || ENV[
|
72
|
+
config[:username] = config[:username] || ENV["VRA_USER_NAME"]
|
73
|
+
config[:password] = config[:password] || ENV["VRA_USER_PASSWORD"]
|
71
74
|
c_load if config[:username].nil? && config[:password].nil?
|
72
75
|
|
73
|
-
config[:username] = ask(
|
74
|
-
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
|
75
78
|
c_save if config[:cache_credentials]
|
76
79
|
end
|
77
80
|
|
78
81
|
def c_save
|
79
|
-
cipher = OpenSSL::Cipher
|
82
|
+
cipher = OpenSSL::Cipher.new("cip-her-aes")
|
80
83
|
cipher.encrypt
|
81
84
|
cipher.key = Digest::SHA1.hexdigest(config[:base_url])
|
82
85
|
iv_user = cipher.random_iv
|
@@ -86,21 +89,21 @@ module Kitchen
|
|
86
89
|
cipher.iv = iv_pwd
|
87
90
|
password = cipher.update(config[:password]) + cipher.final
|
88
91
|
output = "#{Base64.encode64(iv_user).strip!}:#{Base64.encode64(username).strip!}:#{Base64.encode64(iv_pwd).strip!}:#{Base64.encode64(password).strip!}"
|
89
|
-
file = File.open(
|
92
|
+
file = File.open(".kitchen/cached_vra", "w")
|
90
93
|
file.write(output)
|
91
94
|
file.close
|
92
95
|
rescue
|
93
|
-
puts
|
96
|
+
puts "Unable to save credentials"
|
94
97
|
end
|
95
98
|
|
96
99
|
def c_load
|
97
|
-
if File.exist?
|
98
|
-
encrypted = File.read(
|
99
|
-
iv_user = Base64.decode64(encrypted.split(
|
100
|
-
username = Base64.decode64(encrypted.split(
|
101
|
-
iv_pwd = Base64.decode64(encrypted.split(
|
102
|
-
password = Base64.decode64(encrypted.split(
|
103
|
-
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")
|
104
107
|
cipher.decrypt
|
105
108
|
cipher.key = Digest::SHA1.hexdigest(config[:base_url])
|
106
109
|
cipher.iv = iv_user
|
@@ -109,30 +112,31 @@ module Kitchen
|
|
109
112
|
config[:password] = cipher.update(password) + cipher.final
|
110
113
|
end
|
111
114
|
rescue
|
112
|
-
puts
|
115
|
+
puts "Failed to load cached credentials"
|
113
116
|
end
|
114
117
|
|
115
118
|
def create(state)
|
116
|
-
return if state[:
|
119
|
+
return if state[:deployment_id]
|
117
120
|
|
118
121
|
server = request_server
|
119
|
-
state[:
|
122
|
+
state[:deployment_id] = server.deployment_id
|
120
123
|
state[:hostname] = hostname_for(server)
|
121
124
|
state[:ssh_key] = config[:private_key_path] unless config[:private_key_path].nil?
|
122
125
|
|
123
126
|
wait_for_server(state, server)
|
124
|
-
info("Server #{server.
|
127
|
+
info("Server #{server.deployment_id} (#{server.name}) ready.")
|
125
128
|
end
|
126
129
|
|
127
130
|
def hostname_for(server)
|
128
131
|
if config[:use_dns]
|
129
|
-
raise
|
132
|
+
raise "No server name returned for the vRA request" if server.name.nil?
|
133
|
+
|
130
134
|
return config[:dns_suffix] ? "#{server.name}.#{config[:dns_suffix]}" : server.name
|
131
135
|
end
|
132
136
|
|
133
|
-
ip_address = server.
|
137
|
+
ip_address = server.ip_address
|
134
138
|
if ip_address.nil?
|
135
|
-
warn("Server #{server.
|
139
|
+
warn("Server #{server.deployment_id} has no IP address. Falling back to server name (#{server.name})...")
|
136
140
|
server.name
|
137
141
|
else
|
138
142
|
ip_address
|
@@ -140,16 +144,18 @@ module Kitchen
|
|
140
144
|
end
|
141
145
|
|
142
146
|
def request_server
|
143
|
-
info(
|
144
|
-
submitted_request = catalog_request.submit
|
145
|
-
info("Catalog request #{submitted_request.id} submitted.")
|
147
|
+
info("Building vRA catalog request...")
|
146
148
|
|
147
|
-
|
148
|
-
raise "The vRA request failed: #{submitted_request.completion_details}" if submitted_request.failed?
|
149
|
+
deployment_request = catalog_request.submit
|
149
150
|
|
150
|
-
|
151
|
-
|
152
|
-
|
151
|
+
info("Catalog request #{deployment_request.id} submitted.")
|
152
|
+
|
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
|
153
159
|
|
154
160
|
servers.first
|
155
161
|
end
|
@@ -169,7 +175,7 @@ module Kitchen
|
|
169
175
|
sleep_time += 5 if sleep_time < 30
|
170
176
|
|
171
177
|
if try > config[:server_ready_retries]
|
172
|
-
error(
|
178
|
+
error("Retries exceeded. Destroying server...")
|
173
179
|
destroy(state)
|
174
180
|
raise
|
175
181
|
else
|
@@ -181,49 +187,62 @@ module Kitchen
|
|
181
187
|
end
|
182
188
|
|
183
189
|
def destroy(state)
|
184
|
-
return if state[:
|
190
|
+
return if state[:deployment_id].nil?
|
185
191
|
|
186
192
|
begin
|
187
|
-
server = vra_client.
|
193
|
+
server = vra_client.deployments.by_id(state[:deployment_id])
|
188
194
|
rescue ::Vra::Exception::NotFound
|
189
|
-
warn("No server found with ID #{state[:
|
195
|
+
warn("No server found with ID #{state[:deployment_id]}, assuming it has been destroyed already.")
|
190
196
|
return
|
191
197
|
end
|
192
198
|
|
193
199
|
begin
|
194
200
|
destroy_request = server.destroy
|
195
201
|
rescue ::Vra::Exception::NotFound
|
196
|
-
info(
|
202
|
+
info("Server not found, or no destroy action available, perhaps because it is already destroyed.")
|
197
203
|
return
|
198
204
|
end
|
199
205
|
info("Destroy request #{destroy_request.id} submitted.")
|
200
206
|
wait_for_request(destroy_request)
|
201
|
-
info(
|
202
|
-
|
203
|
-
File.delete(
|
204
|
-
info(
|
207
|
+
info("Destroy request complete.")
|
208
|
+
|
209
|
+
File.delete(".kitchen/cached_vra") if File.exist?(".kitchen/cached_vra")
|
210
|
+
info("Removed cached file")
|
205
211
|
end
|
206
212
|
|
207
|
-
def catalog_request
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
213
|
+
def catalog_request # rubocop:disable Metrics/MethodLength
|
214
|
+
unless config[:catalog_name].nil?
|
215
|
+
info("Fetching Catalog ID by Catalog Name")
|
216
|
+
response = vra_client.catalog.fetch_catalog_items(config[:catalog_name])
|
217
|
+
parsed_json = JSON.parse(response.body)
|
218
|
+
begin
|
219
|
+
config[:catalog_id] = parsed_json["content"][0]["catalogItemId"]
|
220
|
+
rescue
|
221
|
+
puts "Unable to retrieve Catalog ID from Catalog Name: #{config[:catalog_name]}"
|
222
|
+
end
|
217
223
|
end
|
218
224
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
+
}
|
232
|
+
|
233
|
+
catalog_request = vra_client.catalog.request(config[:catalog_id], deployment_params)
|
234
|
+
|
235
|
+
unless config[:subtenant_name].nil?
|
236
|
+
info("Fetching Subtenant ID by Subtenant Name")
|
237
|
+
response = vra_client.fetch_subtenant_items(config[:tenant], config[:subtenant_name])
|
238
|
+
parsed_json = JSON.parse(response.body)
|
239
|
+
begin
|
240
|
+
config[:subtenant_id] = parsed_json["content"][0]["id"]
|
241
|
+
rescue
|
242
|
+
puts "Unable to retrieve Subtenant ID from Subtenant Name: #{config[:subtenant_name]}"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
catalog_request.subtenant_id = config[:subtenant_id] unless config[:subtenant_id].nil?
|
227
246
|
|
228
247
|
config[:extra_parameters].each do |key, value_data|
|
229
248
|
catalog_request.set_parameters(key, value_data)
|
@@ -248,9 +267,10 @@ module Kitchen
|
|
248
267
|
def wait_for_request(request)
|
249
268
|
# config = check_config config
|
250
269
|
|
251
|
-
last_status =
|
270
|
+
last_status = ""
|
252
271
|
wait_time = config[:request_timeout]
|
253
272
|
sleep_time = config[:request_refresh_rate]
|
273
|
+
|
254
274
|
Timeout.timeout(wait_time) do
|
255
275
|
loop do
|
256
276
|
request.refresh
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
5
|
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
@@ -19,6 +20,6 @@
|
|
19
20
|
|
20
21
|
module Kitchen
|
21
22
|
module Driver
|
22
|
-
VRA_VERSION =
|
23
|
+
VRA_VERSION = "3.0.0"
|
23
24
|
end
|
24
25
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
4
5
|
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
@@ -17,14 +18,14 @@
|
|
17
18
|
# limitations under the License.
|
18
19
|
#
|
19
20
|
|
20
|
-
require
|
21
|
+
require "webmock/rspec"
|
21
22
|
|
22
23
|
WebMock.disable_net_connect!(allow_localhost: true)
|
23
24
|
|
24
|
-
if ENV[
|
25
|
-
require
|
26
|
-
SimpleCov.profiles.define
|
27
|
-
command_name
|
25
|
+
if ENV["COVERAGE"]
|
26
|
+
require "simplecov"
|
27
|
+
SimpleCov.profiles.define "gem" do
|
28
|
+
command_name "Specs"
|
28
29
|
end
|
29
|
-
SimpleCov.start
|
30
|
+
SimpleCov.start "gem"
|
30
31
|
end
|