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.



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

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

#apiKitchen::Driver::Oci::Api

The API object that contains each of the authenticated clients for interfacing with OCI



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

def api
  @api
end

#configKitchen::LazyHash

The config provided by the driver

Returns:

  • (Kitchen::LazyHash)


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

def config
  @config
end

#ociKitchen::Driver::Oci::Config

The config object that contains properties of the authentication to OCI



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

def oci
  @oci
end

#stateHash

The definition of the state of the instance from the statefile

Returns:

  • (Hash)


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

def state
  @state
end

#volume_attachment_stateHash

The definition of the state of a volume attachment

Returns:

  • (Hash)


78
79
80
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 78

def volume_attachment_state
  @volume_attachment_state
end

#volume_stateHash

The definition of the state of a volume

Returns:

  • (Hash)


72
73
74
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 72

def volume_state
  @volume_state
end

Instance Method Details

#attach_volume(volume_details, server_id, volume_config) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 97

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, volume_config))
  response = attachment_response(attach_volume.data.id)
  info("Finished attaching <#{volume_details.display_name}>.")
  final_state(response)
end

#create_clone_volume(volume) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 88

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

#create_volume(volume) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 80

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



105
106
107
108
109
110
111
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 105

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_volume(volume_attachment) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 113

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



121
122
123
124
125
126
127
128
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 121

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