ubuntu_ami 0.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -0,0 +1,53 @@
1
+ This gem provides a library for retrieving Canonical's Ubuntu AMI
2
+ release list for Amazon EC2.
3
+
4
+ It also includes a knife plugin to easily retrieve AMIs for launching
5
+ instances with Chef.
6
+
7
+ # Usage
8
+
9
+ Find an AMI based on criteria:
10
+
11
+ ami = Ubuntu.release("lucid").amis.find do |ami|
12
+ ami.arch == "amd64" and
13
+ ami.root_store == "instance-store" and
14
+ ami.region == "us-east-1"
15
+ end
16
+
17
+ Return certain information about the AMIs:
18
+
19
+ Ubuntu.release("lucid").amis.each do |ami|
20
+ puts "#{ami.region} #{ami.name} (#{ami.arch}, #{ami.root_store})"
21
+ end
22
+
23
+ Use the knife plugin with Knife, from Chef. Pass just a distro name
24
+ for the list of available AMIs by type:
25
+
26
+ knife ec2 amis ubuntu lucid
27
+
28
+ The first column will be the available types, and the second is the
29
+ associated AMI. Specify the type to return just the AMI.
30
+
31
+ knife ec2 amis ubuntu lucid us_east_small
32
+
33
+ The type is made up of the region, the architecture size (small for 32
34
+ bit, large for 64 bit). If the AMI is an EBS root store, that will be indicated.
35
+
36
+ # License and Authors
37
+
38
+ Author:: Joshua Timberman (<joshua@housepub.org>)
39
+ Author:: Michael Hale (<mike@hales.ws>)
40
+
41
+ Copyright:: 2011, Joshua Timberman
42
+
43
+ Licensed under the Apache License, Version 2.0 (the "License");
44
+ you may not use this file except in compliance with the License.
45
+ You may obtain a copy of the License at
46
+
47
+ http://www.apache.org/licenses/LICENSE-2.0
48
+
49
+ Unless required by applicable law or agreed to in writing, software
50
+ distributed under the License is distributed on an "AS IS" BASIS,
51
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52
+ See the License for the specific language governing permissions and
53
+ limitations under the License.
@@ -0,0 +1,66 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@housepub.org>)
3
+ # Description:: Retrieves AMI information from Canonical's AMI release list.
4
+ #
5
+ # Copyright:: 2011, Joshua Timberman
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'chef/knife'
20
+
21
+ module KnifePlugins
22
+ class Ec2AmisUbuntu < Chef::Knife
23
+
24
+ deps do
25
+ begin
26
+ require 'ubuntu_ami'
27
+ rescue LoadError
28
+ Chef::Log.error("Could not load Ubuntu AMI library.")
29
+ end
30
+ end
31
+
32
+ banner "knife ec2 amis ubuntu DISTRO [TYPE] (options)"
33
+
34
+ def region_fix(region)
35
+ region.gsub(/-1/,'').gsub(/-/,'_')
36
+ end
37
+
38
+ def disk_store(store)
39
+ store =~ /ebs/ ? "_ebs" : ''
40
+ end
41
+
42
+ def size_of(arch)
43
+ String(arch) =~ /(amd64|x86_64|large|^64)/ ? "large" : "small"
44
+ end
45
+
46
+ def build_type(region, arch, root_store)
47
+ "#{region_fix(region)}_#{size_of(arch)}#{disk_store(root_store)}"
48
+ end
49
+
50
+ def list_amis(distro)
51
+ amis = Hash.new
52
+ Ubuntu.release(distro).amis.each do |ami|
53
+ amis[build_type(ami.region, ami.arch, ami.root_store)] = ami.name
54
+ end
55
+ amis
56
+ end
57
+
58
+ def run
59
+ distro = name_args[0]
60
+ type = name_args[1]
61
+ ami_list = list_amis(distro)[type] || list_amis(distro)
62
+ output(format_for_display(ami_list))
63
+ end
64
+
65
+ end
66
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Joshua Timberman (<joshua@opscode.com>)
2
+ # Author:: Joshua Timberman (<joshua@housepub.org>), Michael Hale (<mike@hales.ws>)
3
3
  # Description:: Retrieves AMI information from Canonical's AMI release list.
4
4
  #
5
5
  # Copyright:: 2011, Joshua Timberman
@@ -16,33 +16,56 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
- require 'pp'
20
19
  require 'open-uri'
21
20
 
22
- class UbuntuAmi
23
- def initialize(release)
24
- @uri = "http://uec-images.ubuntu.com/query/#{release}/server/released.current.txt"
21
+ class Ubuntu
22
+ attr_reader :release_name
23
+
24
+ def self.release(release_name)
25
+ instance_for_release(release_name)
26
+ end
27
+
28
+ def self.instance_for_release(release_name)
29
+ @releases ||= {}
30
+ @releases[release_name] ||= new(release_name)
31
+ end
32
+
33
+ def initialize(release_name)
34
+ @release_name = release_name
25
35
  end
