Module: BackendApi::Storage

Defined in:
app/models/backend_api/storage.rb

Instance Method Summary collapse

Instance Method Details

#storage_create(storage) ⇒ String

Instantiates a new storage instance from ::Occi::Infrastructure::Storage. ID given in the occi.core.id attribute is optional and can be changed inside this method. Final occi.core.id must be returned as a String. If the requested instance cannot be created, an error describing the problem must be raised, @see Backends::Errors.

Examples:

storage = ::Occi::Infrastructure::Storage.new
storage_id = storage_create(storage)
    #=> "65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf"

65
66
67
68
69
# File 'app/models/backend_api/storage.rb', line 65

def storage_create(storage)
  fail Errors::ArgumentError, '\'storage\' is a mandatory argument' if storage.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires a storage instance!' unless storage.kind_of? ::Occi::Infrastructure::Storage
  backend_instances['storage'].create(storage)
end

#storage_delete(storage_id) ⇒ true, false

Deletes a specific storage instance, instance to be deleted is specified by an ID, this ID must match the occi.core.id attribute of the deleted instance. If the requested instance cannot be deleted, an error describing the problem must be raised, @see Backends::Errors.

Examples:

storage_delete("65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf") #=> true

99
100
101
102
# File 'app/models/backend_api/storage.rb', line 99

def storage_delete(storage_id)
  fail Errors::ArgumentError, '\'storage_id\' is a mandatory argument' if storage_id.blank?
  backend_instances['storage'].delete(storage_id)
end

#storage_delete_all(mixins = nil) ⇒ true, false

Deletes all storage instances, instances to be deleted must be filtered by the specified filter, filter (if set) must contain an ::Occi::Core::Mixins instance. If the requested instances cannot be deleted, an error describing the problem must be raised, @see Backends::Errors.

Examples:

storage_delete_all #=> true

mixins = ::Occi::Core::Mixins.new << ::Occi::Core::Mixin.new
storage_delete_all(mixins)  #=> true

84
85
86
# File 'app/models/backend_api/storage.rb', line 84

def storage_delete_all(mixins = nil)
  backend_instances['storage'].delete_all(mixins)
end

#storage_get(storage_id) ⇒ ::Occi::Infrastructure::Storage?

Gets a specific storage instance as ::Occi::Infrastructure::Storage. ID given as an argument must match the occi.core.id attribute inside the returned ::Occi::Infrastructure::Storage instance, however it is possible to implement internal mapping to a platform-specific identifier.

Examples:

storage = storage_get('65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf')
    #=> #<::Occi::Infrastructure::Storage>

47
48
49
50
# File 'app/models/backend_api/storage.rb', line 47

def storage_get(storage_id)
  fail Errors::ArgumentError, '\'storage_id\' is a mandatory argument' if storage_id.blank?
  backend_instances['storage'].get(storage_id)
end

#storage_get_extensions::Occi::Collection

Returns a collection of custom mixins introduced (and specific for) the enabled backend. Only mixins and actions are allowed.


197
198
199
# File 'app/models/backend_api/storage.rb', line 197

def storage_get_extensions
  backend_instances['storage'].get_extensions || ::Occi::Collection.new
end

#storage_list(mixins = nil) ⇒ ::Occi::Core::Resources

Gets all storage instances, instances must be filtered by the specified filter, filter (if set) must contain an ::Occi::Core::Mixins instance. Returned collection must contain ::Occi::Infrastructure::Storage instances wrapped in ::Occi::Core::Resources.

Examples:

storages = storage_list #=> #<::Occi::Core::Resources>
storages.first #=> #<::Occi::Infrastructure::Storage>

mixins = ::Occi::Core::Mixins.new << ::Occi::Core::Mixin.new
storages = storage_list(mixins) #=> #<::Occi::Core::Resources>

32
33
34
# File 'app/models/backend_api/storage.rb', line 32

def storage_list(mixins = nil)
  backend_instances['storage'].list(mixins) || ::Occi::Core::Resources.new
end

#storage_list_ids(mixins = nil) ⇒ Array<String>

Gets all storage instance IDs, no details, no duplicates. Returned identifiers must correspond to those found in the occi.core.id attribute of ::Occi::Infrastructure::Storage instances.

