Module: Kitchen::Driver::Oci::Mixin::Volumes

Included in:
Kitchen::Driver::Oci
Defined in:
lib/kitchen/driver/oci/mixin/volumes.rb

Overview

Mixins for working with volumes and attachments.

Author:

  • Justin Steele <justin.steele@oracle.com>

Instance Method Summary collapse

Instance Method Details

#create_and_attach_volumes(config, state, oci, api) ⇒ Object

Create and attach volumes.

Parameters:



34
35
36
37
38
39
# File 'lib/kitchen/driver/oci/mixin/volumes.rb', line 34

def create_and_attach_volumes(config, state, oci, api)
  return if config[:volumes].empty?

  volume_state = process_volumes(config, state, oci, api)
  state.merge!(volume_state)
end

#create_volume(vol, volume) ⇒ Object

Creates or clones the volume.

Parameters:

  • vol (OCI::Core::Models::Volume)

    the volume that has been created.

  • volume (Hash)

    the state of the current volume being cloned.



77
78
79
80
81
82
83
# File 'lib/kitchen/driver/oci/mixin/volumes.rb', line 77

def create_volume(vol, volume)
  if volume.key?(:volume_id)
    vol.create_clone_volume(volume)
  else
    vol.create_volume(volume)
  end
end

#detatch_and_delete_volumes(state, oci, api) ⇒ Object

Detatch and delete volumes.

Parameters:



46
47
48
49
50
51
52
# File 'lib/kitchen/driver/oci/mixin/volumes.rb', line 46

def detatch_and_delete_volumes(state, oci, api)
  return unless state[:volumes]

  bls = Blockstorage.new(config: config, state: state, oci: oci, api: api, action: :destroy, logger: instance.logger)
  state[:volume_attachments].each { |att| bls.detatch_volume(att) }
  state[:volumes].each { |vol| bls.delete_volume(vol) }
end

#process_volumes(config, state, oci, api) ⇒ Hash

Process volumes specified in the kitchen config.

Parameters:

Returns:

  • (Hash)

    the finalized state after the volume(s) have been created and attached.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/kitchen/driver/oci/mixin/volumes.rb', line 61

def process_volumes(config, state, oci, api)
  volume_state = { volumes: [], volume_attachments: [] }
  config[:volumes].each do |volume|
    vol = volume_class(volume[:type], config, state, oci, api)
    volume_details, vol_state = create_volume(vol, volume)
    attach_state = vol.attach_volume(volume_details, state[:server_id], volume)
    volume_state[:volumes] << vol_state
    volume_state[:volume_attachments] << attach_state
  end
  volume_state
end