ubuntu_ami 0.1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/chef/knife/ec2_amis_ubuntu.rb +128 -0
- data/lib/ubuntu_ami.rb +58 -18
- data/lib/ubuntu_ami/version.rb +22 -0
- metadata +29 -47
- data/README.md +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6ea459dc455e28a1196699035bd176a151786f8f6676b3090251fa9a96e3de3f
|
4
|
+
data.tar.gz: f5b91294c206dd5d1fba6089e99c047c45b7a9cb608b6cd405fd2b185cf858b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59a22938260ec46e3e2862c3e9e0fd90eaf113d4342aca98149a247bb1676e65ca581ebdcab7bc3bc511c126f7b76c274e03d63db8ebdb9692ea80b61040944d
|
7
|
+
data.tar.gz: 111894541f28127c505c9a25a85cef92d5f475cba0afdd947d68a320fe0688ad44254c08ca29f021e491f7fff724c10a9ba05d20cb91d453c3bf0aea51eb09db
|
@@ -0,0 +1,128 @@
|
|
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
|
+
# Substitutes dashes for underscores in region portion of type for
|
35
|
+
# nice display. Replaces "1" as implied for most regions.
|
36
|
+
#
|
37
|
+
# === Parameters
|
38
|
+
# region<String>:: comes from Ubuntu::Ami#region
|
39
|
+
#
|
40
|
+
# === Returns
|
41
|
+
# String:: e.g., us_east_small or us_east_small_ebs
|
42
|
+
def region_fix(region)
|
43
|
+
region.gsub(/-1/,'').gsub(/-/,'_')
|
44
|
+
end
|
45
|
+
|
46
|
+
# Identifies the virtualization type as HVM if image is HVM.
|
47
|
+
#
|
48
|
+
# === Parameters
|
49
|
+
# type<String>:: comes from Ubuntu::Ami#virtualization_type
|
50
|
+
#
|
51
|
+
# === Returns
|
52
|
+
# String:: "_hvm" if the #virtualization_type is HVM, otherwise empty.
|
53
|
+
def virt_type(type)
|
54
|
+
type =~ /hvm/ ? "_hvm" : ''
|
55
|
+
end
|
56
|
+
|
57
|
+
# Indicates whether a particular image has EBS root volume.
|
58
|
+
#
|
59
|
+
# === Parameters
|
60
|
+
# store<String>:: comes from Ubuntu::Ami#root_store
|
61
|
+
#
|
62
|
+
# === Returns
|
63
|
+
# String:: "_ebs" if the #root_store is EBS, _ebs_ssd if ebs-ssd,
|
64
|
+
# _ebs_io1 if provisioned IOPS, etc. Otherwise empty.
|
65
|
+
def disk_store(store)
|
66
|
+
if store =~ /ebs/
|
67
|
+
"_#{store.tr('-', '_')}"
|
68
|
+
else
|
69
|
+
''
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Indicates whether the architecture type is a large or small AMI.
|
74
|
+
#
|
75
|
+
# === Parameters
|
76
|
+
# arch<String>:: Values can be amd64, x86_64, large, or begin with
|
77
|
+
# "64". Intended to be from Ubuntu::Ami#arch, but this method
|
78
|
+
# move to Ubuntu directly.
|
79
|
+
#
|
80
|
+
# === Returns
|
81
|
+
# String:: For 64 bit architectures (Ubuntu::Ami#arch #=> amd64),
|
82
|
+
# this will return "large". Otherwise, it returns "small".
|
83
|
+
def size_of(arch)
|
84
|
+
String(arch) =~ /(amd64|x86_64|large|^64)/ ? "large" : "small"
|
85
|
+
end
|
86
|
+
|
87
|
+
# Makes a nice string for the type of AMI to display, including
|
88
|
+
# the region, architecture size and whether the AMI has EBS root
|
89
|
+
# store.
|
90
|
+
#
|
91
|
+
# === Parameters
|
92
|
+
# region<String>:: from Ubuntu::Ami#region
|
93
|
+
# arch<String>:: from Ubuntu::Ami#arch
|
94
|
+
# root_store<String>:: from Ubuntu::Ami#root_store
|
95
|
+
#
|
96
|
+
# === Returns
|
97
|
+
# String:: The region, arch and root_store (if EBS) concatenated
|
98
|
+
# with underscore (_).
|
99
|
+
def build_type(region, arch, root_store, type)
|
100
|
+
"#{region_fix(region)}_#{size_of(arch)}#{disk_store(root_store)}#{virt_type(type)}"
|
101
|
+
end
|
102
|
+
|
103
|
+
# Iterates over the AMIs available for the specified distro.
|
104
|
+
#
|
105
|
+
# === Parameters
|
106
|
+
# distro<String>:: Release name of the distro to display.
|
107
|
+
#
|
108
|
+
# === Returns
|
109
|
+
# Hash:: Keys are the AMI type, values are the AMI ID.
|
110
|
+
def list_amis(distro)
|
111
|
+
amis = Hash.new
|
112
|
+
Ubuntu.release(distro).amis.each do |ami|
|
113
|
+
amis[build_type(ami.region, ami.arch, ami.root_store, ami.virtualization_type)] = ami.name
|
114
|
+
end
|
115
|
+
amis
|
116
|
+
end
|
117
|
+
|
118
|
+
# Runs the plugin. If TYPE (name_args[1]) is passed, then select a
|
119
|
+
# specified type, based on #build_type, above.
|
120
|
+
def run
|
121
|
+
distro = name_args[0]
|
122
|
+
type = name_args[1]
|
123
|
+
ami_list = list_amis(distro)[type] || list_amis(distro)
|
124
|
+
output(format_for_display(ami_list))
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
data/lib/ubuntu_ami.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Joshua Timberman (<joshua@
|
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,73 @@
|
|
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
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
37
|
+
# Map the output from Canonical's image list.
|
38
|
+
#
|
39
|
+
# === Returns
|
40
|
+
# Array:: An array of Ubuntu::Ami objects.
|
41
|
+
def amis
|
42
|
+
content.map do |line|
|
43
|
+
Ami.new(
|
44
|
+
line.split[7],
|
45
|
+
line.split[4],
|
46
|
+
line.split[5],
|
47
|
+
line.split[6],
|
48
|
+
line.split[8..9].last)
|
49
|
+
end
|
29
50
|
end
|
30
51
|
|
31
|
-
|
32
|
-
|
52
|
+
# The URL of Canonical's current released AMIs for the given
|
53
|
+
# release.
|
54
|
+
#
|
55
|
+
# Visit "http://uec-images.ubuntu.com/query" to get a list of
|
56
|
+
# available releases.
|
57
|
+
#
|
58
|
+
# === Returns
|
59
|
+
# String:: The full URL to the released AMIs.
|
60
|
+
def url
|
61
|
+
"http://uec-images.ubuntu.com/query/#{release_name}/server/released.current.txt"
|
33
62
|
end
|
34
63
|
|
35
|
-
|
36
|
-
|
64
|
+
# Reads the URL for processing.
|
65
|
+
# === Exception
|
66
|
+
# Raises an exception if the release name was not specified or was
|
67
|
+
# not found.
|
68
|
+
def content
|
69
|
+
begin
|
70
|
+
@content ||= ::OpenURI.open_uri(url).read.split("\n")
|
71
|
+
rescue
|
72
|
+
raise "Could not find AMI list for distro release '#{release_name}', did you specify it correctly? (e.g., 'lucid')"
|
73
|
+
end
|
37
74
|
end
|
38
75
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
76
|
+
# Provides accessors for the properties of the AMI list.
|
77
|
+
class Ami
|
78
|
+
attr_reader :name, :root_store, :arch, :region, :virtualization_type
|
79
|
+
|
80
|
+
def initialize(name, root_store, arch, region, virtualization_type)
|
81
|
+
@name = name
|
82
|
+
@root_store = root_store
|
83
|
+
@arch = arch
|
84
|
+
@region = region
|
85
|
+
@virtualization_type = virtualization_type
|
45
86
|
end
|
46
|
-
amis
|
47
87
|
end
|
48
88
|
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.3'
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,65 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ubuntu_ami
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
version: "0.1"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.3
|
9
5
|
platform: ruby
|
10
|
-
authors:
|
6
|
+
authors:
|
11
7
|
- Joshua Timberman
|
12
|
-
autorequire:
|
8
|
+
autorequire:
|
13
9
|
bindir: bin
|
14
10
|
cert_chain: []
|
15
|
-
|
16
|
-
date: 2011-01-27 00:00:00 -07:00
|
17
|
-
default_executable:
|
11
|
+
date: 2020-08-18 00:00:00.000000000 Z
|
18
12
|
dependencies: []
|
19
|
-
|
20
|
-
|
21
|
-
email: joshua@
|
13
|
+
description: Retrieves AMI information from Canonical's Ubuntu release list.Also provides
|
14
|
+
a knife plugin to retrieve the list.
|
15
|
+
email: joshua@chef.io
|
22
16
|
executables: []
|
23
|
-
|
24
17
|
extensions: []
|
25
|
-
|
26
18
|
extra_rdoc_files: []
|
27
|
-
|
28
|
-
files:
|
19
|
+
files:
|
29
20
|
- LICENSE
|
30
|
-
-
|
21
|
+
- lib/chef/knife/ec2_amis_ubuntu.rb
|
31
22
|
- lib/ubuntu_ami.rb
|
32
|
-
|
33
|
-
homepage:
|
34
|
-
licenses:
|
35
|
-
|
36
|
-
|
23
|
+
- lib/ubuntu_ami/version.rb
|
24
|
+
homepage: https://github.com/jtimberman/ubuntu_ami
|
25
|
+
licenses:
|
26
|
+
- Apache-2.0
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
37
29
|
rdoc_options: []
|
38
|
-
|
39
|
-
require_paths:
|
30
|
+
require_paths:
|
40
31
|
- lib
|
41
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
|
43
|
-
requirements:
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
44
34
|
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
52
39
|
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
55
|
-
- 0
|
56
|
-
version: "0"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
57
42
|
requirements: []
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
signing_key:
|
62
|
-
specification_version: 3
|
43
|
+
rubygems_version: 3.1.2
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
63
46
|
summary: Retrieves AMI information from Canonical's Ubuntu release list.
|
64
47
|
test_files: []
|
65
|
-
|
data/README.md
DELETED
File without changes
|