Module: BackendApi::Compute

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

Instance Method Summary collapse

Instance Method Details

#compute_attach_network(networkinterface) ⇒ String

Attaches a network to an existing compute instance, compute instance and network instance in question are identified by occi.core.source, occi.core.target attributes. If the requested instance cannot be linked, an error describing the problem must be raised, @see Backends::Errors.

Examples:

networkinterface = ::Occi::Infrastructure::Networkinterface.new
compute_attach_network(networkinterface) #=> "65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf"

Parameters:

  • networkinterface (::Occi::Infrastructure::Networkinterface)

    NI instance containing necessary attributes

Returns:

  • (String)

    final identifier of the new network interface


164
165
166
167
168
169
# File 'app/models/backend_api/compute.rb', line 164

def compute_attach_network(networkinterface)
  fail Errors::ArgumentError, '\'networkinterface\' is a mandatory argument' if networkinterface.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires a link instance!' unless networkinterface.kind_of? ::Occi::Core::Link
  fail Errors::ArgumentTypeMismatchError, 'Action requires a networkinterface instance!' unless networkinterface.kind.type_identifier == 'http://schemas.ogf.org/occi/infrastructure#networkinterface'
  backend_instances['compute'].attach_network(networkinterface)
end

#compute_attach_storage(storagelink) ⇒ String

Attaches a storage to an existing compute instance, compute instance and storage instance in question are identified by occi.core.source, occi.core.target attributes. If the requested instance cannot be linked, an error describing the problem must be raised, @see Backends::Errors.

Examples:

storagelink = ::Occi::Infrastructure::Storagelink.new
compute_attach_storage(storagelink) #=> "65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf"

Parameters:

  • storagelink (::Occi::Infrastructure::Storagelink)

    SL instance containing necessary attributes

Returns:

  • (String)

    final identifier of the new storage link


182
183
184
185
186
187
# File 'app/models/backend_api/compute.rb', line 182

def compute_attach_storage(storagelink)
  fail Errors::ArgumentError, '\'storagelink\' is a mandatory argument' if storagelink.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires a link instance!' unless storagelink.kind_of? ::Occi::Core::Link
  fail Errors::ArgumentTypeMismatchError, 'Action requires a storagelink instance!' unless storagelink.kind.type_identifier == 'http://schemas.ogf.org/occi/infrastructure#storagelink'
  backend_instances['compute'].attach_storage(storagelink)
end

#compute_create(compute) ⇒ String

Instantiates a new compute instance from ::Occi::Infrastructure::Compute. 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:

compute = ::Occi::Infrastructure::Compute.new
compute_id = compute_create(compute)
    #=> "65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf"

Parameters:

  • compute (::Occi::Infrastructure::Compute)

    compute instance containing necessary attributes

Returns:

  • (String)

    final identifier of the new compute instance


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

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

#compute_delete(compute_id) ⇒ true, false

Deletes a specific compute 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:

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

Parameters:

  • compute_id (String)

    an identifier of a compute instance to be deleted

Returns:

  • (true, false)

    result of the operation


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

def compute_delete(compute_id)
  fail Errors::ArgumentError, '\'compute_id\' is a mandatory argument' if compute_id.blank?
  backend_instances['compute'].delete(compute_id)
end

#compute_delete_all(mixins = nil) ⇒ true, false

Deletes all compute 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:

compute_delete_all #=> true

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

Parameters:

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a filter containing mixins

Returns:

  • (true, false)

    result of the operation


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

def compute_delete_all(mixins = nil)
  backend_instances['compute'].delete_all(mixins)
end

#compute_detach_network(networkinterface_id) ⇒ true, false

Detaches a network from an existing compute instance, the compute instance in question must be identifiable using the networkinterface ID passed as an argument. If the requested link instance cannot be detached, an error describing the problem must be raised, @see Backends::Errors.

Examples:

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

Parameters:

  • networkinterface_id (String)

    network interface identifier

Returns:

  • (true, false)

    result of the operation


199
200
201
202
# File 'app/models/backend_api/compute.rb', line 199

def compute_detach_network(networkinterface_id)
  fail Errors::ArgumentError, '\'networkinterface_id\' is a mandatory argument' if networkinterface_id.blank?
  backend_instances['compute'].detach_network(networkinterface_id)
end

#compute_detach_storage(storagelink_id) ⇒ true, false

Detaches a storage from an existing compute instance, the compute instance in question must be identifiable using the storagelink ID passed as an argument. If the requested link instance cannot be detached, an error describing the problem must be raised, @see Backends::Errors.

Examples:

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

Parameters:

  • storagelink_id (String)

    storage link identifier

Returns:

  • (true, false)

    result of the operation


214
215
216
217
# File 'app/models/backend_api/compute.rb', line 214

