formatron 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: d2fbc3682dfed44912c502471c91985385772edc
4
- data.tar.gz: d47b4b18846677185d75bbe1caccb5d49d5e8711
3
+ metadata.gz: 151ab7174411866cef2baa32c55fc5369e005a01
4
+ data.tar.gz: 86caf9686fe667117f449703b28b991b0c86f4e0
5
5
  SHA512:
6
- metadata.gz: a352259c2fa5fa21a28fff086e279bfacd8e1c7ab7a9dd435e15c673ea1907a56e2a669f46f9a22ae60f255441a46d0196d48206d3864b79917e5d123580d59f
7
- data.tar.gz: c31fc3dd6d65b832b820db576e92e3ee28b9f98f430a23dc5993a3277e8a7608d3a8d1e9b6a4d340af0e9eeb1937036e8f90e65778f06794cddf71538be34976
6
+ metadata.gz: 09ba7c7372af63e0f1091e163d249f5da961a7168b83ef24d72e037414bae6df303e7acb1b597b7b9a588f85d2f730884727a0cb39142a5a412337d3a49689ad
7
+ data.tar.gz: eb0926ad7d887d84bb7690051f666adaab4fcb88b27d51758a8f6fb651ea7a7cf6c4391330e860166a897d93791a9dc9d56dba7b774d87a6fd2825b2f98bd9bb
data/exe/formatron CHANGED
@@ -4,6 +4,8 @@ require 'formatron/cli'
4
4
  require 'formatron/cli/generators/credentials'
5
5
  require 'formatron/cli/generators/bootstrap'
6
6
  require 'formatron/cli/generators/instance'
7
+ require 'formatron/cli/generators/guid'
8
+ require 'formatron/cli/generators/databag_secret'
7
9
  require 'formatron/cli/deploy'
8
10
  require 'formatron/cli/destroy'
9
11
  require 'formatron/cli/provision'
@@ -12,6 +14,8 @@ require 'formatron/cli/completion'
12
14
  Formatron::CLI.include Formatron::CLI::Generators::Credentials
13
15
  Formatron::CLI.include Formatron::CLI::Generators::Bootstrap
14
16
  Formatron::CLI.include Formatron::CLI::Generators::Instance
17
+ Formatron::CLI.include Formatron::CLI::Generators::GUID
18
+ Formatron::CLI.include Formatron::CLI::Generators::DatabagSecret
15
19
  Formatron::CLI.include Formatron::CLI::Deploy
16
20
  Formatron::CLI.include Formatron::CLI::Destroy
17
21
  Formatron::CLI.include Formatron::CLI::Provision
@@ -109,15 +109,15 @@ class Formatron
109
109
  end
110
110
 
111
111
  def bootstrap(
112
- environment:,
112
+ guid:,
113
113
  bastion_hostname:,
114
114
  cookbook:,
115
115
  hostname:
116
116
  )
117
117
  # rubocop:disable Metrics/LineLength
118
- command = "knife bootstrap #{hostname} --sudo -x ubuntu -i #{@keys.ec2_key} -E #{environment} -r #{cookbook} -N #{environment} -c #{@knife_file.path}#{@ssl_verify ? '' : ' --node-ssl-verify-mode none'} --secret-file #{@databag_secret_file.path}"
118
+ command = "knife bootstrap #{hostname} --sudo -x ubuntu -i #{@keys.ec2_key} -E #{guid} -r #{cookbook} -N #{guid} -c #{@knife_file.path}#{@ssl_verify ? '' : ' --node-ssl-verify-mode none'} --secret-file #{@databag_secret_file.path}"
119
119
  command = "#{command} -G ubuntu@#{bastion_hostname}" unless bastion_hostname.eql? hostname
120
- fail "failed to bootstrap instance: #{hostname}" unless Util::Shell.exec command
120
+ fail "failed to bootstrap instance: #{guid}" unless Util::Shell.exec command
121
121
  # rubocop:enable Metrics/LineLength
122
122
  end
123
123
 
@@ -92,11 +92,12 @@ class Formatron
92
92
  # rubocop:disable Metrics/MethodLength
93
93
  def provision(
94
94
  sub_domain:,
95
+ guid:,
95
96
  cookbook:,
96
97
  bastion:
97
98
  )
98
99
  Formatron::LOG.info do
99
- "Provision #{sub_domain} with Chef cookbook: #{cookbook}"
100
+ "Provision #{guid} with Chef cookbook: #{cookbook}"
100
101
  end
