Class: Kitchen::Driver::Aws::StandardPlatform::Windows
- Inherits:
-
StandardPlatform
- Object
- StandardPlatform
- Kitchen::Driver::Aws::StandardPlatform::Windows
- Defined in:
- lib/kitchen/driver/aws/standard_platform/windows.rb
Overview
Class Method Summary collapse
-
.from_image(driver, image) ⇒ Windows?
Detect this platform from an EC2 image.
Instance Method Summary collapse
-
#image_search ⇒ Hash{String => String, Array<String>}
EC2 image filters that select Amazon's Windows Server AMIs.
-
#sort_by_version(images) ⇒ Array<Aws::EC2::Image>
Sort images newest release first.
-
#username ⇒ String
The account EC2 creates on this platform's official AMIs.
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.
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_search ⇒ Hash{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.
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.
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 |
#username ⇒ String
The account EC2 creates on this platform's official AMIs.
Used as the SSH username when the transport does not specify one.
31 32 33 |
# File 'lib/kitchen/driver/aws/standard_platform/windows.rb', line 31 def username "administrator" end |