Class: Kitchen::Driver::Aws::StandardPlatform

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/driver/aws/standard_platform.rb,
lib/kitchen/driver/aws/standard_platform/rhel.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/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 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: https://alestic.com/2014/01/ec2-ssh-username/

Direct Known Subclasses

Centos, Debian, El, Fedora, Freebsd, Ubuntu, Windows

Defined Under Namespace

Classes: Centos, Debian, El, Fedora, Freebsd, Ubuntu, Windows

Constant Summary collapse

ARCHITECTURE =

The list of supported architectures

%w[x86_64 i386 i86pc sun4v powerpc]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver, name, version, architecture) ⇒ StandardPlatform

Create a new StandardPlatform object.

Parameters:

  • driver (Kitchen::Driver::Ec2)

    The driver.

  • name (String)

    The name of the platform (rhel, centos, etc.)

  • version (String)

    The version of the platform (7.1, 2008sp1, etc.)

  • architecture (String)

    The architecture (i386, x86_64)



35
36
37
38
39
40
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 35

def initialize(driver, name, version, architecture)
  @driver = driver
  @name = name
  @version = version
  @architecture = architecture
end

Instance Attribute Details

#architectureString (readonly)

The architecture of the platform, e.g. i386, x86_64

Returns:

  • (String)

See Also:

  • ARCHITECTURES


70
71
72
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 70

def architecture
  @architecture
end

#driverKitchen::Driver::Ec2 (readonly)

The driver.



47
48
49
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 47

def driver
  @driver
end

#nameString (readonly)

The name of the platform (e.g. rhel, centos, etc.)

Returns:

  • (String)


54
55
56
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 54

def name
  @name
end

#versionString (readonly)

The version of the platform (e.g. 7.1, 2008sp1, etc.)

Returns:

  • (String)


61
62
63
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 61

def version
  @version
end

Class Method Details

.from_image(driver, image) ⇒ Kitchen::Driver::Aws::StandardPlatform

Detect platform from an image.

Parameters:

Returns:



130
131
132
133
134
135
136
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 130

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.

Parameters:

  • driver (Kitchen::Driver::Ec2)

    The driver.

  • platform_string (String)

    The platform string, e.g. "windows", "ubuntu-7.1", "centos-7-i386"

Returns:



115
116
117
118
119
120
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 115

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

.platformsObject

The list of StandardPlatform objects. StandardPlatforms register themselves with this.



98
99
100
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 98

def self.platforms
  @platforms ||= {}
end

Instance Method Details

#find_image(image_search) ⇒ String

Find the best matching image for the given image search.

Returns:

  • (String)

    The image ID (e.g. ami-213984723)



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 76

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_sObject



102
103
104
# File 'lib/kitchen/driver/aws/standard_platform.rb', line 102

def to_s
  "#{name}#{version ? " #{version}" : ""}#{architecture ? " #{architecture}" : ""}"
end