cloud_powers 0.2.7.22 → 0.2.7.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +15 -17
- data/lib/cloud_powers/node.rb +26 -2
- data/lib/cloud_powers/self_awareness.rb +22 -5
- data/lib/cloud_powers/synapse/websocket/websocclient.rb +25 -29
- data/lib/cloud_powers/version.rb +1 -1
- data/lib/stubs/aws_stubs.rb +21 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97dc22c7470b4936967a4e45da7b3bf962dd2697
|
4
|
+
data.tar.gz: 0b0a347337a1f910bb10c46f8da3e785b3e6af21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f93ff5427fba0268c10899d3103c220167d4461eb5606c89f5d175cf460f1975f7a9e30dd8ffcff7e4899eee3c1b08c3d53f71e6d39f3bc0fa60c027438539fb
|
7
|
+
data.tar.gz: a3cdab518b3ad93891227d615fab39ec9ddcb32d1825e7ed37d4ec3f106cd647809153053fbe09d76868b103e0ed568e8cb6f9dd15bfa18dc4d1429a5818de9b
|
data/.gitignore
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
/
|
6
|
-
/
|
7
|
-
/
|
8
|
-
/
|
9
|
-
/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
lib/tasks
|
17
|
-
.idea
|
1
|
+
**/.bundle
|
2
|
+
**/.yardoc
|
3
|
+
**/Gemfile.lock
|
4
|
+
**/_yardoc/
|
5
|
+
**/coverage/
|
6
|
+
**/doc/
|
7
|
+
**/pkg/
|
8
|
+
**/spec/reports/
|
9
|
+
**/tmp/
|
10
|
+
**/*.env
|
11
|
+
**/.byebug_history
|
12
|
+
**/lib/cloud_powers/synapse/.DS_Store
|
13
|
+
**/.DS_Store
|
14
|
+
**/./**/.DS_Store
|
15
|
+
**/*.swp
|
data/lib/cloud_powers/node.rb
CHANGED
@@ -43,10 +43,11 @@ module Smash
|
|
43
43
|
# * opts +Hash+ (optional)
|
44
44
|
# an optional instance configuration hash can be passed, which will override
|
45
45
|
# the values in the default configuration returned by #instance_config()
|
46
|
-
def spin_up_neurons(opts = {})
|
46
|
+
def spin_up_neurons(opts = {}, tags = [])
|
47
47
|
should_wait = opts.delete(:wait) || true
|
48
48
|
ids = nil
|
49
49
|
begin
|
50
|
+
|
50
51
|
response = ec2.run_instances(node_config(opts))
|
51
52
|
ids = response.instances.map(&:instance_id)
|
52
53
|
|
@@ -61,9 +62,10 @@ module Smash
|
|
61
62
|
# redo unless (count += 1 <=3 )
|
62
63
|
end
|
63
64
|
end
|
65
|
+
|
66
|
+
batch_tag(ids, tags) unless tags.empty?
|
64
67
|
ids
|
65
68
|
|
66
|
-
# tag(ids, { key: 'task', value: to_camel(self.class.to_s) })
|
67
69
|
rescue Aws::EC2::Errors::DryRunOperation
|
68
70
|
ids = (1..(opts[:max_count] || 0)).to_a.map { |n| n.to_s }
|
69
71
|
logger.info "waiting for #{ids.count} Neurons to start..."
|
@@ -71,6 +73,28 @@ module Smash
|
|
71
73
|
|
72
74
|
ids
|
73
75
|
end
|
76
|
+
|
77
|
+
# This method adds certain tags to an array of resource ids.
|
78
|
+
#
|
79
|
+
# Parameters
|
80
|
+
# * ids +Array+|+String+ - an Array or a single instance id, as an Array of Strings or a single String
|
81
|
+
# * tags +Array+ - an Array of key, value hash
|
82
|
+
#
|
83
|
+
# Returns
|
84
|
+
# * Returns an empty response.
|
85
|
+
#
|
86
|
+
# Examples
|
87
|
+
# create_tag('ami-2342354', tags: { key: "stack", value: "production"})
|
88
|
+
# or
|
89
|
+
# create_tag(['ami-2432342'], tags: [{ key: 'stack', value: 'production' }])
|
90
|
+
# or any permutation of those
|
91
|
+
|
92
|
+
def batch_tag(ids, tags)
|
93
|
+
tags_opts = { resources: ids, tags: tags }
|
94
|
+
ec2.create_tags(tags_opts)
|
95
|
+
logger.info "tags for #{ids} created"
|
96
|
+
end
|
97
|
+
|
74
98
|
end
|
75
99
|
end
|
76
100
|
end
|
@@ -182,6 +182,24 @@ module Smash
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
+
|
186
|
+
# Search through tags on an instances using a regex pattern for your tag's
|
187
|
+
# key/name
|
188
|
+
#
|
189
|
+
# Parameters
|
190
|
+
# * pattern +String+|+Regex+
|
191
|
+
#
|
192
|
+
# Returns
|
193
|
+
# * +String+ - if a tag is found
|
194
|
+
# * +nil+ - if a tag is not found
|
195
|
+
def tag_search(pattern, id = @instance_id)
|
196
|
+
resp = ec2.describe_instances(instance_ids: [id].flatten).reservations.first
|
197
|
+
return nil if resp.nil?
|
198
|
+
resp.instances[0].tags.select do |tag|
|
199
|
+
tag.value if (tag.key =~ %r[#{pattern}])
|
200
|
+
end.collect.map(&:value).first
|
201
|
+
end
|
202
|
+
|
185
203
|
# Check self-tags for 'task' and act as an attr_accessor.
|
186
204
|
# A different node's tag's can be checked for a task by passing
|
187
205
|
# that instance's id as a parameter
|
@@ -191,16 +209,15 @@ module Smash
|
|
191
209
|
#
|
192
210
|
# Returns
|
193
211
|
# +String+
|
212
|
+
#
|
213
|
+
# Notes
|
214
|
+
# * See <tt>tag_search()</tt>
|
194
215
|
def task_name(id = @instance_id)
|
195
216
|
# get @task_name
|
196
217
|
return @task_name unless @task_name.nil?
|
197
218
|
# set @task_name
|
198
219
|
# TODO: get all tasks instead of just the first
|
199
|
-
|
200
|
-
return @task_name = nil if resp.nil?
|
201
|
-
@task_name = resp.instances[0].tags.select do |t|
|
202
|
-
t.value if t.key == 'taskType'
|
203
|
-
end.first
|
220
|
+
@task_name = tag_search('task', id)
|
204
221
|
end
|
205
222
|
|
206
223
|
# This method will return true if:
|
@@ -6,49 +6,45 @@ module Smash
|
|
6
6
|
module WebSocClient
|
7
7
|
|
8
8
|
def create_websoc_client(opts = {})
|
9
|
+
ws = {}
|
10
|
+
Thread.new(ws) do
|
11
|
+
EM.run do
|
12
|
+
ws = WebSocket::EventMachine::Client.connect(:uri => 'ws://' + opts[:host] + ':' + opts[:port])
|
9
13
|
|
10
|
-
|
14
|
+
client_name = opts[:client] || 'default_client'
|
11
15
|
|
12
|
-
|
13
|
-
add_to_clients(opts[:name],ws)
|
16
|
+
instance_variable_set(:"@#{client_name}",ws)
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
open_callback = opts[:on_open] || Proc.new do
|
19
|
+
puts "Connected"
|
20
|
+
end
|
18
21
|
|
19
|
-
|
22
|
+
ws.onopen &open_callback
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
on_message_callback = opts[:on_message] || Proc.new do |msg, type|
|
25
|
+
puts "Received message: #{msg}"
|
26
|
+
end
|
24
27
|
|
25
|
-
|
28
|
+
ws.onmessage &on_message_callback
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
on_error_callback = opts[:on_error] || Proc.new do |error|
|
31
|
+
puts "Error ==> #{error}"
|
32
|
+
end
|
30
33
|
|
31
|
-
|
34
|
+
ws.onerror &on_error_callback
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
on_close_callback = opts[:on_close] || Proc.new do |code, reason|
|
37
|
+
puts "Disconnected with status code: #{code}"
|
38
|
+
puts "Disconnected with status message: #{reason}"
|
39
|
+
end
|
37
40
|
|
38
|
-
|
41
|
+
ws.onclose &on_close_callback
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
+
end
|
43
44
|
|
44
|
-
def add_to_clients(name,client)
|
45
|
-
begin
|
46
|
-
@clients[name] = client
|
47
|
-
rescue NoMethodError => e
|
48
|
-
puts e.backtrace
|
49
|
-
puts "no client hash is available"
|
50
45
|
end
|
51
46
|
end
|
47
|
+
|
52
48
|
end
|
53
49
|
end
|
54
50
|
end
|
data/lib/cloud_powers/version.rb
CHANGED
data/lib/stubs/aws_stubs.rb
CHANGED
@@ -74,6 +74,7 @@ module Smash
|
|
74
74
|
# for your own custom configuration
|
75
75
|
def self.node_stub(opts = {})
|
76
76
|
time = opts[:launch_time] || Time.new((Time.now.utc.to_i / 86400 * 86400)) # midnight
|
77
|
+
tags = [{key: 'task', value: 'test'}]
|
77
78
|
{
|
78
79
|
stub_responses: {
|
79
80
|
create_tags: {},
|
@@ -88,11 +89,11 @@ module Smash
|
|
88
89
|
describe_instances: {
|
89
90
|
reservations: [
|
90
91
|
{ instances: [
|
91
|
-
{ instance_id: 'asd-1234', state: { code: 200, name: 'running' } },
|
92
|
-
{ instance_id: 'qwe-4323', state: { code: 200, name: 'running' } },
|
93
|
-
{ instance_id: 'tee-4322', state: { code: 200, name: 'running' } },
|
94
|
-
{ instance_id: 'bbf-6969', state: { code: 200, name: 'running' } },
|
95
|
-
{ instance_id: 'lkj-0987', state: { code: 200, name: 'running' } }
|
92
|
+
{ instance_id: 'asd-1234', state: { code: 200, name: 'running' }, tags: tags },
|
93
|
+
{ instance_id: 'qwe-4323', state: { code: 200, name: 'running' }, tags: tags },
|
94
|
+
{ instance_id: 'tee-4322', state: { code: 200, name: 'running' }, tags: tags },
|
95
|
+
{ instance_id: 'bbf-6969', state: { code: 200, name: 'running' }, tags: tags },
|
96
|
+
{ instance_id: 'lkj-0987', state: { code: 200, name: 'running' }, tags: tags }
|
96
97
|
] }] },
|
97
98
|
describe_images: {
|
98
99
|
images: [
|
@@ -310,6 +311,21 @@ module Smash
|
|
310
311
|
}
|
311
312
|
}.merge(opts)
|
312
313
|
end
|
314
|
+
|
315
|
+
# Stub metadata for EC2 tags
|
316
|
+
#
|
317
|
+
# Notes
|
318
|
+
# * defaults can't be overriden or don't have good support for
|
319
|
+
# for it yet but you can use this hash as a guide
|
320
|
+
# for your own custom configuration
|
321
|
+
def self.instance_tags_stub(opts = {})
|
322
|
+
{
|
323
|
+
tags: [
|
324
|
+
{ key: 'tag_one_key', value: 'tag_one_value' },
|
325
|
+
{ key: 'tag_two_key', value: 'tag_two_value' }
|
326
|
+
]
|
327
|
+
}.merge(opts)
|
328
|
+
end
|
313
329
|
end
|
314
330
|
end
|
315
331
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_powers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.7.
|
4
|
+
version: 0.2.7.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Phillipps
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-11-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport-core-ext
|