kitchen-oci 1.16.2 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf877ab3445b41c9cef61838cee55823f6377fec01a5941b5143707138a65983
4
- data.tar.gz: 3ed5f384f3c6708b0c72fc4af7a574a7197074c1dbd703ff62116bf229fa0886
3
+ metadata.gz: 04441716ec20ae5cf111a087f07990af96826770804f92a67edaa7335622391a
4
+ data.tar.gz: 378640fe182082b49904fcef4671c7954bb794a51090c7e29a74ad25128addd0
5
5
  SHA512:
6
- metadata.gz: 7a2564cb3b997cf6ea1173af0743359e6c6009728e02c260ba3f168479f09c60454bcf1047d4b7d118f7390e1606647ab4b87964c8cda4b285953d8bb1a2acd2
7
- data.tar.gz: 11a6cc7ba6370468dca3615c7224a9878d0b69cc60882107e5896fd5ca29725693040673f544573d8bdd06ba6b8ed4ac996eb62ed5b81ccd35e2f47bbb965042
6
+ metadata.gz: 8cddfba0d04e8a8634656694b1158e9ea6e87eed48bb78b1f949d32aa2b2d0e58de38326c802da9ece1de1d5da209eab75c6b7d6e1e6f2c0e7224fa1dc81033a
7
+ data.tar.gz: 7ed171e81ff8ab9d2559df7b9a4bab80d5d7fee5440ac0816971def8b48e6d4e65eed1b098b2f95cd1d5658e702c8523e053d05998a2929cb41636b846f4d674
@@ -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,75 @@
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 agent_config
53
+ launch_details.agent_config = OCI::Core::Models::LaunchInstanceAgentConfigDetails.new(
54
+ are_all_plugins_disabled: config[:all_plugins_disabled],
55
+ is_management_disabled: config[:management_disabled],
56
+ is_monitoring_disabled: config[:monitoring_disabled]
57
+ )
58
+ end
59
+
60
+ def instance_source_details
61
+ launch_details.source_details = OCI::Core::Models::InstanceSourceViaImageDetails.new(
62
+ sourceType: "image",
63
+ imageId: image_id,
64
+ bootVolumeSizeInGBs: config[:boot_volume_size_in_gbs]
65
+ )
66
+ end
67
+
68
+ def instance_metadata
69
+ launch_details.metadata = metadata
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ 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]
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,63 @@ 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
56
+ def image_id
57
+ return config[:image_id] if config[:image_id]
58
+
59
+ raise "must specify either image_id or image_name" unless config[:image_name]
60
+
61
+ image_id_by_name
59
62
  end
