stemcell 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e65ab6388e741e11ab2f46af451098bd7fe70cb847f3ea8f1b9b9d229c860c2c
4
- data.tar.gz: 568f4aecc9c7518ed156355035b39843b04d006bec7876438d707e097e071d30
3
+ metadata.gz: 941a58d82b39ad807a558b7d569ffee7f28ad7477f5dbc1cb61c11e8daab9ff4
4
+ data.tar.gz: 3736e5f1586336821de1d74b249dd64b65b68042de443600cae166a61d054e82
5
5
  SHA512:
6
- metadata.gz: 53d4581e807c8c1373189437a5e0afb42e0dc00c62b3b2b18797a31ae72d483ac066af02c455cfc3fc9a98dcc5452f433bfef618b8f8e56643f5748cff22ce12
7
- data.tar.gz: 431fe9ee22ac0f42ff40227f1ce39e74a88af53af1fb4dc571cace78d167e346d125a2615d35799060853767801412a8c8d4ba35603d269ebc1b5232ec4bbda5
6
+ metadata.gz: ce9ebf93cd89e275e7bcf01cce447936b99686aad8a0fc82ca5ee3982009b508f5ffa7faa0e3b65cb2c310d06fc991a8268262652bd4b083bc53e924e1eded36
7
+ data.tar.gz: a976b2c11ffb37d4703cf8d5424e3110a01653b6dde3ddcfb6c6879845cbbab6580c5c1c5cca6029ca43fadfe50fe4e64f740fbe4ccadfa38f406c10e58f77ec
data/.travis.yml CHANGED
@@ -5,5 +5,6 @@ rvm:
5
5
  - 2.1.2
6
6
  - 2.2.4
7
7
  - 2.3.1
8
+ - 2.6.8
8
9
  before_install:
9
10
  - gem install bundler -v 1.16.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.14.0
2
+ - Adds support for specifying a custom bootstrap template file
3
+
4
+ # 0.13.2
5
+ - Support for specifying --min-count and --max-count
6
+
7
+ # 0.13.1
8
+ - Support for specifying --cpu-options
9
+
1
10
  # 0.13.0
2
11
  - Migrate to AWS SDK to v3
3
12
  - Drop support for ClassicLink
@@ -132,6 +132,7 @@ module Stemcell
132
132
  # comma-separated list when presented as defaults.
133
133
  pd['security_groups'] &&= pd['security_groups'].join(',')
134
134
  pd['tags'] &&= pd['tags'].to_a.map { |p| p.join('=') }.join(',')
135
+ pd['cpu_options'] &&= pd['cpu_options'].to_a.map { |p| p.join('=') }.join(',')
135
136
  pd['chef_cookbook_attributes'] &&= pd['chef_cookbook_attributes'].join(',')
136
137
  end
137
138
 
@@ -31,6 +31,7 @@ module Stemcell
31
31
  'chef_environment',
32
32
  'chef_data_bag_secret',
33
33
  'chef_data_bag_secret_path',
34
+ 'cpu_options',
34
35
  'git_branch',
35
36
  'git_key',
36
37
  'git_origin',
@@ -46,6 +47,8 @@ module Stemcell
46
47
  'dedicated_tenancy',
47
48
  'associate_public_ip_address',
48
49
  'count',
50
+ 'min_count',
51
+ 'max_count',
49
52
  'security_groups',
50
53
  'security_group_ids',
51
54
  'tags',
@@ -80,6 +83,7 @@ module Stemcell
80
83
  @aws_secret_key = opts['aws_secret_key']
81
84
  @aws_session_token = opts['aws_session_token']
82
85
  @max_attempts = opts['max_attempts'] || 3
86
+ @bootstrap_template_path = opts['bootstrap_template_path']
83
87
  configure_aws_creds_and_region
84
88
  end
85
89
 
