class KnifePlugins::Ec2AmisUbuntu

Public Instance Methods

build_type(region, arch, root_store, type) click to toggle source

Makes a nice string for the type of AMI to display, including the region, architecture size and whether the AMI has EBS root store.

Parameters

region<String>

from Ubuntu::Ami#region

arch<String>

from Ubuntu::Ami#arch

root_store<String>

from Ubuntu::Ami#root_store

Returns

String

The region, arch and root_store (if EBS) concatenated

with underscore (_).

# File lib/chef/knife/ec2_amis_ubuntu.rb, line 99
def build_type(region, arch, root_store, type)
  "#{region_fix(region)}_#{size_of(arch)}#{disk_store(root_store)}#{virt_type(type)}"
end
disk_store(store) click to toggle source

Indicates whether a particular image has EBS root volume.

Parameters

store<String>

comes from Ubuntu::Ami#root_store

Returns

String

“_ebs” if the root_store is EBS, _ebs_ssd if ebs-ssd,

_ebs_io1 if provisioned IOPS, etc. Otherwise empty.

# File lib/chef/knife/ec2_amis_ubuntu.rb, line 65
def disk_store(store)
  if store =~ /ebs/
    "_#{store.tr('-', '_')}"
  else
    ''
  end
end
list_amis(distro) click to toggle source

Iterates over the AMIs available for the specified distro.

Parameters

distro<String>

Release name of the distro to display.

Returns

Hash

Keys are the AMI type, values are the AMI ID.

# File lib/chef/knife/ec2_amis_ubuntu.rb, line 110
def list_amis(distro)
  amis = Hash.new
  Ubuntu.release(distro).amis.each do |ami|
    amis[build_type(ami.region, ami.arch, ami.root_store, ami.virtualization_type)] = ami.name
  end
  amis
end
region_fix(region) click to toggle source

Substitutes dashes for underscores in region portion of type for nice display. Replaces “1” as implied for most regions.

Parameters

region<String>

comes from Ubuntu::Ami#region

Returns

String

e.g., us_east_small or us_east_small_ebs

# File lib/chef/knife/ec2_amis_ubuntu.rb, line 42
def region_fix(region)
  region.gsub(/-1/,'').gsub(/-/,'_')
end
run() click to toggle source

Runs the plugin. If TYPE (name_args) is passed, then select a specified type, based on build_type, above.

# File lib/chef/knife/ec2_amis_ubuntu.rb, line 120
def run
  distro = name_args[0]
  type = name_args[1]
  ami_list = list_amis(distro)[type] || list_amis(distro)
  output(format_for_display(ami_list))
end
size_of(arch) click to toggle source

Indicates whether the architecture type is a large or small AMI.

Parameters

arch<String>

Values can be amd64, x86_64, large, or begin with

“64”. Intended to be from Ubuntu::Ami#arch, but this method move to Ubuntu directly.

Returns

String

For 64 bit architectures (Ubuntu::Ami#arch #=> amd64),

this will return “large”. Otherwise, it returns “small”.

# File lib/chef/knife/ec2_amis_ubuntu.rb, line 83
def size_of(arch)
  String(arch) =~ /(amd64|x86_64|large|^64)/ ? "large" : "small"
end
virt_type(type) click to toggle source

Identifies the virtualization type as HVM if image is HVM.

Parameters

type<String>

comes from Ubuntu::Ami#virtualization_type

Returns

String

“_hvm” if the virtualization_type is HVM, otherwise empty.

# File lib/chef/knife/ec2_amis_ubuntu.rb, line 53
def virt_type(type)
  type =~ /hvm/ ? "_hvm" : ''
end