lib/kitchen/driver/oci/blockstorage.rb in kitchen-oci-1.21.0 vs lib/kitchen/driver/oci/blockstorage.rb in kitchen-oci-1.22.0
- old
+ new
@@ -18,11 +18,11 @@
module Kitchen
module Driver
class Oci
# generic class for blockstorage
- class Blockstorage < Oci
+ class Blockstorage < Oci # rubocop:disable Metrics/ClassLength
require_relative "api"
require_relative "config"
require_relative "models/iscsi"
require_relative "models/paravirtual"
@@ -83,13 +83,22 @@
response = volume_response(result.data.id)
info("Finished creating <#{volume[:name]}>.")
[response, final_state(response)]
end
- def attach_volume(volume_details, server_id)
+ def create_clone_volume(volume)
+ clone_volume_name = clone_volume_display_name(volume[:volume_id])
+ info("Creating <#{clone_volume_name}>...")
+ result = api.blockstorage.create_volume(volume_clone_details(volume, clone_volume_name))
+ response = volume_response(result.data.id)
+ info("Finished creating <#{clone_volume_name}>.")
+ [response, final_state(response)]
+ end
+
+ def attach_volume(volume_details, server_id, volume_config)
info("Attaching <#{volume_details.display_name}>...")
- attach_volume = api.compute.attach_volume(attachment_details(volume_details, server_id))
+ attach_volume = api.compute.attach_volume(attachment_details(volume_details, server_id, volume_config))
response = attachment_response(attach_volume.data.id)
info("Finished attaching <#{volume_details.display_name}>.")
final_state(response)
end
@@ -139,17 +148,38 @@
vpus_per_gb: volume[:vpus_per_gb] || 10,
defined_tags: config[:defined_tags]
)
end
+ def volume_clone_details(volume, clone_volume_name)
+ OCI::Core::Models::CreateVolumeDetails.new(
+ compartment_id: oci.compartment,
+ availability_domain: config[:availability_domain],
+ display_name: clone_volume_name,
+ defined_tags: config[:defined_tags],
+ size_in_gbs: volume[:size_in_gbs],
+ vpus_per_gb: volume[:vpus_per_gb],
+ source_details: OCI::Core::Models::VolumeSourceFromVolumeDetails.new(id: volume[:volume_id])
+ )
+ end
+
def attachment_name(attachment)
attachment[:display_name].gsub(/(?:paravirtual|iscsi)-/, "")
end
+ def server_os(server_id)
+ image_id = api.compute.get_instance(server_id).data.image_id
+ api.compute.get_image(image_id).data.operating_system
+ end
+
def final_volume_state(response)
volume_state.store(:id, response.id)
volume_state.store(:display_name, response.display_name)
volume_state
+ end
+
+ def clone_volume_display_name(volume_id)
+ "#{api.blockstorage.get_volume(volume_id).data.to_hash[:displayName]} (Clone)"
end
end
end
end
end