kitchen-oci 1.16.2 → 1.17.0

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
  SHA256:
3
- metadata.gz: cf877ab3445b41c9cef61838cee55823f6377fec01a5941b5143707138a65983
4
- data.tar.gz: 3ed5f384f3c6708b0c72fc4af7a574a7197074c1dbd703ff62116bf229fa0886
3
+ metadata.gz: 4447f287a8b33c9959c977d4fd50ce99c0f977dcb72438e266b3f936b5ef3a43
4
+ data.tar.gz: 6a8520b6c8d837a71065044ed1e570efa3b303965670d4ce4fcc61de5a4807b6
5
5
  SHA512:
6
- metadata.gz: 7a2564cb3b997cf6ea1173af0743359e6c6009728e02c260ba3f168479f09c60454bcf1047d4b7d118f7390e1606647ab4b87964c8cda4b285953d8bb1a2acd2
7
- data.tar.gz: 11a6cc7ba6370468dca3615c7224a9878d0b69cc60882107e5896fd5ca29725693040673f544573d8bdd06ba6b8ed4ac996eb62ed5b81ccd35e2f47bbb965042
6
+ metadata.gz: a9476e56b93733a640744a3ed8c1f0f4b7dd043000035a5d8d86d8e57cefb302c804c034dc2f1f666ad1175b2ffadb609664f1be4be3886b4d8aabc1ac38cff5
7
+ data.tar.gz: a3c7e8522bf457603f7376387247bec8fdfb9f7d266c630771c5e612577954318cd2873397795d1a440ad2f4c11601cc57bd6a0d5c200eeee71464f50805ee49
@@ -22,12 +22,25 @@ module Kitchen
22
22
  class Oci
23
23
  # Api class that defines the various API classes used to interact with OCI
24
24
  class Api
25
- attr_reader :oci_config, :config
26
25
  def initialize(oci_config, config)
27
26
  @oci_config = oci_config
28
27
  @config = config
29
28
  end
30
29
 
30
+ #
31
+ # The config used to authenticate to OCI
32
+ #
33
+ # @return [OCI::Config]
34
+ #
35
+ attr_reader :oci_config
36
+
37
+ #
38
+ # The config provided by the driver
39
+ #
40
+ # @return [Kitchen::LazyHash]
41
+ #
42
+ attr_reader :config
43
+
31
44
  def compute
32
45
  generic_api(OCI::Core::ComputeClient)
33
46
  end
@@ -26,8 +26,6 @@ module Kitchen
26
26
  require_relative "models/iscsi"
27
27
  require_relative "models/paravirtual"
28
28
 
29
- attr_accessor :config, :state, :oci, :api, :volume_state, :volume_attachment_state
30
-
31
29
  def initialize(config, state, oci, api, action = :create)
32
30
  super()
33
31
  @config = config
@@ -39,6 +37,46 @@ module Kitchen
39
37
  oci.compartment if action == :create
40
38
  end
41
39
 
40
+ #
41
+ # The config provided by the driver
42
+ #
43
+ # @return [Kitchen::LazyHash]
44
+ #
45
+ attr_accessor :config
46
+
47
+ #
48
+ # The definition of the state of the instance from the statefile
49
+ #
50
+ # @return [Hash]
51
+ #
52
+ attr_accessor :state
53
+
54
+ #
55
+ # The config object that contains properties of the authentication to OCI
56
+ #
57
+ # @return [Kitchen::Driver::Oci::Config]
58
+ #
59
+ attr_accessor :oci
60
+
61
+ #
62
+ # The API object that contains each of the authenticated clients for interfacing with OCI
63
+ #
64
+ # @return [Kitchen::Driver::Oci::Api]
65
+ #
66
+ attr_accessor :api
67
+
68
+ # The definition of the state of a volume
69
+ #
70
+ # @return [Hash]
71
+ #
72
+ attr_accessor :volume_state
73
+
74
+ # The definition of the state of a volume attachment
75
+ #
76
+ # @return [Hash]
77
+ #
78
+ attr_accessor :volume_attachment_state
79
+
42
80
  def create_volume(volume)
