Permalink
Browse files

Add rdoc

  • Loading branch information...
1 parent 58f0918 commit 4df87d1b64c4ef0f0fa4e39cdd952e7318f76876 @jtimberman committed Nov 11, 2011
Showing with 77 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +10 −0 Rakefile
  3. +46 −0 lib/chef/knife/ec2_amis_ubuntu.rb
  4. +17 −0 lib/ubuntu_ami.rb
  5. +3 −1 ubuntu_ami.gemspec
View
@@ -1,2 +1,3 @@
*.gem
pkg/
+rdoc/
View
@@ -20,6 +20,7 @@ require File.dirname(__FILE__) + '/lib/ubuntu_ami/version'
require 'rubygems'
require 'rubygems/package_task'
+require 'rake/rdoctask'
require 'rake/testtask'
task :default => :test
Rake::TestTask.new
@@ -38,3 +39,12 @@ end
task :uninstall => :package do
sh %{gem uninstall #{GEM_NAME} -x -v #{Ubuntu::Ami::VERSION}}
end
+
+Rake::RDocTask.new do |rdoc|
+ rdoc.title = 'UbuntuAMI API documentation'
+ rdoc.main = 'README.md'
+ rdoc.options << '--fmt' << 'shtml'
+ rdoc.template = 'direct'
+ rdoc.rdoc_files.include("README.md", "LICENSE", "lib/**/*.rb")
+ rdoc.rdoc_dir = 'rdoc'
+end
@@ -31,22 +31,66 @@ class Ec2AmisUbuntu < Chef::Knife
banner "knife ec2 amis ubuntu DISTRO [TYPE] (options)"
+ # 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
def region_fix(region)
region.gsub(/-1/,'').gsub(/-/,'_')
end
+ # 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.
def disk_store(store)
store =~ /ebs/ ? "_ebs" : ''
end
+ # 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".
def size_of(arch)
String(arch) =~ /(amd64|x86_64|large|^64)/ ? "large" : "small"
end
+ # 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 (_).
def build_type(region, arch, root_store)
"#{region_fix(region)}_#{size_of(arch)}#{disk_store(root_store)}"
end
+ # 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.
def list_amis(distro)
amis = Hash.new
Ubuntu.release(distro).amis.each do |ami|
@@ -55,6 +99,8 @@ def list_amis(distro)
amis
end
+ # Runs the plugin. If TYPE (name_args[1]) is passed, then select a
+ # specified type, based on #build_type, above.
def run
distro = name_args[0]
type = name_args[1]
View
@@ -34,6 +34,10 @@ def initialize(release_name)
@release_name = release_name
end
+ # Map the output from Canonical's image list.
+ #
+ # === Returns
+ # Array:: An array of Ubuntu::Ami objects.
def amis
content.map do |line|
Ami.new(
@@ -45,10 +49,22 @@ def amis
end
end
+ # The URL of Canonical's current released AMIs for the given
+ # release.
+ #
+ # Visit "http://uec-images.ubuntu.com/query" to get a list of
+ # available releases.
+ #
+ # === Returns
+ # String:: The full URL to the released AMIs.
def url
"http://uec-images.ubuntu.com/query/#{release_name}/server/released.current.txt"
end
+ # Reads the URL for processing.
+ # === Exception
+ # Raises an exception if the release name was not specified or was
+ # not found.
def content
begin
@content ||= open(url).read.split("\n")
@@ -57,6 +73,7 @@ def content
end
end
+ # Provides accessors for the properties of the AMI list.
class Ami
attr_reader :name, :root_store, :arch, :region, :virtualization_type
View
@@ -4,8 +4,10 @@ Gem::Specification.new do |s|
s.name = 'ubuntu_ami'
s.version = Ubuntu::Ami::VERSION
s.platform = Gem::Platform::RUBY
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README.md", "LICENSE"]
s.summary = "Retrieves AMI information from Canonical's Ubuntu release list."
- s.description = s.summary
+ s.description = s.summary + "Also provides a knife plugin to retrieve the list."
s.author = "Joshua Timberman"
s.email = "joshua@opscode.com"
s.homepage = "http://github.com/jtimberman/ubuntu_ami"

0 comments on commit 4df87d1

Please sign in to comment.