class Tengine::ResourceEc2::LaunchOptions

Constants

DEFAULT_REGION_CAPTIONS
INSTANCE_TYPES
LAUNCH_OPTIONS_KEYS

Attributes

current_region[R]

Public Class Methods

new(credential) click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 5
def initialize(credential)
  @credential = credential
end

Public Instance Methods

availability_zones() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 37
def availability_zones
  # [
  #   {:region_name=>"us-east-1", :zone_name=>"us-east-1a", :zone_state=>"available"},
  #   {:region_name=>"us-east-1", :zone_name=>"us-east-1b", :zone_state=>"available"},
  #   {:region_name=>"us-east-1", :zone_name=>"us-east-1c", :zone_state=>"available"},
  #   {:region_name=>"us-east-1", :zone_name=>"us-east-1d", :zone_state=>"available"}
  # ]
  raw = @connection.describe_availability_zones
  raw.map{|h| h[:zone_name]}.sort
end
images() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 65
def images
  # [
  #   {
  #     :aws_id=>"ami-5189d814",
  #     :aws_architecture=>"i386", :root_device_type=>"instance-store",
  #     :root_device_name=>"/dev/sda1",
  #     :aws_location=>"akm2000-us-west-2/dev-20100521-01.manifest.xml",
  #     :aws_image_type=>"machine", :aws_state=>"available",
  #     :aws_owner=>"892601002221", :aws_is_public=>false,
  #     :aws_kernel_id=>"aki-773c6d32", :aws_ramdisk_id=>"ari-c12e7f84",
  #   },
  # ]
  saved_images = Tengine::Resource::VirtualServerImage.all
  # raw_images = @connection.describe_images_by_owner('self')
  raw_images = @connection.describe_images(saved_images.map(&:provided_id).uniq.compact) #クラスタに登録されているAMI
  # raw_images += @connection.describe_images_by_executable_by("self") # 実行可能なAMI
  amiid_to_hash = raw_images.inject({}){|d, hash| d[hash[:aws_id]] = hash; d}
  result = saved_images.map do |saved_image|
    if ami = amiid_to_hash[saved_image.provided_id]
      {
        'id' => saved_image.id,
        'name' => ami[:aws_id],
        'caption' => saved_image.description,
        'aws_architecture' => ami[:aws_architecture],
        'aws_arch_root_dev' => to_aws_arch_root_dev(ami),
      }
    else
      nil
    end
  end
  result.compact.uniq
end
instance_types() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 98
def instance_types
  # rawなし
  INSTANCE_TYPES
end
kernel_ids() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 103
def kernel_ids
  # [
  #   {
  #     :aws_id=>"aki-233c6d66",
  #     :aws_architecture=>"i386", :root_device_type=>"instance-store",
  #     :aws_location=>"ec2-paid-ibm-images-us-west-1/vmlinuz-2.6.16.60-0.29-xenpae.i386.manifest.xml",
  #     :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"470254534024",
  #     :aws_is_public=>true, :image_owner_alias=>"amazon",
  #   },
  # ]
  raw = amazon_images.select{|img| img[:aws_image_type] == 'kernel'}
  raw.inject({}) do |dest, hash|
    key = hash[:aws_architecture]
    dest[key] ||= []
    dest[key] << hash[:aws_id]
    dest
  end
end
key_pairs() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 48
def key_pairs
  # [{:aws_key_name=>"west-dev01", :aws_fingerprint=>"7c:89:2f:c9:4a:1c:02:65:1b:14:dc:a5:c9:a0:da:fb:46:08:4a:99"}]
  raw = @connection.describe_key_pairs
  raw.map{|h| h[:aws_key_name]}
end
launch_options(connection, current_region) click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 12
def launch_options(connection, current_region)
  @connection, @current_region = connection, current_region
  LAUNCH_OPTIONS_KEYS.map_to_hash{|m| send(m)}
ensure
  @connection, @current_region = nil, nil
end
ramdisk_ids() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 122
def ramdisk_ids
  # [
  #   {
  #     :aws_id=>"ari-2d3c6d68",
  #     :aws_architecture=>"i386", :root_device_type=>"instance-store",
  #     :aws_location=>"ec2-paid-ibm-images-us-west-1/initrd-2.6.16.60-0.29-xenpae.i386.manifest.xml",
  #     :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"470254534024",
  #     :aws_is_public=>true, :image_owner_alias=>"amazon"
  #   },
  # ]
  raw = amazon_images.select{|img| img[:aws_image_type] == 'ramdisk'}
  raw.inject({}) do |dest, hash|
    key = hash[:aws_architecture]
    dest[key] ||= []
    dest[key] << hash[:aws_id]
    dest
  end
end
regions() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 29
def regions
  # ["eu-west-1", "us-east-1", "us-west-1", "ap-southeast-1"]
  raw = @connection.describe_regions
  raw.inject([]) do |dest, region|
    dest << {"name" => region, "caption" => DEFAULT_REGION_CAPTIONS[region]}
  end
end
security_groups() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 54
def security_groups
  # [
  #   { :aws_owner=>"892601002221", :aws_group_name=>"default", :aws_description=>"default group",
  #     :aws_perms=>[{:owner=>"892601002221", :group=>"default"}, {:from_port=>"22", :to_port=>"22", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]},
  #   { :aws_owner=>"892601002221", :aws_group_name=>"ruby-dev", :aws_description=>"for developmewnt with ruby",
  #     :aws_perms=>[{:from_port=>"80", :to_port=>"80", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]}
  # ]
  raw = @connection.describe_security_groups
  raw.map{|h| h[:aws_group_name]}
end

Private Instance Methods

amazon_images() click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 143
def amazon_images
  @amazon_images ||= @connection.describe_images_by_owner('amazon')
end
to_aws_arch_root_dev(hash) click to toggle source
# File lib/tengine/resource_ec2/launch_options.rb, line 148
def to_aws_arch_root_dev(hash)
  "#{hash[:aws_architecture]}_#{hash[:root_device_type]}"
end