Class: Cloudkeeper::Aws::ProtoHelper
- Inherits:
-
Object
- Object
- Cloudkeeper::Aws::ProtoHelper
- Defined in:
- lib/cloudkeeper/aws/proto_helper.rb
Overview
Module refining basic GRPC structs with additional methods
used for conversion from one format to another
Constant Summary collapse
- APPLIANCE_PREFIX =
'cloudkeeper_appliance_'.freeze
- IMAGE_PREFIX =
'cloudkeeper_image_'.freeze
- NAME_TAG_KEY =
'Name'.freeze
- EXTRA_APPLIANCE_TAGS =
%i[description title].freeze
Class Method Summary collapse
- .appliance_from_tags(tags) ⇒ Object
- .appliance_prepare_values(appliance) ⇒ Object
- .appliance_to_tags(appliance) ⇒ Object
- .filter_tags(tags, prefix) ⇒ Object
- .image_from_tags(tags) ⇒ Object
- .image_prepare_values(image) ⇒ Object
- .image_to_tags(image) ⇒ Object
- .prepare_tags(tags, prefix) ⇒ Object
- .remove_prefix(tags, prefix) ⇒ Object
- .shorten_extra_tags!(appliance_hash) ⇒ Object
Class Method Details
.appliance_from_tags(tags) ⇒ Object
39 40 41 42 43 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 39 def () appliance = appliance_prepare_values((, APPLIANCE_PREFIX)) appliance[:image] = () CloudkeeperGrpc::Appliance.new(appliance) end |
.appliance_prepare_values(appliance) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 45 def appliance_prepare_values(appliance) appliance[:ram] = appliance[:ram].to_i appliance[:core] = appliance[:core].to_i appliance[:expiration_date] = appliance[:expiration_date].to_i appliance end |
.appliance_to_tags(appliance) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 28 def (appliance) appliance_hash = appliance.to_hash (appliance_hash) image = appliance_hash.delete(:image) = appliance_hash.map { |k, v| { key: "#{APPLIANCE_PREFIX}#{k}", value: v.to_s } } += (image) if image << { key: Cloudkeeper::Aws::FilterHelper::TAG_CLOUDKEEPER_IDENTIFIER, value: Cloudkeeper::Aws::Settings['identifier'] } << { key: NAME_TAG_KEY, value: appliance_hash[:title] } end |
.filter_tags(tags, prefix) ⇒ Object
12 13 14 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 12 def (, prefix) .select { |tag| tag[:key].include?(prefix) } end |
.image_from_tags(tags) ⇒ Object
56 57 58 59 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 56 def () image = image_prepare_values((, IMAGE_PREFIX)) CloudkeeperGrpc::Image.new(image) end |
.image_prepare_values(image) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 61 def image_prepare_values(image) image[:size] = image[:size].to_i image[:mode] = image[:mode].upcase.to_sym image[:format] = image[:format].upcase.to_sym image end |
.image_to_tags(image) ⇒ Object
52 53 54 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 52 def (image) image.to_hash.map { |k, v| { key: "#{IMAGE_PREFIX}#{k}", value: v.to_s } } end |
.prepare_tags(tags, prefix) ⇒ Object
20 21 22 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 20 def (, prefix) remove_prefix((, prefix), prefix) end |
.remove_prefix(tags, prefix) ⇒ Object
16 17 18 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 16 def remove_prefix(, prefix) .map { |tag| { tag[:key].sub(prefix, '').to_sym => tag[:value] } }.reduce(&:merge) end |
.shorten_extra_tags!(appliance_hash) ⇒ Object
24 25 26 |
# File 'lib/cloudkeeper/aws/proto_helper.rb', line 24 def (appliance_hash) EXTRA_APPLIANCE_TAGS.each { |key| appliance_hash[key] = appliance_hash[key][0..254] } end |