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

Inherits:
StandardPlatform
  • Object
show all
Defined in:
lib/kitchen/driver/aws/standard_platform/rhel.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver, _name, version, architecture) ⇒ El

Build a Red Hat Enterprise Linux platform.

This class is registered under both "rhel" and "el", so the name it was constructed with is discarded and normalized to "rhel".

Parameters:

  • driver (Kitchen::Driver::Ec2)

    the driver

  • _name (String)

    the registered name, ignored

  • version (String, nil)

    the requested version, e.g. "9.4"

  • architecture (String, nil)

    the requested architecture



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

def initialize(driver, _name, version, architecture)
  # rhel = el
  super(driver, "rhel", version, architecture)
end

Class Method Details

.from_image(driver, image) ⇒ El?

Detect this platform from an EC2 image.

Matching is done on the image name, which is the only reliable signal EC2 exposes about what an AMI actually contains.

Parameters:

  • driver (Kitchen::Driver::Ec2)

    the driver requesting detection

  • image (Aws::EC2::Image)

    the image to inspect

Returns:

  • (El, nil)

    a platform when the image is Red Hat Enterprise Linux, otherwise nil



76
77
78
79
80
81
# File 'lib/kitchen/driver/aws/standard_platform/rhel.rb', line 76

def self.from_image(driver, image)
  return unless /rhel/i.match?(image.name)

  image.name =~ /\b(\d+(\.\d+)?)/i
  new(driver, "rhel", (Regexp.last_match || [])[1], image.architecture)
end

Instance Method Details

#image_searchHash{String => String, Array<String>}

EC2 image filters that select Red Hat Enterprise Linux AMIs published by Red Hat.

A filter is added for Kitchen::Driver::Aws::StandardPlatform#architecture only when one was requested, so that an unspecified architecture matches any of them.

Returns:

  • (Hash{String => String, Array<String>})

    filter name to the value or values it must match

See Also:



59
60
61
62
63
64
65
66
# File 'lib/kitchen/driver/aws/standard_platform/rhel.rb', line 59

def image_search
  search = {
    "owner-id" => "309956199498",
    "name" => "RHEL-#{version}*",
  }
  search["architecture"] = architecture if architecture
  search
end

#sort_by_version(images) ⇒ Array<Aws::EC2::Image>

Sort images newest release first, preferring generally available releases over betas.

A Beta AMI carries a higher version number than the current GA release, so a plain version sort would select it. Betas are pushed to the back after sorting.

Parameters:

  • images (Array<Aws::EC2::Image>)

    the images to sort

Returns:

  • (Array<Aws::EC2::Image>)

    the images, best match first



92
93
94
95
96
97
98
# File 'lib/kitchen/driver/aws/standard_platform/rhel.rb', line 92

def sort_by_version(images)
  # `prefer(super)`, not `super(images)` followed by
  # `prefer(images)`: `prefer` returns a new array rather than
  # reordering in place, so applying it to the original argument
  # discarded the version sort entirely.
  prefer(super) { |image| !image.name.match?(/_Beta-/i) }
end

#usernameString

The account EC2 creates on this platform's official AMIs.

RHEL only gained the unprivileged "ec2-user" account in 6.4; earlier releases are logged into as root.

Returns:

  • (String)

    the default SSH username



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

def username
  version && version.to_f < 6.4 ? "root" : "ec2-user"
end