biosphere 0.0.6 → 0.0.7
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 +4 -4
- data/bin/biosphere +10 -8
- data/lib/biosphere.rb +1 -0
- data/lib/biosphere/ipaddressallocator.rb +21 -0
- data/lib/biosphere/kube.rb +36 -0
- data/lib/biosphere/suite.rb +4 -0
- data/lib/biosphere/terraformproxy.rb +21 -1
- data/lib/biosphere/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a79a5dcf4507e01aac559a9398458e01471e3a6a
|
4
|
+
data.tar.gz: a9191546b52c5e876f6047e1054b3e881428b715
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b93ed09bb9b7bc62a463436c1cb92f44b8e181eadc308e3dec006a6802aad126cecaa7732e0eea5c30eb95a9a8c7561ecbd74e3ce8de386e5f061746b66f292
|
7
|
+
data.tar.gz: 8edb393eb8e5b8c8e16375647ad0a905b37b6c6fbd9ae7a35e3f094ffb79b670c108bd3d62b329a20950024f00d7a8b1502d1adfef40738d5e70ba99b34a42f2
|
data/bin/biosphere
CHANGED
@@ -100,21 +100,23 @@ if ARGV[0] == "json" && options.src
|
|
100
100
|
puts "Wrote #{count} files into #{options.build}"
|
101
101
|
suite.save_node()
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
if ARGV[0] == "plan" && options.src
|
103
|
+
elsif ARGV[0] == "plan" && options.src
|
106
104
|
suite.evaluate_plans()
|
107
105
|
ap suite.node, :indent=>-4
|
108
|
-
|
109
|
-
|
110
|
-
if ARGV[0] == "action" && options.src
|
106
|
+
elsif ARGV[0] == "action" && options.src
|
111
107
|
context = Biosphere::ActionContext.new()
|
112
108
|
|
113
109
|
context.build_directory = options.build
|
114
110
|
|
115
|
-
|
116
|
-
|
111
|
+
if suite.call_action(ARGV[1], context)
|
112
|
+
STDERR.puts "Executing action #{ARGV[1]}"
|
113
|
+
else
|
114
|
+
STDERR.puts "Could not find action #{ARGV[1]}"
|
115
|
+
end
|
117
116
|
|
118
117
|
suite.save_node()
|
118
|
+
else
|
119
|
+
STDERR.puts "\nERROR: Unknown command #{ARGV[0]}. Maybe you wanted to do: \"biosphere action #{ARGV[0]}\"?"
|
120
|
+
exit -1
|
119
121
|
end
|
120
122
|
|
data/lib/biosphere.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'ipaddress'
|
2
|
+
|
3
|
+
class IPAddress::IPv4
|
4
|
+
|
5
|
+
def allocate(skip = 0)
|
6
|
+
if !@allocator
|
7
|
+
@allocator = 1
|
8
|
+
else
|
9
|
+
@allocator += + 1
|
10
|
+
end
|
11
|
+
|
12
|
+
@allocator += skip
|
13
|
+
|
14
|
+
next_ip = network_u32+@allocator
|
15
|
+
if next_ip > broadcast_u32+1
|
16
|
+
raise StopIteration
|
17
|
+
end
|
18
|
+
self.class.parse_u32(network_u32+@allocator, @prefix)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'kubeclient'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
class Biosphere
|
6
|
+
module Kube
|
7
|
+
def kube_test(str)
|
8
|
+
return str
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def kube_load_manifest_file(file)
|
13
|
+
resources = []
|
14
|
+
puts "Loading file #{file}"
|
15
|
+
str = ERB.new(IO.read(file)).result(binding)
|
16
|
+
raise str
|
17
|
+
Psych.load_stream(str) do |document|
|
18
|
+
kind = document["kind"]
|
19
|
+
resource = ::Kubeclient::Resource.new(document)
|
20
|
+
resources << resource
|
21
|
+
end
|
22
|
+
return resources
|
23
|
+
end
|
24
|
+
|
25
|
+
def kube_create_resource(client, resource)
|
26
|
+
name = resource[:metadata][:name]
|
27
|
+
resource_name = client.instance_variable_get("@entities")[resource[:kind].downcase].resource_name
|
28
|
+
ns_prefix = client.build_namespace_prefix(resource[:metadata][:namespace])
|
29
|
+
client.handle_exception do
|
30
|
+
client.rest_client[ns_prefix + resource_name]
|
31
|
+
.post(resource.to_h.to_json, { 'Content-Type' => 'application/json' }.merge(client.instance_variable_get("@headers")))
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/biosphere/suite.rb
CHANGED
@@ -76,11 +76,15 @@ class Biosphere
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def call_action(name, context)
|
79
|
+
found = false
|
79
80
|
@files.each do |file_name, proxy|
|
80
81
|
if proxy.actions[name]
|
82
|
+
found = true
|
81
83
|
proxy.call_action(name, context)
|
82
84
|
end
|
83
85
|
end
|
86
|
+
|
87
|
+
return found
|
84
88
|
end
|
85
89
|
|
86
90
|
def write_json_to(destination_dir)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'biosphere/mixing/from_file.rb'
|
2
|
+
require 'biosphere/kube.rb'
|
2
3
|
require 'json'
|
3
4
|
require 'pathname'
|
4
5
|
require 'base64'
|
@@ -8,6 +9,7 @@ class Biosphere
|
|
8
9
|
class ActionContext
|
9
10
|
attr_accessor :build_directory
|
10
11
|
attr_accessor :caller
|
12
|
+
attr_accessor :src_path
|
11
13
|
|
12
14
|
def initialize()
|
13
15
|
|
@@ -19,8 +21,14 @@ class Biosphere
|
|
19
21
|
if @caller.methods.include?(symbol)
|
20
22
|
return @caller.method(symbol).call(*args)
|
21
23
|
end
|
24
|
+
|
25
|
+
super
|
22
26
|
end
|
23
27
|
|
28
|
+
def find_file(filename)
|
29
|
+
src_path = Pathname.new(@src_path.last + "/" + File.dirname(filename)).cleanpath.to_s
|
30
|
+
return src_path + "/" + File.basename(filename)
|
31
|
+
end
|
24
32
|
|
25
33
|
end
|
26
34
|
|
@@ -43,6 +51,8 @@ class Biosphere
|
|
43
51
|
end
|
44
52
|
|
45
53
|
|
54
|
+
|
55
|
+
|
46
56
|
def respond_to?(symbol, include_private = false)
|
47
57
|
return true
|
48
58
|
end
|
@@ -91,6 +101,8 @@ class Biosphere
|
|
91
101
|
attr_accessor :plan_proxy
|
92
102
|
attr_reader :src_path
|
93
103
|
|
104
|
+
include Kube
|
105
|
+
|
94
106
|
|
95
107
|
def initialize(script_name, plan_proxy = nil)
|
96
108
|
@script_name = script_name
|
@@ -120,6 +132,11 @@ class Biosphere
|
|
120
132
|
self.instance_eval(&block)
|
121
133
|
end
|
122
134
|
|
135
|
+
def find_file(filename)
|
136
|
+
src_path = Pathname.new(@src_path.last + "/" + File.dirname(filename)).cleanpath.to_s
|
137
|
+
return src_path + "/" + File.basename(filename)
|
138
|
+
end
|
139
|
+
|
123
140
|
def load(filename)
|
124
141
|
src_path = Pathname.new(@src_path.last + "/" + File.dirname(filename)).cleanpath.to_s
|
125
142
|
# Push current src_path and overwrite @src_path so that it tracks recursive loads
|
@@ -162,7 +179,8 @@ class Biosphere
|
|
162
179
|
:name => name,
|
163
180
|
:description => description,
|
164
181
|
:block => block,
|
165
|
-
:location => caller[0]
|
182
|
+
:location => caller[0],
|
183
|
+
:src_path => @src_path.clone
|
166
184
|
}
|
167
185
|
end
|
168
186
|
|
@@ -188,6 +206,7 @@ class Biosphere
|
|
188
206
|
|
189
207
|
def call_action(name, context)
|
190
208
|
context.caller = self
|
209
|
+
context.src_path = @actions[name][:src_path]
|
191
210
|
|
192
211
|
context.instance_eval(&@actions[name][:block])
|
193
212
|
end
|
@@ -252,4 +271,5 @@ class Biosphere
|
|
252
271
|
end
|
253
272
|
end
|
254
273
|
end
|
274
|
+
|
255
275
|
end
|
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.0.7
|
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: 2016-11-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: kubeclient
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.0
|
55
69
|
description: "Terraform's HCL lacks quite many programming features like iterators,
|
56
70
|
true variables, advanced string manipulation, functions etc.\n\n This Ruby tool
|
57
71
|
provides an easy-to-use DSL to define Terraform compatible .json files which can
|
@@ -65,6 +79,8 @@ files:
|
|
65
79
|
- bin/biosphere
|
66
80
|
- examples/example.rb
|
67
81
|
- lib/biosphere.rb
|
82
|
+
- lib/biosphere/ipaddressallocator.rb
|
83
|
+
- lib/biosphere/kube.rb
|
68
84
|
- lib/biosphere/mixing/from_file.rb
|
69
85
|
- lib/biosphere/node.rb
|
70
86
|
- lib/biosphere/suite.rb
|