43
81
  info("Creating <#{volume[:name]}>...")
44
82
  result = api.blockstorage.create_volume(volume_details(volume))
@@ -71,16 +109,6 @@ module Kitchen
71
109
  info("Finished detaching <#{attachment_name(volume_attachment)}>.")
72
110
  end
73
111
 
74
- def detatch_and_delete
75
- state[:volume_attachments].each do |att|
76
- detatch_volume(att)
77
- end
78
-
79
- state[:volumes].each do |vol|
80
- delete_volume(vol)
81
- end
82
- end
83
-
84
112
  def final_state(response)
85
113
  case response
86
114
  when OCI::Core::Models::Volume
@@ -24,15 +24,20 @@ module Kitchen
24
24
  class Oci
25
25
  # Config class that defines the oci config that will be used for the API calls
26
26
  class Config
27
- attr_reader :config
28
-
29
27
  def initialize(driver_config)
30
28
  setup_driver_config(driver_config)
31
29
  @config = oci_config
32
30
  end
33
31
 
32
+ #
33
+ # The config used to authenticate to OCI
34
+ #
35
+ # @return [OCI::Config]
36
+ #
37
+ attr_reader :config
38
+
34
39
  def oci_config
35
- # OCI::Config is missing this and we're definitely using compartment and security_token_file if specified in the config
40
+ # OCI::Config is missing this
36
41
  OCI::Config.class_eval { attr_accessor :security_token_file } if @driver_config[:use_token_auth]
37
42
  conf = config_loader(config_file_location: @driver_config[:oci_config_file], profile_name: @driver_config[:oci_profile_name])