26
36
 
27
- def arch_size(arch)
28
- arch =~ /amd64/ ? "large" : "small"
37
+ def amis
38
+ content.map do |line|
39
+ Ami.new(
40
+ line.split[7],
41
+ line.split[4],
42
+ line.split[5],
43
+ line.split[6],
44
+ line.split[8..9].last)
45
+ end
29
46
  end
30
47
 
31
- def disk_store(store)
32
- "_ebs" if store =~ /ebs/
48
+ def url
49
+ "http://uec-images.ubuntu.com/query/#{release_name}/server/released.current.txt"
33
50
  end
34
51
 
35
- def region_fix(region)
36
- region.gsub(/-1/,'').gsub(/-/,'_')
52
+ def content
53
+ begin
54
+ @content ||= open(url).read.split("\n")
55
+ rescue
56
+ raise "Could not find AMI list for distro release '#{release_name}', did you specify it correctly? (e.g., 'lucid')"
57
+ end
37
58
  end
38
59
 
39
- def run
40
- amis = {}
41
- open(@uri).each do |a|
42
- key = a.split[4..6]
43
- ami = a.split[7]
44
- amis["#{region_fix(key[2])}_#{arch_size(key[1])}#{disk_store(key[0])}"] = ami
60
+ class Ami
61
+ attr_reader :name, :root_store, :arch, :region, :virtualization_type
62
+
63
+ def initialize(name, root_store, arch, region, virtualization_type)
64
+ @name = name
65
+ @root_store = root_store
66
+ @arch = arch
67
+ @region = region
68
+ @virtualization_type = virtualization_type
45
69
  end
46
- amis
47
70
  end
48
71
  end
@@ -0,0 +1,22 @@
1
+ # Author:: Joshua Timberman (<joshua@housepub.org>)
2
+ # Description:: Retrieves AMI information from Canonical's AMI release list.
3
+ #
4
+ # Copyright:: 2011, Joshua Timberman
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ class Ubuntu
19
+ class Ami
20
+ VERSION = '0.4.0'
21
+ end
22
+ end
metadata CHANGED
@@ -1,59 +1,49 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ubuntu_ami
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
4
5
  prerelease:
5
- version: "0.2"
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Joshua Timberman
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-04-23 00:00:00 -06:00
14
- default_executable:
12
+ date: 2011-11-11 00:00:00.000000000Z
15
13
  dependencies: []
16
-
17
14
  description: Retrieves AMI information from Canonical's Ubuntu release list.
18
15
  email: joshua@opscode.com
19
16
  executables: []
20
-
21
17
  extensions: []
22
-
23
18
  extra_rdoc_files: []
24
-
25
- files:
19
+ files:
26
20
  - LICENSE
27
21
  - README.md
28
- - lib/chef/knife/ubuntu_amis.rb
22
+ - lib/chef/knife/ec2_amis_ubuntu.rb
23
+ - lib/ubuntu_ami/version.rb
29
24
  - lib/ubuntu_ami.rb
30
- has_rdoc: true
31
25
  homepage: http://github.com/jtimberman/ubuntu_ami
32
26
  licenses: []
33
-
34
27
  post_install_message:
35
28
  rdoc_options: []
36
-
37
- require_paths:
29
+ require_paths:
38
30
  - lib
39
- required_ruby_version: !ruby/object:Gem::Requirement
31
+ required_ruby_version: !ruby/object:Gem::Requirement
40
32
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
45
- required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
38
  none: false
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: "0"
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
51
43
  requirements: []
52
-
53
44
  rubyforge_project:
54
- rubygems_version: 1.5.2
45
+ rubygems_version: 1.8.10
55
46
  signing_key:
56
47
  specification_version: 3
57
48
  summary: Retrieves AMI information from Canonical's Ubuntu release list.
58
49
  test_files: []
59
-
@@ -1,24 +0,0 @@
1
- require 'chef/knife'
2
-
3
- module KnifePlugins
4
- class Ec2AmisUbuntu < Chef::Knife
5
-
6
- deps do
7
- begin
8
- require 'ubuntu_ami'
9
- rescue LoadError
10
- Chef::Log.error("Could not load Ubuntu AMI library.")
11
- end
12
- end
13
-
14
- banner "knife ec2 amis ubuntu DISTRO [TYPE]"
15
-
16
- def run
17
- distro = name_args[0]
18
- type = name_args[1]
19
- ami_list = UbuntuAmi.new(distro).run[type] || UbuntuAmi.new(distro).run
20
- output(format_for_display(ami_list))
21
- end
22
-
23
- end
24
- end