knife-ec2 1.0.11 → 1.0.12

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: 6f2a7bca6d0b163b05f66380d1c3d0dfede7e8d4ccd62f16d1b89d4fbdffe199
4
- data.tar.gz: ff715b4e93d86c630f5cb6b1efc65ea7fa10207e69b89abb8dd5bca4e18d8db5
3
+ metadata.gz: 0e09e4b811ac8fbfc3f15456c64b86e3e66507181825b1af08dbc814de3f1e75
4
+ data.tar.gz: 97ce8aa909d10cf7ffe4e8096176447305bb2559a6a63e05e9801bcad6f17e2b
5
5
  SHA512:
6
- metadata.gz: dd5e6b6b6fc99b4e3170135e50316951d66eb485063b1dad598a30134409928a852e7df47e0fc1b7a52d6e4d38684f0025385896e1f7f49e7ff46fdae34dbd73
7
- data.tar.gz: 05ce9e4a754df26b507693377793969c6ef3b6d7f2fb54177883d7bb9437b0c1635d5da9a11b88610514b729c83137d4c2f024cbd7cf4a734fb0d31fc40c12b3
6
+ metadata.gz: 440dbf0295d37492c076fd3efacb0ec0132701d4860565a974757b5f23063579fccac6dc4086c1891863ea89152236cf43473489c98e5bfd3c9e1f4b3034802a
7
+ data.tar.gz: b331a39d9db68adccabe21217620ebb4d51422b0800b5aac7a80c9f6a94072126f37aa3fc478ac10355a441c7bddd71483b2159729571be5b278d899d19049c2
@@ -361,6 +361,9 @@ class Chef
361
361
 
362
362
  attach_nics if config[:network_interfaces]
363
363
 
364
+ # Re-fetch the latest server data after assigning vpc or network interfaces
365
+ @server = fetch_ec2_instance(instance_id) if reload_server_data_required?
366
+
364
367
  if vpc_mode?
365
368
  msg_pair("Subnet ID", server.subnet_id)
366
369
  msg_pair("Tenancy", server.tenancy)
@@ -856,23 +859,25 @@ class Chef
856
859
  availability_zone: config_value(:availability_zone),
857
860
  },
858
861
  }
862
+
859
863
  network_attrs = {}
860
- if primary_eni = config_value(:primary_eni)
861
- network_attrs[:network_interface_id] = primary_eni
862
- network_attrs[:device_index] = 0
863
- else
864
- attributes[:security_group_ids] = config_value(:security_group_ids)
865
- network_attrs[:subnet_id] = config_value(:subnet_id) if vpc_mode?
864
+ if !!config_value(:primary_eni)
865
+ network_attrs[:network_interface_id] = config_value(:primary_eni)
866
+ elsif vpc_mode?
867
+ network_attrs[:subnet_id] = config_value(:subnet_id)
866
868
  end
867
869
 
868
870
  if vpc_mode?
869
- network_attrs[:groups] = attributes[:security_group_ids]
871
+ network_attrs[:groups] = config_value(:security_group_ids) if !!config_value(:security_group_ids)
870
872
  network_attrs[:private_ip_address] = config_value(:private_ip_address)
871
- network_attrs[:associate_public_ip_address] = config_value(:associate_public_ip) if config[:associate_public_ip]
873
+ network_attrs[:associate_public_ip_address] = config_value(:associate_public_ip)
872
874
  end
873
875
 
874
876
  if network_attrs.length > 0
877
+ network_attrs[:device_index] = 0
875
878
  attributes[:network_interfaces] = [network_attrs]
879
+ else
880
+ attributes[:security_group_ids] = config_value(:security_group_ids)
876
881
  end
877
882
 
878
883
  attributes[:placement][:group_name] = config_value(:placement_group)
@@ -1120,23 +1125,30 @@ class Chef
1120
1125
  subnet.map_public_ip_on_launch
1121
1126
  end
1122
1127
 
1128
+ # Assign connection host based on attribute passed
1129
+ # @return [String]
1123
1130
  def connection_host
1124
- unless @connection_host
1125
- if config[:server_connect_attribute]
1126
- connect_attribute = config[:server_connect_attribute]
1127
- server.send(config[:server_connect_attribute])
1131
+ @connection_host ||= server.send(connect_attribute)
1132
+
1133
+ puts "\nSSH Target Address: #{@connection_host}(#{connect_attribute})"
1134
+ @connection_host
1135
+ end
1136
+
1137
+ # Identify connection attribute if:
1138
+ # Option --server-connect-attribute is set.
1139
+ # For VPC mode check if public IP or elastic IP has been requested.
1140
+ # Otherwise assign public DNS or public IP.
1141
+ # @return [String]
1142
+ def connect_attribute
1143
+ @connect_attribute ||= begin
1144
+ if !!config[:server_connect_attribute]
1145
+ config[:server_connect_attribute]
1128
1146
  elsif vpc_mode? && !(subnet_public_ip_on_launch? || config[:associate_public_ip] || config[:associate_eip])
1129
- connect_attribute = "private_ip_address"
1130
- server.private_ip_address
1147
+ "private_ip_address"
1131
1148
  else
1132
- connect_attribute = server.public_dns_name ? "public_dns_name" : "public_ip_address"
1133
- server.send(connect_attribute)
1149
+ server.public_dns_name ? "public_dns_name" : "public_ip_address"
1134
1150
  end
1135
- @connection_host = server.send(connect_attribute)
1136
1151
  end
1137
-
1138
- puts "\nSSH Target Address: #{@connection_host}(#{connect_attribute})"
1139
- @connection_host
1140
1152
  end
1141
1153
 
1142
1154
  def create_tags(hashed_tags)
@@ -1165,7 +1177,6 @@ class Chef
1165
1177
  ec2_connection.associate_address({
1166
1178
  allocation_id: elastic_ip.allocation_id,
1167
1179
  instance_id: server.id,
1168
- public_ip: elastic_ip.public_ip,
1169
1180
  })
1170
1181
  end
1171
1182
 
@@ -1426,6 +1437,10 @@ class Chef
1426
1437
  "Disabled"
1427
1438
  end
1428
1439
  end
1440
+
1441
+ def reload_server_data_required?
1442
+ !!config[:associate_eip] || !!config[:classic_link_vpc_id] || !!config[:network_interfaces]
1443
+ end
1429
1444
  end
1430
1445
  end
1431
1446
  end
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Ec2
3
- VERSION = "1.0.11".freeze
3
+ VERSION = "1.0.12".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: 1.0.11
4
+ version: 1.0.12
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: 2019-08-08 00:00:00.000000000 Z
11
+ date: 2019-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef