Class: Backends::Ec2::Compute

Constant Summary collapse

COMPUTE_NINTF_REGEXP =
/compute_(?<compute_id>i-[[:alnum:]]+)_nic_(?<compute_nic_id>eni-[[:alnum:]]+)/
/compute_(?<compute_id>i-[[:alnum:]]+)_disk_(?<compute_disk_id>vol-[[:alnum:]]+)/
DALLI_OS_TPL_KEY =
'ec2_os_tpls'
IMAGE_FILTERING_POLICIES_OWNED =
['only_owned', 'owned_and_listed'].freeze
IMAGE_FILTERING_POLICIES_LISTED =
['only_listed', 'owned_and_listed'].freeze

Constants included from Helpers::ComputeCreateHelper

Helpers::ComputeCreateHelper::COMPUTE_BASE64_REGEXP, Helpers::ComputeCreateHelper::COMPUTE_DN_BASED_AUTHS, Helpers::ComputeCreateHelper::COMPUTE_DONT_WAIT_FOR_STATUSES, Helpers::ComputeCreateHelper::COMPUTE_USER_DATA_SIZE_LIMIT

Constants included from Helpers::ComputeParseHelper

Helpers::ComputeParseHelper::COMPUTE_FAKE_INTFS

Constants inherited from Base

Base::API_VERSION, Base::IMAGE_FILTERING_POLICIES

Instance Method Summary collapse

Methods included from Helpers::ComputeDeleteHelper

#delete_release_public

Methods included from Helpers::ComputeNetworkHelper

#attach_network_private, #attach_network_public, #attach_network_vpc, #detach_network_private, #detach_network_public, #detach_network_vpc

Methods included from Helpers::ComputeActionHelper

#trigger_action_restart, #trigger_action_start, #trigger_action_state_check, #trigger_action_stop

Methods included from Helpers::ComputeCreateHelper

#create_with_os_tpl

Methods included from Helpers::ComputeParseHelper

#parse_backend_obj

Methods inherited from Base

#add_other_backend, #initialize

Methods included from Helpers::ExtensionsHelper

#read_extensions

Methods included from Helpers::JsonCollectionHelper

#read_from_json

Constructor Details

This class inherits a constructor from Backends::Ec2::Base

Instance Method Details

#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
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

Server-side Effects:

  • Allocates elastic IP address

  • Associates the allocated address


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/backends/ec2/compute.rb', line 221

def attach_network(networkinterface)
  fail Backends::Errors::ResourceNotValidError, 'Attributes source and target are required!' \
    if networkinterface.target.blank? || networkinterface.source.blank?
  network_id = networkinterface.target.kind_of?(::Occi::Core::Resource) ? networkinterface.target.id : networkinterface.target.split('/').last
  source_id = networkinterface.source.kind_of?(::Occi::Core::Resource) ? networkinterface.source.id : networkinterface.source.split('/').last
  fail Backends::Errors::ResourceNotValidError, 'Attributes source and target are required!' \
    if network_id.blank? || source_id.blank?

  case network_id
  when 'public'
    # attaching a floating public IP address
    attach_network_public(networkinterface)
  when 'private'
    # attaching a floating private IP address
    attach_network_private(networkinterface)
  else
    # attaching a VPC
    attach_network_vpc(networkinterface)
  end
end

#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
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

Server-side Effects:

  • Attaches an existing volume to a running instance


254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/backends/ec2/compute.rb', line 254

def attach_storage(storagelink)
  fail Backends::Errors::ResourceNotValidError, 'Attributes source and target are required!' \
    if storagelink.target.blank? || storagelink.source.blank?
  target_id = storagelink.target.kind_of?(::Occi::Core::Resource) ? storagelink.target.id : storagelink.target.split('/').last
  source_id = storagelink.source.kind_of?(::Occi::Core::Resource) ? storagelink.source.id : storagelink.source.split('/').last
  fail Backends::Errors::ResourceNotValidError, 'Attributes source and target are required!' \
    if target_id.blank? || source_id.blank?

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    @ec2_client.attach_volume(
      volume_id: target_id,
      instance_id: source_id,
      device: storagelink.attributes.occi!.storagelink!.deviceid || '/dev/xvdf',
    )
  end

  "compute_#{source_id}_disk_#{target_id}"
end

#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 = 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

Server-side Effects:

  • Launches an instance

  • Creates tags for it

  • Attaches storage

  • Attaches network interfaces


105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/backends/ec2/compute.rb', line 105

def create(compute)
  compute_id = compute.id

  os_tpl_mixins = compute.mixins.get_related_to(::Occi::Infrastructure::OsTpl.mixin.type_identifier)
  if os_tpl_mixins.empty?
    fail Backends::Errors::ResourceNotValidError,
         "Given instance does not contain an os_tpl " \
         "mixin necessary to create a virtual machine!"
  else
    compute_id = create_with_os_tpl(compute)
  end

  compute_id
end

#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:

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

Server-side Effects:

  • Shuts down the given AWS instance

  • Disassociates and releases elastic IP address assigned to the given instance


159
160
161
162
163
164
165
166
167
# File 'lib/backends/ec2/compute.rb', line 159

