biosphere 0.1.9 → 0.2.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
  SHA1:
3
- metadata.gz: aa6bf1b3024023b7f683aea94a5d9410fb3e5ea2
4
- data.tar.gz: 2595a001d0345ef607f32a7966c577ddc91da16a
3
+ metadata.gz: 6e587744cb4b79991175f86016bcd023fce26456
4
+ data.tar.gz: e7b5a2b107cf724d4cc7f319528e55daf5396c84
5
5
  SHA512:
6
- metadata.gz: 26671009ac8d5ecc2a8a30ca584532aefb447928f1363ee237f5611713d213998a6ea48c813621a9ab8578bc6aa7d69b959ee8809151198a96d9283dc8bf345e
7
- data.tar.gz: 79c83f3259d51e817a70de605256c3cff2759d1d76d73928f0de10d0ee046d35093f9ea5eea767f9697e9ba203f27a87b266bd9a8c75acc1f0cc4ed87092cbcb
6
+ metadata.gz: cd23b2e88b6a75729ec8e18b3e2e39929d526ecbc07ea87d0c710639c610d191e3b225c0876ad93a487e00489103e07bedb6e2100bf3b82c697ae3b6a33287e3
7
+ data.tar.gz: 85e154e3075e05572e3ea6b5d35d7591a8a3b302502044e3bc0479b0e3f1dc5078760043d5061edbcca62bbb41256ad0c506d4af5984cd3d9ffa8a35b35b5b7f
@@ -164,6 +164,23 @@ elsif ARGV[0] == "deployment" && options.src
164
164
  puts "Deployment: #{name}"
165
165
  end
166
166
 
167
+ elsif ARGV[0] == "statereset" && options.src
168
+
169
+ answer = ""
170
+ while answer.empty? || (answer != "y" && answer != "n")
171
+ print "\nAre you sure you want to do a full state reset for #{options.build_dir} y/n: "
172
+ answer = STDIN.gets.chomp
173
+ end
174
+
175
+ if answer == "n"
176
+ puts "\nOk, will not proceed with state reset"
177
+ elsif answer == "y"
178
+ state = Biosphere::State.new
179
+ state.filename = "#{options.build_dir}/state.node"
180
+ state.save()
181
+ s3.save("#{options.build_dir}/state.node")
182
+ end
183
+
167
184
  elsif ARGV[0] == "commit" && options.src
168
185
 
169
186
  if !ARGV[1]
@@ -10,10 +10,11 @@ class Biosphere
10
10
  def initialize(*args)
11
11
 
12
12
  @parent = nil
13
- @name = "unnamed"
13
+ @name = ""
14
14
  if args[0].kind_of?(::Biosphere::Deployment) || args[0].kind_of?(::Biosphere::Suite)
15
15
  @parent = args.shift
16
- elsif args[0].kind_of?(String)
16
+ end
17
+ if args[0].kind_of?(String)
17
18
  @name = args.shift
18
19
  end
19
20
 
@@ -36,15 +37,9 @@ class Biosphere
36
37
  "output" => {}
37
38
  }
38
39
 
40
+ settings[:deployment_name] = @name
41
+
39
42
  if @parent.is_a?(::Biosphere::Suite)
40
- if settings[:deployment_name]
41
- @name = settings[:deployment_name]
42
- else
43
- puts "\nYou need to specify :deployment_name in the Deployment settings. For example:"
44
- puts "cluster = AdsDeliveryCluster.new(suite, MyDeliveryTestSettings.new({deployment_name: \"my-delivery-test-cluster\"})\n\n"
45
- raise RuntimeError.new "No :deployment_name specified in Deployment settings"
46
- end
47
-
48
43
  @parent.register(self)
49
44
  elsif @parent
50
45
  @node = @parent.node
@@ -109,6 +104,9 @@ class Biosphere
109
104
  end
110
105
 
111
106
  def resource(type, name, &block)
107
+ if self.name
108
+ name = self.name + "_" + name
109
+ end
112
110
  @export["resource"][type.to_s] ||= {}
113
111
  if @export["resource"][type.to_s][name.to_s]
114
112
  throw "Tried to create a resource of type #{type} called '#{name}' when one already exists"
@@ -132,13 +130,20 @@ class Biosphere
132
130
  end
