kitchen-oci 1.20.2 → 1.22.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: f48ec8dd3ad22c465333f13ada4460021473e7724ef39cf2069e87136c66ee7b
4
- data.tar.gz: 39a699346ae44ca5cef24788bc3e8313cc3665a7d72cf12f77e44e61b9066be8
3
+ metadata.gz: f91045fdb0ff064f83385b240480320087e7b37d65998bfac58992f029979626
4
+ data.tar.gz: 05c3559342b40ddb201123ef8be3769b12adac2dbbcce79c957f0caa187a5d22
5
5
  SHA512:
6
- metadata.gz: 15033fffadf3a1b0d9f53b51cb06085a55af0a4e395362b63e93a7be12557ac52f9fedf47faf259ccaaaccb829baccb3c5aa1264f25f13086a5a9f42a550329c
7
- data.tar.gz: 39ecbf8d16c0cda53559b2a103a59e0611d92805807bb62a755291e1e7b72d8d486474e198ee9f202850cce3e7357abf67a4e2e79e3d2be0e60ae243b0fe9f26
6
+ metadata.gz: 344ddb1169b34e6e40dad70d5d60fa5d848af6d20d7cf2175f011a97f2248b9e530664a09103b16bcc4249088fb8464fd4e280e4f1368f91de15aeb66a4e8ae1
7
+ data.tar.gz: 63d6b2ec541e4253e8ac5b46b293196e3ef981898147129b5f8439e4449046af947861e2d4526f6b796a50c4b10a6398658c8babbe1db95b03d9169ed43dc7c4
@@ -20,7 +20,7 @@ module Kitchen
20
20
  module Driver
21
21
  class Oci
22
22
  # generic class for blockstorage
23
- class Blockstorage < Oci
23
+ class Blockstorage < Oci # rubocop:disable Metrics/ClassLength
24
24
  require_relative "api"
25
25
  require_relative "config"
26
26
  require_relative "models/iscsi"
@@ -85,9 +85,18 @@ module Kitchen
85
85
  [response, final_state(response)]
86
86
  end
87
87
 
88
- def attach_volume(volume_details, server_id)
88
+ def create_clone_volume(volume)
89
+ clone_volume_name = clone_volume_display_name(volume[:volume_id])
90
+ info("Creating <#{clone_volume_name}>...")
91
+ result = api.blockstorage.create_volume(volume_clone_details(volume, clone_volume_name))
92
+ response = volume_response(result.data.id)
93
+ info("Finished creating <#{clone_volume_name}>.")
94
+ [response, final_state(response)]
95
+ end
96
+
97
+ def attach_volume(volume_details, server_id, volume_config)
89
98
  info("Attaching <#{volume_details.display_name}>...")
90
- attach_volume = api.compute.attach_volume(attachment_details(volume_details, server_id))
99
+ attach_volume = api.compute.attach_volume(attachment_details(volume_details, server_id, volume_config))
91
100
  response = attachment_response(attach_volume.data.id)
92
101
  info("Finished attaching <#{volume_details.display_name}>.")
93
102
  final_state(response)
@@ -141,15 +150,36 @@ module Kitchen
141
150
  )
142
151
  end
143
152
 
153
+ def volume_clone_details(volume, clone_volume_name)
154
+ OCI::Core::Models::CreateVolumeDetails.new(
155
+ compartment_id: oci.compartment,
156
+ availability_domain: config[:availability_domain],
157
+ display_name: clone_volume_name,
158
+ defined_tags: config[:defined_tags],
159
+ size_in_gbs: volume[:size_in_gbs],
160
+ vpus_per_gb: volume[:vpus_per_gb],
161
+ source_details: OCI::Core::Models::VolumeSourceFromVolumeDetails.new(id: volume[:volume_id])
162
+ )
163
+ end
164
+
144
165
  def attachment_name(attachment)
145
166
  attachment[:display_name].gsub(/(?:paravirtual|iscsi)-/, "")
146
167
  end
147
168
 
169
+ def server_os(server_id)
170
+ image_id = api.compute.get_instance(server_id).data.image_id
171
+ api.compute.get_image(image_id).data.operating_system
172
+ end
173
+
148
174
  def final_volume_state(response)
149
175
  volume_state.store(:id, response.id)
150
176
  volume_state.store(:display_name, response.display_name)
151
177
  volume_state
152
178
  end
