knife-ec2 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +32 -2
- data/RELEASE_NOTES.md +18 -6
- data/knife-ec2.gemspec +1 -1
- data/lib/chef/knife/ec2_ami_list.rb +101 -0
- data/lib/chef/knife/ec2_base.rb +33 -1
- data/lib/chef/knife/ec2_server_create.rb +42 -13
- data/lib/knife-ec2/version.rb +1 -1
- data/spec/spec_helper.rb +19 -18
- data/spec/unit/ec2_ami_list_spec.rb +273 -0
- data/spec/unit/ec2_server_create_spec.rb +86 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 889db53ef2c074e00e6f39d699546e1c559aa8aa
|
4
|
+
data.tar.gz: 9295959d153ee997e857113dde66c746435502a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7921659633817867c17ddfcde5f256128761e8b5c9c1a675786099a4244d5d134aed0df8b8c2f6bb915df8fe1de24ef1ced5fdfab98981ad27635a8b4b1935a
|
7
|
+
data.tar.gz: 713004b60d245461dc9bede11abac218cc29b77fc898207abc2388d0d5bf45b1fb4fd59575328e00a38d3f56d22252f6f3cc812389a54289f12a905ea27bbcb3
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,20 @@ Note: this log contains only changes from knife-ec2 release 0.8.0 and later
|
|
4
4
|
-- it does not contain the changes from prior releases. To view change history
|
5
5
|
prior to release 0.8.0, please visit the [source repository](https://github.com/chef/knife-ec2/commits).
|
6
6
|
|
7
|
+
|
8
|
+
## Latest Release 0.15.0 (2017-02-15)
|
9
|
+
* [knife-ec2:#484](https://github.com/chef/knife-ec2/pull/484) sleep for collecting windows password
|
10
|
+
* [knife-ec2:#481](https://github.com/chef/knife-ec2/pull/481) Updated readme for EC2 AMI list
|
11
|
+
* [knife-ec2:#482](https://github.com/chef/knife-ec2/pull/482) Allow search for EC2 AMIs
|
12
|
+
* [knife-ec2:#471](https://github.com/chef/knife-ec2/pull/471) Added support to include ec2 server id in the node name using `-N "www-server-%s" or --chef-node-name "-www-server-%s"`
|
13
|
+
* [knife-ec2:#478](https://github.com/chef/knife-ec2/pull/478) Allow for hosts without public ip addresses
|
14
|
+
* [knife-ec2:#476](https://github.com/chef/knife-ec2/pull/476) Tag node in chef
|
15
|
+
* [knife-ec2:#458](https://github.com/chef/knife-ec2/pull/458) Fix where yes option wasn’t being passed to bootstrap
|
16
|
+
* [knife-ec2:#468](https://github.com/chef/knife-ec2/pull/468) In VPC mode use private IP when public IP and DNS not available
|
17
|
+
* [knife-ec2:#464](https://github.com/chef/knife-ec2/pull/464) default value and desription is changed for --ebs-volume-type
|
18
|
+
|
7
19
|
## Latest Release 0.14.0 (2016-12-02)
|
20
|
+
* `knife-ec2` requires `chef-client 12.14` or newer.
|
8
21
|
* [knife-ec2:#442](https://github.com/chef/knife-ec2/pull/442) Added support to show flavor list in json format.
|
9
22
|
* [knife-ec2:#439](https://github.com/chef/knife-ec2/pull/439) Allow to accept multiple security group ids using --security-group-id option multiple times and added deprecated message for comma seprated --security-group-ids option.
|
10
23
|
|
data/README.md
CHANGED
@@ -203,6 +203,10 @@ knife ec2 server create -I ami-173d747e -x ubuntu --server-connect-attribute pub
|
|
203
203
|
|
204
204
|
View additional information on configuring Windows images for bootstrap in the documentation for [knife-windows](https://docs.chef.io/plugin_knife_windows.html).
|
205
205
|
|
206
|
+
#### Adding server_id to the node name
|
207
|
+
|
208
|
+
Users can also include the ec2 server id in the node name by placing `%s` in the string passed to the `--chef-node-name` option. The %s is replaced by the ec2 server id dynamically.
|
209
|
+
e.g. `-N "www-server-%s" or --chef-node-name "www-server-%s"`
|
206
210
|
|
207
211
|
#### Bootstrap Windows (2012 R2 and above platform) instance without user-data through winrm ssl transport
|
208
212
|
|
@@ -230,13 +234,39 @@ The `knife ec2 server create` command also supports the following options for bo
|
|
230
234
|
:kerberos_realm The Kerberos realm used for authentication
|
231
235
|
:kerberos_service The Kerberos service used for authentication
|
232
236
|
```
|
237
|
+
### `knife ec2 ami list`
|
238
|
+
This command provides the feature to list all EC2 AMIs. It also provides the feature to filter the AMIs based on owner and platform.
|
233
239
|
|
234
|
-
|
235
|
-
|
240
|
+
```
|
241
|
+
knife ec2 ami list
|
242
|
+
```
|
243
|
+
|
244
|
+
#### Options for AMIs list
|
245
|
+
- **Owner:**
|
246
|
+
By default owner is aws-marketplace but you can specify following owner with the help of -o or --owner:
|
247
|
+
|
248
|
+
**command:** knife ec2 ami list -o (options)
|
249
|
+
|
250
|
+
```
|
251
|
+
:self Displays the list of AMIs created by the user.
|
252
|
+
:aws-marketplace Displays all AMIs form trusted vendors like Ubuntu, Microsoft, SAP, Zend as well as many open source offering.
|
253
|
+
:micosoft Displays only Microsoft vendor AMIs.
|
254
|
+
```
|
255
|
+
- **Platform:**
|
256
|
+
By default all platform AMIs are displayed, but you can filter your response by specifying the platform using -p or --platform:
|
257
|
+
|
258
|
+
**command:** knife ec2 ami list -p (options)
|
259
|
+
|
260
|
+
```
|
261
|
+
:Allowed platform windows, ubuntu, debian, centos, fedora, rhel, nginx, turnkey, jumpbox, coreos, cisco, amazon, nessus
|
262
|
+
```
|
236
263
|
|
237
264
|
### `knife ec2 server list`
|
238
265
|
Outputs a list of all servers in the currently configured AWS account. **Note, this shows all instances associated with the account, some of which may not be currently managed by the Chef server.**
|
239
266
|
|
267
|
+
### `knife ec2 server delete`
|
268
|
+
Deletes an existing server in the currently configured AWS account. **By default, this does not delete the associated node and client objects from the Chef server. To do so, add the `--purge` flag**
|
269
|
+
|
240
270
|
## License and Authors
|
241
271
|
- Author:: Adam Jacob ([adam@chef.io](mailto:adam@chef.io))
|
242
272
|
|
data/RELEASE_NOTES.md
CHANGED
@@ -7,14 +7,26 @@ Example Note:
|
|
7
7
|
Details about the thing that changed that needs to get included in the Release Notes in markdown.
|
8
8
|
-->
|
9
9
|
|
10
|
-
# knife-ec2 0.
|
10
|
+
# knife-ec2 0.15.0 release notes:
|
11
|
+
In this release we have added a command to list EC2 AMIs. Also added a feature to append server_id to the chef-node-name. There are a couple of bug fixes as well.
|
11
12
|
|
12
|
-
|
13
|
+
## Features added in knife-ec2 0.15.0
|
13
14
|
|
14
|
-
|
15
|
+
* Added command to list EC2 AMIs using `knife ec2 ami list` PR: [482](https://github.com/chef/knife-ec2/pull/482)
|
15
16
|
|
16
|
-
* Added support to
|
17
|
+
* Added support to insert ec2 server id into node name using -N "<Node Name>%s" PR: [471](https://github.com/chef/knife-ec2/pull/471)
|
17
18
|
|
18
|
-
*
|
19
|
+
* Changed source of vm name to allow for hosts without public ip addresses PR: [478](https://github.com/chef/knife-ec2/pull/478)
|
19
20
|
|
20
|
-
|
21
|
+
* Automatically pass tags to Chef as well as EC2 PR: [476](https://github.com/chef/knife-ec2/pull/476)
|
22
|
+
|
23
|
+
|
24
|
+
## Fixed issue in knife-ec2 0.15.0
|
25
|
+
|
26
|
+
* Wait for Windows Admin password to be available PR: [484](https://github.com/chef/knife-ec2/pull/484), issue: [479](https://github.com/chef/knife-ec2/issues/479), issue: [453](https://github.com/chef/knife-ec2/issues/453)
|
27
|
+
|
28
|
+
* Fix where `--yes` option was not being passed to bootstrap PR: [458](https://github.com/chef/knife-ec2/pull/458)
|
29
|
+
|
30
|
+
* In VPC mode use private IP when public IP and DNS are not available PR: [468](https://github.com/chef/knife-ec2/pull/468), issue: [344](https://github.com/chef/knife-ec2/issues/344)
|
31
|
+
|
32
|
+
* Default value and description improved for `--ebs-volume-type` improved for clarity PR: [464](https://github.com/chef/knife-ec2/pull/464), issue: [450](https://github.com/chef/knife-ec2/issues/450), issue [451](https://github.com/chef/knife-ec2/issues/451)
|
data/knife-ec2.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
18
|
s.required_ruby_version = ">= 2.2.2"
|
19
19
|
|
20
|
-
s.add_dependency 'fog-aws', '~> 0
|
20
|
+
s.add_dependency 'fog-aws', '~> 1.0'
|
21
21
|
s.add_dependency 'mime-types'
|
22
22
|
s.add_dependency 'knife-windows', '~> 1.0'
|
23
23
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Piyush Awasthi (<piyush.awasthi@msystechnologies.com>)
|
3
|
+
# Copyright:: Copyright (c) 2017 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
|
19
|
+
require "chef/knife/ec2_base"
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class Ec2AmiList < Knife
|
24
|
+
|
25
|
+
# == Overview
|
26
|
+
#
|
27
|
+
# This file provides the facility to display AMI list.
|
28
|
+
#
|
29
|
+
# == Owner
|
30
|
+
# By default owner is aws-marketplace but you can specify following owner with the help of -o or --owner
|
31
|
+
# * self => Displays the list of AMIs created by the user
|
32
|
+
# * aws-marketplace => Displays all AMIs form trusted vendors like Ubuntu, Microsoft, SAP, Zend as well as many open source offering
|
33
|
+
# * micosoft => Displays only Microsoft vendor AMIs
|
34
|
+
#
|
35
|
+
# == Platform
|
36
|
+
# By default all platform AMI's will display but you can filter your response
|
37
|
+
# by specify the platform using -p or --platform
|
38
|
+
# * Valid Platform => ubuntu, debian, centos, fedora, rhel, nginx, turnkey, jumpbox, coreos, cisco
|
39
|
+
#
|
40
|
+
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html]
|
41
|
+
|
42
|
+
include Knife::Ec2Base
|
43
|
+
|
44
|
+
banner "knife ec2 ami list (options)"
|
45
|
+
|
46
|
+
option :platform,
|
47
|
+
:short => "-p PLATFORM",
|
48
|
+
:long => "--platform PLATFORM",
|
49
|
+
:description => "Platform of the server. Allowed values are ubuntu, debian, centos, fedora, rhel, nginx, turnkey, jumpbox, coreos, cisco, amazon, nessus"
|
50
|
+
|
51
|
+
option :owner,
|
52
|
+
:short => "-o OWNER",
|
53
|
+
:long => "--owner OWNER",
|
54
|
+
:description => "The server owner (self, aws-marketplace, microsoft). Default is aws-marketplace"
|
55
|
+
|
56
|
+
def run
|
57
|
+
$stdout.sync = true
|
58
|
+
|
59
|
+
validate!
|
60
|
+
custom_warnings!
|
61
|
+
|
62
|
+
server_list = [
|
63
|
+
ui.color("AMI ID", :bold),
|
64
|
+
ui.color("Platform", :bold),
|
65
|
+
ui.color("Architecture", :bold),
|
66
|
+
ui.color("Size", :bold),
|
67
|
+
ui.color("Name", :bold)
|
68
|
+
].flatten.compact
|
69
|
+
|
70
|
+
output_column_count = server_list.length
|
71
|
+
begin
|
72
|
+
owner = locate_config_value(:owner) || "aws-marketplace"
|
73
|
+
servers = connection.describe_images({"Owner"=>"#{owner}"}) # aws-marketplace, microsoft
|
74
|
+
rescue Exception => api_error
|
75
|
+
raise api_error
|
76
|
+
end
|
77
|
+
servers.body["imagesSet"].each do |server|
|
78
|
+
server_name = server["name"]
|
79
|
+
server["platform"] = find_server_platform(server_name) unless server["platform"]
|
80
|
+
|
81
|
+
if locate_config_value(:platform)
|
82
|
+
if server["platform"] == locate_config_value(:platform)
|
83
|
+
server_list << server["imageId"]
|
84
|
+
server_list << server["platform"]
|
85
|
+
server_list << server["architecture"]
|
86
|
+
server_list << server["blockDeviceMapping"].first["volumeSize"].to_s
|
87
|
+
server_list << server_name.split(/\W+/).first
|
88
|
+
end
|
89
|
+
else
|
90
|
+
server_list << server["imageId"]
|
91
|
+
server_list << server["platform"]
|
92
|
+
server_list << server["architecture"]
|
93
|
+
server_list << server["blockDeviceMapping"].first["volumeSize"].to_s
|
94
|
+
server_list << server_name.split(/\W+/).first
|
95
|
+
end
|
96
|
+
end
|
97
|
+
puts ui.list(server_list, :uneven_columns_across, output_column_count)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/chef/knife/ec2_base.rb
CHANGED
@@ -106,7 +106,7 @@ class Chef
|
|
106
106
|
|
107
107
|
def msg_pair(label, value, color=:cyan)
|
108
108
|
if value && !value.to_s.empty?
|
109
|
-
|
109
|
+
ui.info("#{ui.color(label, color)}: #{value}")
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -177,6 +177,18 @@ class Chef
|
|
177
177
|
exit 1
|
178
178
|
end
|
179
179
|
end
|
180
|
+
|
181
|
+
if locate_config_value(:platform)
|
182
|
+
unless valid_platforms.include? (locate_config_value(:platform))
|
183
|
+
raise ArgumentError, "Invalid platform: #{locate_config_value(:platform)}. Allowed platforms are: #{valid_platforms.join(", ")}."
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
if locate_config_value(:owner)
|
188
|
+
unless ["self", "aws-marketplace", "microsoft"].include? (locate_config_value(:owner))
|
189
|
+
raise ArgumentError, "Invalid owner: #{locate_config_value(:owner)}. Allowed owners are self, aws-marketplace or microsoft."
|
190
|
+
end
|
191
|
+
end
|
180
192
|
end
|
181
193
|
|
182
194
|
end
|
@@ -207,5 +219,25 @@ class Chef
|
|
207
219
|
end
|
208
220
|
map
|
209
221
|
end
|
222
|
+
|
223
|
+
# All valid platforms
|
224
|
+
def valid_platforms
|
225
|
+
["ubuntu", "debian", "centos", "fedora", "rhel", "nginx", "turnkey", "jumpbox", "coreos", "cisco", "amazon", "nessus"]
|
226
|
+
end
|
227
|
+
|
228
|
+
# Get the platform from server name
|
229
|
+
def find_server_platform(server_name)
|
230
|
+
available_platforms = valid_platforms
|
231
|
+
get_platform = available_platforms.select { |name| server_name.downcase.include?(name) }
|
232
|
+
return get_platform.first
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
# Custom Warning
|
237
|
+
def custom_warnings!
|
238
|
+
if !config[:region] && Chef::Config[:knife][:region].nil?
|
239
|
+
ui.warn "No region was specified in knife.rb or as an argument. The default region, us-east-1, will be used:"
|
240
|
+
end
|
241
|
+
end
|
210
242
|
end
|
211
243
|
end
|
@@ -254,7 +254,7 @@ class Chef
|
|
254
254
|
|
255
255
|
option :fqdn,
|
256
256
|
:long => "--fqdn FQDN",
|
257
|
-
:description => "Pre-defined FQDN",
|
257
|
+
:description => "Pre-defined FQDN. This is used for Kerberos Authentication purpose only",
|
258
258
|
:proc => Proc.new { |key| Chef::Config[:knife][:fqdn] = key },
|
259
259
|
:default => nil
|
260
260
|
|
@@ -294,9 +294,9 @@ class Chef
|
|
294
294
|
|
295
295
|
option :ebs_volume_type,
|
296
296
|
:long => "--ebs-volume-type TYPE",
|
297
|
-
:description => "
|
297
|
+
:description => "Possible values are standard (magnetic) | io1 | gp2 | sc1 | st1. Default is gp2",
|
298
298
|
:proc => Proc.new { |key| Chef::Config[:knife][:ebs_volume_type] = key },
|
299
|
-
:default => "
|
299
|
+
:default => "gp2"
|
300
300
|
|
301
301
|
option :ebs_provisioned_iops,
|
302
302
|
:long => "--provisioned-iops IOPS",
|
@@ -500,7 +500,11 @@ class Chef
|
|
500
500
|
|
501
501
|
# Always set the Name tag
|
502
502
|
unless hashed_tags.keys.include? "Name"
|
503
|
-
|
503
|
+
if locate_config_value(:chef_node_name)
|
504
|
+
hashed_tags["Name"] = evaluate_node_name(locate_config_value(:chef_node_name))
|
505
|
+
else
|
506
|
+
hashed_tags["Name"] = server.id
|
507
|
+
end
|
504
508
|
end
|
505
509
|
|
506
510
|
printed_tags = hashed_tags.map{ |tag, val| "#{tag}: #{val}" }.join(", ")
|
@@ -735,6 +739,7 @@ class Chef
|
|
735
739
|
bootstrap.config[:bootstrap_vault_json] = locate_config_value(:bootstrap_vault_json)
|
736
740
|
bootstrap.config[:bootstrap_vault_item] = locate_config_value(:bootstrap_vault_item)
|
737
741
|
bootstrap.config[:use_sudo_password] = locate_config_value(:use_sudo_password)
|
742
|
+
bootstrap.config[:yes] = locate_config_value(:yes)
|
738
743
|
# Modify global configuration state to ensure hint gets set by
|
739
744
|
# knife-bootstrap
|
740
745
|
Chef::Config[:knife][:hints] ||= {}
|
@@ -780,7 +785,12 @@ class Chef
|
|
780
785
|
bootstrap.config[:msi_url] = locate_config_value(:msi_url)
|
781
786
|
bootstrap.config[:install_as_service] = locate_config_value(:install_as_service)
|
782
787
|
bootstrap.config[:session_timeout] = locate_config_value(:session_timeout)
|
783
|
-
bootstrap.config[:
|
788
|
+
bootstrap.config[:tags] = config[:tags]
|
789
|
+
if locate_config_value(:chef_node_name)
|
790
|
+
bootstrap.config[:chef_node_name] = evaluate_node_name(locate_config_value(:chef_node_name))
|
791
|
+
else
|
792
|
+
bootstrap.config[:chef_node_name] = server.id
|
793
|
+
end
|
784
794
|
bootstrap_common_params(bootstrap)
|
785
795
|
end
|
786
796
|
|
@@ -792,7 +802,12 @@ class Chef
|
|
792
802
|
bootstrap.config[:ssh_port] = config[:ssh_port]
|
793
803
|
bootstrap.config[:ssh_gateway] = config[:ssh_gateway]
|
794
804
|
bootstrap.config[:identity_file] = config[:identity_file]
|
795
|
-
bootstrap.config[:
|
805
|
+
bootstrap.config[:tags] = config[:tags]
|
806
|
+
if locate_config_value(:chef_node_name)
|
807
|
+
bootstrap.config[:chef_node_name] = evaluate_node_name(locate_config_value(:chef_node_name))
|
808
|
+
else
|
809
|
+
bootstrap.config[:chef_node_name] = server.id
|
810
|
+
end
|
796
811
|
bootstrap.config[:use_sudo] = true unless config[:ssh_user] == 'root'
|
797
812
|
# may be needed for vpc_mode
|
798
813
|
bootstrap.config[:host_key_verify] = config[:host_key_verify]
|
@@ -972,6 +987,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
972
987
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
973
988
|
}
|
974
989
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
990
|
+
If (-Not $vm_name) {
|
991
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
992
|
+
}
|
975
993
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
976
994
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
977
995
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1216,18 +1234,22 @@ EOH
|
|
1216
1234
|
}
|
1217
1235
|
end
|
1218
1236
|
|
1237
|
+
def subnet_public_ip_on_launch?
|
1238
|
+
connection.subnets.get(server.subnet_id).map_public_ip_on_launch
|
1239
|
+
end
|
1240
|
+
|
1219
1241
|
def ssh_connect_host
|
1220
1242
|
unless @ssh_connect_host
|
1221
1243
|
if config[:server_connect_attribute]
|
1222
1244
|
connect_attribute = config[:server_connect_attribute]
|
1245
|
+
server.send(config[:server_connect_attribute])
|
1246
|
+
elsif vpc_mode? && !(subnet_public_ip_on_launch? || config[:associate_public_ip] || config[:associate_eip])
|
1247
|
+
connect_attribute = "private_ip_address"
|
1248
|
+
server.private_ip_address
|
1223
1249
|
else
|
1224
|
-
|
1225
|
-
|
1226
|
-
else
|
1227
|
-
connect_attribute = server.dns_name ? "dns_name" : "public_ip_address"
|
1228
|
-
end
|
1250
|
+
connect_attribute = server.dns_name ? "dns_name" : "public_ip_address"
|
1251
|
+
server.send(connect_attribute)
|
1229
1252
|
end
|
1230
|
-
|
1231
1253
|
@ssh_connect_host = server.send(connect_attribute)
|
1232
1254
|
end
|
1233
1255
|
|
@@ -1381,6 +1403,7 @@ EOH
|
|
1381
1403
|
end
|
1382
1404
|
|
1383
1405
|
def check_windows_password_available(server_id)
|
1406
|
+
sleep 10
|
1384
1407
|
response = connection.get_password_data(server_id)
|
1385
1408
|
if not response.body["passwordData"]
|
1386
1409
|
return false
|
@@ -1393,7 +1416,6 @@ EOH
|
|
1393
1416
|
if locate_config_value(:identity_file)
|
1394
1417
|
print "\n#{ui.color("Waiting for Windows Admin password to be available", :magenta)}"
|
1395
1418
|
print(".") until check_windows_password_available(@server.id) {
|
1396
|
-
sleep 1000 #typically is available after 30 mins
|
1397
1419
|
puts("done")
|
1398
1420
|
}
|
1399
1421
|
response = connection.get_password_data(@server.id)
|
@@ -1415,6 +1437,13 @@ EOH
|
|
1415
1437
|
require 'chef/knife/bootstrap_windows_ssh'
|
1416
1438
|
require 'chef/knife/core/windows_bootstrap_context'
|
1417
1439
|
end
|
1440
|
+
|
1441
|
+
#Returns the name of node after evaluation of server id if %s is present.
|
1442
|
+
#Eg: "Test-%s" will return "Test-i-12345" in case the instance id is i-12345
|
1443
|
+
def evaluate_node_name(node_name)
|
1444
|
+
return node_name%server.id
|
1445
|
+
end
|
1446
|
+
|
1418
1447
|
end
|
1419
1448
|
end
|
1420
1449
|
end
|
data/lib/knife-ec2/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
-
require 'chef'
|
3
|
-
require 'chef/knife/winrm_base'
|
4
|
-
require 'chef/knife/ec2_server_create'
|
5
|
-
require 'chef/knife/ec2_server_delete'
|
6
|
-
require 'chef/knife/ec2_server_list'
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
c.
|
13
|
-
c.
|
14
|
-
|
15
|
-
Chef::Config
|
16
|
-
|
17
|
-
end
|
18
|
-
|
1
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'chef'
|
3
|
+
require 'chef/knife/winrm_base'
|
4
|
+
require 'chef/knife/ec2_server_create'
|
5
|
+
require 'chef/knife/ec2_server_delete'
|
6
|
+
require 'chef/knife/ec2_server_list'
|
7
|
+
require 'chef/knife/ec2_ami_list'
|
8
|
+
|
9
|
+
# Clear config between each example
|
10
|
+
# to avoid dependencies between examples
|
11
|
+
RSpec.configure do |c|
|
12
|
+
c.raise_errors_for_deprecations!
|
13
|
+
c.filter_run_excluding :exclude => true
|
14
|
+
c.before(:each) do
|
15
|
+
Chef::Config.reset
|
16
|
+
Chef::Config[:knife] ={}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,273 @@
|
|
1
|
+
# License:: Apache License, Version 2.0
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
|
16
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
17
|
+
require 'fog/aws'
|
18
|
+
|
19
|
+
describe Chef::Knife::Ec2AmiList do
|
20
|
+
|
21
|
+
describe '#run' do
|
22
|
+
let(:knife_ec2_ami_list) { Chef::Knife::Ec2AmiList.new }
|
23
|
+
let(:ec2_connection) { double(Fog::Compute::AWS) }
|
24
|
+
before (:each) do
|
25
|
+
allow(knife_ec2_ami_list).to receive(:connection).and_return(ec2_connection)
|
26
|
+
@describe_images_format = double("describe_image_output", :body => {
|
27
|
+
'imagesSet' => [{
|
28
|
+
'architecture' => "x86_64",
|
29
|
+
'blockDeviceMapping' => [{"deviceName"=>"/dev/sda1",
|
30
|
+
"snapshotId"=>"snap-f7e645f4",
|
31
|
+
"volumeSize"=>30,
|
32
|
+
"deleteOnTermination"=>"true",
|
33
|
+
"volumeType"=>"standard",
|
34
|
+
"encrypted"=>"false"}],
|
35
|
+
'description' => "DC for Quan",
|
36
|
+
'hypervisor' => "xen",
|
37
|
+
'imageId' => "ami-4ace6d23",
|
38
|
+
'imageLocation' => "microsoft/Windows_Server-2008-R2-SP1-English-64Bit-WebMatrix_Hosting-2012.06.12",
|
39
|
+
'imageOwnerAlias' => "microsoft",
|
40
|
+
'name' => "Windows_Server-2008-R2-SP1-English-64Bit-Windows_Media_Services_4.1-2012.06.12",
|
41
|
+
'imageOwnerId' => "461346954234",
|
42
|
+
'imageState' => "available",
|
43
|
+
'imageType' => "machine",
|
44
|
+
'isPublic' => true,
|
45
|
+
'platform' => "windows",
|
46
|
+
'productCodes' => [],
|
47
|
+
'rootDeviceName' => "/dev/sda1",
|
48
|
+
'rootDeviceType' => "ebs",
|
49
|
+
'stateReason' => {},
|
50
|
+
'tagSet' => {},
|
51
|
+
'virtualizationType' => "hvm"
|
52
|
+
}, {
|
53
|
+
'architecture' => "i386",
|
54
|
+
'blockDeviceMapping' => [{"deviceName"=>"/dev/sda1",
|
55
|
+
"snapshotId"=>"snap-f7e645f4",
|
56
|
+
"volumeSize"=>10,
|
57
|
+
"deleteOnTermination"=>"true",
|
58
|
+
"volumeType"=>"standard",
|
59
|
+
"encrypted"=>"false"}],
|
60
|
+
'description' => "DC for Quan",
|
61
|
+
'hypervisor' => "xen",
|
62
|
+
'imageId' => "ami-4ace6d21",
|
63
|
+
'imageOwnerAlias' => "aws-marketplace",
|
64
|
+
'name' => "ubuntu i386",
|
65
|
+
'imageOwnerId' => "461346954235",
|
66
|
+
'imageState' => "available",
|
67
|
+
'imageType' => "machine",
|
68
|
+
'isPublic' => true,
|
69
|
+
'productCodes' => [],
|
70
|
+
'rootDeviceName' => "/dev/sda1",
|
71
|
+
'rootDeviceType' => "ebs",
|
72
|
+
'stateReason' => {},
|
73
|
+
'tagSet' => {},
|
74
|
+
'virtualizationType' => "hvm"
|
75
|
+
}, {
|
76
|
+
'architecture' => "x86_64",
|
77
|
+
'blockDeviceMapping' => [{"deviceName"=>"/dev/sda1",
|
78
|
+
"snapshotId"=>"snap-f7e645f4",
|
79
|
+
"volumeSize"=>8,
|
80
|
+
"deleteOnTermination"=>"true",
|
81
|
+
"volumeType"=>"standard",
|
82
|
+
"encrypted"=>"false"}],
|
83
|
+
'description' => "DC for Quan",
|
84
|
+
'hypervisor' => "xen",
|
85
|
+
'imageId' => "ami-4ace6d29",
|
86
|
+
'imageOwnerAlias' => "aws-marketplace",
|
87
|
+
'name' => "fedora i64",
|
88
|
+
'imageOwnerId' => "461346954234",
|
89
|
+
'imageState' => "available",
|
90
|
+
'imageType' => "machine",
|
91
|
+
'isPublic' => true,
|
92
|
+
'productCodes' => [],
|
93
|
+
'rootDeviceName' => "/dev/sda1",
|
94
|
+
'rootDeviceType' => "ebs",
|
95
|
+
'stateReason' => {},
|
96
|
+
'tagSet' => {},
|
97
|
+
'virtualizationType' => "hvm"
|
98
|
+
}],
|
99
|
+
'requestId' => "ba38c315-f1b4-4822-b336-6309bed6d50c"
|
100
|
+
}
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'invokes validate!' do
|
105
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
106
|
+
allow(knife_ec2_ami_list.ui).to receive(:warn)
|
107
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
108
|
+
knife_ec2_ami_list.run
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'when region is not specified' do
|
112
|
+
it 'shows warning that default region will be will be used' do
|
113
|
+
knife_ec2_ami_list.config.delete(:region)
|
114
|
+
Chef::Config[:knife].delete(:region)
|
115
|
+
ec2_servers = double()
|
116
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
117
|
+
allow(knife_ec2_ami_list).to receive(:validate!)
|
118
|
+
expect(knife_ec2_ami_list.ui).to receive(:warn).with("No region was specified in knife.rb or as an argument. The default region, us-east-1, will be used:")
|
119
|
+
knife_ec2_ami_list.run
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'when --owner is passed' do
|
124
|
+
before do
|
125
|
+
allow(knife_ec2_ami_list.ui).to receive(:warn)
|
126
|
+
allow(knife_ec2_ami_list).to receive(:custom_warnings!)
|
127
|
+
knife_ec2_ami_list.config[:use_iam_profile] = true
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'When value for owner is nil' do
|
131
|
+
it 'shows the available AMIs List' do
|
132
|
+
knife_ec2_ami_list.config[:owner] = nil
|
133
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
134
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
135
|
+
images = ec2_connection.describe_images.body['imagesSet']
|
136
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
137
|
+
output_column_count = output_column.length
|
138
|
+
images.each do |image|
|
139
|
+
output_column << image["imageId"].to_s
|
140
|
+
output_column << (image["platform"] ? image["platform"] : image["name"].split(/\W+/).first)
|
141
|
+
output_column << image["architecture"].to_s
|
142
|
+
output_column << image["blockDeviceMapping"].first["volumeSize"].to_s
|
143
|
+
output_column << image["name"].split(/\W+/).first
|
144
|
+
end
|
145
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
146
|
+
knife_ec2_ami_list.run
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'When value for owner is self' do
|
151
|
+
it 'does not raise any error' do
|
152
|
+
knife_ec2_ami_list.config[:owner] = 'self'
|
153
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
154
|
+
expect{ knife_ec2_ami_list.validate! }.not_to raise_error
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'When value for owner is microsoft' do
|
159
|
+
it 'does not raise any error' do
|
160
|
+
knife_ec2_ami_list.config[:owner] = 'microsoft'
|
161
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
162
|
+
expect{ knife_ec2_ami_list.validate! }.not_to raise_error
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'When value for owner is aws-marketplace' do
|
167
|
+
it 'does not raise any error' do
|
168
|
+
knife_ec2_ami_list.config[:owner] = 'aws-marketplace'
|
169
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
170
|
+
expect{ knife_ec2_ami_list.validate! }.not_to raise_error
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'When owner is invalid' do
|
175
|
+
it 'raises error' do
|
176
|
+
knife_ec2_ami_list.config[:owner] = 'xyz'
|
177
|
+
knife_ec2_ami_list.config[:use_iam_profile] = true
|
178
|
+
expect{ knife_ec2_ami_list.validate! }.to raise_error "Invalid owner: #{knife_ec2_ami_list.config[:owner]}. Allowed owners are self, aws-marketplace or microsoft."
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'when --platform is passed' do
|
184
|
+
before do
|
185
|
+
allow(knife_ec2_ami_list.ui).to receive(:warn)
|
186
|
+
allow(knife_ec2_ami_list).to receive(:custom_warnings!)
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'When platform is nil' do
|
190
|
+
it 'shows all the AMIs List' do
|
191
|
+
knife_ec2_ami_list.config[:platform] = nil
|
192
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
193
|
+
images = ec2_connection.describe_images.body['imagesSet']
|
194
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
195
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
196
|
+
output_column_count = output_column.length
|
197
|
+
images.each do |image|
|
198
|
+
output_column << image["imageId"].to_s
|
199
|
+
output_column << (image["platform"] ? image["platform"] : image["name"].split(/\W+/).first)
|
200
|
+
output_column << image["architecture"].to_s
|
201
|
+
output_column << image["blockDeviceMapping"].first["volumeSize"].to_s
|
202
|
+
output_column << image["name"].split(/\W+/).first
|
203
|
+
end
|
204
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
205
|
+
knife_ec2_ami_list.run
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'When platform is windows' do
|
210
|
+
it 'shows only windows AMIs List' do
|
211
|
+
knife_ec2_ami_list.config[:platform] = 'windows'
|
212
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
213
|
+
window_image = ec2_connection.describe_images.body['imagesSet'].first
|
214
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
215
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
216
|
+
output_column_count = output_column.length
|
217
|
+
output_column << window_image["imageId"]
|
218
|
+
output_column << window_image["platform"]
|
219
|
+
output_column << window_image["architecture"]
|
220
|
+
output_column << window_image["blockDeviceMapping"].first["volumeSize"].to_s
|
221
|
+
output_column << window_image["name"].split(/\W+/).first
|
222
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
223
|
+
knife_ec2_ami_list.run
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'When platform is ubuntu' do
|
228
|
+
it 'shows only ubuntu AMIs List' do
|
229
|
+
knife_ec2_ami_list.config[:platform] = 'ubuntu'
|
230
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
231
|
+
ubuntu_image = ec2_connection.describe_images.body['imagesSet'][1]
|
232
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
233
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
234
|
+
output_column_count = output_column.length
|
235
|
+
output_column << ubuntu_image["imageId"]
|
236
|
+
output_column << ubuntu_image["name"].split(/\W+/).first
|
237
|
+
output_column << ubuntu_image["architecture"]
|
238
|
+
output_column << ubuntu_image["blockDeviceMapping"].first["volumeSize"].to_s
|
239
|
+
output_column << ubuntu_image["name"].split(/\W+/).first
|
240
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
241
|
+
knife_ec2_ami_list.run
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
context 'When platform is fedora' do
|
246
|
+
it 'shows only fedora AMIs List' do
|
247
|
+
knife_ec2_ami_list.config[:platform] = 'fedora'
|
248
|
+
allow(ec2_connection).to receive(:describe_images).and_return(@describe_images_format)
|
249
|
+
expect(knife_ec2_ami_list).to receive(:validate!)
|
250
|
+
fedora_image = ec2_connection.describe_images.body['imagesSet'].last
|
251
|
+
output_column = ["AMI ID", "Platform", "Architecture", "Size", "Name"]
|
252
|
+
output_column_count = output_column.length
|
253
|
+
output_column << fedora_image["imageId"]
|
254
|
+
output_column << fedora_image["name"].split(/\W+/).first
|
255
|
+
output_column << fedora_image["architecture"]
|
256
|
+
output_column << fedora_image["blockDeviceMapping"].first["volumeSize"].to_s
|
257
|
+
output_column << fedora_image["name"].split(/\W+/).first
|
258
|
+
expect(knife_ec2_ami_list.ui).to receive(:list).with(output_column,:uneven_columns_across, output_column_count)
|
259
|
+
knife_ec2_ami_list.run
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
context 'When platform is invalid' do
|
264
|
+
it 'raises error' do
|
265
|
+
knife_ec2_ami_list.config[:platform] = 'xyz'
|
266
|
+
knife_ec2_ami_list.config[:use_iam_profile] = true
|
267
|
+
knife_ec2_ami_list.config[:owner] = true
|
268
|
+
expect{ knife_ec2_ami_list.validate! }.to raise_error "Invalid platform: #{knife_ec2_ami_list.config[:platform]}. Allowed platforms are: ubuntu, debian, centos, fedora, rhel, nginx, turnkey, jumpbox, coreos, cisco, amazon, nessus."
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
@@ -48,6 +48,8 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
48
48
|
:private_ip_address => '10.251.75.20',
|
49
49
|
:root_device_type => 'not_ebs' } }
|
50
50
|
|
51
|
+
let (:server) { double(:id => "i-123" ) }
|
52
|
+
|
51
53
|
let(:spot_request_attribs) { { :id => 'test_spot_request_id',
|
52
54
|
:price => 0.001,
|
53
55
|
:request_type => 'persistent',
|
@@ -630,6 +632,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
630
632
|
|
631
633
|
describe "when configuring the bootstrap process" do
|
632
634
|
before do
|
635
|
+
allow(knife_ec2_create).to receive(:evaluate_node_name).and_return('blarf')
|
633
636
|
knife_ec2_create.config[:ssh_user] = "ubuntu"
|
634
637
|
knife_ec2_create.config[:identity_file] = "~/.ssh/aws-key.pem"
|
635
638
|
knife_ec2_create.config[:ssh_port] = 22
|
@@ -740,6 +743,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
740
743
|
describe "when configuring the winrm bootstrap process for windows" do
|
741
744
|
before do
|
742
745
|
allow(knife_ec2_create).to receive(:fetch_server_fqdn).and_return("SERVERNAME")
|
746
|
+
allow(knife_ec2_create).to receive(:evaluate_node_name).and_return(server)
|
743
747
|
knife_ec2_create.config[:winrm_user] = "Administrator"
|
744
748
|
knife_ec2_create.config[:winrm_password] = "password"
|
745
749
|
knife_ec2_create.config[:winrm_port] = 12345
|
@@ -1379,15 +1383,39 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1379
1383
|
|
1380
1384
|
end
|
1381
1385
|
|
1386
|
+
describe "#subnet_public_ip_on_launch?" do
|
1387
|
+
before do
|
1388
|
+
allow(new_ec2_server).to receive_messages(:subnet_id => 'subnet-1a2b3c4d')
|
1389
|
+
allow(knife_ec2_create).to receive_messages(:server => new_ec2_server)
|
1390
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
1391
|
+
end
|
1392
|
+
|
1393
|
+
context "when auto_assign_public_ip is enabled" do
|
1394
|
+
it "returns true" do
|
1395
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :map_public_ip_on_launch => true )
|
1396
|
+
expect(knife_ec2_create.subnet_public_ip_on_launch?).to eq(true)
|
1397
|
+
end
|
1398
|
+
end
|
1399
|
+
|
1400
|
+
context "when auto_assign_public_ip is disabled" do
|
1401
|
+
it "returns false" do
|
1402
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :map_public_ip_on_launch => false )
|
1403
|
+
expect(knife_ec2_create.subnet_public_ip_on_launch?).to eq(false)
|
1404
|
+
end
|
1405
|
+
end
|
1406
|
+
end
|
1407
|
+
|
1382
1408
|
describe "ssh_connect_host" do
|
1383
1409
|
before(:each) do
|
1384
1410
|
allow(new_ec2_server).to receive_messages(
|
1385
1411
|
:dns_name => 'public.example.org',
|
1386
1412
|
:private_ip_address => '192.168.1.100',
|
1387
1413
|
:custom => 'custom',
|
1388
|
-
:public_ip_address => '111.111.111.111'
|
1414
|
+
:public_ip_address => '111.111.111.111',
|
1415
|
+
:subnet_id => 'subnet-1a2b3c4d'
|
1389
1416
|
)
|
1390
1417
|
allow(knife_ec2_create).to receive_messages(:server => new_ec2_server)
|
1418
|
+
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
1391
1419
|
end
|
1392
1420
|
|
1393
1421
|
describe "by default" do
|
@@ -1408,9 +1436,18 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1408
1436
|
allow(knife_ec2_create).to receive_messages(:vpc_mode? => true)
|
1409
1437
|
end
|
1410
1438
|
|
1439
|
+
context "subnet_public_ip_on_launch? is true" do
|
1440
|
+
it "uses the dns_name or public_ip_address" do
|
1441
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :map_public_ip_on_launch => true )
|
1442
|
+
expect(knife_ec2_create.subnet_public_ip_on_launch?).to eq(true)
|
1443
|
+
expect(knife_ec2_create.ssh_connect_host).to eq('public.example.org')
|
1444
|
+
end
|
1445
|
+
end
|
1446
|
+
|
1411
1447
|
context "--associate-public-ip is specified" do
|
1412
1448
|
it "uses the dns_name or public_ip_address" do
|
1413
1449
|
knife_ec2_create.config[:associate_public_ip] = true
|
1450
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :map_public_ip_on_launch => false )
|
1414
1451
|
expect(knife_ec2_create.ssh_connect_host).to eq('public.example.org')
|
1415
1452
|
end
|
1416
1453
|
end
|
@@ -1418,12 +1455,14 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1418
1455
|
context "--associate-eip is specified" do
|
1419
1456
|
it "uses the dns_name or public_ip_address" do
|
1420
1457
|
knife_ec2_create.config[:associate_eip] = '111.111.111.111'
|
1458
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :map_public_ip_on_launch => false )
|
1421
1459
|
expect(knife_ec2_create.ssh_connect_host).to eq('public.example.org')
|
1422
1460
|
end
|
1423
1461
|
end
|
1424
1462
|
|
1425
1463
|
context "with no other ip flags" do
|
1426
1464
|
it 'uses private_ip_address' do
|
1465
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :map_public_ip_on_launch => false )
|
1427
1466
|
expect(knife_ec2_create.ssh_connect_host).to eq('192.168.1.100')
|
1428
1467
|
end
|
1429
1468
|
end
|
@@ -1546,6 +1585,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1546
1585
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1547
1586
|
}
|
1548
1587
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1588
|
+
If (-Not $vm_name) {
|
1589
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1590
|
+
}
|
1549
1591
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1550
1592
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1551
1593
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1575,6 +1617,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1575
1617
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1576
1618
|
}
|
1577
1619
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1620
|
+
If (-Not $vm_name) {
|
1621
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1622
|
+
}
|
1578
1623
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1579
1624
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1580
1625
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1632,6 +1677,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1632
1677
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1633
1678
|
}
|
1634
1679
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1680
|
+
If (-Not $vm_name) {
|
1681
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1682
|
+
}
|
1635
1683
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1636
1684
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1637
1685
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1696,6 +1744,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1696
1744
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1697
1745
|
}
|
1698
1746
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1747
|
+
If (-Not $vm_name) {
|
1748
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1749
|
+
}
|
1699
1750
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1700
1751
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1701
1752
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1743,6 +1794,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1743
1794
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1744
1795
|
}
|
1745
1796
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1797
|
+
If (-Not $vm_name) {
|
1798
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1799
|
+
}
|
1746
1800
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1747
1801
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1748
1802
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1783,6 +1837,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1783
1837
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1784
1838
|
}
|
1785
1839
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1840
|
+
If (-Not $vm_name) {
|
1841
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1842
|
+
}
|
1786
1843
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1787
1844
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1788
1845
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1805,6 +1862,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1805
1862
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1806
1863
|
}
|
1807
1864
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1865
|
+
If (-Not $vm_name) {
|
1866
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1867
|
+
}
|
1808
1868
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1809
1869
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1810
1870
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1889,6 +1949,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1889
1949
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1890
1950
|
}
|
1891
1951
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1952
|
+
If (-Not $vm_name) {
|
1953
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1954
|
+
}
|
1892
1955
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1893
1956
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1894
1957
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -1930,6 +1993,9 @@ If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b
|
|
1930
1993
|
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1931
1994
|
}
|
1932
1995
|
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1996
|
+
If (-Not $vm_name) {
|
1997
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1998
|
+
}
|
1933
1999
|
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
|
1934
2000
|
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1935
2001
|
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
@@ -2245,4 +2311,23 @@ netstat > c:\\netstat_data.txt
|
|
2245
2311
|
end
|
2246
2312
|
end
|
2247
2313
|
end
|
2314
|
+
|
2315
|
+
describe 'evaluate_node_name' do
|
2316
|
+
before do
|
2317
|
+
knife_ec2_create.instance_variable_set(:@server, server)
|
2318
|
+
end
|
2319
|
+
|
2320
|
+
context 'when ec2 server attributes are not passed in node name' do
|
2321
|
+
it 'returns the node name unchanged' do
|
2322
|
+
expect(knife_ec2_create.evaluate_node_name("Test")).to eq("Test")
|
2323
|
+
end
|
2324
|
+
end
|
2325
|
+
|
2326
|
+
context 'when %s is passed in the node name' do
|
2327
|
+
it 'returns evaluated node name' do
|
2328
|
+
expect(knife_ec2_create.evaluate_node_name("Test-%s")).to eq("Test-i-123")
|
2329
|
+
end
|
2330
|
+
end
|
2331
|
+
end
|
2332
|
+
|
2248
2333
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-ec2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog-aws
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '0
|
20
|
+
version: '1.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '0
|
27
|
+
version: '1.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: mime-types
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- RELEASE_NOTES.md
|
136
136
|
- Rakefile
|
137
137
|
- knife-ec2.gemspec
|
138
|
+
- lib/chef/knife/ec2_ami_list.rb
|
138
139
|
- lib/chef/knife/ec2_base.rb
|
139
140
|
- lib/chef/knife/ec2_flavor_list.rb
|
140
141
|
- lib/chef/knife/ec2_server_create.rb
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- lib/chef/knife/s3_source.rb
|
144
145
|
- lib/knife-ec2/version.rb
|
145
146
|
- spec/spec_helper.rb
|
147
|
+
- spec/unit/ec2_ami_list_spec.rb
|
146
148
|
- spec/unit/ec2_flavor_list_spec.rb
|
147
149
|
- spec/unit/ec2_server_create_spec.rb
|
148
150
|
- spec/unit/ec2_server_delete_spec.rb
|
@@ -169,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
171
|
version: '0'
|
170
172
|
requirements: []
|
171
173
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.6.
|
174
|
+
rubygems_version: 2.6.10
|
173
175
|
signing_key:
|
174
176
|
specification_version: 4
|
175
177
|
summary: EC2 Support for Chef's Knife Command
|