knife-ec2 2.0.3 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0792e566da930105ef238d8d64cb2fe79501895dcace746aa1a255b3e9d4a7f5'
4
- data.tar.gz: 9078a6bb126100a28800abc87cd20d0344b33cbe090303795f414a9523e427d3
3
+ metadata.gz: 02d8b51f3d7816f686f27c4c29def2a77a68b01fa1b7f355f52bd197260eb39c
4
+ data.tar.gz: 49d8c7158eb351a7d28b51b65c1b783ed310952ef19184f9d202886db126a2aa
5
5
  SHA512:
6
- metadata.gz: 4992729a869dd890f29f7d1d52cf957a4faf4d806f295abd62e760e60e0f9cb2916984c5f06e93538e362e39b71db2b9b56e8f2778661b04dafc6949b681e75d
7
- data.tar.gz: a9f75d6fd86635c9cd67dcd50fc52ed5aae503d8004e212f53fc9d87f0b7159936a4f274b996e56a829cf28e04758c08b34e555c63096412553646561ca6142f
6
+ metadata.gz: ddab9d29dc217b890ba188904e1204112b140c9aa21f7e811306d0c92fee3d96ba33a47c25ea9deeedf6ff8bbc993fc83fc7dbe29bd6a0d271e9bdb55dee2e07
7
+ data.tar.gz: 3b2e99e4c7f2d0d11902f6f284412f9e21591798928dcc6d4242a4d054490bc4af8e0388313aefa2a8f6be41ca184e2e05821c631af7dfd45da6c9ba9aafc80f
@@ -28,9 +28,9 @@ class Chef
28
28
  include Knife::Ec2Base
29
29
 
30
30
  deps do
31
- require "tempfile"
32
- require "uri"
33
- require "net/ssh"
31
+ require "tempfile" unless defined?(Tempfile)
32
+ require "uri" unless defined?(URI)
33
+ require "net/ssh" unless defined?(Net::SSH)
34
34
  require "net/ssh/gateway"
35
35
  Chef::Knife::Bootstrap.load_deps
36
36
  end
@@ -104,9 +104,11 @@ class Chef
104
104
  long: "--ebs-optimized",
105
105
  description: "Enabled optimized EBS I/O"
106
106
 
107
- option :ebs_no_delete_on_term,
108
- long: "--ebs-no-delete-on-term",
109
- description: "Do not delete EBS volume on instance termination"
107
+ option :ebs_delete_on_term,
108
+ long: "--ebs-delete-on-term",
109
+ description: "Delete EBS volume on instance termination",
110
+ boolean: true,
111
+ default: true
110
112
 
111
113
  option :secret,
112
114
  long: "--secret ",
@@ -624,12 +626,18 @@ class Chef
624
626
  exit 1
625
627
  end
626
628
 
627
- if config[:ebs_volume_type] && ! %w{gp2 io1 standard}.include?(config[:ebs_volume_type])
628
- ui.error("--ebs-volume-type must be 'standard' or 'io1' or 'gp2'")
629
+ if config[:ebs_volume_type] && ! %w{gp2 io1 standard st1 sc1}.include?(config[:ebs_volume_type])
630
+ ui.error("--ebs-volume-type must be 'standard' or 'io1' or 'gp2' or 'st1' or 'sc1'")
629
631
  msg opt_parser
630
632
  exit 1
631
633
  end
632
634
 
635
+ # validation for ebs_size
636
+ if (%w{st1 sc1}.include?(config[:ebs_volume_type])) && ! config[:ebs_size].to_i.between?(500, 16384)
637
+ ui.error("--ebs-size should be in between 500-16384 for 'st1' or 'sc1' ebs volume type.")
638
+ exit 1
639
+ end
640
+
633
641
  if config[:security_groups] && config[:security_groups].class == String
634
642
  ui.error("Invalid value type for knife[:security_groups] in knife configuration file (i.e knife.rb/config.rb). Type should be array. e.g - knife[:security_groups] = ['sgroup1']")
635
643
  exit 1
@@ -826,7 +834,7 @@ class Chef
826
834
 
827
835
  # base64-encoded text
828
836
  def encode_data(text)
829
- require "base64"
837
+ require "base64" unless defined?(Base64)
830
838
  Base64.encode64(text)
831
839
  end
832
840
 
@@ -907,7 +915,7 @@ class Chef
907
915
  attributes[:ebs_optimized] = !!config[:ebs_optimized]
908
916
 
909
917
  if ami.root_device_type == "ebs"
910
- if config[:ebs_encrypted]
918
+ if config[:ebs_encrypted] || %w{st1 sc1}.include?(config[:ebs_volume_type])
911
919
  ami_map = ami.block_device_mappings[1]