60
63
 
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)
64
+ def image_id_by_name
65
+ image_name = config[:image_name].gsub(" ", "-")
66
+ image_list = images.select { |i| i.display_name.match?(/#{image_name}/) }
67
+ raise "unable to find image_id" if image_list.empty?
68
+
69
+ image_list = filter_image_list(image_list, image_name) if image_list.count > 1
70
+ raise "unable to find image_id" if image_list.empty?
71
+
72
+ latest_image_id(image_list)
65
73
  end
66
74
 
67
- def hostname
68
- [config[:hostname_prefix], random_string(6)].compact.join("-")
75
+ def filter_image_list(image_list, image_name)
76
+ image_list.select { |i| i.display_name.match?(/#{image_name}-[0-9]{4}\.[0-9]{2}\.[0-9]{2}/) }
69
77
  end
70
78
 
71
- def preemptible_instance_config
72
- return unless config[:preemptible_instance]
79
+ def latest_image_id(image_list)
80
+ image_list.sort_by! { |o| ((DateTime.parse(Time.now.utc.to_s) - o.time_created) * 24 * 60 * 60).to_i }.first.id
81
+ end
73
82
 
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
- )
83
+ def images(image_list = [], page = nil)
84
+ current_images = api.compute.list_images(oci.compartment, page: page)
85
+ next_page = current_images.next_page
86
+ image_list << current_images.data
87
+ images(image_list, next_page) unless next_page.nil?
88
+ image_list.flatten
80
89
  end
81
90
 
82
- def shape_config
83
- return if config[:shape_config].empty?
91
+ def instance_ip(instance_id)
92
+ vnic = vnics(instance_id).select(&:is_primary).first
93
+ if public_ip_allowed?
94
+ config[:use_private_ip] ? vnic.private_ip : vnic.public_ip
95
+ else
96
+ vnic.private_ip
97
+ end
98
+ end
84
99
 
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
- )
100
+ def vnics(instance_id)
101
+ vnic_attachments(instance_id).map { |att| api.network.get_vnic(att.vnic_id).data }
90
102
  end
91
103
 
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
- )
104
+ def vnic_attachments(instance_id)
105
+ att = api.compute.list_vnic_attachments(oci.compartment, instance_id: instance_id).data
106
+ raise "Could not find any VNIC attachments" unless att.any?
107
+
108
+ att
109
+ end
110
+
111
+ def hostname
112
+ [config[:hostname_prefix], random_string(6)].compact.join("-")
98
113
  end
99
114
 
100
115
  def create_vnic_details(name)
@@ -111,10 +126,6 @@ module Kitchen
111
126
  File.readlines(config[:ssh_keypath]).first.chomp
112
127
  end
113
128
 
114
- def instance_metadata
115
- launch_details.metadata = metadata
116
- end
117
-
118
129
  def metadata
119
130
  md = {}
120
131
  inject_powershell
@@ -124,26 +135,6 @@ module Kitchen
124
135
  md
125
136
  end
126
137
 
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
138
  def process_windows_options
148
139
  return unless windows_state?
149
140
 
@@ -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
@@ -50,7 +51,8 @@ module Kitchen
50
51
  default_config :compartment_id, nil
51
52
  default_config :compartment_name, nil
52
53
  default_config :instance_type, "compute"
53
- default_config :image_id
54
+ default_config :image_id, nil
55
+ default_config :image_name, nil
54
56
  default_config :hostname_prefix do |hnp|
55
57
  hnp.instance.name
56
58
  end
@@ -66,6 +68,9 @@ module Kitchen
66
68
  default_config :use_token_auth, false
67
69
  default_config :shape_config, {}
68
70
  default_config :nsg_ids, []
71
+ default_config :all_plugins_disabled, false
72
+ default_config :management_disabled, false
73
+ default_config :monitoring_disabled, false
69
74
 
70
75
  # compute only configs
71
76
  default_config :setup_winrm, false
@@ -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.18.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,15 @@
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.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Pearson
8
+ - Justin Steele
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2024-03-28 00:00:00.000000000 Z
12
+ date: 2024-04-04 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: oci
@@ -111,6 +112,7 @@ dependencies:
111
112
  description: A Test Kitchen Driver for Oracle OCI
112
113
  email:
113
114
  - stephen.pearson@oracle.com
115
+ - justin.steele@oracle.com
114
116
  executables: []
115
117
  extensions: []
116
118
  extra_rdoc_files: []
@@ -121,6 +123,11 @@ files:
121
123
  - lib/kitchen/driver/oci/blockstorage.rb
122
124
  - lib/kitchen/driver/oci/config.rb
123
125
  - lib/kitchen/driver/oci/instance.rb
126
+ - lib/kitchen/driver/oci/instance/common.rb
127
+ - lib/kitchen/driver/oci/instance/compute.rb
128
+ - lib/kitchen/driver/oci/instance/database.rb
129
+ - lib/kitchen/driver/oci/instance/db_home.rb
130
+ - lib/kitchen/driver/oci/instance/dbaas.rb
124
131
  - lib/kitchen/driver/oci/models.rb
125
132
  - lib/kitchen/driver/oci/models/compute.rb
126
133
  - lib/kitchen/driver/oci/models/dbaas.rb