38
43
  @driver_config[:oci_config].each do |key, value|
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
4
+ #
5
+ # Copyright (C) 2024, Stephen Pearson
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Kitchen
20
+ module Driver
21
+ class Oci
22
+ class Instance
23
+ # setter methods that populate launch details common to all instance models
24
+ module CommonLaunchDetails
25
+ def compartment_id
26
+ launch_details.compartment_id = oci.compartment
27
+ end
28
+
29
+ def availability_domain
30
+ launch_details.availability_domain = config[:availability_domain]
31
+ end
32
+
33
+ def defined_tags
34
+ launch_details.defined_tags = config[:defined_tags]
35
+ end
36
+
37
+ def shape
38
+ launch_details.shape = config[:shape]
39
+ end
40
+
41
+ def freeform_tags
42
+ launch_details.freeform_tags = process_freeform_tags
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
4
+ #
5
+ # Copyright (C) 2024, Stephen Pearson
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Kitchen
20
+ module Driver
21
+ class Oci
22
+ class Instance
23
+ # setter methods that populate the details of OCI::Core::Models::LaunchInstanceDetails
24
+ module ComputeLaunchDetails
25
+ def hostname_display_name
26
+ display_name = hostname
27
+ launch_details.display_name = display_name
28
+ launch_details.create_vnic_details = create_vnic_details(display_name)
29
+ end
30
+
31
+ def preemptible_instance_config
32
+ return unless config[:preemptible_instance]
33
+
34
+ launch_details.preemptible_instance_config = OCI::Core::Models::PreemptibleInstanceConfigDetails.new(
35
+ preemption_action:
36
+ OCI::Core::Models::TerminatePreemptionAction.new(
37
+ type: "TERMINATE", preserve_boot_volume: true
38
+ )
39
+ )
40
+ end
41
+
42
+ def shape_config
43
+ return if config[:shape_config].empty?
44
+
45
+ launch_details.shape_config = OCI::Core::Models::LaunchInstanceShapeConfigDetails.new(
46
+ ocpus: config[:shape_config][:ocpus],
47
+ memory_in_gbs: config[:shape_config][:memory_in_gbs],
48
+ baseline_ocpu_utilization: config[:shape_config][:baseline_ocpu_utilization] || "BASELINE_1_1"
49
+ )
50
+ end
51
+
52
+ def instance_source_details
53
+ launch_details.source_details = OCI::Core::Models::InstanceSourceViaImageDetails.new(
54
+ sourceType: "image",
55
+ imageId: config[:image_id],
56
+ bootVolumeSizeInGBs: config[:boot_volume_size_in_gbs]
57
+ )
58
+ end
59
+
60
+ def instance_metadata
61
+ launch_details.metadata = metadata
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
4
+ #
5
+ # Copyright (C) 2024, Stephen Pearson
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Kitchen
20
+ module Driver
21
+ class Oci
22
+ class Instance
23
+ # setter methods that populate the details of OCI::Database::Models::CreateDatabaseDetails
24
+ module DatabaseDetails
25
+ def character_set
26
+ database_details.character_set = config[:dbaas][:character_set] ||= "AL32UTF8"
27
+ end
28
+
29
+ def ncharacter_set
30
+ database_details.ncharacter_set = config[:dbaas][:ncharacter_set] ||= "AL16UTF16"
31
+ end
32
+
33
+ def db_workload
34
+ workload = config[:dbaas][:db_workload] ||= OCI::Database::Models::CreateDatabaseDetails::DB_WORKLOAD_OLTP
35
+ database_details.db_workload = workload
36
+ end
37
+
38
+ def admin_password
39
+ database_details.admin_password = config[:dbaas][:admin_password] ||= random_password(%w{# _ -})
40
+ end
41
+
42
+ def db_name
43
+ database_details.db_name = config[:dbaas][:db_name] ||= "dbaas1"
44
+ end
45
+
46
+ def pdb_name
47
+ database_details.pdb_name = config[:dbaas][:pdb_name] ||= "pdb001"
48
+ end
49
+
50
+ def db_backup_config
51
+ database_details.db_backup_config = OCI::Database::Models::DbBackupConfig.new.tap do |l|
52
+ l.auto_backup_enabled = false
53
+ end
54
+ database_details
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
4
+ #
5
+ # Copyright (C) 2024, Stephen Pearson
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Kitchen
20
+ module Driver
21
+ class Oci
22
+ class Instance
23
+ # setter methods that populate the details of OCI::Database::Models::CreateDbHomeDetails
24
+ module DbHomeDetails
25
+ def database
26
+ db_home_details.database = database_details
27
+ end
28
+
29
+ def db_version
30
+ raise "db_version cannot be nil!" if config[:dbaas][:db_version].nil?
31
+
32
+ db_home_details.db_version = config[:dbaas][:db_version]
33
+ end
34
+
35
+ def db_home_display_name
36
+ db_home_details.display_name = ["dbhome", random_number(10)].compact.join
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
4
+ #
5
+ # Copyright (C) 2024, Stephen Pearson
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative "../instance/database"
20
+ require_relative "../instance/db_home"
21
+
22
+ module Kitchen
23
+ module Driver
24
+ class Oci
25
+ class Instance
26
+ # setter methods that populate the details of OCI::Database::Models::LaunchDbSystemDetails
27
+ module DbaasLaunchDetails
28
+ include DatabaseDetails
29
+ include DbHomeDetails
30
+ #
31
+ # TODO: add support for the #domain property
32
+ # add support for #database_software_image_id property
33
+ #
34
+ def db_home
35
+ launch_details.db_home = db_home_details
36
+ end
37
+
38
+ def subnet_id
39
+ launch_details.subnet_id = config[:subnet_id]
40
+ end
41
+
42
+ def nsg_ids
43
+ launch_details.nsg_ids = config[:nsg_ids]
44
+ end
45
+
46
+ def hostname
47
+ # The hostname must begin with an alphabetic character, and can contain alphanumeric characters and hyphens (-).
48
+ # The maximum length of the hostname is 16 characters
49
+ long_name = [hostname_prefix, long_hostname_suffix].compact.join("-")
50
+ trimmed_name = [hostname_prefix[0, 12], random_string(3)].compact.join("-")
51
+ launch_details.hostname = [long_name, trimmed_name].min { |l, t| l.size <=> t.size }
52
+ end
53
+
54
+ def display_name
55
+ # The user-friendly name for the DB system. The name does not have to be unique.
56
+ launch_details.display_name = [config[:hostname_prefix], random_string(4), random_number(2)].compact.join("-")
57
+ end
58
+
59
+ def node_count
60
+ launch_details.node_count = 1
61
+ end
62
+
63
+ def pubkey
64
+ result = []
65
+ result << File.readlines(config[:ssh_keypath]).first.chomp
66
+ launch_details.ssh_public_keys = result
67
+ end
68
+
69
+ def cpu_core_count
70
+ launch_details.cpu_core_count = config[:dbaas][:cpu_core_count] ||= 2
71
+ end
72
+
73
+ def license_model
74
+ license = config[:dbaas][:license_model] ||= OCI::Database::Models::DbSystem::LICENSE_MODEL_BRING_YOUR_OWN_LICENSE
75
+ launch_details.license_model = license
76
+ end
77
+
78
+ def initial_data_storage_size_in_gb
79
+ launch_details.initial_data_storage_size_in_gb = config[:dbaas][:initial_data_storage_size_in_gb] ||= 256
80
+ end
81
+
82
+ def database_edition
83
+ db_edition = config[:dbaas][:database_edition] ||= OCI::Database::Models::DbSystem::DATABASE_EDITION_ENTERPRISE_EDITION
84
+ launch_details.database_edition = db_edition
85
+ end
86
+
87
+ def cluster_name
88
+ prefix = config[:hostname_prefix].split("-")[0]
89
+ # 11 character limit for cluster_name in DBaaS
90
+ cn = if prefix.length >= 11
91
+ prefix[0, 11]
92
+ else
93
+ [prefix, random_string(10 - prefix.length)].compact.join("-")
94
+ end
95
+ launch_details.cluster_name = cn
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+
@@ -21,13 +21,14 @@ module Kitchen
21
21
  module Driver
22
22
  class Oci
23
23
  # generic class for instance models
24
- class Instance < Oci
24
+ class Instance < Oci # rubocop:disable Metrics/ClassLength
25
25
  require_relative "api"
26
26
  require_relative "config"
27
27
  require_relative "models/compute"
28
28
  require_relative "models/dbaas"
29
+ require_relative "instance/common"
29
30
 
30
- attr_accessor :config, :state, :oci, :api
31
+ include CommonLaunchDetails
31
32
 
32
33
  def initialize(config, state, oci, api, action)
33
34
  super()
@@ -37,25 +38,33 @@ module Kitchen
37
38
  @api = api
38
39
  end
39
40
 
40
- def compartment_id
41
- launch_details.compartment_id = oci.compartment
42
- end
43
-
44
- def availability_domain
45
- launch_details.availability_domain = config[:availability_domain]
46
- end
47
-
48
- def defined_tags
49
- launch_details.defined_tags = config[:defined_tags]
50
- end
51
-
52
- def shape
53
- launch_details.shape = config[:shape]
54
- end
55
-
56
- def freeform_tags
57
- launch_details.freeform_tags = process_freeform_tags
58
- end
41
+ #
42
+ # The config provided by the driver
43
+ #
44
+ # @return [Kitchen::LazyHash]
45
+ #
46
+ attr_accessor :config
47
+
48
+ #
49
+ # The definition of the state of the instance from the statefile
50
+ #
51
+ # @return [Hash]
52
+ #
53
+ attr_accessor :state
54
+
55
+ #
56
+ # The config object that contains properties of the authentication to OCI
57
+ #
58
+ # @return [Kitchen::Driver::Oci::Config]
59
+ #
60
+ attr_accessor :oci
61
+
62
+ #
63
+ # The API object that contains each of the authenticated clients for interfacing with OCI
64
+ #
65
+ # @return [Kitchen::Driver::Oci::Api]
66
+ #
67
+ attr_accessor :api
59
68
 
60
69
  def final_state(state, instance_id)
61
70
  state.store(:server_id, instance_id)
@@ -65,6 +74,15 @@ module Kitchen
65
74
 
66
75
  private
67
76
 
77
+ def launch_instance_details
78
+ launch_methods = []
79
+ self.class.ancestors.reverse.select { |m| m.is_a?(Module) && m.name.start_with?("#{self.class.superclass}::") }.each do |klass|
80
+ launch_methods << klass.instance_methods(false)
81
+ end
82
+ launch_methods.flatten.each { |m| send(m) }
83
+ launch_details
84
+ end
85
+
68
86
  def public_ip_allowed?
69
87
  subnet = api.network.get_subnet(config[:subnet_id]).data
70
88
  !subnet.prohibit_public_ip_on_vnic
@@ -16,19 +16,28 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
+ require_relative "../instance/compute"
20
+
19
21
  module Kitchen
20
22
  module Driver
21
23
  class Oci
22
24
  module Models
23
25
  # Compute instance model
24
26
  class Compute < Instance # rubocop:disable Metrics/ClassLength
25
- attr_accessor :launch_details
27
+ include ComputeLaunchDetails
26
28
 
27
- def initialize(config, state, oci, api, action = :create)
29
+ def initialize(config, state, oci, api, action)
28
30
  super
29
31
  @launch_details = OCI::Core::Models::LaunchInstanceDetails.new
30
32
  end
31
33
 
34
+ #
35
+ # The details model that describes a compute instance
36
+ #
37
+ # @return [OCI::Core::Models::LaunchInstanceDetails]
38
+ #
39
+ attr_accessor :launch_details
40
+
32
41
  def launch
33
42
  process_windows_options
34
43
  response = api.compute.launch_instance(launch_instance_details)
@@ -44,57 +53,28 @@ module Kitchen
44
53
 
45
54
  private
46
55
 
47
- def launch_instance_details # rubocop:disable Metrics/MethodLength
48
- compartment_id
49
- availability_domain
50
- defined_tags
51
- shape
52
- freeform_tags
53
- hostname_display_name
54
- instance_source_details
55
- instance_metadata
56
- preemptible_instance_config
57
- shape_config
58
- launch_details
59
- end
60
-
61
- def hostname_display_name
62
- display_name = hostname
63
- launch_details.display_name = display_name
64
- launch_details.create_vnic_details = create_vnic_details(display_name)
65
- end
66
-
67
- def hostname
68
- [config[:hostname_prefix], random_string(6)].compact.join("-")
56
+ def instance_ip(instance_id)
57
+ vnic = vnics(instance_id).select(&:is_primary).first
58
+ if public_ip_allowed?
59
+ config[:use_private_ip] ? vnic.private_ip : vnic.public_ip
60
+ else
61
+ vnic.private_ip
62
+ end
69
63
  end
70
64
 
71
- def preemptible_instance_config
72
- return unless config[:preemptible_instance]
73
-
74
- launch_details.preemptible_instance_config = OCI::Core::Models::PreemptibleInstanceConfigDetails.new(
75
- preemption_action:
76
- OCI::Core::Models::TerminatePreemptionAction.new(
77
- type: "TERMINATE", preserve_boot_volume: true
78
- )
79
- )
65
+ def vnics(instance_id)
66
+ vnic_attachments(instance_id).map { |att| api.network.get_vnic(att.vnic_id).data }
80
67
  end
81
68
 
82
- def shape_config
83
- return if config[:shape_config].empty?
69
+ def vnic_attachments(instance_id)
70
+ att = api.compute.list_vnic_attachments(oci.compartment, instance_id: instance_id).data
71
+ raise "Could not find any VNIC attachments" unless att.any?
84
72
 
85
- launch_details.shape_config = OCI::Core::Models::LaunchInstanceShapeConfigDetails.new(
86
- ocpus: config[:shape_config][:ocpus],
87
- memory_in_gbs: config[:shape_config][:memory_in_gbs],
88
- baseline_ocpu_utilization: config[:shape_config][:baseline_ocpu_utilization] || "BASELINE_1_1"
89
- )
73
+ att
90
74
  end
91
75
 
92
- def instance_source_details
93
- launch_details.source_details = OCI::Core::Models::InstanceSourceViaImageDetails.new(
94
- sourceType: "image",
95
- imageId: config[:image_id],
96
- bootVolumeSizeInGBs: config[:boot_volume_size_in_gbs]
97
- )
76
+ def hostname
77
+ [config[:hostname_prefix], random_string(6)].compact.join("-")
98
78
  end
99
79
 
100
80
  def create_vnic_details(name)
@@ -111,10 +91,6 @@ module Kitchen
111
91
  File.readlines(config[:ssh_keypath]).first.chomp
112
92
  end
113
93
 
114
- def instance_metadata
115
- launch_details.metadata = metadata
116
- end
117
-
118
94
  def metadata
119
95
  md = {}
120
96
  inject_powershell
@@ -124,26 +100,6 @@ module Kitchen
124
100
  md
125
101
  end
126
102
 
127
- def vnics(instance_id)
128
- vnic_attachments(instance_id).map { |att| api.network.get_vnic(att.vnic_id).data }
129
- end
130
-
131
- def vnic_attachments(instance_id)
132
- att = api.compute.list_vnic_attachments(oci.compartment, instance_id: instance_id).data
133
- raise "Could not find any VNIC attachments" unless att.any?
134
-
135
- att
136
- end
137
-
138
- def instance_ip(instance_id)
139
- vnic = vnics(instance_id).select(&:is_primary).first
140
- if public_ip_allowed?
141
- config[:use_private_ip] ? vnic.private_ip : vnic.public_ip
142
- else
143
- vnic.private_ip
144
- end
145
- end
146
-
147
103
  def process_windows_options
148
104
  return unless windows_state?
149
105
 
@@ -16,21 +16,44 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
+ require_relative "../instance/dbaas"
20
+
19
21
  module Kitchen
20
22
  module Driver
21
23
  class Oci
22
24
  module Models
23
25
  # dbaas model
24
26
  class Dbaas < Instance # rubocop:disable Metrics/ClassLength
25
- attr_accessor :launch_details, :database_details, :db_home_details
27
+ include DbaasLaunchDetails
26
28
 
27
- def initialize(config, state, oci, api, action = :create)
29
+ def initialize(config, state, oci, api, action)
28
30
  super
29
31
  @launch_details = OCI::Database::Models::LaunchDbSystemDetails.new
30
32
  @database_details = OCI::Database::Models::CreateDatabaseDetails.new
31
33
  @db_home_details = OCI::Database::Models::CreateDbHomeDetails.new
32
34
  end
33
35
 
36
+ #
37
+ # The details model that describes the db system
38
+ #
39
+ # @return [OCI::Database::Models::LaunchDbSystemDetails]
40
+ #
41
+ attr_accessor :launch_details
42
+
43
+ #
44
+ # The details model that describes the database
45
+ #
46
+ # @return [OCI::Database::Models::CreateDatabaseDetails]
47
+ #
48
+ attr_accessor :database_details
49
+
50
+ #
51
+ # The details model that describes the database home
52
+ #
53
+ # @return [OCI::Database::Models::CreateDbHomeDetails]
54
+ #
55
+ attr_accessor :db_home_details
56
+
34
57
  def launch
35
58
  response = api.dbaas.launch_db_system(launch_instance_details)
36
59
  instance_id = response.data.id
@@ -48,106 +71,6 @@ module Kitchen
48
71
 
49
72
  private
50
73
 
51
- def launch_instance_details # rubocop:disable Metrics/MethodLength
52
- # TODO: add support for the #domain property
53
- compartment_id
54
- availability_domain
55
- defined_tags
56
- shape
57
- freeform_tags
58
- names
59
- cpu_core_count
60
- create_db_home_details
61
- subnet_id
62
- nsg_ids
63
- pubkey
64
- initial_data_storage_size_in_gb
65
- node_count
66
- license_model
67
- launch_details
68
- end
69
-
70
- def create_db_home_details
71
- db_version
72
- db_home_display_name
73
- database_edition
74
- db_home_details.database = create_database_details
75
- launch_details.db_home = db_home_details
76
- end
77
-
78
- def create_database_details
79
- cluster_name
80
- db_name
81
- pdb_name
82
- admin_password
83
- character_set
84
- db_workload
85
- ncharacter_set
86
- db_backup_config
87
- end
88
-
89
- def subnet_id
90
- launch_details.subnet_id = config[:subnet_id]
91
- end
92
-
93
- def nsg_ids
94
- launch_details.nsg_ids = config[:nsg_ids]
95
- end
96
-
97
- def names
98
- hostname
99
- display_name
100
- launch_details
101
- end
102
-
103
- def hostname
104
- # The hostname must begin with an alphabetic character, and can contain alphanumeric characters and hyphens (-).
105
- # The maximum length of the hostname is 16 characters
106
- long_name = [hostname_prefix, long_hostname_suffix].compact.join("-")
107
- trimmed_name = [hostname_prefix[0, 12], random_string(3)].compact.join("-")
108
- launch_details.hostname = [long_name, trimmed_name].min { |l, t| l.size <=> t.size }
109
- end
110
-
111
- def display_name
112
- # The user-friendly name for the DB system. The name does not have to be unique.
113
- launch_details.display_name = [config[:hostname_prefix], random_string(4), random_number(2)].compact.join("-")
114
- end
115
-
116
- def hostname_prefix
117
- config[:hostname_prefix]
118
- end
119
-
120
- def node_count
121
- launch_details.node_count = 1
122
- end
123
-
124
- def long_hostname_suffix
125
- [random_string(25 - hostname_prefix.length), random_string(3)].compact.join("-")
126
- end
127
-
128
- def pubkey
129
- result = []
130
- result << File.readlines(config[:ssh_keypath]).first.chomp
131
- launch_details.ssh_public_keys = result
132
- end
133
-
134
- def cpu_core_count
135
- launch_details.cpu_core_count = config[:dbaas][:cpu_core_count] ||= 2
136
- end
137
-
138
- def license_model
139
- license = config[:dbaas][:license_model] ||= OCI::Database::Models::DbSystem::LICENSE_MODEL_BRING_YOUR_OWN_LICENSE
140
- launch_details.license_model = license
141
- end
142
-
143
- def initial_data_storage_size_in_gb
144
- launch_details.initial_data_storage_size_in_gb = config[:dbaas][:initial_data_storage_size_in_gb] ||= 256
145
- end
146
-
147
- def dbaas_node(instance_id)
148
- api.dbaas.list_db_nodes(oci.compartment, db_system_id: instance_id).data
149
- end
150
-
151
74
  def instance_ip(instance_id)
152
75
  vnic = dbaas_node(instance_id).select(&:vnic_id).first.vnic_id
153
76
  if public_ip_allowed?
@@ -157,62 +80,16 @@ module Kitchen
157
80
  end
158
81
  end
159
82
 
160
- def db_version
161
- raise "db_version cannot be nil!" if config[:dbaas][:db_version].nil?
162
-
163
- db_home_details.db_version = config[:dbaas][:db_version]
164
- end
165
-
166
- def db_home_display_name
167
- db_home_details.display_name = ["dbhome", random_number(10)].compact.join
168
- end
169
-
170
- def character_set
171
- database_details.character_set = config[:dbaas][:character_set] ||= "AL32UTF8"
172
- end
173
-
174
- def ncharacter_set
175
- database_details.ncharacter_set = config[:dbaas][:ncharacter_set] ||= "AL16UTF16"
176
- end
177
-
178
- def db_workload
179
- workload = config[:dbaas][:db_workload] ||= OCI::Database::Models::CreateDatabaseDetails::DB_WORKLOAD_OLTP
180
- database_details.db_workload = workload
181
- end
182
-
183
- def admin_password
184
- database_details.admin_password = config[:dbaas][:admin_password] ||= random_password(%w{# _ -})
185
- end
186
-
187
- def db_name
188
- database_details.db_name = config[:dbaas][:db_name] ||= "dbaas1"
189
- end
190
-
191
- def pdb_name
192
- database_details.pdb_name = config[:dbaas][:pdb_name] ||= "pdb001"
193
- end
194
-
195
- def db_backup_config
196
- database_details.db_backup_config = OCI::Database::Models::DbBackupConfig.new.tap do |l|
197
- l.auto_backup_enabled = false
198
- end
199
- database_details
83
+ def dbaas_node(instance_id)
84
+ api.dbaas.list_db_nodes(oci.compartment, db_system_id: instance_id).data
200
85
  end
201
86
 
202
- def database_edition
203
- db_edition = config[:dbaas][:database_edition] ||= OCI::Database::Models::DbSystem::DATABASE_EDITION_ENTERPRISE_EDITION
204
- launch_details.database_edition = db_edition
87
+ def hostname_prefix
88
+ config[:hostname_prefix]
205
89
  end
206
90
 
207
- def cluster_name
208
- prefix = config[:hostname_prefix].split("-")[0]
209
- # 11 character limit for cluster_name in DBaaS
210
- cn = if prefix.length >= 11
211
- prefix[0, 11]
212
- else
213
- [prefix, random_string(10 - prefix.length)].compact.join("-")
214
- end
215
- launch_details.cluster_name = cn
91
+ def long_hostname_suffix
92
+ [random_string(25 - hostname_prefix.length), random_string(3)].compact.join("-")
216
93
  end
217
94
  end
218
95
  end
@@ -23,13 +23,18 @@ module Kitchen
23
23
  module Models
24
24
  # iscsi volume attachment model
25
25
  class Iscsi < Blockstorage
26
- attr_reader :attachment_type
27
-
28
26
  def initialize(config, state, oci, api)
29
27
  super
30
28
  @attachment_type = "iscsi"
31
29
  end
32
30
 
31
+ #
32
+ # The type of attachment being created
33
+ #
34
+ # @return [String]
35
+ #
36
+ attr_reader :attachment_type
37
+
33
38
  def attachment_details(volume_details, server_id)
34
39
  OCI::Core::Models::AttachIScsiVolumeDetails.new(
35
40
  display_name: "#{attachment_type}-#{volume_details.display_name}",
@@ -23,13 +23,18 @@ module Kitchen
23
23
  module Models
24
24
  # paravirtual attachment model
25
25
  class Paravirtual < Blockstorage
26
- attr_reader :attachment_type
27
-
28
26
  def initialize(config, state, oci, api)
29
27
  super
30
28
  @attachment_type = "paravirtual"
31
29
  end
32
30
 
31
+ #
32
+ # The type of attachment being created
33
+ #
34
+ # @return [String]
35
+ #
36
+ attr_reader :attachment_type
37
+
33
38
  def attachment_details(volume_details, server_id)
34
39
  OCI::Core::Models::AttachParavirtualizedVolumeDetails.new(
35
40
  display_name: "#{attachment_type}-#{volume_details.display_name}",
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Author:: Stephen Pearson (<stephen.pearson@oracle.com>)
4
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
5
5
  #
6
- # Copyright (C) 2019, Stephen Pearson
6
+ # Copyright (C) 2024, Stephen Pearson
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ module Kitchen
37
37
  require_relative "oci/models"
38
38
 
39
39
  plugin_version Kitchen::Driver::OCI_VERSION
40
+ kitchen_driver_api_version 1
40
41
 
41
42
  # required config items
42
43
  required_config :availability_domain
@@ -20,6 +20,6 @@
20
20
  module Kitchen
21
21
  module Driver
22
22
  # Version string for Oracle OCI Kitchen driver
23
- OCI_VERSION = "1.16.2"
23
+ OCI_VERSION = "1.17.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-oci
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.2
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Pearson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-28 00:00:00.000000000 Z
11
+ date: 2024-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oci
@@ -121,6 +121,11 @@ files:
121
121
  - lib/kitchen/driver/oci/blockstorage.rb
122
122
  - lib/kitchen/driver/oci/config.rb
123
123
  - lib/kitchen/driver/oci/instance.rb
124
+ - lib/kitchen/driver/oci/instance/common.rb
125
+ - lib/kitchen/driver/oci/instance/compute.rb
126
+ - lib/kitchen/driver/oci/instance/database.rb
127
+ - lib/kitchen/driver/oci/instance/db_home.rb
128
+ - lib/kitchen/driver/oci/instance/dbaas.rb
124
129
  - lib/kitchen/driver/oci/models.rb
125
130
  - lib/kitchen/driver/oci/models/compute.rb
126
131
  - lib/kitchen/driver/oci/models/dbaas.rb