def delete(compute_id)
  delete_release_public([compute_id])

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    @ec2_client.terminate_instances(instance_ids: [compute_id])
  end

  true
end

#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:

delete_all #=> true

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

Parameters:

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

    a filter containing mixins

Returns:

  • (true, false)

    result of the operation

Server-side Effects:

  • Disassociates and releases elastic IP addresses

  • Shuts down multiple AWS instances


135
136
137
138
139
140
141
142
143
144
# File 'lib/backends/ec2/compute.rb', line 135

def delete_all(mixins = nil)
  all_ids = list_ids(mixins)
  delete_release_public(all_ids)

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    @ec2_client.terminate_instances(instance_ids: all_ids)
  end unless all_ids.blank?

  true
end

#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:

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

Parameters:

  • networkinterface_id (String)

    network interface identifier

Returns:

  • (true, false)

    result of the operation

Server-side Effects:

  • Dissasociates an elastic IP address

  • Releases an elastic IP address


285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/backends/ec2/compute.rb', line 285

def detach_network(networkinterface_id)
  networkinterface = get_network(networkinterface_id)
  network_id = networkinterface.attributes['occi.core.target'].split('/').last

  case network_id
  when 'public'
    # detaching a floating public IP address
    detach_network_public(networkinterface)
  when 'private'
    # detaching a floating private IP address
    detach_network_private(networkinterface)
  else
    # detaching a VPC
    detach_network_vpc(networkinterface)
  end

  true
end

#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:

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

Parameters:

  • storagelink_id (String)

    storage link identifier

Returns:

  • (true, false)

    result of the operation

Server-side Effects:

  • Detaches a volume from a running instance


315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/backends/ec2/compute.rb', line 315

def detach_storage(storagelink_id)
  matched = COMPUTE_SLINK_REGEXP.match(storagelink_id)
  fail Backends::Errors::IdentifierNotValidError, 'ID of the given storagelink is not valid!' unless matched

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    @ec2_client.detach_volume(
      volume_id: matched[:compute_disk_id],
      instance_id: matched[:compute_id],
      force: true,
    )
  end

  true
end

#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 = 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`

Server-side Effects:

  • Gets the status of a existing AWS instance


75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/backends/ec2/compute.rb', line 75

def get(compute_id)
  filters = []
  filters << { name: 'instance-id', values: [compute_id] }

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    rsrvts = @ec2_client.describe_instances(filters: filters).reservations
    rsrvt = rsrvts ? rsrvts.first : nil
    return nil unless rsrvt && rsrvt.instances && rsrvt.instances.first

    parse_backend_obj(rsrvt.instances.first, rsrvt[:reservation_id])
  end
end

#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)


431
432
433
# File 'lib/backends/ec2/compute.rb', line 431

def get_extensions
  read_extensions 'compute', @options.model_extensions_dir
end

#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:

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

Server-side Effects:

  • Gets the status of an existing instance


342
343
344
345
346
347
348
349
350
351
# File 'lib/backends/ec2/compute.rb', line 342

def get_network(networkinterface_id)
  matched = COMPUTE_NINTF_REGEXP.match(networkinterface_id)
  fail Backends::Errors::IdentifierNotValidError, 'ID of the given networkinterface is not valid!' unless matched

  compute = get(matched[:compute_id]) || ::Occi::Infrastructure::Compute.new
  intf = compute.links.to_a.select { |l| l.id == networkinterface_id }
  fail Backends::Errors::ResourceNotFoundError, 'Networkinterface with the given ID does not exist!' if intf.blank?

  intf.first
end

