quandl_sandbox 0.1.0 → 0.1.1
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/lib/quandl/sandbox/dataset.rb +1 -1
- data/lib/quandl/sandbox/ec2.rb +5 -5
- data/lib/quandl/sandbox/job.rb +0 -2
- data/lib/quandl/sandbox/server/instance.rb +3 -6
- data/lib/quandl/sandbox/server/ssh.rb +21 -8
- data/lib/quandl/sandbox/version.rb +1 -1
- data/spec/lib/quandl/sandbox/job_spec.rb +1 -2
- data/spec/lib/quandl/sandbox/server_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e0dc5f353591da55a850a0076ba20382193fef0
|
4
|
+
data.tar.gz: e1089e784ea2d9e405f6fe10b4fe3329b0b4c095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e318b6cb4718e4bea0f2bd2e802772cb179cfedce2a1f21ef58ed6f2fe7d8bcdc715c72043e6dce914b21a6ae22057d3b74798aba816d59646b85e16af1e90c
|
7
|
+
data.tar.gz: 9d1989f9164b8252a74c83d22ac348702a37cc0bc9938af30346d7d9528b1cf5e3e7775a9eb0ebdec8cdb0bf5c4267e478023561a41ad5d65c4524545f5d57cd
|
data/lib/quandl/sandbox/ec2.rb
CHANGED
@@ -16,7 +16,7 @@ class Quandl::Sandbox::EC2
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def instances
|
19
|
-
interface.instances.filter('subnet-id', Sandbox.configuration.subnet_id )
|
19
|
+
interface.instances.filter('subnet-id', Quandl::Sandbox.configuration.subnet_id )
|
20
20
|
end
|
21
21
|
|
22
22
|
def gateway_reset!
|
@@ -31,17 +31,17 @@ class Quandl::Sandbox::EC2
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def gateway_user
|
34
|
-
@gateway_user ||= Sandbox.configuration.ssh_gateway.split("@").first
|
34
|
+
@gateway_user ||= Quandl::Sandbox.configuration.ssh_gateway.split("@").first
|
35
35
|
end
|
36
36
|
|
37
37
|
def gateway_host
|
38
|
-
@gateway_host ||= Sandbox.configuration.ssh_gateway.split("@").last
|
38
|
+
@gateway_host ||= Quandl::Sandbox.configuration.ssh_gateway.split("@").last
|
39
39
|
end
|
40
40
|
|
41
41
|
def interface
|
42
42
|
@interface ||= AWS::EC2.new(
|
43
|
-
access_key_id: Sandbox.configuration.aws_access_key_id,
|
44
|
-
secret_access_key: Sandbox.configuration.aws_secret_access_key)
|
43
|
+
access_key_id: Quandl::Sandbox.configuration.aws_access_key_id,
|
44
|
+
secret_access_key: Quandl::Sandbox.configuration.aws_secret_access_key)
|
45
45
|
end
|
46
46
|
|
47
47
|
end
|
data/lib/quandl/sandbox/job.rb
CHANGED
@@ -21,7 +21,7 @@ module Quandl::Sandbox::Server::Instance
|
|
21
21
|
|
22
22
|
def find(uid)
|
23
23
|
# lookup instance
|
24
|
-
instance = Sandbox::EC2.find(uid)
|
24
|
+
instance = Quandl::Sandbox::EC2.find(uid)
|
25
25
|
# build server given instance
|
26
26
|
instance.present? ? self.new( instance: instance ) : nil
|
27
27
|
end
|
@@ -33,7 +33,7 @@ module Quandl::Sandbox::Server::Instance
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def delete(id)
|
36
|
-
i = Sandbox::EC2.find(id)
|
36
|
+
i = Quandl::Sandbox::EC2.find(id)
|
37
37
|
i.present? ? i.delete : false
|
38
38
|
end
|
39
39
|
|
@@ -61,9 +61,6 @@ module Quandl::Sandbox::Server::Instance
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def launch!
|
64
|
-
# only new servers can be launched
|
65
|
-
return false unless new_record
|
66
|
-
# create, tag, wait
|
67
64
|
self.instance = create_instance!
|
68
65
|
add_tags_to_instance
|
69
66
|
end
|
@@ -92,7 +89,7 @@ module Quandl::Sandbox::Server::Instance
|
|
92
89
|
end
|
93
90
|
|
94
91
|
def create_instance!
|
95
|
-
Sandbox::EC2.instances.create({
|
92
|
+
Quandl::Sandbox::EC2.instances.create({
|
96
93
|
image_id: image,
|
97
94
|
subnet_id: subnet_id,
|
98
95
|
availability_zone: availability_zone,
|
@@ -2,8 +2,21 @@ module Quandl::Sandbox::Server::SSH
|
|
2
2
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
def
|
6
|
-
|
5
|
+
def launch!
|
6
|
+
# only new servers can be launched
|
7
|
+
return false unless new_record
|
8
|
+
# launch instance
|
9
|
+
super if defined?(super)
|
10
|
+
# wait for sshd to start on server
|
11
|
+
await_sshd_uninterruptedly
|
12
|
+
end
|
13
|
+
|
14
|
+
def await_sshd_uninterruptedly
|
15
|
+
t1 = Time.now
|
16
|
+
Quandl::Logger.debug("#{instance_id}: await_sshd_uninterruptedly")
|
17
|
+
@await_sshd_uninterruptedly ||= Quandl::Sandbox::EC2.auto_retry(3){ exec("hostname") }
|
18
|
+
Quandl::Logger.debug "#{instance_id}: await_sshd_uninterruptedly finished (#{t1.elapsed_ms})"
|
19
|
+
@await_sshd_uninterruptedly
|
7
20
|
end
|
8
21
|
|
9
22
|
def upload!(local_path, remote_path="/home/ubuntu/")
|
@@ -44,21 +57,21 @@ module Quandl::Sandbox::Server::SSH
|
|
44
57
|
end
|
45
58
|
channel.wait
|
46
59
|
end
|
60
|
+
result[:stdout] = result[:stdout].to_s.strip.rstrip
|
61
|
+
result[:stderr] = result[:stderr].to_s.strip.rstrip
|
47
62
|
result
|
48
63
|
end
|
49
64
|
|
50
65
|
def ssh(&block)
|
51
|
-
# wait for server to
|
66
|
+
# wait for server to launch
|
52
67
|
await_instance_uninterruptedly unless running?
|
53
|
-
# establish connection
|
54
|
-
Quandl::Logger.debug "#{instance_id}: Waiting for sshd to start ... "
|
55
68
|
# execute block through tunnel
|
56
69
|
output = nil
|
57
|
-
Sandbox::EC2.gateway.ssh( private_ip_address, ssh_user,
|
58
|
-
key_data: Sandbox.configuration.key_data, keys_only: true ) do |ssh|
|
70
|
+
Quandl::Sandbox::EC2.gateway.ssh( private_ip_address, ssh_user,
|
71
|
+
key_data: Quandl::Sandbox.configuration.key_data, keys_only: true ) do |ssh|
|
59
72
|
output = block.call(ssh)
|
60
73
|
end
|
61
74
|
output
|
62
75
|
end
|
63
|
-
|
76
|
+
|
64
77
|
end
|
@@ -51,7 +51,7 @@ describe Quandl::Sandbox::Server do
|
|
51
51
|
describe "#exec" do
|
52
52
|
it "should get the hostname" do
|
53
53
|
# get internal_ip through exec('hostname')
|
54
|
-
internal_ip = subject.exec('hostname').
|
54
|
+
internal_ip = subject.exec('hostname')[:stdout].split('-')[1..-1].join('.')
|
55
55
|
# compare against private ip address
|
56
56
|
subject.private_ip_address.should eq internal_ip
|
57
57
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -28,11 +28,12 @@ RSpec.configure do |config|
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def stubbed_job_output
|
31
|
-
4.times.collect do |i|
|
31
|
+
{ stdout: 4.times.collect do |i|
|
32
32
|
"QUANDL_SANDBOX_TEST/DATASET_#{i}\n" +
|
33
33
|
"Test Dataset #{i}\n" +
|
34
34
|
"Description of the dataset #{i}\n" +
|
35
35
|
"Date, High, Low, Average\n" +
|
36
36
|
"#{Quandl::Fabricate::Data.rand(rows: 10, columns: 3).to_csv}}"
|
37
37
|
end.join("----\n")
|
38
|
+
}
|
38
39
|
end
|