179
+
180
+ def clone_volume_display_name(volume_id)
181
+ "#{api.blockstorage.get_volume(volume_id).data.to_hash[:displayName]} (Clone)"
182
+ end
153
183
  end
154
184
  end
155
185
  end
@@ -23,7 +23,7 @@ module Kitchen
23
23
  # setter methods that populate the details of OCI::Core::Models::LaunchInstanceDetails
24
24
  module ComputeLaunchDetails
25
25
  def hostname_display_name
26
- display_name = hostname
26
+ display_name = config[:display_name] || hostname
27
27
  launch_details.display_name = display_name
28
28
  launch_details.create_vnic_details = create_vnic_details(display_name)
29
29
  end
@@ -35,11 +35,13 @@ module Kitchen
35
35
  #
36
36
  attr_reader :attachment_type
37
37
 
38
- def attachment_details(volume_details, server_id)
38
+ def attachment_details(volume_details, server_id, volume_config)
39
+ device = volume_config[:device] unless server_os(server_id).downcase =~ /windows/
39
40
  OCI::Core::Models::AttachIScsiVolumeDetails.new(
40
41
  display_name: "#{attachment_type}-#{volume_details.display_name}",
41
42
  volume_id: volume_details.id,
42
- instance_id: server_id
43
+ instance_id: server_id,
44
+ device: device
43
45
  )
44
46
  end
45
47
 
@@ -35,11 +35,13 @@ module Kitchen
35
35
  #
36
36
  attr_reader :attachment_type
37
37
 
38
- def attachment_details(volume_details, server_id)
38
+ def attachment_details(volume_details, server_id, volume_config)
39
+ device = volume_config[:device] unless server_os(server_id).downcase =~ /windows/
39
40
  OCI::Core::Models::AttachParavirtualizedVolumeDetails.new(
40
41
  display_name: "#{attachment_type}-#{volume_details.display_name}",
41
42
  volume_id: volume_details.id,
42
- instance_id: server_id
43
+ instance_id: server_id,
44
+ device: device
43
45
  )
44
46
  end
45
47
 
@@ -60,6 +60,7 @@ module Kitchen
60
60
  default_config :instance_name do |inst|
61
61
  inst.instance.name
62
62
  end
63
+ default_config :display_name, nil
63
64
  default_keypath = File.expand_path(File.join(%w{~ .ssh id_rsa.pub}))
64
65
  default_config :ssh_keypath, default_keypath
65
66
  default_config :post_create_script, nil
@@ -152,15 +153,28 @@ module Kitchen
152
153
  def create_and_attach_volumes(config, state, oci, api)
153
154
  return if config[:volumes].empty?
154
155
 
156
+ volume_state = process_volumes(config, state, oci, api)
157
+ state.merge!(volume_state)
158
+ end
159
+
160
+ def process_volumes(config, state, oci, api)
155
161
  volume_state = { volumes: [], volume_attachments: [] }
156
162
  config[:volumes].each do |volume|
157
163
  vol = volume_class(volume[:type], config, state, oci, api)
158
- volume_details, vol_state = vol.create_volume(volume)
159
- attach_state = vol.attach_volume(volume_details, state[:server_id])
164
+ volume_details, vol_state = create_volume(vol, volume)
165
+ attach_state = vol.attach_volume(volume_details, state[:server_id], volume)
160
166
  volume_state[:volumes] << vol_state
161
167
  volume_state[:volume_attachments] << attach_state
162
168
  end
163
- state.merge!(volume_state)
169
+ volume_state
170
+ end
171
+
172
+ def create_volume(vol, volume)
173
+ if volume.key?(:volume_id)
174
+ vol.create_clone_volume(volume)
175
+ else
176
+ vol.create_volume(volume)
177
+ end
164
178
  end
165
179
 
166
180
  def process_post_script(state)
@@ -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.20.2"
23
+ OCI_VERSION = "1.22.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-oci
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.20.2
4
+ version: 1.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Pearson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-05-21 00:00:00.000000000 Z
12
+ date: 2024-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oci
@@ -135,7 +135,7 @@ files:
135
135
  - lib/kitchen/driver/oci/models/paravirtual.rb
136
136
  - lib/kitchen/driver/oci_version.rb
137
137
  - tpl/setup_winrm.ps1.erb
138
- homepage: ''
138
+ homepage: https://github.com/stephenpearson/kitchen-oci
139
139
  licenses:
140
140
  - Apache-2.0
141
141
  metadata: {}