Module: Enscalator::Plugins::Ubuntu

Included in:
Redis
Defined in:
lib/enscalator/plugins/ubuntu.rb

Overview

Ubuntu appliance

Constant Summary collapse

STORAGE =

Supported storage types in AWS

[:ebs, :'ebs-io1', :'ebs-ssd', :'instance-store']
ARCH =

Supported Ubuntu image architectures

[:amd64, :i386]
RELEASE =

Supported Ubuntu releases

{
  vivid: '15.04',
  utopic: '14.10',
  trusty: '14.04',
  saucy: '13.10',
  raring: '13.04',
  quantal: '12.10',
  precise: '12.04'
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_mapping(release: :trusty, storage: :ebs, arch: :amd64) ⇒ Hash

Get mapping for Ubuntu images

Parameters:

  • release (Symbol, String) (defaults to: :trusty)

    a codename or version number

  • storage (Symbol) (defaults to: :ebs)

    storage kind

  • arch (Symbol) (defaults to: :amd64)

    architecture

Returns:

  • (Hash)

    mapping for Ubuntu amis

Raises:

  • (ArgumentError)

    if release is nil, empty or not one of supported values

  • (ArgumentError)

    if storage is nil, empty or not one of supported values

  • (ArgumentError)

    if arch is nil, empty or not one of supported values



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/enscalator/plugins/ubuntu.rb', line 35

def get_mapping(release: :trusty, storage: :ebs, arch: :amd64)
  fail ArgumentError, 'release can be either codename or version' unless RELEASE.to_a.flatten.include? release
  fail ArgumentError, "storage can only be one of #{STORAGE}" unless STORAGE.include? storage
  fail ArgumentError, "arch can only be one of #{ARCH}" unless ARCH.include? arch
  begin
    version = RELEASE.keys.include?(release) ? release : RELEASE.key(release)
    body = open("https://cloud-images.ubuntu.com/query/#{version}/server/released.current.txt") { |f| f.read }
    body.split("\n").map { |m| m.squeeze("\t").split("\t").reject { |r| r.include? 'aki' } }
      .map { |l| Struct::Ubuntu.new(*l) }
      .select { |r| r.root_storage == storage.to_s && r.arch == arch.to_s }
      .group_by(&:region)
      .map { |k, v| [k, v.map { |i| [i.virtualization, i.ami] }.to_h] }
      .to_h
      .with_indifferent_access
  end
end

Instance Method Details

#ubuntu_init(instance_name, storage: :ebs, arch: :amd64, instance_type: 't2.medium', properties: {}) ⇒ Object

Create new Ubuntu instance

Parameters:

  • instance_name (String)

    instance name

  • storage (String) (defaults to: :ebs)

    storage kind (ebs or ephemeral)

  • arch (String) (defaults to: :amd64)

    architecture (amd64 or i386)

  • instance_type (String) (defaults to: 't2.medium')

    instance type



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/enscalator/plugins/ubuntu.rb', line 59

def ubuntu_init(instance_name,
                storage: :ebs,
                arch: :amd64,
                instance_type: 't2.medium', properties: {})

  mapping 'AWSUbuntuAMI', Ubuntu.get_mapping(storage: storage, arch: arch)

  parameter_allocated_storage "Ubuntu#{instance_name}",
                              default: 5,
                              min: 5,
                              max: 1024

  parameter_ec2_instance_type "Ubuntu#{instance_name}", type: instance_type

  instance_vpc "Ubuntu#{instance_name}",
               find_in_map('AWSUbuntuAMI', ref('AWS::Region'), 'hvm'),
               ref_application_subnets.first,
               [ref_private_security_group, ref_application_security_group],
               depends_on: [],
               properties: {
                 KeyName: ref("Ubuntu#{instance_name}KeyName"),
                 InstanceType: ref("Ubuntu#{instance_name}InstanceType")
               }.merge(properties)
end