@@ -101,16 +105,19 @@ module Stemcell
101
105
  tags['Name'] = opts['chef_role'] if opts['chef_environment'] == 'production'
102
106
  tags.merge!(opts['tags']) if opts['tags']
103
107
 
108
+ # Min/max number of instances to launch
109
+ min_count = opts['min_count'] || opts['count']
110
+ max_count = opts['max_count'] || opts['count']
111
+
104
112
  # generate launch options
105
113
  launch_options = {
106
114
  :image_id => opts['image_id'],
107
115
  :instance_type => opts['instance_type'],
108
116
  :key_name => opts['key_name'],
109
- :min_count => opts['count'],
110
- :max_count => opts['count'],
117
+ :min_count => min_count,
118
+ :max_count => max_count,
111
119
  }
112
120
 
113
-
114
121
  # Associate Public IP can only bet set on network_interfaces, and if present
115
122
  # security groups and subnet should be set on the interface. VPC-only.
116
123
  # Primary network interface
@@ -178,6 +185,11 @@ module Stemcell
178
185
  launch_options[:block_device_mappings] = opts['block_device_mappings']
179
186
  end
180
187
 
188
+ # specify cpu options (optional)
189
+ if opts['cpu_options']
190
+ launch_options[:cpu_options] = opts['cpu_options']
191
+ end
192
+
181
193
  # specify ephemeral block device mappings (optional)
182
194
  if opts['ephemeral_devices']
183
195
  launch_options[:block_device_mappings] ||= []
@@ -246,7 +258,7 @@ module Stemcell
246
258
 
247
259
  # this is made public for ec2admin usage
248
260
  def render_template(opts={})
249
- template_file_path = File.expand_path(TEMPLATE_PATH, __FILE__)
261
+ template_file_path = @bootstrap_template_path || File.expand_path(TEMPLATE_PATH, __FILE__)
250
262
  template_file = File.read(template_file_path)
251
263
  erb_template = ERB.new(template_file)
252
264
  last_bootstrap_line = LAST_BOOTSTRAP_LINE
@@ -187,6 +187,12 @@ module Stemcell
187
187
  :type => String,
188
188
  :env => 'CHEF_DATA_BAG_SECRET_PATH'
189
189
  },
190
+ {
191
+ :name => 'cpu_options',
192
+ :desc => "comma-separated list of cpu option key=value pairs",
193
+ :type => String,
194
+ :env => 'CPU_OPTIONS'
195
+ },
190
196
  {
191
197
  :name => 'chef_role',
192
198
  :desc => "chef role of instance to be launched",
@@ -253,6 +259,18 @@ module Stemcell
253
259
  :type => Integer,
254
260
  :env => 'COUNT'
255
261
  },
