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

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

Overview

Base class for blockstorage models.

Author:

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

Direct Known Subclasses

Models::Iscsi, Models::Paravirtual

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Kitchen::Driver::Oci

#create, #destroy, #finalize_config!, validation_error

Methods included from Mixin::Volumes

#create_and_attach_volumes, #detatch_and_delete_volumes, #process_volumes

Methods included from Mixin::Models

#instance_class, #volume_class

Methods included from Mixin::Actions

#are_legacy_imds_endpoints_disbled?, #auth, #execute_post_create_file, #execute_post_create_script, #execute_post_create_string, #instance_options, #instance_options?, #launch, #reboot, #terminate

Constructor Details

#initialize(opts = {}) ⇒ Blockstorage

Returns a new instance of Blockstorage.



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

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

Instance Attribute Details

#apiKitchen::Driver::Oci::Api

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



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

def api
  @api
end

#configKitchen::LazyHash

The config provided by the driver.

Returns:

  • (Kitchen::LazyHash)


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

def config
  @config
end

#loggerKitchen::Logger

The instance of Kitchen::Logger in use by the active Kitchen::Instance.

Returns:

  • (Kitchen::Logger)


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

def logger
  @logger
end

#ociKitchen::Driver::Oci::Config

The config object that contains properties of the authentication to OCI.



56
57
58
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 56

def oci
  @oci
end

#stateHash

The definition of the state of the instance from the statefile.

Returns:

  • (Hash)


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

def state
  @state
end

#volume_attachment_stateHash

The definition of the state of a volume attachment.

Returns:

  • (Hash)


76
77
78
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 76

def volume_attachment_state
  @volume_attachment_state
end

#volume_stateHash

The definition of the state of a volume.

Returns:

  • (Hash)


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

def volume_state
  @volume_state
end

Instance Method Details

#attach_volume(volume_details, server_id, volume_config) ⇒ Hash

Attaches the volume to the instance.

Parameters:

  • volume_details (OCI::Core::Models::Volume)
  • server_id (String)

    the ocid of the compute instance we are attaching the volume to.

Returns:

  • (Hash)

    the updated state hash.



108
109
110
111
112
113
114
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 108

def attach_volume(volume_details, server_id, volume_config)
  logger.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)
  logger.info("Finished attaching <#{volume_details.display_name}>.")
  final_state(response)
end

#create_clone_volume(volume) ⇒ Array(OCI::Core::Models::Volume, Hash)

Clones the specified volume.

Parameters:

  • volume (Hash)

    the state of the current volume being cloned.

Returns:

  • (Array(OCI::Core::Models::Volume, Hash))

    returns the actual volume response from OCI for the cloned volume and the state hash.



94
95
96
97
98
99
100
101
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 94

def create_clone_volume(volume)
  clone_volume_name = clone_volume_display_name(volume[:volume_id])
  logger.info("Creating <#{clone_volume_name}>...")
  result = api.blockstorage.create_volume(volume_clone_details(volume, clone_volume_name))
  response = volume_response(result.data.id)
  logger.info("Finished creating <#{clone_volume_name}>.")
  [response, final_state(response)]
end

#create_volume(volume) ⇒ Array(OCI::Core::Models::Volume, Hash)

Create the volume as specified in the kitchen config.

Parameters:

  • volume (Hash)

    the state of the current volume being created.

Returns:

  • (Array(OCI::Core::Models::Volume, Hash))

    returns the actual volume response from OCI for the created volume and the state hash.



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

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

#delete_volume(volume) ⇒ Object

Deletes the specified volume.

Parameters:

  • volume (Hash)

    the state of the current volume being deleted from the state file.



119
120
121
122
123
124
125
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 119

def delete_volume(volume)
  logger.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)
  logger.info("Finished deleting <#{volume[:display_name]}>.")
end

#detatch_volume(volume_attachment) ⇒ Object

Detaches the specified volume.

Parameters:

  • volume_attachment (Hash)

    the state of the current volume being deleted from the state file.



130
131
132
133
134
135
136
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 130

def detatch_volume(volume_attachment)
  logger.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)
  logger.info("Finished detaching <#{attachment_name(volume_attachment)}>.")
end

#final_state(response) ⇒ Hash

Adds the volume and attachment info into the state.

Parameters:

  • response (OCI::Core::Models::Volume, OCI::Core::Models::VolumeAttachment)

    The response from volume creation or attachment.

Returns:

  • (Hash)


142
143
144
145
146
147
148
149
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 142

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