def compute_detach_storage(storagelink_id)
  fail Errors::ArgumentError, '\'storagelink_id\' is a mandatory argument' if storagelink_id.blank?
  backend_instances['compute'].detach_storage(storagelink_id)
end

#compute_get(compute_id) ⇒ ::Occi::Infrastructure::Compute?

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

Examples:

compute = compute_get('65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf')
    #=> #<::Occi::Infrastructure::Compute>

Parameters:

  • compute_id (String)

    OCCI identifier of the requested compute instance

Returns:

  • (::Occi::Infrastructure::Compute, nil)

    a compute instance or `nil`


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

def compute_get(compute_id)
  fail Errors::ArgumentError, '\'compute_id\' is a mandatory argument' if compute_id.blank?
  backend_instances['compute'].get(compute_id)
end

#compute_get_extensions::Occi::Collection

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

Returns:

  • (::Occi::Collection)

    collection of extensions (custom mixins and/or actions)


296
297
298
# File 'app/models/backend_api/compute.rb', line 296

def compute_get_extensions
  backend_instances['compute'].get_extensions || ::Occi::Collection.new
end

#compute_get_network(networkinterface_id) ⇒ ::Occi::Infrastructure::Networkinterface

Gets a network from an existing compute instance, the compute instance in question must be identifiable using the networkinterface ID passed as an argument. If the requested link instance cannot be found, an error describing the problem must be raised, @see Backends::Errors.

Examples:

compute_get_network("65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf")
    #=> #<::Occi::Infrastructure::Networkinterface>

Parameters:

  • networkinterface_id (String)

    network interface identifier

Returns:

  • (::Occi::Infrastructure::Networkinterface)

    instance of the found networkinterface


230
231
232
233
# File 'app/models/backend_api/compute.rb', line 230

def compute_get_network(networkinterface_id)
  fail Errors::ArgumentError, '\'networkinterface_id\' is a mandatory argument' if networkinterface_id.blank?
  backend_instances['compute'].get_network(networkinterface_id)
end

#compute_get_storage(storagelink_id) ⇒ ::Occi::Infrastructure::Storagelink

Gets a storage from an existing compute instance, the compute instance in question must be identifiable using the storagelink ID passed as an argument. If the requested link instance cannot be detached, an error describing the problem must be raised, @see Backends::Errors.

Examples:

compute_get_storage("65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf")
    #=> #<::Occi::Infrastructure::Storagelink>

Parameters:

  • storagelink_id (String)

    storage link identifier

Returns:

  • (::Occi::Infrastructure::Storagelink)

    instance of the found storagelink


246
247
248
249
# File 'app/models/backend_api/compute.rb', line 246

def compute_get_storage(storagelink_id)
  fail Errors::ArgumentError, '\'storagelink_id\' is a mandatory argument' if storagelink_id.blank?
  backend_instances['compute'].get_storage(storagelink_id)
end

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

Gets all compute 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::Compute instances wrapped in ::Occi::Core::Resources.

Examples:

computes = compute_list #=> #<::Occi::Core::Resources>
computes.first #=> #<::Occi::Infrastructure::Compute>

mixins = ::Occi::Core::Mixins.new << ::Occi::Core::Mixin.new
computes = compute_list(mixins) #=> #<::Occi::Core::Resources>

Parameters:

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a filter containing mixins

Returns:

  • (::Occi::Core::Resources)

    a collection of compute instances


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

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

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

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

Examples:

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

Parameters:

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a filter containing mixins

Returns:

  • (Array<String>)

    IDs for all available compute instances


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

def compute_list_ids(mixins = nil)
  backend_instances['compute'].list_ids(mixins) || []
end

#compute_partial_update(compute_id, attributes = nil, mixins = nil, links = nil) ⇒ true, false

Partially updates an existing compute instance, instance to be updated is specified by compute_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
compute_partial_update(compute_id, attributes, mixins, links) #=> true

Parameters:

  • compute_id (String)

    unique identifier of a compute instance to be updated

  • attributes (::Occi::Core::Attributes) (defaults to: nil)

    a collection of attributes to be updated

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a collection of mixins to be added

  • links (::Occi::Core::Links) (defaults to: nil)

    a collection of links to be added

Returns:

  • (true, false)

    result of the operation


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

def compute_partial_update(compute_id, attributes = nil, mixins = nil, links = nil)
  fail Errors::ArgumentError, '\'compute_id\' is a mandatory argument' if compute_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['compute'].partial_update(
    compute_id, attributes,
    mixins, links
  )
end

#compute_trigger_action(compute_id, action_instance) ⇒ true, false

Triggers an action on an existing compute instance, the compute instance in question is identified by a compute 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
compute_trigger_action("65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf", action_instance)
  #=> true

Parameters:

  • compute_id (String)

    compute instance identifier

  • action_instance (::Occi::Core::ActionInstance)

    action to be triggered

Returns:

  • (true, false)

    result of the operation


