Class: Kitchen::Driver::Aws::StandardPlatform
- Inherits:
-
Object
- Object
- Kitchen::Driver::Aws::StandardPlatform
- Defined in:
- lib/kitchen/driver/aws/standard_platform.rb,
lib/kitchen/driver/aws/standard_platform/rhel.rb,
lib/kitchen/driver/aws/standard_platform/macos.rb,
lib/kitchen/driver/aws/standard_platform/amazon.rb,
lib/kitchen/driver/aws/standard_platform/centos.rb,
lib/kitchen/driver/aws/standard_platform/debian.rb,
lib/kitchen/driver/aws/standard_platform/fedora.rb,
lib/kitchen/driver/aws/standard_platform/ubuntu.rb,
lib/kitchen/driver/aws/standard_platform/amazon2.rb,
lib/kitchen/driver/aws/standard_platform/freebsd.rb,
lib/kitchen/driver/aws/standard_platform/windows.rb
Overview
Lets you grab StandardPlatform objects that help search for official AMIs in your region and tell you useful tidbits like usernames.
To use these, set your platform name to a supported platform name like:
centos rhel fedora freebsd macos ubuntu windows
The implementation will select the latest matching version and AMI.
You can specify a version and optional architecture as well:
windows-2012r2-i386 centos-7
Useful reference for platform AMIs: alestic.com/2014/01/ec2-ssh-username/
Direct Known Subclasses
Amazon, Amazon2, Centos, Debian, El, Fedora, Freebsd, MacOS, Ubuntu, Windows
Defined Under Namespace
Classes: Amazon, Amazon2, Centos, Debian, El, Fedora, Freebsd, MacOS, Ubuntu, Windows
Constant Summary collapse
- SUPPORTED_ARCHITECTURES =
The list of supported architectures
%w{x86_64 i386 arm64}.freeze
Instance Attribute Summary collapse
-
#architecture ⇒ String
readonly
The architecture of the platform, e.g.
-
#driver ⇒ Kitchen::Driver::Ec2
readonly
The driver.
-
#name ⇒ String
readonly
The name of the platform (e.g. rhel, centos, etc.).
-
#version ⇒ String
readonly
The version of the platform (e.g. 7.1, 2008sp1, etc.).
Class Method Summary collapse
-
.from_image(driver, image) ⇒ Kitchen::Driver::Aws::StandardPlatform
Detect platform from an image.
-
.from_platform_string(driver, platform_string) ⇒ Kitchen::Driver::Aws::StandardPlatform
Instantiate a platform from a platform name.
-
.platforms ⇒ Object
The list of StandardPlatform objects.
Instance Method Summary collapse
-
#find_image(image_search) ⇒ String
Find the best matching image for the given image search.
-
#initialize(driver, name, version, architecture) ⇒ StandardPlatform
constructor
Create a new StandardPlatform object.
- #to_s ⇒ Object
Constructor Details
#initialize(driver, name, version, architecture) ⇒ StandardPlatform
Create a new StandardPlatform object.
52 53 54 55 56 57 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 52 def initialize(driver, name, version, architecture) @driver = driver @name = name @version = version @architecture = architecture end |
Instance Attribute Details
#architecture ⇒ String (readonly)
The architecture of the platform, e.g. i386, x86_64
87 88 89 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 87 def architecture @architecture end |
#driver ⇒ Kitchen::Driver::Ec2 (readonly)
The driver.
64 65 66 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 64 def driver @driver end |
#name ⇒ String (readonly)
The name of the platform (e.g. rhel, centos, etc.)
71 72 73 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 71 def name @name end |
#version ⇒ String (readonly)
The version of the platform (e.g. 7.1, 2008sp1, etc.)
78 79 80 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 78 def version @version end |
Class Method Details
.from_image(driver, image) ⇒ Kitchen::Driver::Aws::StandardPlatform
Detect platform from an image.
152 153 154 155 156 157 158 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 152 def self.from_image(driver, image) platforms.each_value do |platform| result = platform.from_image(driver, image) return result if result end nil end |
.from_platform_string(driver, platform_string) ⇒ Kitchen::Driver::Aws::StandardPlatform
Instantiate a platform from a platform name.
137 138 139 140 141 142 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 137 def self.from_platform_string(driver, platform_string) platform, version, architecture = parse_platform_string(platform_string) if platform && platforms[platform] platforms[platform].new(driver, platform, version, architecture) end end |
.platforms ⇒ Object
The list of StandardPlatform objects. StandardPlatforms register themselves with this.
120 121 122 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 120 def self.platforms @platforms ||= {} end |
Instance Method Details
#find_image(image_search) ⇒ String
Find the best matching image for the given image search.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 98 def find_image(image_search) driver.debug("Searching for images matching #{image_search} ...") # Convert to ec2 search format (pairs of name+values) filters = image_search.map do |key, value| { name: key.to_s, values: Array(value).map(&:to_s) } end # We prefer most recent first images = driver.ec2.resource.images(filters: filters) images = sort_images(images) show_returned_images(images) # Grab the best match images.first && images.first.id end |
#to_s ⇒ Object
124 125 126 |
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 124 def to_s "#{name}#{version ? " #{version}" : ""}#{architecture ? " #{architecture}" : ""}" end |