Class: Ironfan::Dsl::Ec2

Inherits:
Cloud show all
Defined in:
lib/ironfan/dsl/ec2.rb,
lib/ironfan/headers.rb

Defined Under Namespace

Classes: ElasticLoadBalancer, IamServerCertificate, SecurityGroup

Instance Attribute Summary

Attributes included from Gorillib::Resolution

#underlay

Instance Method Summary collapse

Methods inherited from Cloud

#defaults, receive

Methods inherited from Ironfan::Dsl

#_skip_fields, #skip_fields, #to_manifest

Methods included from Gorillib::Resolution

#deep_resolve, #merge_resolve, #merge_values, #read_resolved_attribute, #read_set_attribute, #read_set_or_underlay_attribute, #read_underlay_attribute, #resolve, #resolve!, #resolve_value

Methods included from CookbookRequirements

#_cookbook_reqs, #children, #cookbook_req, #cookbook_reqs, #join_req

Methods inherited from Builder

ui, #ui

Instance Method Details

#default_regionObject



59
60
61
# File 'lib/ironfan/dsl/ec2.rb', line 59

def default_region
  default_availability_zone ? default_availability_zone.gsub(/^(\w+-\w+-\d)[a-z]/, '\1') : nil
end

#domainObject



41
# File 'lib/ironfan/dsl/ec2.rb', line 41

def domain;                       vpc.nil? ? 'standard' : 'vpc';       end

#flavor_infoObject



74
75
76
77
78
79
80
81
# File 'lib/ironfan/dsl/ec2.rb', line 74

def flavor_info
  if not Chef::Config[:ec2_flavor_info].has_key?(flavor)
    ui.warn("Unknown machine image flavor '#{flavor}'")
    list_flavors
    return nil
  end
  Chef::Config[:ec2_flavor_info][flavor]
end

#image_idObject



51
52
53
# File 'lib/ironfan/dsl/ec2.rb', line 51

def image_id
  result = read_attribute(:image_id) || image_info[:image_id]
end

#image_infoObject



43
44
45
46
47
48
49
# File 'lib/ironfan/dsl/ec2.rb', line 43

def image_info
  bit_str = "#{self.bits.to_i}-bit" # correct for legacy image info.
  keys = [region, bit_str, backing, image_name]
  info = Chef::Config[:ec2_image_info][ keys ]
  ui.warn("Can't find image for #{[region, bit_str, backing, image_name].inspect}") if info.blank?
  return info || {}
end

#implied_volumesObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ironfan/dsl/ec2.rb', line 83

def implied_volumes
  result = []
  if backing == 'ebs'
    result << Ironfan::Dsl::Volume.new(:name => 'root') do
      device              '/dev/sda1'
      fstype              'ext4'
      keep                false
      mount_point         '/'
    end
  end
  return result unless (mount_ephemerals and (flavor_info[:ephemeral_volumes] > 0))

  layout = {  0 => ['/dev/sdb','/mnt'],
              1 => ['/dev/sdc','/mnt2'],
              2 => ['/dev/sdd','/mnt3'],
              3 => ['/dev/sde','/mnt4']   }
  ( 0 .. (flavor_info[:ephemeral_volumes]-1) ).each do |idx|
    dev, mnt = layout[idx]
    ephemeral = Ironfan::Dsl::Volume.new(:name => "ephemeral#{idx}") do
      attachable          'ephemeral'
      fstype              'ext3'
      device              dev
      mount_point         mnt
      mount_options       'defaults,noatime'
      tags({:bulk => true, :local => true, :fallback => true})
    end
    ephemeral_attrs = mount_ephemerals.clone
    if ephemeral_attrs.has_key?(:disks)
      disk_attrs = mount_ephemerals[:disks][idx] || { }
      ephemeral_attrs.delete(:disks)
      ephemeral_attrs.merge!(disk_attrs)
    end
    ephemeral.receive! ephemeral_attrs
    result << ephemeral
  end
  result
end

#receive_provider(obj) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/ironfan/dsl/ec2.rb', line 121

def receive_provider(obj)
  if obj.is_a?(String)
    write_attribute :provider, Gorillib::Inflector.constantize(Gorillib::Inflector.camelize(obj.gsub(/\./, '/')))
  else
    super(obj)
  end
end

#ssh_key_name(computer) ⇒ Object



55
56
57
# File 'lib/ironfan/dsl/ec2.rb', line 55

def ssh_key_name(computer)
  keypair ? keypair.to_s : computer.server.keypair_name
end

#to_display(style, values = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/ironfan/dsl/ec2.rb', line 63

def to_display(style,values={})
  return values if style == :minimal

  values["Flavor"] =            flavor
  values["AZ"] =                default_availability_zone
  return values if style == :default

  values["Public IP"] =        elastic_ip if elastic_ip
  values
end