262
+ {
263
+ :name => 'min_count',
264
+ :desc => "minimum number of instances to launch",
265
+ :type => Integer,
266
+ :env => 'MIN_COUNT'
267
+ },
268
+ {
269
+ :name => 'max_count',
270
+ :desc => "maximum number of instances to launch",
271
+ :type => Integer,
272
+ :env => 'MAX_COUNT'
273
+ },
256
274
  {
257
275
  :name => 'tail',
258
276
  :desc => "interactively tail the initial converge",
@@ -345,6 +363,16 @@ module Stemcell
345
363
  options['tags'] = tags
346
364
  end
347
365
 
366
+ # convert cpu_options from comma separated string to ruby hash
367
+ if options['cpu_options']
368
+ cpu_options = {}
369
+ options['cpu_options'].split(',').each do |cpu_opt|
370
+ key, value = cpu_opt.split('=')
371
+ cpu_options[key] = value
372
+ end
373
+ options['cpu_options'] = cpu_options
374
+ end
375
+
348
376
  # parse block_device_mappings to convert it from the standard CLI format
349
377
  # to the EC2 Ruby API format.
350
378
  # All of this is a bit hard to find so here are some docs links to
@@ -1,3 +1,3 @@
1
1
  module Stemcell
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
@@ -23,6 +23,51 @@ describe Stemcell::Launcher do
23
23
  end
24
24
  let(:instance_ids) { instances.map(&:id) }
25
25
 
26
+ describe '#render_template' do
27
+
28
+ context 'when bootstrap_template_path is not provided' do
29
+ let(:subject) do
30
+ launcher.render_template()
31
+ end
32
+
33
+ before do
34
+ allow(File).to receive(:expand_path).and_return('/path/to/default/bootstrap.sh.erb')
35
+ allow(File).to receive(:read).and_return('default template content')
36
+ end
37
+
38
+ it 'launches the default template' do
39
+ expect(File).to receive(:expand_path)
40
+ expect(File).to receive(:read).with('/path/to/default/bootstrap.sh.erb')
41
+
42
+ expect(subject).not_to be_empty
43
+ end
44
+ end
45
+
46
+ context 'when bootstrap_template_path is provided' do
47
+ let(:subject) do
48
+ launcher.render_template()
49
+ end
50
+
51
+ let(:launcher) do
52
+ opts = {'region' => 'region', 'vpc_id' => 'vpc-1', 'bootstrap_template_path' => '/path/to/file.sh.erb'}
53
+ launcher = Stemcell::Launcher.new(opts)
54
+
55
+ launcher
56
+ end
57
+
58
+ before do
59
+ allow(File).to receive(:read).and_return('custom template content')
60
+ end
61
+
62
+ it 'launches the override template' do
63
+ expect(File).not_to receive(:expand_path)
64
+ expect(File).to receive(:read).with('/path/to/file.sh.erb')
65
+
66
+ expect(subject).not_to be_empty
67
+ end
68
+ end
69
+ end
70
+
26
71
  describe '#launch' do
27
72
  let(:ec2) do
28
73
  ec2 = Aws::EC2::Client.new
@@ -71,7 +116,8 @@ describe Stemcell::Launcher do
71
116
  'count' => 2,
72
117
  'security_groups' => ['sg_name1', 'sg_name2'],
73
118
  'user' => 'some_user',
74
- 'wait' => true
119
+ 'wait' => true,
120
+ 'cpu_options' => 'core_count=1,threads_per_core=1'
75
121
  }
76
122
  }
77
123
 
@@ -107,11 +153,25 @@ describe Stemcell::Launcher do
107
153
  { :key => "stemcell", :value => Stemcell::VERSION },
108
154
  ]},
109
155
  ],
110
- :user_data => Base64.encode64('template')
156
+ :user_data => Base64.encode64('template'),
157
+ :cpu_options => 'core_count=1,threads_per_core=1'
111
158
  )).and_return(instances)
112
159
  launched_instances = launcher.send(:launch, launch_options)
113
160
  expect(launched_instances.map(&:public_ip_address)).to all(be_truthy)
114
161
  end
162
+
163
+ it 'launches with min/max count' do
164
+ expect(launcher).to receive(:do_launch).with(a_hash_including(
165
+ :min_count => 3,
166
+ :max_count => 6,
167
+ )).and_return(instances)
168
+ options = launch_options.merge(
169
+ 'min_count' => 3,
170
+ 'max_count' => 6,
171
+ )
172
+ launched_instances = launcher.send(:launch,
173
+ launch_options.merge('min_count' => 3, 'max_count' => 6))
174
+ end
115
175
  end
116
176
 
117
177
  describe '#kill' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stemcell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Rhoads
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-12-14 00:00:00.000000000 Z
14
+ date: 2022-07-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: aws-eventstream
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  - !ruby/object:Gem::Version
268
268
  version: '0'
269
269
  requirements: []
270
- rubygems_version: 3.0.3
270
+ rubygems_version: 3.0.3.1
271
271
  signing_key:
272
272
  specification_version: 4
273
273
  summary: no summary