912
920
  else
913
921
  ami_map = ami.block_device_mappings.first
@@ -924,11 +932,9 @@ class Chef
924
932
  msg opt_parser
925
933
  exit 1
926
934
  end
927
- delete_term = if config[:ebs_no_delete_on_term]
928
- "false"
929
- else
930
- ami_map.ebs.delete_on_termination if ami_map.ebs.respond_to?(:delete_on_termination)
931
- end
935
+
936
+ delete_term = config[:ebs_delete_on_term]
937
+
932
938
  iops_rate = begin
933
939
  if config[:ebs_provisioned_iops]
934
940
  Integer(config[:ebs_provisioned_iops]).to_s
@@ -957,7 +963,7 @@ class Chef
957
963
  if config[:ephemeral] && config[:ephemeral].length > 0
958
964
  ephemeral_blocks = []
959
965
  config[:ephemeral].each_with_index do |device_name, i|
960
- ephemeral_blocks << { virtual_name: "ephemeral#{i}", device_name: device_name, ebs: { volume_size: ebs_size } }
966
+ ephemeral_blocks << { virtual_name: "ephemeral#{i}", device_name: device_name }
961
967
  end
962
968
  attributes[:block_device_mappings] += ephemeral_blocks
963
969
  end
@@ -1321,8 +1327,8 @@ class Chef
1321
1327
  end
1322
1328
 
1323
1329
  def decrypt_admin_password(encoded_password, key)
1324
- require "base64"
1325
- require "openssl"
1330
+ require "base64" unless defined?(Base64)
1331
+ require "openssl" unless defined?(OpenSSL)
1326
1332
  private_key = OpenSSL::PKey::RSA.new(key)
1327
1333
  encrypted_password = Base64.decode64(encoded_password)
1328
1334
  private_key.private_decrypt(encrypted_password)
@@ -1398,13 +1404,7 @@ class Chef
1398
1404
  end
1399
1405
 
1400
1406
  def server_name
1401
- return nil unless server
1402
-
1403
- if !server.public_dns_name.empty?
1404
- server.public_dns_name
1405
- else
1406
- server.private_ip_address
1407
- end
1407
+ server ? connection_host : nil
1408
1408
  end
1409
1409
 
1410
1410
  alias host_descriptor server_name
@@ -148,7 +148,7 @@ class Chef
148
148
  server_data[id] = i.instances[0].send(id)
149
149
  end
150
150
 
151
- server_data["name"] = i.instances[0].tags[0].value
151
+ server_data["name"] = find_name_tag(i.instances[0].tags)
152
152
  server_data["az"] = i.instances[0].placement.availability_zone
153
153
  server_data["iam_instance_profile"] = ( i.instances[0].iam_instance_profile.nil? ? nil : i.instances[0].iam_instance_profile.arn[%r{instance-profile/(.*)}] )
154
154
  server_data["security_groups"] = i.instances[0].security_groups.map(&:group_name).join(", ")
@@ -166,7 +166,7 @@ class Chef
166
166
  tags = extract_tags(i.instances[0].tags)
167
167
 
168
168
  if config[:name]
169
- server_data["name"] = tags[0]
169
+ server_data["name"] = find_name_tag(i.instances[0].tags)
170
170
  end
171
171
 
172
172
  if config[:az]
@@ -151,7 +151,7 @@ class Chef
151
151
  server_data["id"] = server_data["instance_id"]
152
152
 
153
153
  tags = server_obj.instances[0].tags.map(&:value)
154
- server_data["name"] = tags[0]
154
+ server_data["name"] = find_name_tag(server_obj.instances[0].tags)
155
155
  server_data["placement_group"] = server_obj.instances[0].placement.group_name
156
156
  server_data["security_groups"] = server_obj.instances[0].security_groups.map(&:group_name)
157
157
  server_data["security_group_ids"] = server_obj.instances[0].security_groups.map(&:group_id)
@@ -181,6 +181,13 @@ class Chef
181
181
  @ami ||= fetch_ami(config[:image])
182
182
  end
183
183
 
184
+ # Name tag value return.
185
+ # @return [String]
186
+ def find_name_tag(tags)
187
+ name_tag = tags.find { |tag| tag[:key] == "Name" }
188
+ name_tag ? name_tag[:value] : nil
189
+ end
190
+
184
191
  # Platform value return for Windows AMIs; otherwise, it is blank.
185
192
  # @return [Boolean]
186
193
  def is_image_windows?
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Ec2
3
- VERSION = "2.0.3".freeze
3
+ VERSION = "2.1.2".freeze
4
4
  MAJOR, MINOR, TINY = VERSION.split(".")
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-06 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef