Class: Kitchen::Driver::Oci::Blockstorage

Inherits:
Kitchen::Driver::Oci show all
Defined in:
lib/kitchen/driver/oci/blockstorage.rb

Overview

generic class for blockstorage

Direct Known Subclasses

Models::Iscsi, Models::Paravirtual

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Kitchen::Driver::Oci

#create, #destroy, validation_error

Methods included from Models

#instance_class, #volume_class

Constructor Details

#initialize(config, state, oci, api, action = :create) ⇒ Blockstorage

Returns a new instance of Blockstorage.



31
32
33
34
35
36
37
38
39
40
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 31

def initialize(config, state, oci, api, action = :create)
  super()
  @config = config
  @state = state
  @oci = oci
  @api = api
  @volume_state = {}
  @volume_attachment_state = {}
  oci.compartment if action == :create
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



29
30
31
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 29

def api
  @api
end

#configObject

Returns the value of attribute config.



29
30
31
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 29

def config
  @config
end

#ociObject

Returns the value of attribute oci.



29
30
31
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 29

def oci
  @oci
end

#stateObject

Returns the value of attribute state.



29
30
31
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 29

def state
  @state
end

#volume_attachment_stateObject

Returns the value of attribute volume_attachment_state.



29
30
31
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 29

def volume_attachment_state
  @volume_attachment_state
end

#volume_stateObject

Returns the value of attribute volume_state.



29
30
31
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 29

def volume_state
  @volume_state
end

Instance Method Details

#attach_volume(volume_details, server_id) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 50

def attach_volume(volume_details, server_id)
  info("Attaching <#{volume_details.display_name}>...")
  attach_volume = api.compute.attach_volume(attachment_details(volume_details, server_id))
  response = attachment_response(attach_volume.data.id)
  info("Finished attaching <#{volume_details.display_name}>.")
  final_state(response)
end

#create_volume(volume) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 42

def create_volume(volume)
  info("Creating <#{volume[:name]}>...")
  result = api.blockstorage.create_volume(volume_details(volume))
  response = volume_response(result.data.id)
  info("Finished creating <#{volume[:name]}>.")
  [response, final_state(response)]
end

#delete_volume(volume) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 58

def delete_volume(volume)
  info("Deleting <#{volume[:display_name]}>...")
  api.blockstorage.delete_volume(volume[:id])
  api.blockstorage.get_volume(volume[:id])
    .wait_until(:lifecycle_state, OCI::Core::Models::Volume::LIFECYCLE_STATE_TERMINATED)
  info("Finished deleting <#{volume[:display_name]}>.")
end

#detatch_and_deleteObject



74
75
76
77
78
79
80
81
82
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 74

def detatch_and_delete
  state[:volume_attachments].each do |att|
    detatch_volume(att)
  end

  state[:volumes].each do |vol|
    delete_volume(vol)
  end
end

#detatch_volume(volume_attachment) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 66

def detatch_volume(volume_attachment)
  info("Detaching <#{attachment_name(volume_attachment)}>...")
  api.compute.detach_volume(volume_attachment[:id])
  api.compute.get_volume_attachment(volume_attachment[:id])
    .wait_until(:lifecycle_state, OCI::Core::Models::VolumeAttachment::LIFECYCLE_STATE_DETACHED)
  info("Finished detaching <#{attachment_name(volume_attachment)}>.")
end

#final_state(response) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 84

def final_state(response)
  case response
  when OCI::Core::Models::Volume
    final_volume_state(response)
  when OCI::Core::Models::VolumeAttachment
    final_volume_attachment_state(response)
  end
end