Class: KnifePlugins::Ec2AmisUbuntu
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- KnifePlugins::Ec2AmisUbuntu
- Defined in:
- lib/chef/knife/ec2_amis_ubuntu.rb
Instance Method Summary collapse
-
#build_type(region, arch, root_store) ⇒ Object
Makes a nice string for the type of AMI to display, including the region, architecture size and whether the AMI has EBS root store.
-
#disk_store(store) ⇒ Object
Indicates whether a particular image has EBS root volume.
-
#list_amis(distro) ⇒ Object
Iterates over the AMIs available for the specified distro.
-
#region_fix(region) ⇒ Object
Substitutes dashes for underscores in region portion of type for nice display.
-
#run ⇒ Object
Runs the plugin.
-
#size_of(arch) ⇒ Object
Indicates whether the architecture type is a large or small AMI.
Instance Method Details
#build_type(region, arch, root_store) ⇒ Object
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 (_).
83 84 85 |
# File 'lib/chef/knife/ec2_amis_ubuntu.rb', line 83 def build_type(region, arch, root_store) "#{region_fix(region)}_#{size_of(arch)}#{disk_store(root_store)}" end |
#disk_store(store) ⇒ Object
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, otherwise empty.
53 54 55 |
# File 'lib/chef/knife/ec2_amis_ubuntu.rb', line 53 def disk_store(store) store =~ /ebs/ ? "_ebs" : '' end |
#list_amis(distro) ⇒ Object
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.
94 95 96 97 98 99 100 |
# File 'lib/chef/knife/ec2_amis_ubuntu.rb', line 94 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.name end amis end |
#region_fix(region) ⇒ Object
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
42 43 44 |
# File 'lib/chef/knife/ec2_amis_ubuntu.rb', line 42 def region_fix(region) region.gsub(/-1/,'').gsub(/-/,'_') end |
#run ⇒ Object
Runs the plugin. If TYPE (name_args) is passed, then select a specified type, based on #build_type, above.
104 105 106 107 108 109 |
# File 'lib/chef/knife/ec2_amis_ubuntu.rb', line 104 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) ⇒ Object
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”.
67 68 69 |
# File 'lib/chef/knife/ec2_amis_ubuntu.rb', line 67 def size_of(arch) String(arch) =~ /(amd64|x86_64|large|^64)/ ? "large" : "small" end |