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

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

Overview

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_image(driver, image) ⇒ Windows?

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:

  • (Windows, nil)

    a platform when the image is Windows Server, otherwise nil



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/kitchen/driver/aws/standard_platform/windows.rb', line 94

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

  # 2008 R2 SP2
  if image.name =~ /(\b\d+)\W*(r\d+)?/i
    major = (Regexp.last_match || [])[1]
    revision = (Regexp.last_match || [])[2]
    service_pack = (Regexp.last_match || [])[1] if image.name =~ /(sp\d+|rtm)/i
    revision = revision.downcase if revision
    service_pack ||= "rtm"
    service_pack = service_pack.downcase
    version = "#{major}#{revision}#{service_pack}"
  end

  new(driver, "windows", version, image.architecture)
end

Instance Method Details

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

EC2 image filters that select Amazon's Windows Server AMIs.

Windows AMI names encode the release, an optional revision ("R2") and an optional service pack, and the naming scheme changed with Server 2016. The requested version is decomposed by #windows_version_parts and turned into whichever set of name patterns can match it:

"windows"          Windows_Server-*-RTM-, -SP*-, -R*_RTM-,
                   -R*_SP*-, and Windows_Server-*-Full-Base-*
"windows-2012"     Windows_Server-2012-RTM-, -2012-SP*-
"windows-2012r2"   Windows_Server-2012-R2_RTM-, -R2_SP*-
"windows-2012sp1"  Windows_Server-2012-SP1-
"windows-2012r2sp1" Windows_Server-2012-R2_SP1-
"windows-2016"     Windows_Server-2016-English-Full-Base-*
"windows-2019"     Windows_Server-2019-English-Full-Base-*

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

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/windows.rb', line 59

def image_search
  search = {
    "owner-alias" => "amazon",
    "name" => windows_name_filter,
  }
  search["architecture"] = architecture if architecture
  search
end

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

Sort images newest release first.

Windows versions cannot be compared as numbers -- "2012r2" is newer than "2012" but older than "2016" -- so each image is reduced to a [major, revision, service_pack] tuple and those are compared instead.

Parameters:

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

    the images to sort

Returns:

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

    the images, newest release first



77
78
79
80
81
82
83
84
# File 'lib/kitchen/driver/aws/standard_platform/windows.rb', line 77

def sort_by_version(images)
  # 2008r2rtm -> [ img1, img2, img3 ]
  # 2012r2sp1 -> [ img4, img5 ]
  # ...
  images.group_by { |image| self.class.from_image(driver, image).windows_version_parts }
    .sort_by { |version, _platform_images| version }
    .reverse.flat_map { |_version, platform_images| platform_images }
end

#usernameString

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

Used as the SSH username when the transport does not specify one.

Returns:

  • (String)

    the default SSH username



31
32
33
# File 'lib/kitchen/driver/aws/standard_platform/windows.rb', line 31

def username
  "administrator"
end