formatron 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/formatron.rb +5 -8
- data/lib/formatron/chef.rb +27 -16
- data/lib/formatron/chef/knife.rb +17 -15
- data/lib/formatron/chef_clients.rb +0 -8
- data/lib/formatron/cli.rb +1 -0
- data/lib/formatron/cli/deploy.rb +3 -3
- data/lib/formatron/cli/destroy.rb +3 -3
- data/lib/formatron/cli/generators/bootstrap.rb +1 -1
- data/lib/formatron/cli/provision.rb +17 -3
- data/lib/formatron/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f65ce71a403a7fb9643dc55ded5f5db6e29ed56a
|
4
|
+
data.tar.gz: 017ba0b1ecf0fb92becc855038b3bc1023bba5cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 719acdc0c0e57bb503253f1a37c4b9543701a2112d9a069a4488ad50fc7b2a524d84d83b96771a3a683183652bfcb6d3c880f13385c0b0ea57616ef89b0de8d2
|
7
|
+
data.tar.gz: e429955eade1cd8f89039e43991583f02b47d00152a7389e120f133aa360ab072d6ec9bc7eb7b57a1c9993af12be21b5466864c533747adf49e4b2f8fe2c7dfe
|
data/lib/formatron.rb
CHANGED
@@ -147,26 +147,26 @@ class Formatron
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
-
def provision
|
150
|
+
def provision(guid: nil)
|
151
151
|
@all_instances.each do |key, instances|
|
152
|
-
_provision_vpc key, instances
|
152
|
+
_provision_vpc key, instances, guid
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
156
|
# rubocop:disable Metrics/MethodLength
|
157
157
|
# rubocop:disable Metrics/AbcSize
|
158
|
-
def _provision_vpc(key, instances)
|
158
|
+
def _provision_vpc(key, instances, guid_filter)
|
159
159
|
chef_clients = @chef_clients[key]
|
160
160
|
chef_clients.init
|
161
|
-
chef_clients.deploy_databags
|
162
161
|
instances.values.each do |instance|
|
162
|
+
guid = instance.guid
|
163
|
+
next unless guid_filter.nil? || guid_filter.eql?(guid)
|
163
164
|
dsl_chef = instance.chef
|
164
165
|
next if dsl_chef.nil?
|
165
166
|
chef = chef_clients.get dsl_chef.server
|
166
167
|
cookbook = dsl_chef.cookbook
|
167
168
|
bastion = dsl_chef.bastion
|
168
169
|
sub_domain = instance.sub_domain
|
169
|
-
guid = instance.guid
|
170
170
|
_provision_instance chef, cookbook, sub_domain, guid, bastion
|
171
171
|
end
|
172
172
|
ensure
|
@@ -323,7 +323,6 @@ class Formatron
|
|
323
323
|
def _destroy_chef_vpc_instances(key, instances)
|
324
324
|
chef_clients = @chef_clients[key]
|
325
325
|
chef_clients.init
|
326
|
-
chef_clients.delete_databags
|
327
326
|
instances.values.each do |instance|
|
328
327
|
dsl_chef = instance.chef
|
329
328
|
next if dsl_chef.nil?
|
@@ -331,8 +330,6 @@ class Formatron
|
|
331
330
|
guid = instance.guid
|
332
331
|
_destroy_chef_instance chef, guid
|
333
332
|
end
|
334
|
-
rescue => error
|
335
|
-
LOG.warn error
|
336
333
|
ensure
|
337
334
|
chef_clients.unlink
|
338
335
|
end
|
data/lib/formatron/chef.rb
CHANGED
@@ -50,7 +50,6 @@ class Formatron
|
|
50
50
|
username: username,
|
51
51
|
organization: organization,
|
52
52
|
ssl_verify: ssl_verify,
|
53
|
-
name: @name,
|
54
53
|
databag_secret: databag_secret,
|
55
54
|
configuration: configuration
|
56
55
|
)
|
@@ -75,21 +74,8 @@ class Formatron
|
|
75
74
|
@berkshelf.init
|
76
75
|
end
|
77
76
|
|
78
|
-
def deploy_databag
|
79
|
-
Formatron::LOG.info do
|
80
|
-
"Deploying data bag to chef server: #{@chef_sub_domain}"
|
81
|
-
end
|
82
|
-
@knife.deploy_databag
|
83
|
-
end
|
84
|
-
|
85
|
-
def delete_databag
|
86
|
-
Formatron::LOG.info do
|
87
|
-
"Deleting data bag from chef server: #{@chef_sub_domain}"
|
88
|
-
end
|
89
|
-
@knife.delete_databag
|
90
|
-
end
|
91
|
-
|
92
77
|
# rubocop:disable Metrics/MethodLength
|
78
|
+
# rubocop:disable Metrics/AbcSize
|
93
79
|
def provision(
|
94
80
|
sub_domain:,
|
95
81
|
guid:,
|
@@ -112,8 +98,18 @@ class Formatron
|
|
112
98
|
hostname = _hostname(
|
113
99
|
sub_domain: sub_domain
|
114
100
|
)
|
101
|
+
Formatron::LOG.info do
|
102
|
+
"Deploying data bag item '#{guid}' to chef server: #{@chef_sub_domain}"
|
103
|
+
end
|
104
|
+
@knife.deploy_databag name: guid
|
105
|
+
Formatron::LOG.info do
|
106
|
+
"Lock cookbook versions for environment #{guid}"
|
107
|
+
end
|
115
108
|
@knife.create_environment environment: guid
|
116
109
|
@berkshelf.upload environment: guid, cookbook: cookbook
|
110
|
+
Formatron::LOG.info do
|
111
|
+
"Bootstrap node #{guid}"
|
112
|
+
end
|
117
113
|
@knife.bootstrap(
|
118
114
|
bastion_hostname: bastion_hostname,
|
119
115
|
guid: guid,
|
@@ -121,17 +117,32 @@ class Formatron
|
|
121
117
|
hostname: hostname
|
122
118
|
)
|
123
119
|
end
|
124
|
-
# rubocop:enable Metrics/
|
120
|
+
# rubocop:enable Metrics/AbcSize
|
125
121
|
# rubocop:enable Metrics/MethodLength
|
126
122
|
|
123
|
+
# rubocop:disable Metrics/MethodLength
|
127
124
|
def destroy(guid:)
|
128
125
|
Formatron::LOG.info do
|
129
126
|
"Delete Chef configuration for node: #{guid}"
|
130
127
|
end
|
128
|
+
Formatron::LOG.info do
|
129
|
+
"Deleting data bag item '#{guid}' from chef server: #{@chef_sub_domain}"
|
130
|
+
end
|
131
|
+
@knife.delete_databag name: guid
|
132
|
+
Formatron::LOG.info do
|
133
|
+
"Deleting node '#{guid}' from chef server: #{@chef_sub_domain}"
|
134
|
+
end
|
131
135
|
@knife.delete_node node: guid
|
136
|
+
Formatron::LOG.info do
|
137
|
+
"Deleting client '#{guid}' from chef server: #{@chef_sub_domain}"
|
138
|
+
end
|
132
139
|
@knife.delete_client client: guid
|
140
|
+
Formatron::LOG.info do
|
141
|
+
"Deleting environment '#{guid}' from chef server: #{@chef_sub_domain}"
|
142
|
+
end
|
133
143
|
@knife.delete_environment environment: guid
|
134
144
|
end
|
145
|
+
# rubocop:enable Metrics/MethodLength
|
135
146
|
|
136
147
|
def unlink
|
137
148
|
@keys.unlink
|
data/lib/formatron/chef/knife.rb
CHANGED
@@ -15,7 +15,6 @@ class Formatron
|
|
15
15
|
username:,
|
16
16
|
organization:,
|
17
17
|
ssl_verify:,
|
18
|
-
name:,
|
19
18
|
databag_secret:,
|
20
19
|
configuration:
|
21
20
|
)
|
@@ -24,7 +23,6 @@ class Formatron
|
|
24
23
|
@username = username
|
25
24
|
@organization = organization
|
26
25
|
@ssl_verify = ssl_verify
|
27
|
-
@name = name
|
28
26
|
@databag_secret = databag_secret
|
29
27
|
@configuration = configuration
|
30
28
|
end
|
@@ -47,15 +45,20 @@ class Formatron
|
|
47
45
|
@databag_secret_file = Tempfile.new 'formatron-databag-secret-'
|
48
46
|
@databag_secret_file.write @databag_secret
|
49
47
|
@databag_secret_file.close
|
50
|
-
@databag_file = Tempfile.new ['formatron-databag-', '.json']
|
51
|
-
@databag_file.write @configuration.merge(id: @name).to_json
|
52
|
-
@databag_file.close
|
53
48
|
end
|
54
49
|
# rubocop:enable Metrics/MethodLength
|
55
50
|
|
56
|
-
def deploy_databag
|
51
|
+
def deploy_databag(name:)
|
52
|
+
databag_file = Tempfile.new ['formatron-databag-', '.json']
|
53
|
+
databag_file.write @configuration.merge(id: name).to_json
|
54
|
+
databag_file.close
|
57
55
|
_attempt_to_create_databag unless _databag_exists
|
58
|
-
_attempt_to_create_databag_item
|
56
|
+
_attempt_to_create_databag_item(
|
57
|
+
name: name,
|
58
|
+
databag_file: databag_file
|
59
|
+
)
|
60
|
+
ensure
|
61
|
+
databag_file.unlink unless databag_file.nil?
|
59
62
|
end
|
60
63
|
|
61
64
|
def _databag_exists
|
@@ -72,15 +75,15 @@ class Formatron
|
|
72
75
|
# rubocop:enable Metrics/LineLength
|
73
76
|
end
|
74
77
|
|
75
|
-
def _attempt_to_create_databag_item
|
78
|
+
def _attempt_to_create_databag_item(name:, databag_file:)
|
76
79
|
# rubocop:disable Metrics/LineLength
|
77
|
-
fail "failed to create data bag item: #{
|
80
|
+
fail "failed to create data bag item: #{name}" unless _create_databag_item databag_file: databag_file
|
78
81
|
# rubocop:enable Metrics/LineLength
|
79
82
|
end
|
80
83
|
|
81
|
-
def _create_databag_item
|
84
|
+
def _create_databag_item(databag_file:)
|
82
85
|
# rubocop:disable Metrics/LineLength
|
83
|
-
Util::Shell.exec "knife data bag from file formatron #{
|
86
|
+
Util::Shell.exec "knife data bag from file formatron #{databag_file.path} --secret-file #{@databag_secret_file.path} -c #{@knife_file.path}"
|
84
87
|
# rubocop:enable Metrics/LineLength
|
85
88
|
end
|
86
89
|
|
@@ -121,10 +124,10 @@ class Formatron
|
|
121
124
|
# rubocop:enable Metrics/LineLength
|
122
125
|
end
|
123
126
|
|
124
|
-
def delete_databag
|
127
|
+
def delete_databag(name:)
|
125
128
|
# rubocop:disable Metrics/LineLength
|
126
|
-
command = "knife data bag delete formatron #{
|
127
|
-
fail "failed to delete data bag item: #{
|
129
|
+
command = "knife data bag delete formatron #{name} -y -c #{@knife_file.path}"
|
130
|
+
fail "failed to delete data bag item: #{name}" unless Util::Shell.exec command
|
128
131
|
# rubocop:enable Metrics/LineLength
|
129
132
|
end
|
130
133
|
|
@@ -150,7 +153,6 @@ class Formatron
|
|
150
153
|
def unlink
|
151
154
|
@knife_file.unlink unless @knife_file.nil?
|
152
155
|
@databag_secret_file.unlink unless @databag_secret_file.nil?
|
153
|
-
@databag_file.unlink unless @databag_file.nil?
|
154
156
|
end
|
155
157
|
|
156
158
|
private(
|
data/lib/formatron/cli.rb
CHANGED
data/lib/formatron/cli/deploy.rb
CHANGED
@@ -23,8 +23,8 @@ class Formatron
|
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
|
-
def deploy_ok(formatron, target)
|
27
|
-
!formatron.protected? || agree(
|
26
|
+
def deploy_ok(options, formatron, target)
|
27
|
+
options.yes || !formatron.protected? || agree(
|
28
28
|
"Are you sure you wish to deploy protected target: #{target}?"
|
29
29
|
) do |q|
|
30
30
|
q.default = 'no'
|
@@ -40,7 +40,7 @@ class Formatron
|
|
40
40
|
directory: directory,
|
41
41
|
target: target
|
42
42
|
)
|
43
|
-
formatron.deploy if deploy_ok
|
43
|
+
formatron.deploy if deploy_ok options, formatron, target
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -23,8 +23,8 @@ class Formatron
|
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
|
-
def destroy_ok(formatron, target)
|
27
|
-
!formatron.protected? || agree(
|
26
|
+
def destroy_ok(options, formatron, target)
|
27
|
+
options.yes || !formatron.protected? || agree(
|
28
28
|
"Are you sure you wish to destroy protected target: #{target}?"
|
29
29
|
) do |q|
|
30
30
|
q.default = 'no'
|
@@ -40,7 +40,7 @@ class Formatron
|
|
40
40
|
directory: directory,
|
41
41
|
target: target
|
42
42
|
)
|
43
|
-
formatron.destroy if destroy_ok formatron, target
|
43
|
+
formatron.destroy if destroy_ok options, formatron, target
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -5,6 +5,15 @@ class Formatron
|
|
5
5
|
class CLI
|
6
6
|
# CLI command for provision
|
7
7
|
module Provision
|
8
|
+
def provision_options(c)
|
9
|
+
c.option(
|
10
|
+
'-g',
|
11
|
+
'--guid STRING',
|
12
|
+
'The guid of an instance to provision ' \
|
13
|
+
'(will provision all instances if not specified)'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
8
17
|
def provision_directory(options)
|
9
18
|
options.directory || Dir.pwd
|
10
19
|
end
|
@@ -23,14 +32,15 @@ class Formatron
|
|
23
32
|
)
|
24
33
|
end
|
25
34
|
|
26
|
-
def provision_ok(formatron, target)
|
27
|
-
!formatron.protected? || agree(
|
35
|
+
def provision_ok(options, formatron, target)
|
36
|
+
options.yes || !formatron.protected? || agree(
|
28
37
|
"Are you sure you wish to provision protected target: #{target}?"
|
29
38
|
) do |q|
|
30
39
|
q.default = 'no'
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
43
|
+
# rubocop:disable Metrics/MethodLength
|
34
44
|
def provision_action(c)
|
35
45
|
c.action do |args, options|
|
36
46
|
directory = provision_directory options
|
@@ -40,9 +50,12 @@ class Formatron
|
|
40
50
|
directory: directory,
|
41
51
|
target: target
|
42
52
|
)
|
43
|
-
formatron.provision
|
53
|
+
formatron.provision(
|
54
|
+
guid: options.guid
|
55
|
+
) if provision_ok options, formatron, target
|
44
56
|
end
|
45
57
|
end
|
58
|
+
# rubocop:enable Metrics/MethodLength
|
46
59
|
|
47
60
|
def provision_formatron_command
|
48
61
|
command :provision do |c|
|
@@ -51,6 +64,7 @@ class Formatron
|
|
51
64
|
'stack using Opscode Chef'
|
52
65
|
c.description = 'Provision the instances in a Formatron ' \
|
53
66
|
'stack using Opscode Chef'
|
67
|
+
provision_options c
|
54
68
|
provision_action c
|
55
69
|
end
|
56
70
|
end
|
data/lib/formatron/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.10
|
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-12-
|
11
|
+
date: 2015-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -413,7 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
413
413
|
version: '0'
|
414
414
|
requirements: []
|
415
415
|
rubyforge_project:
|
416
|
-
rubygems_version: 2.
|
416
|
+
rubygems_version: 2.4.5.1
|
417
417
|
signing_key:
|
418
418
|
specification_version: 4
|
419
419
|
summary: AWS/Chef Deployment Tool
|