133
131
 
134
132
  def output(name, value, &block)
135
- @export["output"][name] = {
133
+ if self.name
134
+ resource_name = self.name + "_" + name
135
+ else
136
+ resource_name = name
137
+ end
138
+
139
+ @export["output"][resource_name] = {
136
140
  "value" => value
137
141
  }
138
142
 
139
143
  if block_given?
140
144
  output = {
141
145
  :name => name,
146
+ :resource_name => resource_name,
142
147
  :block => block
143
148
  }
144
149
 
@@ -154,8 +159,8 @@ class Biosphere
154
159
  end
155
160
 
156
161
  @outputs.each do |output|
157
- value = outputs[output[:name]]
158
- instance_exec(output[:name], value["value"], value, &output[:block])
162
+ value = outputs[output[:resource_name]]
163
+ instance_exec(self.name, output[:name], value["value"], value, &output[:block])
159
164
  end
160
165
  end
161
166
 
@@ -195,6 +200,17 @@ class Biosphere
195
200
  end
196
201
  end
197
202
 
203
+ def id_of(type,name)
204
+ "${#{type}.#{name}.id}"
205
+ end
206
+
207
+ def output_of(type, name, *values)
208
+ if self.name
209
+ name = self.name + "_" + name
210
+ end
211
+ "${#{type}.#{name}.#{values.join(".")}}"
212
+ end
213
+
198
214
  def to_json(pretty=false)
199
215
  if pretty
200
216
  return JSON.pretty_generate(@export)
@@ -176,7 +176,7 @@ class Biosphere
176
176
 
177
177
  def self.load_resources(file, context={})
178
178
  resources = []
179
- #puts "Loading file #{File.absolute_path(file)}"
179
+ puts "Loading file #{File.absolute_path(file)}"
180
180
  data = IO.read(file)
181
181
  begin
182
182
  str = ERB.new(data).result(OpenStruct.new(context).instance_eval { binding })
@@ -184,7 +184,7 @@ class Biosphere
184
184
  puts "Error evaluating erb templating for #{file}. Error: #{e}"
185
185
  m = /\(erb\):([0-9]+):/.match(e.backtrace.first)
186
186
  if m
187
- puts "Error at line #{m[1]}. This is before ERB templating."
187
+ puts "Error at line #{m[1]}. This is before ERB templating. Remember to run biosphere build if you changed settings."
188
188
  linenumber = m[1].to_i
189
189
  if linenumber > 0 # Linenumbers seems to be off with 1 as the array is starting at zero
190
190
  linenumber = linenumber - 1
@@ -51,6 +51,24 @@ class S3
51
51
  end
52
52
  end
53
53
 
54
+ def delete_object(path_to_file)
55
+ filename = path_to_file.split('/')[-1]
56
+ key = "#{@main_key}/#{filename}"
57
+ puts "Fetching #{filename} from S3 from #{key}"
58
+ begin
59
+ resp = @client.delete_object({
60
+ :bucket => @bucket_name,
61
+ :key => key
62
+ })
63
+ rescue Aws::S3::Errors::NoSuchKey
64
+ puts "Couldn't find remote file #{filename} from S3 at #{key}"
65
+ rescue
66
+ puts "\nError occurred while deleting file #{path_to_file}."
67
+ puts "Error: #{$!}"
68
+ exit 1
69
+ end
70
+ end
71
+
54
72
  def set_lock()
55
73
  begin
56
74
  resp = @client.get_object({
@@ -81,10 +81,17 @@ class Biosphere
81
81
  end
82
82
 
83
83
  def id_of(type,name)
84
+ if self.name
85
+ name = self.name + "_" + name
86
+ end
84
87
  "${#{type}.#{name}.id}"
85
88
  end
86
89
 
87
90
  def output_of(type, name, *values)
91
+ if self.name
92
+ name = self.name + "_" + name
93
+ end
94
+
88
95
  "${#{type}.#{name}.#{values.join(".")}}"
89
96
  end
90
97
 
@@ -1,3 +1,3 @@
1
1
  class Biosphere
2
- Version = "0.1.9"
2
+ Version = "0.2.0"
3
3
  end
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.1.9
4
+ version: 0.2.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-03-28 00:00:00.000000000 Z
11
+ date: 2017-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec