biosphere 0.0.14 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/biosphere +172 -111
- data/lib/biosphere.rb +5 -0
- data/lib/biosphere/deployment.rb +165 -0
- data/lib/biosphere/kube.rb +26 -8
- data/lib/biosphere/node.rb +52 -9
- data/lib/biosphere/s3.rb +7 -5
- data/lib/biosphere/settings.rb +72 -0
- data/lib/biosphere/state.rb +60 -0
- data/lib/biosphere/suite.rb +99 -101
- data/lib/biosphere/terraformproxy.rb +44 -126
- data/lib/biosphere/version.rb +1 -1
- metadata +33 -2
@@ -15,6 +15,10 @@ class Biosphere
|
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
+
def state
|
19
|
+
return @caller.state.node
|
20
|
+
end
|
21
|
+
|
18
22
|
def method_missing(symbol, *args)
|
19
23
|
#puts ">>>>>>>> method missing: #{symbol}, #{args}"
|
20
24
|
|
@@ -32,15 +36,6 @@ class Biosphere
|
|
32
36
|
|
33
37
|
end
|
34
38
|
|
35
|
-
|
36
|
-
class PlanProxy
|
37
|
-
attr_accessor :node
|
38
|
-
def initialize()
|
39
|
-
@node = Node.new
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
39
|
class ResourceProxy
|
45
40
|
attr_reader :output
|
46
41
|
attr_reader :caller
|
@@ -50,46 +45,52 @@ class Biosphere
|
|
50
45
|
@caller = caller
|
51
46
|
end
|
52
47
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
48
|
def respond_to?(symbol, include_private = false)
|
57
49
|
return true
|
58
50
|
end
|
59
51
|
|
60
52
|
def set(symbol, value)
|
61
|
-
@output[symbol] = value
|
62
|
-
end
|
63
|
-
|
64
|
-
def method_missing(symbol, *args)
|
65
|
-
#puts ">>>>>>>> method missing: #{symbol}, #{args}"
|
66
|
-
|
67
|
-
if @caller.methods.include?(symbol)
|
68
|
-
return @caller.method(symbol).call(*args)
|
69
|
-
end
|
70
|
-
|
71
|
-
# Support getter here
|
72
|
-
if args.length == 0
|
73
|
-
return @output[symbol]
|
74
|
-
end
|
75
53
|
|
76
54
|
# Support setter here
|
77
55
|
if [:ingress, :egress, :route].include?(symbol)
|
78
56
|
@output[symbol] ||= []
|
79
|
-
if
|
80
|
-
@output[symbol] +=
|
57
|
+
if value.kind_of?(Array)
|
58
|
+
@output[symbol] += value
|
81
59
|
else
|
82
|
-
@output[symbol] <<
|
60
|
+
@output[symbol] << value
|
83
61
|
end
|
84
62
|
else
|
85
|
-
@output[symbol] =
|
63
|
+
@output[symbol] = value
|
86
64
|
end
|
87
65
|
|
88
|
-
# We need to first gzip and then base64-encode the user_data string to work around the 16kb size limitation in AWS
|
89
66
|
if symbol === :user_data
|
90
|
-
@output[symbol] = Base64.strict_encode64(Zlib::Deflate.new(nil, 31).deflate(
|
67
|
+
@output[symbol] = Base64.strict_encode64(Zlib::Deflate.new(nil, 31).deflate(value, Zlib::FINISH))
|
91
68
|
end
|
92
69
|
end
|
70
|
+
|
71
|
+
def get(symbol)
|
72
|
+
return @output[symbol]
|
73
|
+
end
|
74
|
+
|
75
|
+
def node
|
76
|
+
return @caller.node
|
77
|
+
end
|
78
|
+
|
79
|
+
def state
|
80
|
+
return @caller.state.node
|
81
|
+
end
|
82
|
+
|
83
|
+
def id_of(type,name)
|
84
|
+
"${#{type}.#{name}.id}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def output_of(type, name, *values)
|
88
|
+
"${#{type}.#{name}.#{values.join(".")}}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def method_missing(symbol, *args)
|
92
|
+
return @caller.method(symbol).call(*args)
|
93
|
+
end
|
93
94
|
end
|
94
95
|
|
95
96
|
class TerraformProxy
|
@@ -97,14 +98,12 @@ class Biosphere
|
|
97
98
|
attr_accessor :export
|
98
99
|
attr_accessor :resources
|
99
100
|
attr_accessor :actions
|
100
|
-
attr_accessor :plans
|
101
|
-
attr_accessor :plan_proxy
|
102
101
|
attr_reader :src_path
|
103
102
|
|
104
103
|
include Kube
|
105
104
|
|
106
105
|
|
107
|
-
def initialize(script_name,
|
106
|
+
def initialize(script_name, suite)
|
108
107
|
@script_name = script_name
|
109
108
|
@src_path = [File.dirname(script_name)]
|
110
109
|
|
@@ -114,16 +113,16 @@ class Biosphere
|
|
114
113
|
"variable" => {},
|
115
114
|
"output" => {}
|
116
115
|
}
|
117
|
-
|
118
|
-
plan_proxy = PlanProxy.new
|
119
|
-
end
|
120
|
-
@plan_proxy = plan_proxy
|
121
|
-
@resources = []
|
116
|
+
@suite = suite
|
122
117
|
@actions = {}
|
123
|
-
@
|
118
|
+
@deployments = []
|
124
119
|
|
125
120
|
end
|
126
121
|
|
122
|
+
def register(deployment)
|
123
|
+
@suite.register(deployment)
|
124
|
+
end
|
125
|
+
|
127
126
|
def load_from_file()
|
128
127
|
self.from_file(@script_name)
|
129
128
|
end
|
@@ -159,25 +158,8 @@ class Biosphere
|
|
159
158
|
@src_path.pop
|
160
159
|
end
|
161
160
|
|
162
|
-
|
163
161
|
include Biosphere::Mixing::FromFile
|
164
162
|
|
165
|
-
def provider(name, spec={})
|
166
|
-
@export["provider"][name.to_s] = spec
|
167
|
-
end
|
168
|
-
|
169
|
-
def variable(name, value)
|
170
|
-
@export["variable"][name] = {
|
171
|
-
"default" => value
|
172
|
-
}
|
173
|
-
end
|
174
|
-
|
175
|
-
def output(name, value)
|
176
|
-
@export["output"][name] = {
|
177
|
-
"value" => value
|
178
|
-
}
|
179
|
-
end
|
180
|
-
|
181
163
|
def action(name, description, &block)
|
182
164
|
@actions[name] = {
|
183
165
|
:name => name,
|
@@ -188,26 +170,6 @@ class Biosphere
|
|
188
170
|
}
|
189
171
|
end
|
190
172
|
|
191
|
-
def plan(name, &block)
|
192
|
-
plan = {
|
193
|
-
:name => name,
|
194
|
-
:block => block,
|
195
|
-
:location => caller[0]
|
196
|
-
}
|
197
|
-
@plans << plan
|
198
|
-
end
|
199
|
-
|
200
|
-
def node
|
201
|
-
return @plan_proxy.node
|
202
|
-
end
|
203
|
-
|
204
|
-
def evaluate_plans()
|
205
|
-
@plans.each do |resource|
|
206
|
-
@plan_proxy.instance_eval(&resource[:block])
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
173
|
def call_action(name, context)
|
212
174
|
context.caller = self
|
213
175
|
context.src_path = @actions[name][:src_path]
|
@@ -215,40 +177,6 @@ class Biosphere
|
|
215
177
|
context.instance_eval(&@actions[name][:block])
|
216
178
|
end
|
217
179
|
|
218
|
-
def resource(type, name, &block)
|
219
|
-
@export["resource"][type.to_s] ||= {}
|
220
|
-
if @export["resource"][type.to_s][name.to_s]
|
221
|
-
throw "Tried to create a resource of type #{type} called '#{name}' when one already exists"
|
222
|
-
end
|
223
|
-
|
224
|
-
spec = {}
|
225
|
-
resource = {
|
226
|
-
:name => name,
|
227
|
-
:type => type,
|
228
|
-
:location => caller[0] + "a"
|
229
|
-
}
|
230
|
-
|
231
|
-
if block_given?
|
232
|
-
resource[:block] = block
|
233
|
-
else
|
234
|
-
STDERR.puts("WARNING: No block set for resource call '#{type}', '#{name}' at #{caller[0]}")
|
235
|
-
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
@resources << resource
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
def evaluate_resources()
|
244
|
-
@resources.each do |resource|
|
245
|
-
proxy = ResourceProxy.new(self)
|
246
|
-
proxy.instance_eval(&resource[:block])
|
247
|
-
|
248
|
-
@export["resource"][resource[:type].to_s][resource[:name].to_s] = proxy.output
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
180
|
def id_of(type,name)
|
253
181
|
"${#{type}.#{name}.id}"
|
254
182
|
end
|
@@ -257,22 +185,12 @@ class Biosphere
|
|
257
185
|
"${#{type}.#{name}.#{values.join(".")}}"
|
258
186
|
end
|
259
187
|
|
260
|
-
def
|
261
|
-
|
262
|
-
resource(type, name, spec)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
def use_resource_shortcuts!
|
267
|
-
require_relative 'resource_shortcuts'
|
188
|
+
def state
|
189
|
+
return @suite.state
|
268
190
|
end
|
269
191
|
|
270
|
-
def
|
271
|
-
|
272
|
-
return JSON.pretty_generate(@export)
|
273
|
-
else
|
274
|
-
return JSON.generate(@export)
|
275
|
-
end
|
192
|
+
def suite
|
193
|
+
return @suite
|
276
194
|
end
|
277
195
|
end
|
278
196
|
|
data/lib/biosphere/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biosphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juho Mäkinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: deep_merge
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.1.1
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.1.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: deep_dup
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.0.3
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.0.3
|
111
139
|
description: "Terraform's HCL lacks quite many programming features like iterators,
|
112
140
|
true variables, advanced string manipulation, functions etc.\n\n This Ruby tool
|
113
141
|
provides an easy-to-use DSL to define Terraform compatible .json files which can
|
@@ -121,11 +149,14 @@ files:
|
|
121
149
|
- bin/biosphere
|
122
150
|
- examples/example.rb
|
123
151
|
- lib/biosphere.rb
|
152
|
+
- lib/biosphere/deployment.rb
|
124
153
|
- lib/biosphere/ipaddressallocator.rb
|
125
154
|
- lib/biosphere/kube.rb
|
126
155
|
- lib/biosphere/mixing/from_file.rb
|
127
156
|
- lib/biosphere/node.rb
|
128
157
|
- lib/biosphere/s3.rb
|
158
|
+
- lib/biosphere/settings.rb
|
159
|
+
- lib/biosphere/state.rb
|
129
160
|
- lib/biosphere/suite.rb
|
130
161
|
- lib/biosphere/terraformproxy.rb
|
131
162
|
- lib/biosphere/version.rb
|