kitchen-oci 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.cane +0 -0
- data/.gitignore +18 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -0
- data/LICENSE +15 -0
- data/README.md +89 -0
- data/Rakefile +21 -0
- data/kitchen-oci.gemspec +29 -0
- data/lib/kitchen/driver/oci.rb +146 -0
- data/lib/kitchen/driver/oci_version.rb +23 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 28a500ab2c3ac91b3fc827a78bfcb8c50cf1f1a2
|
4
|
+
data.tar.gz: 97a476e7eeb9d8fb1c9fcc43ddbe9471b88915f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6cbb83bc027ff4d4f66f5a48184749b7bdd08342a2a42adc3ca6e87f084501f7c1101011aa76310630eaee53c4fb7c0d2a2021bb8ec669dcac8e0483c2334278
|
7
|
+
data.tar.gz: dfc1c9221d4d5f93af40d28805472c420cdadd81cfd6c6fb8412ec06edb067f6e34f65f1309c6f099bb7cfe72bd0451bc293e93ea2f90de9f28108138fefff90
|
data/.cane
ADDED
File without changes
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Author:: Stephen Pearson (<stevieweavie@gmail.com>)
|
2
|
+
|
3
|
+
Copyright (C) 2017, Stephen Pearson
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Kitchen::OCI
|
2
|
+
|
3
|
+
A Test Kitchen Driver for Oracle Bare Metal Cloud
|
4
|
+
|
5
|
+
WARNING: This is alpha quality. Use at your own risk!
|
6
|
+
|
7
|
+
## Prerequisites
|
8
|
+
|
9
|
+
You need an ssh keypair defined for your current user. By default the driver
|
10
|
+
expects to find the public key in ~/.ssh/id_rsa.pub, but this can be
|
11
|
+
overridden in .kitchen.yml.
|
12
|
+
|
13
|
+
You need to create suitable configuration for OCI in ~/.oci/config but this
|
14
|
+
can be created using the CLI:
|
15
|
+
```
|
16
|
+
oci setup config
|
17
|
+
```
|
18
|
+
|
19
|
+
Ensure that you have a suitable compartment defined, an external subnet, and
|
20
|
+
security rules that allow incoming SSH and outgoing HTTP (to allow Kitchen to
|
21
|
+
pull the Chef binaries).
|
22
|
+
|
23
|
+
## Building the gem
|
24
|
+
|
25
|
+
Ensure you have the ChefDK installed.
|
26
|
+
|
27
|
+
```
|
28
|
+
eval "$(chef shell-init bash)"
|
29
|
+
rake build
|
30
|
+
gem install pkg/kitchen-oci-<VERSION>.gem
|
31
|
+
```
|
32
|
+
|
33
|
+
## Example .kitchen.yml
|
34
|
+
|
35
|
+
Adjust below template as required. The following configuration is mandatory:
|
36
|
+
|
37
|
+
- compartment\_id
|
38
|
+
- availability\_domain
|
39
|
+
- image\_id
|
40
|
+
- shape
|
41
|
+
- subnet\_id
|
42
|
+
|
43
|
+
These settings are optional:
|
44
|
+
|
45
|
+
- oci\_config\_file, by default this is ~/.oci/config
|
46
|
+
- oci\_profile\_name, default value is "DEFAULT"
|
47
|
+
- ssh\_keypath, default is ~/.ssh/id\_rsa.pub
|
48
|
+
- post\_create\_script, does not run a script by default
|
49
|
+
|
50
|
+
```
|
51
|
+
---
|
52
|
+
driver:
|
53
|
+
name: oci
|
54
|
+
|
55
|
+
provisioner:
|
56
|
+
name: chef_zero
|
57
|
+
always_update_cookbooks: true
|
58
|
+
|
59
|
+
verifier:
|
60
|
+
name: inspec
|
61
|
+
|
62
|
+
platforms:
|
63
|
+
- name: ubuntu-16.04
|
64
|
+
driver:
|
65
|
+
availability_domain: "ad1"
|
66
|
+
compartment_id: "ocid1.compartment.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
67
|
+
image_id: "ocid1.image.oc1.phx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
68
|
+
shape: "VM.Standard1.2"
|
69
|
+
subnet_id: "ocid1.subnet.oc1.phx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
70
|
+
post_create_script: >-
|
71
|
+
touch /tmp/example.txt;
|
72
|
+
transport:
|
73
|
+
username: "opc"
|
74
|
+
|
75
|
+
suites:
|
76
|
+
- name: default
|
77
|
+
run_list:
|
78
|
+
- recipe[my_cookbook::default]
|
79
|
+
verifier:
|
80
|
+
inspec_tests:
|
81
|
+
- test/smoke/default
|
82
|
+
attributes:
|
83
|
+
```
|
84
|
+
|
85
|
+
Created and maintained by [Stephen Pearson][author] (<stevieweavie@gmail.com>)
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
Apache 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'cane/rake_task'
|
3
|
+
require 'tailor/rake_task'
|
4
|
+
|
5
|
+
desc 'Run cane to check quality metrics'
|
6
|
+
Cane::RakeTask.new do |cane|
|
7
|
+
cane.canefile = './.cane'
|
8
|
+
end
|
9
|
+
|
10
|
+
Tailor::RakeTask.new
|
11
|
+
|
12
|
+
desc 'Display LOC stats'
|
13
|
+
task :stats do
|
14
|
+
puts '\n## Production Code Stats'
|
15
|
+
sh 'countloc -r lib'
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Run all quality tasks'
|
19
|
+
task quality: %i[cane tailor stats]
|
20
|
+
|
21
|
+
task default: %i[quality]
|
data/kitchen-oci.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'kitchen/driver/oci_version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'kitchen-oci'
|
7
|
+
spec.version = Kitchen::Driver::OCI_VERSION
|
8
|
+
spec.authors = ['Stephen Pearson']
|
9
|
+
spec.email = ['stevieweavie@gmail.com']
|
10
|
+
spec.description = 'A Test Kitchen Driver for Oracle OCI'
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.homepage = ''
|
13
|
+
spec.license = 'Apache-2.0'
|
14
|
+
|
15
|
+
# rubocop:disable SpecialGlobalVars
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
# rubocop:enable SpecialGlobalVars
|
18
|
+
spec.executables = []
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'oci', '~> 2.0'
|
23
|
+
spec.add_dependency 'test-kitchen'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'cane'
|
27
|
+
spec.add_development_dependency 'countloc'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Stephen Pearson (<stevieweavie@gmail.com>)
|
3
|
+
#
|
4
|
+
# Copyright (C) 2017, Stephen Pearson
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require 'kitchen'
|
19
|
+
require 'oci'
|
20
|
+
|
21
|
+
module Kitchen
|
22
|
+
module Driver
|
23
|
+
# Oracle OCI driver for Kitchen.
|
24
|
+
#
|
25
|
+
# @author Stephen Pearson <stevieweavie@gmail.com>
|
26
|
+
class Oci < Kitchen::Driver::Base
|
27
|
+
required_config :compartment_id
|
28
|
+
required_config :availability_domain
|
29
|
+
required_config :image_id
|
30
|
+
required_config :shape
|
31
|
+
required_config :subnet_id
|
32
|
+
|
33
|
+
default_config :oci_config_file, nil
|
34
|
+
default_config :oci_profile_name, nil
|
35
|
+
default_keypath = File.expand_path(File.join(%w[~ .ssh id_rsa.pub]))
|
36
|
+
default_config :ssh_keypath, default_keypath
|
37
|
+
default_config :post_create_script, nil
|
38
|
+
|
39
|
+
def create(state) # rubocop:disable Metrics/AbcSize
|
40
|
+
return if state[:server_id]
|
41
|
+
|
42
|
+
instance_id = launch_instance(config)
|
43
|
+
state[:server_id] = instance_id
|
44
|
+
state[:hostname] = public_ip(config, instance_id)
|
45
|
+
|
46
|
+
instance.transport.connection(state).wait_until_ready
|
47
|
+
|
48
|
+
return unless config[:post_create_script]
|
49
|
+
|
50
|
+
info('Running post create script')
|
51
|
+
script = config[:post_create_script]
|
52
|
+
instance.transport.connection(state).execute(script)
|
53
|
+
end
|
54
|
+
|
55
|
+
def destroy(state)
|
56
|
+
return unless state[:server_id]
|
57
|
+
|
58
|
+
instance.transport.connection(state).close
|
59
|
+
comp_api(config).terminate_instance(state[:server_id])
|
60
|
+
|
61
|
+
state.delete(:server_id)
|
62
|
+
state.delete(:hostname)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def oci_config(config)
|
68
|
+
params = [:load_config]
|
69
|
+
opts = {}
|
70
|
+
if config[:oci_config_file]
|
71
|
+
opts[:config_file_location] = config[:oci_config_file]
|
72
|
+
end
|
73
|
+
if config[:oci_profile_name]
|
74
|
+
opts[:profile_name] = config[:oci_profile_name]
|
75
|
+
end
|
76
|
+
params << opts
|
77
|
+
OCI::ConfigFileLoader.send(*params)
|
78
|
+
end
|
79
|
+
|
80
|
+
def comp_api(config)
|
81
|
+
OCI::Core::ComputeClient.new(config: oci_config(config))
|
82
|
+
end
|
83
|
+
|
84
|
+
def net_api(config)
|
85
|
+
OCI::Core::VirtualNetworkClient.new(config: oci_config(config))
|
86
|
+
end
|
87
|
+
|
88
|
+
def launch_instance(config)
|
89
|
+
request = compute_instance_request(config)
|
90
|
+
|
91
|
+
response = comp_api(config).launch_instance(request)
|
92
|
+
instance_id = response.data.id
|
93
|
+
comp_api(config).get_instance(instance_id).wait_until(
|
94
|
+
:lifecycle_state,
|
95
|
+
OCI::Core::Models::Instance::LIFECYCLE_STATE_RUNNING
|
96
|
+
)
|
97
|
+
instance_id
|
98
|
+
end
|
99
|
+
|
100
|
+
def public_ip(config, instance_id)
|
101
|
+
vnics = comp_api(config).list_vnic_attachments(
|
102
|
+
config[:compartment_id],
|
103
|
+
instance_id: instance_id
|
104
|
+
)
|
105
|
+
vnic_id = vnics.data.first.vnic_id
|
106
|
+
net_api(config).get_vnic(vnic_id).data.public_ip
|
107
|
+
end
|
108
|
+
|
109
|
+
def pubkey(config)
|
110
|
+
File.readlines(config[:ssh_keypath]).first.chomp
|
111
|
+
end
|
112
|
+
|
113
|
+
def instance_source_details(config)
|
114
|
+
OCI::Core::Models::InstanceSourceViaImageDetails.new(
|
115
|
+
source_type: 'image',
|
116
|
+
imageId: config[:image_id]
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
def create_vnic_details(config)
|
121
|
+
OCI::Core::Models::CreateVnicDetails.new(
|
122
|
+
assign_public_ip: true,
|
123
|
+
display_name: 'primary_nic',
|
124
|
+
subnetId: config[:subnet_id]
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
def compute_instance_request(config)
|
129
|
+
request = OCI::Core::Models::LaunchInstanceDetails.new
|
130
|
+
request.availability_domain = config[:availability_domain]
|
131
|
+
request.compartment_id = config[:compartment_id]
|
132
|
+
request.display_name = random_hostname(instance.name)
|
133
|
+
request.source_details = instance_source_details(config)
|
134
|
+
request.shape = config[:shape]
|
135
|
+
request.create_vnic_details = create_vnic_details(config)
|
136
|
+
request.metadata = { 'ssh_authorized_keys' => pubkey(config) }
|
137
|
+
request
|
138
|
+
end
|
139
|
+
|
140
|
+
def random_hostname(prefix)
|
141
|
+
randstr = Array.new(6) { ('a'..'z').to_a.sample }.join
|
142
|
+
"#{prefix}-#{randstr}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Stephen Pearson (<stevieweavie@gmail.com>)
|
3
|
+
#
|
4
|
+
# Copyright (C) 2017, Stephen Pearson
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
module Kitchen
|
19
|
+
module Driver
|
20
|
+
# Version string for Oracle OCI Kitchen driver
|
21
|
+
OCI_VERSION = '1.0.0'.freeze
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-oci
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Pearson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oci
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: test-kitchen
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cane
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: countloc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A Test Kitchen Driver for Oracle OCI
|
98
|
+
email:
|
99
|
+
- stevieweavie@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".cane"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CHANGELOG.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- kitchen-oci.gemspec
|
113
|
+
- lib/kitchen/driver/oci.rb
|
114
|
+
- lib/kitchen/driver/oci_version.rb
|
115
|
+
homepage: ''
|
116
|
+
licenses:
|
117
|
+
- Apache-2.0
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.6.13
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: A Test Kitchen Driver for Oracle OCI
|
139
|
+
test_files: []
|