#get_os_tpl(term) ⇒ ::Occi::Core::Mixin?

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 = get_os_tpl('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`

Server-side Effects:

  • Gets status of a given machine image


484
485
486
487
488
489
490
491
492
493
# File 'lib/backends/ec2/compute.rb', line 484

def get_os_tpl(term)
  filters = []
  filters << { name: 'image-type', values: ['machine'] }
  filters << { name: 'image-id', values: [term] }

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    ec2_images = @ec2_client.describe_images(filters: filters).images
    (ec2_images && ec2_images.first) ? mixin_from_image(ec2_images.first) : nil
  end
end

#get_resource_tpl(term) ⇒ ::Occi::Core::Mixin?

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 = get_resource_tpl('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`

Server-side Effects:

  • none: call answered from within the backend


519
520
521
# File 'lib/backends/ec2/compute.rb', line 519

def get_resource_tpl(term)
  list_resource_tpl.to_a.select { |m| m.term == term }.first
end

#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:

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

Server-side Effects:

  • Gets the status of an existing instance


365
366
367
368
369
370
371
372
373
374
# File 'lib/backends/ec2/compute.rb', line 365

def get_storage(storagelink_id)
  matched = COMPUTE_SLINK_REGEXP.match(storagelink_id)
  fail Backends::Errors::IdentifierNotValidError, 'ID of the given storagelink is not valid!' unless matched

  compute = get(matched[:compute_id]) || ::Occi::Infrastructure::Compute.new
  link = compute.links.to_a.select { |l| l.id == storagelink_id }
  fail Backends::Errors::ResourceNotFoundError, 'Storagelink with the given ID does not exist!' if link.blank?

  link.first
end

#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 = list #=> #<::Occi::Core::Resources>
computes.first #=> #<::Occi::Infrastructure::Compute>

mixins = ::Occi::Core::Mixins.new << ::Occi::Core::Mixin.new
computes = 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

Server-side Effects:

  • Gets the status of existing AWS instances


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/backends/ec2/compute.rb', line 49

def list(mixins = nil)
  computes = ::Occi::Core::Resources.new

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    rsrvts = @ec2_client.describe_instances.reservations
    rsrvts.each do |reservation|
      next unless reservation && reservation.instances
      reservation.instances.each { |instance| computes << parse_backend_obj(instance, reservation[:reservation_id]) }
    end if rsrvts
  end

  computes
end

#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:

list_ids #=> []
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

Server-side Effects:

  • Gets the status of existing AWS instances


23
24
25
26
27
28
29
30
31
32
# File 'lib/backends/ec2/compute.rb', line 23

def list_ids(mixins = nil)
  id_list = []

  Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
    instance_statuses = @ec2_client.describe_instance_status(include_all_instances: true).instance_statuses
    instance_statuses.each { |istatus| id_list << istatus[:instance_id] } if instance_statuses
  end

  id_list
end

#list_os_tpl::Occi::Core::Mixins

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

Examples:

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

Returns:

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

    a collection of mixins

Server-side Effects:

  • Gets status of machine images


444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/backends/ec2/compute.rb', line 444

def list_os_tpl
  filters = []
  filters << { name: 'image-type', values: ['machine'] }
  filters << { name: 'image-id', values: @image_filtering_image_list } if IMAGE_FILTERING_POLICIES_LISTED.include?(@image_filtering_policy)
  owners = IMAGE_FILTERING_POLICIES_OWNED.include?(@image_filtering_policy) ? [ 'self' ] : nil

  ec2_images_ary = nil
  unless ec2_images_ary = Backends::Helpers::CachingHelper.load(@dalli_cache, DALLI_OS_TPL_KEY)
    ec2_images_ary = []

    Backends::Ec2::Helpers::AwsConnectHelper.rescue_aws_service(@logger) do
      ec2_images = if owners
                     @ec2_client.describe_images(filters: filters, owners: owners).images
                   else
                     @ec2_client.describe_images(filters: filters).images
                   end

      ec2_images.each { |ec2_image| ec2_images_ary << { image_id: ec2_image[:image_id], name: ec2_image[:name] } } if ec2_images
    end

    Backends::Helpers::CachingHelper.save(@dalli_cache, DALLI_OS_TPL_KEY, ec2_images_ary)
  end

  os_tpls = ::Occi::Core::Mixins.new
  ec2_images_ary.each { |ec2_image| os_tpls << mixin_from_image(ec2_image) }

  os_tpls
end

#list_resource_tpl::Occi::Core::Mixins

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

Examples:

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

Returns:

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

    a collection of mixins

Server-side Effects:

  • none: call answered from within the backend


504
505
506
# File 'lib/backends/ec2/compute.rb', line 504

def list_resource_tpl
  @resource_tpl
end

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

TODO:

Method not yet implemented

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
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


186
187
188
189
# File 'lib/backends/ec2/compute.rb', line 186

def partial_update(compute_id, attributes = nil, mixins = nil, links = nil)
  # TODO: impl, do not forget the effects tag
  fail Backends::Errors::MethodNotImplementedError, 'Not Implemented!'
end

#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
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

Server-side Effects:

  • Makes an instance start, restart or stop


411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/backends/ec2/compute.rb', line 411

def trigger_action(compute_id, action_instance)
  case action_instance.action.type_identifier
  when 'http://schemas.ogf.org/occi/infrastructure/compute/action#stop'
    trigger_action_stop(compute_id, action_instance.attributes)
  when 'http://schemas.ogf.org/occi/infrastructure/compute/action#start'
    trigger_action_start(compute_id, action_instance.attributes)
  when 'http://schemas.ogf.org/occi/infrastructure/compute/action#restart'
    trigger_action_restart(compute_id, action_instance.attributes)
  else
    fail Backends::Errors::ActionNotImplementedError,
         "Action #{action_instance.action.type_identifier.inspect} is not implemented!"
  end

  true
end

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

Triggers an action on all existing compute instances, 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
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

Server-side Effects:

  • Makes all instances start, restart or stop


391
392
393
394
# File 'lib/backends/ec2/compute.rb', line 391

def trigger_action_on_all(action_instance, mixins = nil)
  list_ids(mixins).each { |cmpt| trigger_action(cmpt, action_instance) }
  true
end

#update(compute) ⇒ true, false

TODO:

Method not yet implemented

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
update(compute) #=> true

Parameters:

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

    instance containing updated information

Returns:

  • (true, false)

    result of the operation


203
204
205
206
# File 'lib/backends/ec2/compute.rb', line 203

def update(compute)
  # TODO: impl, do not forget the effects tag
  fail Backends::Errors::MethodNotImplementedError, 'Not Implemented!'
end