Class: Ubuntu

Inherits:
Object
  • Object
show all
Defined in:
lib/ubuntu_ami/version.rb,
lib/ubuntu_ami.rb

Overview

Author

Joshua Timberman (<[email protected]>)

Description

Retrieves AMI information from Canonical’s AMI release list.

Copyright

2011, Joshua Timberman

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Classes: Ami

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(release_name) ⇒ Ubuntu

Returns a new instance of Ubuntu.



33
34
35
# File 'lib/ubuntu_ami.rb', line 33

def initialize(release_name)
  @release_name = release_name
end

Instance Attribute Details

#release_nameObject (readonly)

Returns the value of attribute release_name.



22
23
24
# File 'lib/ubuntu_ami.rb', line 22

def release_name
  @release_name
end

Class Method Details

.instance_for_release(release_name) ⇒ Object



28
29
30
31
# File 'lib/ubuntu_ami.rb', line 28

def self.instance_for_release(release_name)
  @releases ||= {}
  @releases[release_name] ||= new(release_name)
end

.release(release_name) ⇒ Object



24
25
26
# File 'lib/ubuntu_ami.rb', line 24

def self.release(release_name)
  instance_for_release(release_name)
end

Instance Method Details

#amisObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/ubuntu_ami.rb', line 37

def amis
  content.map do |line|
    Ami.new(
            line.split[7],
            line.split[4],
            line.split[5],
            line.split[6],
            line.split[8..9].last)
  end
end

#contentObject



52
53
54
55
56
57
58
# File 'lib/ubuntu_ami.rb', line 52

def content
  begin
    @content ||= open(url).read.split("\n")
  rescue
    raise "Could not find AMI list for distro release '#{release_name}', did you specify it correctly? (e.g., 'lucid')"
  end
end

#urlObject



48
49
50
# File 'lib/ubuntu_ami.rb', line 48

def url
  "http://uec-images.ubuntu.com/query/#{release_name}/server/released.current.txt"
end