cnvrg 0.0.15000 → 0.0.142561
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cnvrg.gemspec +0 -2
- data/lib/cnvrg.rb +1 -0
- data/lib/cnvrg/Images.rb +0 -69
- data/lib/cnvrg/api.rb +3 -7
- data/lib/cnvrg/cli.rb +5 -102
- data/lib/cnvrg/data.rb +2 -6
- data/lib/cnvrg/datafiles.rb +41 -41
- data/lib/cnvrg/version.rb +1 -1
- metadata +3 -19
- data/lib/cnvrg/ssh.rb +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2a92149e9b565661704f3f91438b28c89976475
|
4
|
+
data.tar.gz: 9f5c2dc4a71823c9b5657fd941361e33305d06f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aace663fb6460ade819c6676fb96b11cbbb286340e0b2599b6be6bb6d1ae5f3e6098270b9f37976cae7ec743b6381f46dd1e1054cb4f56e71d249cbb875f43b
|
7
|
+
data.tar.gz: 47dd9900f83b208196690862ceba2511643fbf84fc2d1daa6a23b66c51c63279aa9766bcaee9811b72af9b4f44e605e7fa34e5b0e450bcbe67f4e62a7480c173
|
data/cnvrg.gemspec
CHANGED
data/lib/cnvrg.rb
CHANGED
data/lib/cnvrg/Images.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'cnvrg/files'
|
3
3
|
require 'docker'
|
4
|
-
require 'net/ssh'
|
5
|
-
|
6
4
|
|
7
5
|
module Cnvrg
|
8
6
|
class Images
|
@@ -95,73 +93,6 @@ module Cnvrg
|
|
95
93
|
|
96
94
|
|
97
95
|
end
|
98
|
-
def self.create_new_custom_image(type,owner,image_name,is_public,is_base,image_extend,python3)
|
99
|
-
response = Cnvrg::API.request("users/#{owner}/images/custom", 'POST', {instance_type:type,image_name:image_name,is_public:is_public,
|
100
|
-
is_base:is_base,image_extend:image_extend,
|
101
|
-
python3:python3})
|
102
|
-
return response
|
103
|
-
end
|
104
|
-
def self.revoke_custom_new_image(owner,slug)
|
105
|
-
response = Cnvrg::API.request("users/#{owner}/images/#{slug}/revoke_image", 'GET')
|
106
|
-
return response
|
107
|
-
end
|
108
|
-
def self.commit_custom_image(owner,slug)
|
109
|
-
response = Cnvrg::API.request("users/#{owner}/images/#{slug}/commit_custom_image", 'GET')
|
110
|
-
return response
|
111
|
-
end
|
112
|
-
def self.ssh_to_machine(resp)
|
113
|
-
|
114
|
-
sts_path = resp["result"]["sts_path"]
|
115
|
-
|
116
|
-
uri = URI.parse(sts_path)
|
117
|
-
|
118
|
-
http_object = Net::HTTP.new(uri.host, uri.port)
|
119
|
-
http_object.use_ssl = true if uri.scheme == 'https'
|
120
|
-
request = Net::HTTP::Get.new(sts_path)
|
121
|
-
|
122
|
-
body = ""
|
123
|
-
http_object.start do |http|
|
124
|
-
response = http.request request
|
125
|
-
body = response.read_body
|
126
|
-
end
|
127
|
-
|
128
|
-
URLcrypt::key = [body].pack('H*')
|
129
|
-
|
130
|
-
ip = URLcrypt.decrypt(resp["result"]["machine_i"])
|
131
|
-
|
132
|
-
user = URLcrypt.decrypt(resp["result"]["machine_u"])
|
133
|
-
key = URLcrypt.decrypt(resp["result"]["machine_k"])
|
134
|
-
tempssh = Tempfile.new "sshkey"
|
135
|
-
tempssh.write open(key).read
|
136
|
-
tempssh.rewind
|
137
|
-
key_path = tempssh.path
|
138
|
-
count = 0
|
139
|
-
while count < 5
|
140
|
-
|
141
|
-
begin
|
142
|
-
ssh = Net::SSH.start(ip, user=user, :keys => key_path, :timeout => 10)
|
143
|
-
if !ssh.nil?
|
144
|
-
return ssh
|
145
|
-
else
|
146
|
-
count+=1
|
147
|
-
sleep(2)
|
148
|
-
|
149
|
-
end
|
150
|
-
rescue
|
151
|
-
count+=1
|
152
|
-
sleep(2)
|
153
|
-
|
154
|
-
|
155
|
-
end
|
156
|
-
end
|
157
|
-
if tempssh
|
158
|
-
tempssh.close
|
159
|
-
tempssh.unlink
|
160
|
-
end
|
161
|
-
return false
|
162
|
-
end
|
163
|
-
|
164
|
-
|
165
96
|
|
166
97
|
def create_custom_image(new_image_name,working_dir,stored_commands)
|
167
98
|
|
data/lib/cnvrg/api.rb
CHANGED
@@ -57,10 +57,7 @@ module Cnvrg
|
|
57
57
|
else
|
58
58
|
response
|
59
59
|
end
|
60
|
-
|
61
|
-
conn.options.timeout = 420
|
62
|
-
conn.options.open_timeout =420
|
63
|
-
|
60
|
+
when 'POST'
|
64
61
|
response = conn.post "#{endpoint_uri}/#{resource}", data
|
65
62
|
|
66
63
|
if parse_request == true
|
@@ -73,12 +70,12 @@ module Cnvrg
|
|
73
70
|
fr.headers['Auth-Token'] = @pass
|
74
71
|
fr.headers['User-Agent'] = "#{Cnvrg::API::USER_AGENT}"
|
75
72
|
fr.headers["Content-Type"] = "multipart/form-data"
|
76
|
-
|
73
|
+
|
77
74
|
fr.request :multipart
|
78
75
|
fr.request :url_encoded
|
79
76
|
fr.adapter :net_http
|
80
77
|
end
|
81
|
-
|
78
|
+
|
82
79
|
|
83
80
|
# what if windows?
|
84
81
|
# data[:file] = Faraday::UploadIO.new(data[:absolute_path], content_type)
|
@@ -107,7 +104,6 @@ module Cnvrg
|
|
107
104
|
else
|
108
105
|
end
|
109
106
|
rescue => e
|
110
|
-
puts e
|
111
107
|
return nil
|
112
108
|
end
|
113
109
|
|
data/lib/cnvrg/cli.rb
CHANGED
@@ -21,7 +21,6 @@ require 'cnvrg/Images'
|
|
21
21
|
require 'cnvrg/dataset'
|
22
22
|
require 'cnvrg/datafiles'
|
23
23
|
require 'cnvrg/data'
|
24
|
-
require 'cnvrg/ssh'
|
25
24
|
require 'etc'
|
26
25
|
require 'logstash-logger'
|
27
26
|
require 'cnvrg/job'
|
@@ -1155,9 +1154,8 @@ module Cnvrg
|
|
1155
1154
|
method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
|
1156
1155
|
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
1157
1156
|
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
1158
|
-
method_option :no_compression, :type => :boolean, :aliases => ["-nc", "--no_compression"], :default => false
|
1159
1157
|
|
1160
|
-
def upload_data_tar(ignore, verbose, sync
|
1158
|
+
def upload_data_tar(ignore, verbose, sync)
|
1161
1159
|
|
1162
1160
|
begin
|
1163
1161
|
verify_logged_in(true)
|
@@ -1227,7 +1225,7 @@ module Cnvrg
|
|
1227
1225
|
tar_files_path = "#{home_dir}/.cnvrg/tmp/#{@dataset.slug}_#{commit_sha1}.txt"
|
1228
1226
|
tar_files = (result["added"] + result["updated_on_local"]).join("\n")
|
1229
1227
|
File.open(tar_files_path, 'w') { |f| f.write tar_files }
|
1230
|
-
is_tar = create_tar(dataset_dir, tar_path, tar_files_path
|
1228
|
+
is_tar = create_tar(dataset_dir, tar_path, tar_files_path)
|
1231
1229
|
if !is_tar
|
1232
1230
|
say "ERROR: Couldn't compress data", Thor::Shell::Color::RED
|
1233
1231
|
FileUtils.rm_rf([tar_path]) if File.exist? tar_path
|
@@ -3543,6 +3541,7 @@ module Cnvrg
|
|
3543
3541
|
container.stop()
|
3544
3542
|
end
|
3545
3543
|
rescue SignalException
|
3544
|
+
log_End(-1)
|
3546
3545
|
if container
|
3547
3546
|
container.stop()
|
3548
3547
|
end
|
@@ -3552,98 +3551,6 @@ module Cnvrg
|
|
3552
3551
|
|
3553
3552
|
end
|
3554
3553
|
|
3555
|
-
method_option :small, :type => :boolean, :aliases => ["-sm", "--small"], :default => false
|
3556
|
-
method_option :medium, :type => :boolean, :aliases => ["-md", "--medium"], :default => false
|
3557
|
-
method_option :large, :type => :boolean, :aliases => ["-lg", "--large"], :default => false
|
3558
|
-
method_option :gpu, :type => :boolean, :aliases => ["--gpu"], :default => false
|
3559
|
-
method_option :gpuxl, :type => :boolean, :aliases => ["--gpuxl"], :default => false
|
3560
|
-
method_option :gpuxxl, :type => :boolean, :aliases => ["--gpuxxl"], :default => false
|
3561
|
-
method_option :image, :type => :string, :aliases => ["-i","--image"], :default => ""
|
3562
|
-
method_option :public, :type => :boolean, :aliases => ["-p","--public"], :default => false
|
3563
|
-
method_option :base, :type => :boolean, :aliases => ["-b","--base"], :default => false
|
3564
|
-
method_option :python3, :type => :boolean, :aliases => ["--python3"], :default => false
|
3565
|
-
|
3566
|
-
desc 'create_custom_image', 'run commands inside containers', :hide=>true
|
3567
|
-
|
3568
|
-
def create_custom_image(image_name)
|
3569
|
-
begin
|
3570
|
-
verify_logged_in(false)
|
3571
|
-
log_start(__method__, args, options)
|
3572
|
-
instances = {"small" => options["small"], "medium" => options["medium"], "large" => options["large"],
|
3573
|
-
"gpu" => options["gpu"], "gpuxl" => options["gpuxl"], "gpuxxl" => options["gpuxxl"]}
|
3574
|
-
instance_type = get_instance_type(instances)
|
3575
|
-
image_extend = options["image"]
|
3576
|
-
public = options["public"]
|
3577
|
-
base = options["base"]
|
3578
|
-
python3 = options["python3"]
|
3579
|
-
owner = CLI.get_owner
|
3580
|
-
checks = Helpers.checkmark()
|
3581
|
-
|
3582
|
-
say "Creating machine for custom image, this may take a few moments...", Thor::Shell::Color::BLUE
|
3583
|
-
|
3584
|
-
resp = Images.create_new_custom_image(instance_type,owner,image_name,public,base,image_extend,python3)
|
3585
|
-
if Cnvrg::CLI.is_response_success(resp,false)
|
3586
|
-
image_slug = resp["result"]["slug"]
|
3587
|
-
container = resp["result"]["machine_c"]
|
3588
|
-
say "#{checks} Created image and machine successfully", Thor::Shell::Color::GREEN
|
3589
|
-
say "Connecting to machine", Thor::Shell::Color::BLUE
|
3590
|
-
ssh = Ssh.new(resp)
|
3591
|
-
if !ssh.is_ssh
|
3592
|
-
say "Couldn't connect to machine,aborting", Thor::Shell::Color::RED
|
3593
|
-
Images.revoke_custom_new_image(owner, image_slug)
|
3594
|
-
log_end(-1,"Couldn't connect to machine,aborting")
|
3595
|
-
end
|
3596
|
-
say "run command until ctrl + c initiates", Thor::Shell::Color::BLUE
|
3597
|
-
begin
|
3598
|
-
|
3599
|
-
while true
|
3600
|
-
command = ask("$>")
|
3601
|
-
puts ssh.exec_command(command)
|
3602
|
-
end
|
3603
|
-
|
3604
|
-
rescue SignalException
|
3605
|
-
say "Commiting Image..", Thor::Shell::Color::BLUE
|
3606
|
-
|
3607
|
-
end
|
3608
|
-
resp = Images.commit_custom_image(owner,image_slug)
|
3609
|
-
if Cnvrg::CLI.is_response_success(resp,false)
|
3610
|
-
say "#{checks} Image commited successfuly, email will be sent when image is ready", Thor::Shell::Color::GREEN
|
3611
|
-
end
|
3612
|
-
if ssh
|
3613
|
-
ssh.close_ssh()
|
3614
|
-
end
|
3615
|
-
|
3616
|
-
|
3617
|
-
|
3618
|
-
|
3619
|
-
|
3620
|
-
|
3621
|
-
|
3622
|
-
end
|
3623
|
-
rescue =>e
|
3624
|
-
puts e
|
3625
|
-
if image_slug
|
3626
|
-
Images.revoke_custom_new_image(owner, image_slug)
|
3627
|
-
end
|
3628
|
-
if ssh
|
3629
|
-
ssh.close_ssh()
|
3630
|
-
end
|
3631
|
-
|
3632
|
-
|
3633
|
-
rescue SignalException
|
3634
|
-
if image_slug
|
3635
|
-
Images.revoke_custom_new_image(owner, image_slug)
|
3636
|
-
end
|
3637
|
-
if ssh
|
3638
|
-
ssh.close_ssh
|
3639
|
-
end
|
3640
|
-
say "\nAborting"
|
3641
|
-
exit(1)
|
3642
|
-
end
|
3643
|
-
|
3644
|
-
end
|
3645
|
-
|
3646
|
-
|
3647
3554
|
desc 'build', 'run commands inside containers'
|
3648
3555
|
method_option :install, :type => :string, :aliases => ["--i"], :default => nil, :desc => "Install from the given instructions file"
|
3649
3556
|
|
@@ -5045,14 +4952,10 @@ module Cnvrg
|
|
5045
4952
|
end
|
5046
4953
|
end
|
5047
4954
|
|
5048
|
-
def create_tar(path_in, path_out, tar_files
|
4955
|
+
def create_tar(path_in, path_out, tar_files)
|
5049
4956
|
#The cd is meant for cases when running cnvrg data uplaod not in the main folder
|
5050
4957
|
begin
|
5051
|
-
|
5052
|
-
`cd #{path_in} && tar -cf #{path_out} -T #{tar_files}`
|
5053
|
-
else
|
5054
|
-
`cd #{path_in} && tar -czf #{path_out} -T #{tar_files}`
|
5055
|
-
end
|
4958
|
+
`cd #{path_in} && tar -czf #{path_out} -T #{tar_files}`
|
5056
4959
|
rescue => e
|
5057
4960
|
puts "Exception while compressing data: #{e.message}"
|
5058
4961
|
end
|
data/lib/cnvrg/data.rb
CHANGED
@@ -11,9 +11,7 @@ class SubCommandBase < Thor
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module Cnvrg
|
14
|
-
|
15
14
|
class Data < SubCommandBase
|
16
|
-
class_option :no_compression, :type => :boolean, :aliases => ["-nc", "--no_compression"], :default => false
|
17
15
|
desc "data init", "init data folder"
|
18
16
|
method_option :public, :type => :boolean, :aliases => ["-p", "--public"], :default => false
|
19
17
|
def init
|
@@ -25,15 +23,13 @@ module Cnvrg
|
|
25
23
|
method_option :ignore, :type => :array, :aliases => ["-i", "--i"], :desc => "ignore following files"
|
26
24
|
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
27
25
|
method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
|
28
|
-
method_option :no_compression, :type => :boolean, :aliases => ["-nc", "--no_compression"], :default => false
|
29
|
-
|
30
26
|
def upload
|
31
27
|
cli = Cnvrg::CLI.new()
|
32
28
|
ignore = options["ignore"]
|
33
29
|
verbose = options["verbose"]
|
34
30
|
sync = options["sync"]
|
35
|
-
|
36
|
-
cli.upload_data_tar(ignore, verbose,sync
|
31
|
+
|
32
|
+
cli.upload_data_tar(ignore, verbose,sync)
|
37
33
|
end
|
38
34
|
desc 'data download', 'pull data'
|
39
35
|
method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
|
data/lib/cnvrg/datafiles.rb
CHANGED
@@ -234,7 +234,7 @@ module Cnvrg
|
|
234
234
|
def upload_large_files_s3(upload_resp, file_path)
|
235
235
|
begin
|
236
236
|
sts_path = upload_resp["result"]["path_sts"]
|
237
|
-
|
237
|
+
s4cmd_path = upload_resp["result"]["path_s4cmd"]
|
238
238
|
|
239
239
|
uri = URI.parse(sts_path)
|
240
240
|
http_object = Net::HTTP.new(uri.host, uri.port)
|
@@ -261,51 +261,51 @@ module Cnvrg
|
|
261
261
|
# end
|
262
262
|
#
|
263
263
|
# end
|
264
|
-
resp = false
|
265
264
|
|
266
265
|
if !s4cmd_suc and !s4cmd_install_suc
|
267
266
|
s3 = Aws::S3::Resource.new(
|
268
|
-
:access_key_id => URLcrypt.decrypt(upload_resp["result"]["
|
269
|
-
:secret_access_key => URLcrypt.decrypt(upload_resp["result"]["
|
267
|
+
:access_key_id => URLcrypt.decrypt(upload_resp["result"]["sts_a"]),
|
268
|
+
:secret_access_key => URLcrypt.decrypt(upload_resp["result"]["sts_s"]),
|
269
|
+
:session_token => URLcrypt.decrypt(upload_resp["result"]["sts_st"]),
|
270
270
|
:region => URLcrypt.decrypt(upload_resp["result"]["region"]))
|
271
271
|
resp = s3.bucket(URLcrypt.decrypt(upload_resp["result"]["bucket"])).
|
272
272
|
object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
|
273
273
|
upload_file(file_path,{:use_accelerate_endpoint=>true})
|
274
274
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
275
|
+
else
|
276
|
+
|
277
|
+
s4cmd_uri = URI.parse(s4cmd_path)
|
278
|
+
s4cmd_http_object = Net::HTTP.new(s4cmd_uri.host, s4cmd_uri.port)
|
279
|
+
s4cmd_http_object.use_ssl = true if s4cmd_uri.scheme == 'https'
|
280
|
+
s4cmd_request = Net::HTTP::Get.new(s4cmd_path)
|
281
|
+
|
282
|
+
s4cmd_body = ""
|
283
|
+
s4cmd_http_object.start do |http|
|
284
|
+
response = http.request s4cmd_request
|
285
|
+
s4cmd_body = response.read_body
|
286
|
+
end
|
287
|
+
|
288
|
+
s4cmd_new_body = s4cmd_body.gsub(" self.client = self.boto3.client('s3',
|
289
|
+
aws_access_key_id=aws_access_key_id,
|
290
|
+
aws_secret_access_key=aws_secret_access_key)"," self.client = self.boto3.client('s3',
|
291
|
+
aws_access_key_id='#{ URLcrypt.decrypt(upload_resp["result"]["sts_a"])}',
|
292
|
+
aws_secret_access_key='#{URLcrypt.decrypt(upload_resp["result"]["sts_s"])}',
|
293
|
+
aws_session_token='#{URLcrypt.decrypt(upload_resp["result"]["sts_st"])}')")
|
294
|
+
|
295
|
+
tmp = Tempfile.new('s4cmd.py')
|
296
|
+
tmp << s4cmd_new_body
|
297
|
+
tmp.flush
|
298
|
+
tmp.close
|
299
|
+
|
300
|
+
is_success = false
|
301
|
+
count = 0
|
302
|
+
while !is_success and count <3
|
303
|
+
resp = `python #{tmp.path} --num-threads=8 --max-singlepart-upload-size=#{MULTIPART_SPLIT} put -f #{file_path} s3://#{URLcrypt.decrypt(upload_resp["result"]["bucket"])}/#{upload_resp["result"]["path"]+"/"+File.basename(file_path)} > /dev/null 2>&1`
|
304
|
+
is_success =$?.success?
|
305
|
+
count +=1
|
306
|
+
|
307
|
+
end
|
308
|
+
resp= is_success
|
309
309
|
|
310
310
|
end
|
311
311
|
|
@@ -313,9 +313,9 @@ module Cnvrg
|
|
313
313
|
|
314
314
|
rescue => e
|
315
315
|
puts e.message
|
316
|
-
|
317
|
-
|
318
|
-
|
316
|
+
if File.exist? tmp
|
317
|
+
FileUtils.rm_rf [tmp]
|
318
|
+
end
|
319
319
|
return false
|
320
320
|
|
321
321
|
end
|
data/lib/cnvrg/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cnvrg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.142561
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yochay Ettun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-07-
|
12
|
+
date: 2017-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -329,20 +329,6 @@ dependencies:
|
|
329
329
|
- - ">="
|
330
330
|
- !ruby/object:Gem::Version
|
331
331
|
version: '0'
|
332
|
-
- !ruby/object:Gem::Dependency
|
333
|
-
name: net-ssh
|
334
|
-
requirement: !ruby/object:Gem::Requirement
|
335
|
-
requirements:
|
336
|
-
- - ">="
|
337
|
-
- !ruby/object:Gem::Version
|
338
|
-
version: '0'
|
339
|
-
type: :runtime
|
340
|
-
prerelease: false
|
341
|
-
version_requirements: !ruby/object:Gem::Requirement
|
342
|
-
requirements:
|
343
|
-
- - ">="
|
344
|
-
- !ruby/object:Gem::Version
|
345
|
-
version: '0'
|
346
332
|
description: A CLI tool for interacting with cnvrg.io.
|
347
333
|
email:
|
348
334
|
- info@cnvrg.io
|
@@ -367,7 +353,6 @@ files:
|
|
367
353
|
- lib/cnvrg/job.rb
|
368
354
|
- lib/cnvrg/project.rb
|
369
355
|
- lib/cnvrg/runner.rb
|
370
|
-
- lib/cnvrg/ssh.rb
|
371
356
|
- lib/cnvrg/version.rb
|
372
357
|
homepage: https://cnvrg.io
|
373
358
|
licenses: []
|
@@ -388,9 +373,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
388
373
|
version: '0'
|
389
374
|
requirements: []
|
390
375
|
rubyforge_project:
|
391
|
-
rubygems_version: 2.
|
376
|
+
rubygems_version: 2.6.12
|
392
377
|
signing_key:
|
393
378
|
specification_version: 4
|
394
379
|
summary: A CLI tool for interacting with cnvrg.io.
|
395
380
|
test_files: []
|
396
|
-
has_rdoc:
|
data/lib/cnvrg/ssh.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'cnvrg/files'
|
3
|
-
require 'docker'
|
4
|
-
require 'net/ssh'
|
5
|
-
|
6
|
-
|
7
|
-
module Cnvrg
|
8
|
-
class Ssh
|
9
|
-
attr_reader :is_ssh
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(resp)
|
13
|
-
begin
|
14
|
-
@is_ssh = false
|
15
|
-
sts_path = resp["result"]["sts_path"]
|
16
|
-
|
17
|
-
uri = URI.parse(sts_path)
|
18
|
-
|
19
|
-
http_object = Net::HTTP.new(uri.host, uri.port)
|
20
|
-
http_object.use_ssl = true if uri.scheme == 'https'
|
21
|
-
request = Net::HTTP::Get.new(sts_path)
|
22
|
-
|
23
|
-
body = ""
|
24
|
-
http_object.start do |http|
|
25
|
-
response = http.request request
|
26
|
-
body = response.read_body
|
27
|
-
end
|
28
|
-
|
29
|
-
URLcrypt::key = [body].pack('H*')
|
30
|
-
ip = URLcrypt.decrypt(resp["result"]["machine_i"])
|
31
|
-
|
32
|
-
@user = URLcrypt.decrypt(resp["result"]["machine_u"])
|
33
|
-
key = URLcrypt.decrypt(resp["result"]["machine_k"])
|
34
|
-
@container = URLcrypt.decrypt(resp["result"]["machine_c"])
|
35
|
-
|
36
|
-
tempssh = Tempfile.new "sshkey"
|
37
|
-
tempssh.write open(key).read
|
38
|
-
tempssh.rewind
|
39
|
-
key_path = tempssh.path
|
40
|
-
count = 0
|
41
|
-
while count < 5
|
42
|
-
|
43
|
-
begin
|
44
|
-
@ssh = Net::SSH.start(ip, user=@user, :keys => key_path, :timeout => 10)
|
45
|
-
if !@ssh.nil?
|
46
|
-
@is_ssh = true
|
47
|
-
return
|
48
|
-
else
|
49
|
-
count+=1
|
50
|
-
sleep(2)
|
51
|
-
|
52
|
-
end
|
53
|
-
rescue
|
54
|
-
count+=1
|
55
|
-
sleep(2)
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
if tempssh
|
61
|
-
tempssh.close
|
62
|
-
tempssh.unlink
|
63
|
-
end
|
64
|
-
return false
|
65
|
-
rescue => e
|
66
|
-
|
67
|
-
puts e
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def exec_command(command)
|
74
|
-
exec_command = "sudo -i -u #{@user} cnvrg exec_container #{@container} \"#{command}\" "
|
75
|
-
return @ssh.exec!(exec_command)
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
def close_ssh()
|
80
|
-
|
81
|
-
|
82
|
-
begin
|
83
|
-
|
84
|
-
@ssh.close
|
85
|
-
rescue => e
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|