101
102
  bastion ||= @bastions.keys[0]
102
103
  bastion_hostname = _hostname(
@@ -111,11 +112,11 @@ class Formatron
111
112
  hostname = _hostname(
112
113
  sub_domain: sub_domain
113
114
  )
114
- @knife.create_environment environment: sub_domain
115
- @berkshelf.upload environment: sub_domain, cookbook: cookbook
115
+ @knife.create_environment environment: guid
116
+ @berkshelf.upload environment: guid, cookbook: cookbook
116
117
  @knife.bootstrap(
117
118
  bastion_hostname: bastion_hostname,
118
- environment: sub_domain,
119
+ guid: guid,
119
120
  cookbook: cookbook_name,
120
121
  hostname: hostname
121
122
  )
@@ -123,13 +124,13 @@ class Formatron
123
124
  # rubocop:enable Metrics/ParameterLists
124
125
  # rubocop:enable Metrics/MethodLength
125
126
 
126
- def destroy(sub_domain:)
127
+ def destroy(guid:)
127
128
  Formatron::LOG.info do
128
- "Delete Chef configuration for node: #{sub_domain}"
129
+ "Delete Chef configuration for node: #{guid}"
129
130
  end
130
- @knife.delete_node node: sub_domain
131
- @knife.delete_client client: sub_domain
132
- @knife.delete_environment environment: sub_domain
131
+ @knife.delete_node node: guid
132
+ @knife.delete_client client: guid
133
+ @knife.delete_environment environment: guid
133
134
  end
134
135
 
135
136
  def unlink
@@ -0,0 +1,25 @@
1
+ require 'formatron/generators/util'
2
+
3
+ class Formatron
4
+ class CLI
5
+ module Generators
6
+ # CLI command for databag secret generator
7
+ module DatabagSecret
8
+ def databag_secret_action(c)
9
+ c.action do |_args, _options|
10
+ puts Formatron::Generators::Util.databag_secret
11
+ end
12
+ end
13
+
14
+ def databag_secret_formatron_command
15
+ command :'generate data bag secret' do |c|
16
+ c.syntax = 'formatron generate data bag secret [options]'
17
+ c.summary = 'Generate a random data bag secret'
18
+ c.description = 'Generate a random data bag secret'
19
+ databag_secret_action c
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'formatron/generators/util'
2
+
3
+ class Formatron
4
+ class CLI
5
+ module Generators
6
+ # CLI command for GUID generator
7
+ module GUID
8
+ def guid_action(c)
9
+ c.action do |_args, _options|
10
+ puts Formatron::Generators::Util.guid
11
+ end
12
+ end
13
+
14
+ def guid_formatron_command
15
+ command :'generate guid' do |c|
16
+ c.syntax = 'formatron generate guid [options]'
17
+ c.summary = 'Generate a random GUID'
18
+ c.description = 'Generate a random GUID'
19
+ guid_action c
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -6,6 +6,8 @@ class Formatron
6
6
  # Generates CloudFormation template EC2 resources
7
7
  # rubocop:disable Metrics/ModuleLength
8
8
  module EC2
9
+ BLOCK_DEVICE_MAPPINGS = :BlockDeviceMappings
10
+
9
11
  def self.vpc(cidr:)
10
12
  {
11
13
  Type: 'AWS::EC2::VPC',
@@ -232,6 +234,42 @@ class Formatron
232
234
  end
233
235
  # rubocop:enable Metrics/MethodLength
234
236
 
237
+ def self.block_device_mapping(device:, size:, type:, iops:)
238
+ mapping = {
239
+ DeviceName: device,
240
+ Ebs: {
241
+ VolumeSize: size
242
+ }
243
+ }
244
+ mapping[:Ebs][:VolumeType] = type unless type.nil?
245
+ mapping[:Ebs][:Iops] = iops unless iops.nil?
246
+ mapping
247
+ end
248
+
249
+ def self.volume(size:, type:, iops:, availability_zone:)
250
+ volume = {
251
+ Type: 'AWS::EC2::Volume',
252
+ Properties: {
253
+ AvailabilityZone: availability_zone,
254
+ Size: size
255
+ }
256
+ }
257
+ volume[:Properties][:VolumeType] = type unless type.nil?
258
+ volume[:Properties][:Iops] = iops unless iops.nil?
259
+ volume
260
+ end
261
+
262
+ def self.volume_attachment(device:, instance:, volume:)
263
+ {
264
+ Type: 'AWS::EC2::VolumeAttachment',
265
+ Properties: {
266
+ Device: device,
267
+ InstanceId: Template.ref(instance),
268
+ VolumeId: Template.ref(volume)
269
+ }
270
+ }
271
+ end
272
+
235
273
  # rubocop:disable Metrics/MethodLength
236
274
  # rubocop:disable Metrics/ParameterLists
237
275
  # rubocop:disable Metrics/AbcSize
@@ -0,0 +1,36 @@
1
+ require 'formatron/cloud_formation/resources/ec2'
2
+
3
+ class Formatron
4
+ module CloudFormation
5
+ class Template
6
+ class VPC
7
+ class Subnet
8
+ class Instance
9
+ # Adds block device mappings to an instance
10
+ class BlockDevices
11
+ def initialize(block_devices:)
12
+ @block_devices = block_devices
13
+ end
14
+
15
+ # rubocop:disable Metrics/MethodLength
16
+ def merge(properties:)
17
+ return if @block_devices.length == 0
18
+ block_device_mappings = @block_devices.map do |block_device|
19
+ Resources::EC2.block_device_mapping(
20
+ device: block_device.device,
21
+ size: block_device.size,
22
+ type: block_device.type,
23
+ iops: block_device.iops
24
+ )
25
+ end
26
+ properties[Resources::EC2::BLOCK_DEVICE_MAPPINGS] =
27
+ block_device_mappings
28
+ end
29
+ # rubocop:enable Metrics/MethodLength
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -5,6 +5,7 @@ require 'formatron/cloud_formation/resources/route53'
5
5
  require_relative 'instance/policy'
6
6
  require_relative 'instance/security_group'
7
7
  require_relative 'instance/setup'
8
+ require_relative 'instance/block_devices'
8
9
 
9
10
  class Formatron
10
11
  module CloudFormation
@@ -21,6 +22,9 @@ class Formatron
21
22
  WAIT_CONDITION_PREFIX = 'waitCondition'
22
23
  PRIVATE_RECORD_SET_PREFIX = 'privateRecordSet'
23
24
  PUBLIC_RECORD_SET_PREFIX = 'publicRecordSet'
25
+ PUBLIC_ALIAS_RECORD_SET_PREFIX = 'publicAliasRecordSet'
26
+ VOLUME_PREFIX = 'volume'
27
+ VOLUME_ATTACHMENT_PREFIX = 'volumeAttachment'
24
28
 
25
29
  # rubocop:disable Metrics/MethodLength
26
30
  # rubocop:disable Metrics/AbcSize
@@ -43,6 +47,7 @@ class Formatron
43
47
  @instance = instance
44
48
  @guid = @instance.guid
45
49
  @setup = @instance.setup
50
+ @block_devices = @instance.block_device
46
51
  @instance_id = "#{INSTANCE_PREFIX}#{@guid}"
47
52
  @role_id = "#{ROLE_PREFIX}#{@guid}"
48
53
  @instance_profile_id = "#{INSTANCE_PROFILE_PREFIX}#{@guid}"
@@ -73,6 +78,8 @@ class Formatron
73
78
  "#{PRIVATE_RECORD_SET_PREFIX}#{@guid}"
74
79
  @public_record_set_id =
75
80
  "#{PUBLIC_RECORD_SET_PREFIX}#{@guid}"
81
+ @public_aliases = @instance.public_alias
82
+ @volumes = @instance.volume
76
83
  @bucket = bucket
77
84
  @name = name
78
85
  @target = target
@@ -125,6 +132,10 @@ class Formatron
125
132
  hosted_zone_name: @hosted_zone_name
126
133
  )
127
134
  setup.merge instance: instance
135
+ block_devices = BlockDevices.new(
136
+ block_devices: @block_devices
137
+ )
138
+ block_devices.merge properties: instance[:Properties]
128
139
  resources[@instance_id] = instance
129
140
  outputs[@instance_id] = Template.output(
130
141
  Template.ref(@instance_id)
@@ -150,9 +161,55 @@ class Formatron
150
161
  instance: @instance_id,
151
162
  attribute: 'PublicIp'
152
163
  ) unless @public_hosted_zone_id.nil?
164
+ _add_public_aliases resources unless @public_hosted_zone_id.nil?
165
+ _add_volumes resources
153
166
  end
154
167
  # rubocop:enable Metrics/AbcSize
155
168
  # rubocop:enable Metrics/MethodLength
169
+
170
+ # rubocop:disable Metrics/MethodLength
171
+ def _add_public_aliases(resources)
172
+ @public_aliases.each_index do |index|
173
+ sub_domain = @public_aliases[index]
174
+ logical_id = "#{PUBLIC_ALIAS_RECORD_SET_PREFIX}#{index}#{@guid}"
175
+ resources[logical_id] = Resources::Route53.record_set(
176
+ hosted_zone_id: @public_hosted_zone_id,
177
+ sub_domain: sub_domain,
178
+ hosted_zone_name: @hosted_zone_name,
179
+ instance: @instance_id,
180
+ attribute: 'PublicIp'
181
+ )
182
+ end
183
+ end
184
+ # rubocop:enable Metrics/MethodLength
185
+
186
+ # rubocop:disable Metrics/MethodLength
187
+ def _add_volumes(resources)
188
+ @volumes.each_index do |index|
189
+ volume = @volumes[index]
190
+ volume_id = "#{VOLUME_PREFIX}#{index}#{@guid}"
191
+ volume_attachment_id =
192
+ "#{VOLUME_ATTACHMENT_PREFIX}#{index}#{@guid}"
193
+ resources[volume_id] = Resources::EC2.volume(
194
+ availability_zone: @availability_zone,
195
+ size: volume.size,
196
+ type: volume.type,
197
+ iops: volume.iops
198
+ )
199
+ resources[volume_attachment_id] =
200
+ Resources::EC2.volume_attachment(
201
+ device: volume.device,
202
+ instance: "#{INSTANCE_PREFIX}#{@guid}",
203
+ volume: volume_id
204
+ )
205
+ end
206
+ end
207
+ # rubocop:enable Metrics/MethodLength
208
+
209
+ private(
210
+ :_add_public_aliases,
211
+ :_add_volumes
212
+ )
156
213
  end
157
214
  # rubocop:enable Metrics/ClassLength
158
215
  end
@@ -0,0 +1,23 @@
1
+ require 'formatron/util/dsl'
2
+
3
+ class Formatron
4
+ class DSL
5
+ class Formatron
6
+ class VPC
7
+ class Subnet
8
+ class Instance
9
+ # Instance block device mappings
10
+ class BlockDevice
11
+ extend Util::DSL
12
+ dsl_initialize_block
13
+ dsl_property :device
14
+ dsl_property :size
15
+ dsl_property :type
16
+ dsl_property :iops
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'formatron/util/dsl'
2
+
3
+ class Formatron
4
+ class DSL
5
+ class Formatron
6
+ class VPC
7
+ class Subnet
8
+ class Instance
9
+ # Instance volume attachments
10
+ class Volume
11
+ extend Util::DSL
12
+ dsl_initialize_block
13
+ dsl_property :device
14
+ dsl_property :size
15
+ dsl_property :type
16
+ dsl_property :iops
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -2,6 +2,8 @@ require_relative 'instance/chef'
2
2
  require_relative 'instance/policy'
3
3
  require_relative 'instance/security_group'
4
4
  require_relative 'instance/setup'
5
+ require_relative 'instance/volume'
6
+ require_relative 'instance/block_device'
5
7
  require 'formatron/util/dsl'
6
8
 
7
9
  class Formatron
@@ -15,12 +17,15 @@ class Formatron
15
17
  dsl_initialize_hash
16
18
  dsl_property :guid
17
19
  dsl_property :sub_domain
20
+ dsl_array :public_alias
18
21
  dsl_property :source_dest_check
19
22
  dsl_property :instance_type
20
23
  dsl_block :chef, 'Chef'
21
24
  dsl_block :policy, 'Policy'
22
25
  dsl_block :security_group, 'SecurityGroup'
23
26
  dsl_block :setup, 'Setup'
27
+ dsl_block_array :volume, 'Volume'
28
+ dsl_block_array :block_device, 'BlockDevice'
24
29
  end
25
30
  end
26
31
  end
@@ -7,7 +7,7 @@ class Formatron
7
7
  end
8
8
 
9
9
  def self.databag_secret
10
- Random.rand(36**40).to_s(36).upcase
10
+ SecureRandom.random_number(36**40).to_s(36).upcase
11
11
  end
12
12
  end
13
13
  end
@@ -1,4 +1,4 @@
1
1
  # add version to class
2
2
  class Formatron
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
data/lib/formatron.rb CHANGED
@@ -159,7 +159,8 @@ class Formatron
159
159
  cookbook = dsl_chef.cookbook
160
160
  bastion = dsl_chef.bastion
161
161
  sub_domain = instance.sub_domain
162
- _provision_instance chef, cookbook, sub_domain, bastion
162
+ guid = instance.guid
163
+ _provision_instance chef, cookbook, sub_domain, guid, bastion
163
164
  end
164
165
  ensure
165
166
  chef_clients.unlink
@@ -167,9 +168,10 @@ class Formatron
167
168
  # rubocop:enable Metrics/AbcSize
168
169
  # rubocop:enable Metrics/MethodLength
169
170
 
170
- def _provision_instance(chef, cookbook, sub_domain, bastion)
171
+ def _provision_instance(chef, cookbook, sub_domain, guid, bastion)
171
172
  chef.provision(
172
173
  sub_domain: sub_domain,
174
+ guid: guid,
173
175
  cookbook: cookbook,
174
176
  bastion: bastion
175
177
  )
@@ -319,8 +321,8 @@ class Formatron
319
321
  dsl_chef = instance.chef
320
322
  next if dsl_chef.nil?
321
323
  chef = chef_clients.get dsl_chef.server
322
- sub_domain = instance.sub_domain
323
- _destroy_chef_instance chef, sub_domain
324
+ guid = instance.guid
325
+ _destroy_chef_instance chef, guid
324
326
  end
325
327
  rescue => error
326
328
  LOG.warn error
@@ -329,9 +331,9 @@ class Formatron
329
331
  end
330
332
  # rubocop:enable Metrics/MethodLength
331
333
 
332
- def _destroy_chef_instance(chef, sub_domain)
334
+ def _destroy_chef_instance(chef, guid)
333
335
  chef.destroy(
334
- sub_domain: sub_domain
336
+ guid: guid
335
337
  )
336
338
  rescue => error
337
339
  LOG.warn error
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Halliday
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -314,6 +314,8 @@ files:
314
314
  - lib/formatron/cli/destroy.rb
315
315
  - lib/formatron/cli/generators/bootstrap.rb
316
316
  - lib/formatron/cli/generators/credentials.rb
317
+ - lib/formatron/cli/generators/databag_secret.rb
318
+ - lib/formatron/cli/generators/guid.rb
317
319
  - lib/formatron/cli/generators/instance.rb
318
320
  - lib/formatron/cli/provision.rb
319
321
  - lib/formatron/cloud_formation.rb
@@ -330,6 +332,7 @@ files:
330
332
  - lib/formatron/cloud_formation/template/vpc/subnet/bastion.rb
331
333
  - lib/formatron/cloud_formation/template/vpc/subnet/chef_server.rb
332
334
  - lib/formatron/cloud_formation/template/vpc/subnet/instance.rb
335
+ - lib/formatron/cloud_formation/template/vpc/subnet/instance/block_devices.rb
333
336
  - lib/formatron/cloud_formation/template/vpc/subnet/instance/policy.rb
334
337
  - lib/formatron/cloud_formation/template/vpc/subnet/instance/security_group.rb
335
338
  - lib/formatron/cloud_formation/template/vpc/subnet/instance/setup.rb
@@ -348,12 +351,14 @@ files:
348
351
  - lib/formatron/dsl/formatron/vpc/subnet/chef_server.rb
349
352
  - lib/formatron/dsl/formatron/vpc/subnet/chef_server/organization.rb
350
353
  - lib/formatron/dsl/formatron/vpc/subnet/instance.rb
354
+ - lib/formatron/dsl/formatron/vpc/subnet/instance/block_device.rb
351
355
  - lib/formatron/dsl/formatron/vpc/subnet/instance/chef.rb
352
356
  - lib/formatron/dsl/formatron/vpc/subnet/instance/policy.rb
353
357
  - lib/formatron/dsl/formatron/vpc/subnet/instance/policy/statement.rb
354
358
  - lib/formatron/dsl/formatron/vpc/subnet/instance/security_group.rb
355
359
  - lib/formatron/dsl/formatron/vpc/subnet/instance/setup.rb
356
360
  - lib/formatron/dsl/formatron/vpc/subnet/instance/setup/variable.rb
361
+ - lib/formatron/dsl/formatron/vpc/subnet/instance/volume.rb
357
362
  - lib/formatron/external.rb
358
363
  - lib/formatron/external/dsl.rb
359
364
  - lib/formatron/external/outputs.rb