module Backends::Ec2::OsTpl
Constants
- DALLI_OS_TPL_KEY
- IMAGE_FILTERING_POLICIES_LISTED
- IMAGE_FILTERING_POLICIES_OWNED
Public Instance Methods
os_tpl_get(term)
click to toggle source
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.
@example
os_tpl = os_tpl_get('65d4f65adfadf-ad2f4ad-daf5ad-f5ad4fad4ffdf') #=> #<Occi::Core::Mixin>
@param term [String] OCCI term of the requested os_tpl mixin instance @return [Occi::Core::Mixin, nil] a mixin instance or `nil` @effects Gets status of a given machine image
# File lib/backends/ec2/os_tpl.rb, line 59 def os_tpl_get(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) ? os_tpl_list_mixin_from_image(ec2_images.first) : nil end end
os_tpl_list()
click to toggle source
Gets backend-specific `os_tpl` mixins which should be merged into Occi::Model of the server.
@example
mixins = os_tpl_list #=> #<Occi::Core::Mixins> mixins.first #=> #<Occi::Core::Mixin>
@return [Occi::Core::Mixins] a collection of mixins @effects Gets status of machine images
# File lib/backends/ec2/os_tpl.rb, line 18 def os_tpl_list 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 = Backends::Helpers::CachingHelper.load(@dalli_cache, DALLI_OS_TPL_KEY) unless ec2_images_ary 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 << os_tpl_list_mixin_from_image(ec2_image) } os_tpls end
os_tpl_list_image_to_term(ec2_image)
click to toggle source
# File lib/backends/ec2/os_tpl.rb, line 72 def os_tpl_list_image_to_term(ec2_image) ec2_image[:image_id] end
os_tpl_list_mixin_from_image(ec2_image)
click to toggle source
# File lib/backends/ec2/os_tpl.rb, line 84 def os_tpl_list_mixin_from_image(ec2_image) depends = %w|http://schemas.ogf.org/occi/infrastructure#os_tpl| term = os_tpl_list_image_to_term(ec2_image) scheme = "#{@options.backend_scheme}/occi/infrastructure/os_tpl#" title = ec2_image[:name] || 'unknown' location = "/mixin/os_tpl/#{term}/" applies = %w|http://schemas.ogf.org/occi/infrastructure#compute| Occi::Core::Mixin.new(scheme, term, title, nil, depends, nil, location, applies) end
os_tpl_list_term_to_image_id(term)
click to toggle source
# File lib/backends/ec2/os_tpl.rb, line 78 def os_tpl_list_term_to_image_id(term) term end