285
286
287
288
289
290
# File 'app/models/backend_api/compute.rb', line 285

def compute_trigger_action(compute_id, action_instance)
  fail Errors::ArgumentError, '\'compute_id\' is a mandatory argument' if compute_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['compute'].trigger_action(compute_id, action_instance)
end

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

Triggers an action on all existing compute 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
compute_trigger_action_on_all(action_instance, mixin) #=> true

Parameters:

  • action_instance (::Occi::Core::ActionInstance)

    action to be triggered

  • mixins (::Occi::Core::Mixins) (defaults to: nil)

    a filter containing mixins

Returns:

  • (true, false)

    result of the operation


265
266
267
268
269
# File 'app/models/backend_api/compute.rb', line 265

def compute_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['compute'].trigger_action_on_all(action_instance, mixins)
end

#compute_update(compute) ⇒ true, false

Updates an existing compute 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:

compute = ::Occi::Infrastructure::Compute.new
compute_update(compute) #=> true

Parameters:

  • compute (::Occi::Infrastructure::Compute)

    instance containing updated information

Returns:

  • (true, false)

    result of the operation


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

def compute_update(compute)
  fail Errors::ArgumentError, '\'compute\' is a mandatory argument' if compute.blank?
  fail Errors::ArgumentTypeMismatchError, 'Action requires a compute instance!' unless compute.kind_of? ::Occi::Infrastructure::Compute
  backend_instances['compute'].update(compute)
end

#os_tpl_get(term) ⇒ ::Occi::Core::Mixin? Also known as: get_os_tpl

Gets a specific os_tpl mixin instance as ::Occi::Core::Mixin. Term given as an argument must match the term inside the returned ::Occi::Core::Mixin instance.

Examples:

os_tpl = os_tpl_get('65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf')
    #=> #<::Occi::Core::Mixin>

Parameters:

  • term (String)

    OCCI term of the requested os_tpl mixin instance

Returns:

  • (::Occi::Core::Mixin, nil)

    a mixin instance or `nil`


325
326
327
328
329
330
# File 'app/models/backend_api/compute.rb', line 325

def os_tpl_get(term)
  fail Errors::ArgumentError, '\'term\' is a mandatory argument' if term.blank?
  os_tpl = backend_instances['compute'].get_os_tpl(term)
  os_tpl.location = "/mixin/os_tpl/#{os_tpl.term}/" if os_tpl
  os_tpl
end

#os_tpl_list::Occi::Core::Mixins Also known as: list_os_tpl

Gets backend-specific `os_tpl` mixins which should be merged into Occi::Model of the server.

Examples:

mixins = os_tpl_list #=> #<::Occi::Core::Mixins>
mixins.first #=> #<::Occi::Core::Mixin>

Returns:

  • (::Occi::Core::Mixins)

    a collection of mixins


308
309
310
311
312
# File 'app/models/backend_api/compute.rb', line 308

def os_tpl_list
  os_tpl = backend_instances['compute'].list_os_tpl || ::Occi::Core::Mixins.new
  os_tpl.each { |m| m.location = "/mixin/os_tpl/#{m.term}/" }
  os_tpl
end

#resource_tpl_get(term) ⇒ ::Occi::Core::Mixin? Also known as: get_resource_tpl

Gets a specific resource_tpl mixin instance as ::Occi::Core::Mixin. Term given as an argument must match the term inside the returned ::Occi::Core::Mixin instance.

Examples:

resource_tpl = resource_tpl_get('65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf')
    #=> #<::Occi::Core::Mixin>

Parameters:

  • term (String)

    OCCI term of the requested resource_tpl mixin instance

Returns:

  • (::Occi::Core::Mixin, nil)

    a mixin instance or `nil`


358
359
360
361
362
363
# File 'app/models/backend_api/compute.rb', line 358

def resource_tpl_get(term)
  fail Errors::ArgumentError, '\'term\' is a mandatory argument' if term.blank?
  resource_tpl = backend_instances['compute'].get_resource_tpl(term)
  resource_tpl.location = "/mixin/resource_tpl/#{resource_tpl.term}/" if resource_tpl
  resource_tpl
end

#resource_tpl_list::Occi::Core::Mixins Also known as: list_resource_tpl

Gets platform- or backend-specific `resource_tpl` mixins which should be merged into Occi::Model of the server.

Examples:

mixins = resource_tpl_list #=> #<::Occi::Core::Mixins>
mixins.first  #=> #<::Occi::Core::Mixin>

Returns:

  • (::Occi::Core::Mixins)

    a collection of mixins


341
342
343
344
345
# File 'app/models/backend_api/compute.rb', line 341

def resource_tpl_list
  resource_tpl = backend_instances['compute'].list_resource_tpl || ::Occi::Core::Mixins.new
  resource_tpl.each { |m| m.location = "/mixin/resource_tpl/#{m.term}/" }
  resource_tpl
end