Skip to content

Commit

Permalink
Merge pull request #51 from kasif-adnan/INFCT-6-make-version-optional…
Browse files Browse the repository at this point in the history
…-attr

make version parameter optional in kitchen yml
  • Loading branch information
tas50 authored Feb 4, 2022
2 parents 14beda9 + 45725f2 commit 72a1110
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 107 deletions.
102 changes: 2 additions & 100 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,107 +22,9 @@ Or even better, install it via ChefDK:

$ chef gem install kitchen-vra

## Usage

After installing the gem as described above, edit your .kitchen.yml file to set the driver to 'vra' and supply your login credentials:

```yaml
driver:
name: vra
username: [email protected]
password: mypassword
tenant: mytenant
base_url: https://vra.corp.local
verify_ssl: true
```
If you want username and password to be prompted, remove usename and password in your .kitchen.yml as shown below:
```yaml
driver:
name: vra
tenant: mytenant
base_url: https://vra.corp.local
verify_ssl: true
```
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
$ export VRA_USER_NAME='[email protected]'
$ export VRA_USER_PASSWORD='mypassword'
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.
```yaml
platforms:
- name: centos6
driver:
catalog_id: e9db1084-d1c6-4c1f-8e3c-eb8f3dc574f9
project_id: 6ba69375-79d5-42c3-a099-7d32739f71a9
image_mapping: SQL 2016
flavor_mapping: Small
version: 1
- name: centos7
driver:
catalog_name: my_catalog_name
project_id: 6ba69375-79d5-42c3-a099-7d32739f71a9
image_mapping: VRA-nc-lnx-ce8.4-Docker
flavor_mapping: Small
version: 1
```
## Configuration

Other options that you can set include:
* **request_timeout**: amount of time, in seconds, to wait for a vRA request to complete. Default is 600 seconds.
* **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.
* **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.
* **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.
* **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.
* **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.
* **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.
* **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.

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:

```yaml
driver:
name: vra
platforms:
- name: small
driver:
catalog_name: my_catalog_name_small
catalog_id: 8a189191-fea6-43eb-981e-ee0fa40f8f57
project_id: 6ba69375-79d5-42c3-a099-7d32739f71a9
image_mapping: SQL 2016
flavor_mapping: Small
version: 1
extra_parameters:
mycustompropname:
type: string
value: smallvalue
Vrm.DataCenter.Location:
type: string
value: Non-Prod
- name: large
driver:
catalog_name: my_catalog_name_large
catalog_id: 1d7c6122-18fa-4ed6-bd13-8a33b6c6ed50
project_id: 6ba69375-79d5-42c3-a099-7d32739f71a9
image_mapping: VRA-nc-lnx-ce8.4-Docker
flavor_mapping: Large
version: 1
subtenant_name: my_subtenant_name
extra_parameters:
mycustompropname:
type: string
value: largevalue
Vrm.DataCenter.Location:
type: string
value: Prod
```
See the [kitchen.ci kitchen-vra docs](https://kitchen.ci/docs/drivers/vra/) for a complete list of configuration options.

## License and Authors

Expand Down
2 changes: 1 addition & 1 deletion kitchen-vra.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 2.7"

spec.add_dependency "test-kitchen"
spec.add_dependency "vmware-vra", "~> 3.0" # 3.0 required for vRA 8.x
spec.add_dependency "vmware-vra", ">= 3.1.0" # 3.0 required for vRA 8.x
spec.add_dependency "highline"
spec.add_dependency "rack", ">= 1.6", "< 3.0"
spec.add_dependency "ffi-yajl", ">= 2.2.3", "< 2.5.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/vra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Vra < Kitchen::Driver::Base # rubocop:disable Metrics/ClassLength
required_config :project_id
required_config :image_mapping
required_config :flavor_mapping
required_config :version

default_config :version, nil
default_config :catalog_id, nil
default_config :catalog_name, nil

Expand Down
7 changes: 2 additions & 5 deletions spec/vra_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
subtenant_id: "160b473a-0ec9-473d-8156-28dd96c0b6b7",
use_dns: false,
deployment_name: "test-instance",
version: 1,
}
end

Expand Down Expand Up @@ -421,7 +420,6 @@
project_id: "6ba69375-79d5-42c3-a099-7d32739f71a7",
image_mapping: "VRA-nc-lnx-ce8.4-Docker",
flavor_mapping: "Small",
version: 1,
}
end

Expand All @@ -442,15 +440,14 @@
project_id: "6ba69375-79d5-42c3-a099-7d32739f71a7",
image_mapping: "VRA-nc-lnx-ce8.4-Docker",
flavor_mapping: "Small",
version: 1,
extra_parameters: { "key1" => { type: "string", value: "value1" },
"key2" => { type: "integer", value: 123 } },
}
end

it "sets extra parmeters" do
expect(catalog_request).to receive(:set_parameters).with("key1", type: "string", value: "value1")
expect(catalog_request).to receive(:set_parameters).with("key2", type: "integer", value: 123)
expect(catalog_request).to receive(:set_parameters).with("key1", { type: "string", value: "value1" })
expect(catalog_request).to receive(:set_parameters).with("key2", { type: "integer", value: 123 })
driver.catalog_request
end
end
Expand Down

0 comments on commit 72a1110

Please sign in to comment.