Class: Kitchen::Driver::Oci::Blockstorage
- Inherits:
-
Kitchen::Driver::Oci
- Object
- Base
- Kitchen::Driver::Oci
- Kitchen::Driver::Oci::Blockstorage
- Defined in:
- lib/kitchen/driver/oci/blockstorage.rb
Overview
Base class for blockstorage models.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api ⇒ Kitchen::Driver::Oci::Api
The API object that contains each of the authenticated clients for interfacing with OCI.
-
#config ⇒ Kitchen::LazyHash
The config provided by the driver.
-
#logger ⇒ Kitchen::Logger
The instance of Kitchen::Logger in use by the active Kitchen::Instance.
-
#oci ⇒ Kitchen::Driver::Oci::Config
The config object that contains properties of the authentication to OCI.
-
#state ⇒ Hash
The definition of the state of the instance from the statefile.
-
#volume_attachment_state ⇒ Hash
The definition of the state of a volume attachment.
-
#volume_state ⇒ Hash
The definition of the state of a volume.
Instance Method Summary collapse
-
#attach_volume(volume_details, server_id, volume_config) ⇒ Hash
Attaches the volume to the instance.
-
#create_clone_volume(volume) ⇒ Array(OCI::Core::Models::Volume, Hash)
Clones the specified volume.
-
#create_volume(volume) ⇒ Array(OCI::Core::Models::Volume, Hash)
Create the volume as specified in the kitchen config.
-
#delete_volume(volume) ⇒ Object
Deletes the specified volume.
-
#detatch_volume(volume_attachment) ⇒ Object
Detaches the specified volume.
-
#final_state(response) ⇒ Hash
Adds the volume and attachment info into the state.
-
#initialize(opts = {}) ⇒ Blockstorage
constructor
A new instance of Blockstorage.
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
#api ⇒ Kitchen::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 |
#config ⇒ Kitchen::LazyHash
The config provided by the driver.
46 47 48 |
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 46 def config @config end |
#logger ⇒ Kitchen::Logger
The instance of Kitchen::Logger in use by the active Kitchen::Instance.
66 67 68 |
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 66 def logger @logger end |
#oci ⇒ Kitchen::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 |
#state ⇒ Hash
The definition of the state of the instance from the statefile.
51 52 53 |
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 51 def state @state end |
#volume_attachment_state ⇒ Hash
The definition of the state of a volume attachment.
76 77 78 |
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 76 def @volume_attachment_state end |
#volume_state ⇒ Hash
The definition of the state of a volume.
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.
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((volume_details, server_id, volume_config)) 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.
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.
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.
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.
130 131 132 133 134 135 136 |
# File 'lib/kitchen/driver/oci/blockstorage.rb', line 130 def detatch_volume() logger.info("Detaching <#{()}>...") api.compute.detach_volume([:id]) api.compute.([:id]) .wait_until(:lifecycle_state, OCI::Core::Models::VolumeAttachment::LIFECYCLE_STATE_DETACHED) logger.info("Finished detaching <#{()}>.") end |
#final_state(response) ⇒ Hash
Adds the volume and attachment info into the state.
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 (response) end end |