Examples:

storage_list_ids #=> []
storage_list_ids #=> ["65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf",
                         "ggf4f65adfadf-adgg4ad-daggad-fydd4fadyfdfd"]

14
15
16
# File 'app/models/backend_api/storage.rb', line 14

def storage_list_ids(mixins = nil)
  backend_instances['storage'].list_ids(mixins) || []
end

#storage_partial_update(storage_id, attributes = nil, mixins = nil, links = nil) ⇒ true, false

Partially updates an existing storage instance, instance to be updated is specified by storage_id. If the requested instance cannot be updated, an error describing the problem must be raised, @see Backends::Errors.

Examples:

attributes = ::Occi::Core::Attributes.new
mixins = ::Occi::Core::Mixins.new
links = ::Occi::Core::Links.new
storage_partial_update(storage_id, attributes, mixins, links) #=> true

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/backend_api/storage.rb', line 120

def storage_partial_update(storage_id, attributes = nil, mixins = nil, links = nil)
  fail Errors::ArgumentError, '\'storage_id\' is a mandatory argument' if storage_id.blank?
  attributes ||= ::Occi::Core::Attributes.new
  mixins ||= ::Occi::Core::Mixins.new
  links ||= ::Occi::Core::Links.new

  unless attributes.kind_of?(::Occi::Core::Attributes) && mixins.kind_of?(::Occi::Core::Mixins) && links.kind_of?(::Occi::Core::Links)
    fail Errors::ArgumentTypeMismatchError, 'Action requires attributes, mixins or links to be updated!'
  end

  backend_instances['storage'].partial_update(
    storage_id, attributes,
    mixins, links
  )
end

#storage_trigger_action(storage_id, action_instance) ⇒ true, false

Triggers an action on an existing storage instance, the storage instance in question is identified by a storage instance ID, action is identified by the action.term attribute of the action instance passed as an argument. If the requested action cannot be triggered, an error describing the problem must be raised, @see Backends::Errors.

Examples:

action_instance = ::Occi::Core::ActionInstance.new
storage_trigger_action("65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf", action_instance)
  #=> true

186
187
188
189
190
191
# File 'app/models/backend_api/storage.rb', line 186

def storage_trigger_action(storage_id, action_instance)
  fail Errors::ArgumentError, '\'storage_id\' is a mandatory argument' if storage_id.blank?
  fail Errors::ArgumentError, '\'action_instance\' is a mandatory argument' if action_instance.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires an action instance!' unless action_instance.kind_of? ::Occi::Core::ActionInstance
  backend_instances['storage'].trigger_action(storage_id, action_instance)
end

#storage_trigger_action_on_all(action_instance, mixins = nil) ⇒ true, false

Triggers an action on all existing storage instance, instances must be filtered by the specified filter, filter (if set) must contain an ::Occi::Core::Mixins instance, action is identified by the action.term attribute of the action instance passed as an argument. If the requested action cannot be triggered, an error describing the problem must be raised, @see Backends::Errors.

Examples:

action_instance = ::Occi::Core::ActionInstance.new
mixins = ::Occi::Core::Mixins.new << ::Occi::Core::Mixin.new
storage_trigger_action_on_all(action_instance, mixin) #=> true

166
167
168
169
170
# File 'app/models/backend_api/storage.rb', line 166

def storage_trigger_action_on_all(action_instance, mixins = nil)
  fail Errors::ArgumentError, '\'action_instance\' is a mandatory argument' if action_instance.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires an action instance!' unless action_instance.kind_of? ::Occi::Core::ActionInstance
  backend_instances['storage'].trigger_action_on_all(action_instance, mixins)
end

#storage_update(storage) ⇒ true, false

Updates an existing storage instance, instance to be updated is specified using the occi.core.id attribute of the instance passed as an argument. If the requested instance cannot be updated, an error describing the problem must be raised, @see Backends::Errors.

Examples:

storage = ::Occi::Infrastructure::Storage.new
storage_update(storage) #=> true

147
148
149
150
# File 'app/models/backend_api/storage.rb', line 147

def storage_update(storage)
  fail Errors::ArgumentError, '\'storage\' is a mandatory argument' if storage.blank?
  backend_instances['storage'].update(storage)
end