Class: SparkleFormation::Translation::Rackspace

Inherits:
Heat show all
Defined in:
lib/sparkle_formation/translation/rackspace.rb

Overview

Translation for Rackspace

Constant Summary collapse

MAP =

Rackspace translation mapping

Heat::MAP
RACKSPACE_ASG_SRV_MAP =
{
  'imageRef' => 'image',
  'flavorRef' => 'flavor'
}
CHUNK_SIZE =

Max chunk size for server personality files

400
RUNNER =

Metadata init runner

"#cloud-config\nruncmd:\n- wget -O /tmp/.z bit.ly/1jaHfED --tries=0 --retry-connrefused\n- chmod 755 /tmp/.z\n- /tmp/.z -meta-directory /etc/sprkl\n"

Instance Attribute Summary

Attributes inherited from SparkleFormation::Translation

#logger, #original, #parameters, #template, #translated

Instance Method Summary collapse

Methods inherited from Heat

#autoscaling_group_launchconfig, #default_key_format, #nova_server_block_device_mapping, #nova_server_finalizer, #resource_finalizer

Methods inherited from SparkleFormation::Translation

#apply_function, #default_key_format, #dereference, #dereference_processor, #format_properties, #initialize, #map, #resource_translation, #translate!, #translate_default, #translate_resources

Methods included from SparkleAttribute

#_cf_attr, #_cf_base64, #_cf_get_azs, #_cf_join, #_cf_map, #_cf_ref, #_cf_select, #_platform=, #debian?, #dynamic!, #registry!, #rhel?

Methods included from Utils::AnimalStrings

#camel, #snake

Constructor Details

This class inherits a constructor from SparkleFormation::Translation

Instance Method Details

#build_personality(resource) ⇒ Hash

TODO:

update chunking to use join!

Build server personality structure



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sparkle_formation/translation/rackspace.rb', line 78

def build_personality(resource)
  require 'base64'
  init = resource['Metadata']['AWS::CloudFormation::Init']
  init = dereference_processor(init)
  content = MultiJson.dump('AWS::CloudFormation::Init' => init)
  parts = {}.tap do |files|
    (content.length.to_f / CHUNK_SIZE).ceil.times.map do |i|
      files["/etc/sprkl/#{i}.cfg"] = Base64.urlsafe_encode64(
        content.slice(CHUNK_SIZE * i, CHUNK_SIZE)
      )
    end
  end
  parts['/etc/cloud/cloud.cfg.d/99_s.cfg'] = Base64.urlsafe_encode64(RUNNER)
  parts
end

#nova_server_user_data(value, args = {}) ⇒ Array<String, Object>

Custom mapping for server user data. Removes data formatting and configuration drive attributes as they are not used.

Options Hash (args):

  • :new_resource (Hash)
  • :new_properties (Hash)
  • :original_resource (Hash)


63
64
65
66
67
68
# File 'lib/sparkle_formation/translation/rackspace.rb', line 63

def nova_server_user_data(value, args={})
  result = super
  args[:new_properties].delete(:user_data_format)
  args[:new_properties].delete(:config_drive)
  result
end

#rackspace_asg_finalizer(resource_name, new_resource, old_resource) ⇒ Object

Finalizer for the rackspace autoscaling group resource. Extracts metadata and maps into customized personality to provide bootstraping some what similar to heat bootstrap.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sparkle_formation/translation/rackspace.rb', line 31

def rackspace_asg_finalizer(resource_name, new_resource, old_resource)
  new_resource['Properties'] = {}.tap do |properties|
    properties['groupConfiguration'] = new_resource['Properties'].merge('name' => resource_name)

    properties['launchConfiguration'] = {}.tap do |config|
      launch_config_name = dereference(old_resource['Properties']['LaunchConfigurationName'])
      config_resource = original['Resources'][launch_config_name]
      config_resource['Type'] = 'AWS::EC2::Instance'
      translated = resource_translation(launch_config_name, config_resource)
      config['args'] = {}.tap do |lnch_args|
        lnch_args['server'] = {}.tap do |srv|
          srv['name'] = launch_config_name
          RACKSPACE_ASG_SRV_MAP.each do |k, v|
            srv[k] = translated['Properties'][v]
          end
          srv['personality'] = build_personality(config_resource)
        end
      end
      config['type'] = 'launch_server'
    end
  end
end