cnvrg 0.2 → 0.2.2

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: f693e07f97fdef6be962e7c57f9fd79ef2699748
4
- data.tar.gz: cace232784aef2beec2b93efd2599363c1452796
3
+ metadata.gz: 89388312156199c10f60b2495c05305ea4342a54
4
+ data.tar.gz: 072a8e7f4bfcba47ec648eb48516f8fc53111541
5
5
  SHA512:
6
- metadata.gz: 2910879d667310718d23da4f1ff228e46b6705c61e7c1f975316a568d8c9733d61c5e8d07e3f80836b637fc0fcddf10fe2ba3a4f41826e9e843d6af423c9af21
7
- data.tar.gz: cdecfa7b57355410235bd8742c67bc0d53640d863cc4e7cdac1b47bf83e6e22b811b6c1b1509cdfc20f595a0ac41ba413b1dafdb4030b08140ff01361f17c442
6
+ metadata.gz: ed33b00c74cf61f4bfd259fff6656298f6250acd5f7c8668106e0a67974987b101e8d7923d02bd13c98a51d9fd532279f888ce72931abdcb1be336c394a0b1f5
7
+ data.tar.gz: aeff07a3e9181dbb3a4610206e4852918d9ea24b338ce307a585dea2739bf6260461b9eb64537ec24c4dfac8f1161b8a8b49d5e0376d802152722046f18d5153
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_runtime_dependency 'sucker_punch', '~> 2.0'
36
36
  spec.add_runtime_dependency 'urlcrypt', '~> 0.1.1'
37
37
  spec.add_runtime_dependency 'parallel', '~> 1.12.0'
38
+ spec.add_runtime_dependency 'net_http_ssl_fix'
38
39
 
39
40
  spec.add_runtime_dependency 'logstash-logger', '~> 0.22.1'
40
41
  spec.add_runtime_dependency 'launchy', '~> 2.4'
@@ -85,8 +85,14 @@ module Cnvrg
85
85
  # what if windows?
86
86
  # data[:file] = Faraday::UploadIO.new(data[:absolute_path], content_type)
87
87
  file_base = File.basename(data[:relative_path])
88
+ begin
88
89
  temp_path = File.expand_path('~')+"/.cnvrg/tmp_files/#{file_base}"
89
90
  FileUtils.touch(temp_path)
91
+ rescue
92
+ temp_path ="/tmp/#{file_base}"
93
+ FileUtils.touch(temp_path)
94
+ end
95
+
90
96
 
91
97
 
92
98
  data[:file] = Faraday::UploadIO.new("#{temp_path}", "plain/text")
@@ -2,7 +2,6 @@
2
2
  require "pty"
3
3
  require 'etc'
4
4
  require 'parallel'
5
- require "open4"
6
5
  require 'netrc'
7
6
  require 'net/http'
8
7
  require 'uri'
@@ -12,7 +11,6 @@ require 'yaml'
12
11
  require 'digest' # sha1up
13
12
  require "highline/import"
14
13
  require 'socket'
15
- include Open4
16
14
  require 'cnvrg/helpers'
17
15
  require 'cnvrg/api'
18
16
  require 'cnvrg/auth'
@@ -37,6 +35,7 @@ require 'thor'
37
35
  require 'pathname'
38
36
  require 'enumerator'
39
37
  require 'ruby-progressbar'
38
+ require 'open3'
40
39
 
41
40
  class Thor
42
41
  module Base
@@ -238,7 +237,33 @@ module Cnvrg
238
237
  say "Couldn't set default api, contact help@cnvrg.io", Thor::Shell::Color::RED
239
238
  end
240
239
  end
240
+ desc '', '', :hide => true
241
241
 
242
+ def set_remote_login(current_user,owner,url, email, secret)
243
+ netrc = Netrc.read
244
+ netrc[Cnvrg::Helpers.netrc_domain] = email, secret
245
+ netrc.save
246
+ home_dir = File.expand_path('~')
247
+ if !url.end_with? "/api"
248
+ url = url+"/api"
249
+ end
250
+ begin
251
+ if !File.directory? home_dir+"/.cnvrg"
252
+ FileUtils.mkdir_p([home_dir+"/.cnvrg", home_dir+"/.cnvrg/tmp"])
253
+ end
254
+ if !File.exist?(home_dir+"/.cnvrg/config.yml")
255
+ FileUtils.touch [home_dir+"/.cnvrg/config.yml"]
256
+ end
257
+ config = YAML.load_file(home_dir+"/.cnvrg/config.yml")
258
+
259
+ compression_path = "#{home_dir}/.cnvrg/tmp"
260
+ config = {owner: owner, username: current_user, version_last_check: get_start_day(), api: url, compression_path: compression_path}
261
+ File.open(home_dir+"/.cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
262
+ say "Done"
263
+ rescue
264
+ say "ERROR", Thor::Shell::Color::RED
265
+ end
266
+ end
242
267
  desc '', '', :hide => true
243
268
 
244
269
  def set_remote_api_url(owner, current_user, url)
@@ -479,6 +504,9 @@ module Cnvrg
479
504
  netrc.delete(Cnvrg::Helpers.netrc_domain)
480
505
  netrc.save
481
506
  log_message("Logged out successfully.\n", Thor::Shell::Color::GREEN)
507
+ rescue => e
508
+ puts e.message
509
+ puts e.backtrace
482
510
  rescue SignalException
483
511
  say "\nAborting"
484
512
  exit(1)
@@ -1516,6 +1544,7 @@ module Cnvrg
1516
1544
  in_thread: ParallelThreads
1517
1545
  }
1518
1546
  begin
1547
+ is_success = true
1519
1548
  clone_result = Parallel.map((response["result"]["tree"]), parallel_options) do |f|
1520
1549
 
1521
1550
  relative_path = f[0].gsub(/^#{@project.local_path}/, "")
@@ -1525,6 +1554,7 @@ module Cnvrg
1525
1554
  f
1526
1555
  successful_changes << relative_path
1527
1556
  else
1557
+ is_success =false
1528
1558
  log_message("Could not create directory: #{f[0]}", Thor::Shell::Color::RED)
1529
1559
  raise Parallel::Kill
1530
1560
  end
@@ -1535,6 +1565,7 @@ module Cnvrg
1535
1565
  f
1536
1566
  successful_changes << relative_path
1537
1567
  else
1568
+ is_success =false
1538
1569
  log_message("Could not download file: #{f[0]}", Thor::Shell::Color::RED)
1539
1570
  raise Parallel::Kill
1540
1571
 
@@ -1542,7 +1573,7 @@ module Cnvrg
1542
1573
  end
1543
1574
  end
1544
1575
  rescue Interrupt
1545
-
1576
+ is_success =false
1546
1577
  log_message("Couldn't download, Rolling Back all changes.", Thor::Shell::Color::RED)
1547
1578
 
1548
1579
  @files.revoke_download([], response["result"]["tree"])
@@ -1552,7 +1583,7 @@ module Cnvrg
1552
1583
 
1553
1584
  end
1554
1585
  successful_changes = response["result"]["tree"]
1555
- if !successful_changes.nil?
1586
+ if !successful_changes.nil? and is_success
1556
1587
  Project.verify_cnvrgignore_exist(project_name)
1557
1588
  log_message("Done.\nDownloaded #{successful_changes.size}/#{response["result"]["tree"].size} files", Thor::Shell::Color::GREEN)
1558
1589
  else
@@ -1575,7 +1606,7 @@ module Cnvrg
1575
1606
 
1576
1607
  desc 'status', 'Show the working tree status'
1577
1608
  method_option :new_branch, :type => :boolean, :aliases => ["-nb", "--nb"], :desc => "create new branch of commits"
1578
-
1609
+ method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
1579
1610
 
1580
1611
  def status
1581
1612
  begin
@@ -1583,8 +1614,9 @@ module Cnvrg
1583
1614
  log_start(__method__, args, options)
1584
1615
  @project = Project.new(get_project_home)
1585
1616
  new_branch = options["new_branch"] || false
1617
+ force = options["force"] || false
1586
1618
 
1587
- result = @project.compare_idx(new_branch)["result"]
1619
+ result = @project.compare_idx(new_branch,force:force)["result"]
1588
1620
  commit = result["commit"]
1589
1621
  result = result["tree"]
1590
1622
  log_message("Comparing local changes with remote version:", Thor::Shell::Color::BLUE)
@@ -1661,6 +1693,7 @@ module Cnvrg
1661
1693
  method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
1662
1694
  method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
1663
1695
  method_option :sync, :type => :boolean, :aliases => ["-s"], :default => false
1696
+ method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
1664
1697
 
1665
1698
  def upload(link=false, sync=false, direct=false, ignore_list="")
1666
1699
 
@@ -1672,6 +1705,7 @@ module Cnvrg
1672
1705
 
1673
1706
  @files = Cnvrg::Files.new(@project.owner, @project.slug)
1674
1707
  ignore = options[:ignore] || ""
1708
+ force = options[:force] || false
1675
1709
 
1676
1710
  if ignore.nil? or ignore.empty?
1677
1711
  ignore = ignore_list
@@ -1696,7 +1730,7 @@ module Cnvrg
1696
1730
  end
1697
1731
  end
1698
1732
 
1699
- result = @project.compare_idx(new_branch)
1733
+ result = @project.compare_idx(new_branch,force:force)
1700
1734
  commit = result["result"]["commit"]
1701
1735
  if !link
1702
1736
  if commit != @project.last_local_commit and !@project.last_local_commit.nil? and !result["result"]["tree"]["updated_on_server"].empty?
@@ -1741,7 +1775,7 @@ module Cnvrg
1741
1775
 
1742
1776
  end
1743
1777
  # Start commit
1744
- commit_sha1 = @files.start_commit(new_branch)["result"]["commit_sha1"]
1778
+ commit_sha1 = @files.start_commit(new_branch,force:force)["result"]["commit_sha1"]
1745
1779
 
1746
1780
  # upload / update
1747
1781
  begin
@@ -1868,7 +1902,7 @@ module Cnvrg
1868
1902
  end
1869
1903
 
1870
1904
  if update_count == update_total
1871
- res = @files.end_commit(commit_sha1)
1905
+ res = @files.end_commit(commit_sha1,force:force)
1872
1906
  if (Cnvrg::CLI.is_response_success(res, false))
1873
1907
  # save idx
1874
1908
  begin
@@ -2283,6 +2317,7 @@ module Cnvrg
2283
2317
  method_option :new_branch, :type => :boolean, :aliases => ["-nb"], :desc => "create new branch of commits"
2284
2318
  method_option :verbose, :type => :boolean, :aliases => ["-v"], :default => false
2285
2319
  method_option :ignore, :type => :string, :aliases => ["-i", "--ignore"], :default => ""
2320
+ method_option :force, :type => :boolean, :aliases => ["-f","--force"], :default => false
2286
2321
 
2287
2322
  def sync(direct=true)
2288
2323
  verify_logged_in(true) if direct
@@ -2293,7 +2328,7 @@ module Cnvrg
2293
2328
 
2294
2329
  invoke :download, [], :new_branch => options["new_branch"], :verbose => options["verbose"], :sync => true
2295
2330
  invoke :upload, [link=false, sync=true, direct=direct], :new_branch => options["new_branch"], :verbose => options["verbose"], :sync => true,
2296
- :ignore => options[:ignore]
2331
+ :ignore => options[:ignore], :force=> options[:force]
2297
2332
 
2298
2333
 
2299
2334
  end
@@ -2374,7 +2409,6 @@ module Cnvrg
2374
2409
  # end
2375
2410
  end
2376
2411
 
2377
-
2378
2412
  desc '', '', :hide => true
2379
2413
  method_option :sync_before, :type => :boolean, :aliases => ["-sb,--sync_before"], :default => true
2380
2414
  method_option :sync_after, :type => :boolean, :aliases => ["-sa,--sync_after"], :default => true
@@ -2481,6 +2515,7 @@ module Cnvrg
2481
2515
  memory_total = []
2482
2516
  cpu_total = []
2483
2517
  start_loop = Time.now
2518
+ stdout, stderr = '', ''
2484
2519
  begin
2485
2520
  PTY.spawn(cmd) do |stdout, stdin, pid, stderr|
2486
2521
  begin
@@ -2563,7 +2598,7 @@ module Cnvrg
2563
2598
 
2564
2599
  log_message("command \"#{cmd}\" couldn't be executed, verify command is valid", Thor::Shell::Color::RED)
2565
2600
  log_error(e)
2566
- rescue PTY::ChildExited
2601
+ rescue Open4::ChildExited
2567
2602
  exp_success = false
2568
2603
  log_message("The process exited!", Thor::Shell::Color::RED)
2569
2604
  rescue => e
@@ -2574,6 +2609,8 @@ module Cnvrg
2574
2609
  exit(0)
2575
2610
  end
2576
2611
  ::Process.wait pid
2612
+ end
2613
+
2577
2614
  cpu_average = cpu_total.inject(0) { |sum, el| sum + el }.to_f / cpu_total.size
2578
2615
  memory_average = memory_total.inject(0) { |sum, el| sum + el }.to_f / memory_total.size
2579
2616
  exit_status = $?.exitstatus
@@ -2614,12 +2651,24 @@ module Cnvrg
2614
2651
  res = @exp.end(log, exit_status, end_commit, cpu_average, memory_average)
2615
2652
  check = Helpers.checkmark()
2616
2653
  log_message("#{check} Done. Experiment's results were updated!", Thor::Shell::Color::GREEN)
2617
- end
2618
2654
  rescue => e
2619
2655
  if container
2620
2656
  container.stop()
2621
2657
  end
2622
2658
  log_message("Couldn't run #{cmd}, check your input parameters", Thor::Shell::Color::RED)
2659
+ if @exp
2660
+ cur_time = Time.now
2661
+ real_time= Time.now-real
2662
+ cur_log = {time: cur_time,
2663
+ message: "Couldn't run #{cmd}, check your input parameters",
2664
+ type: "stdout",
2665
+ real: real_time
2666
+
2667
+ }
2668
+ log << cur_log
2669
+ res = @exp.end(log, "-1", end_commit, cpu_average, memory_average)
2670
+
2671
+ end
2623
2672
  log_error(e)
2624
2673
 
2625
2674
  exit(1)
@@ -2897,6 +2946,7 @@ module Cnvrg
2897
2946
 
2898
2947
  end
2899
2948
  project = Project.new(working_dir)
2949
+
2900
2950
  choose_image = options["image"]
2901
2951
 
2902
2952
  if !choose_image.nil? and !choose_image.empty?
@@ -3156,7 +3206,7 @@ module Cnvrg
3156
3206
 
3157
3207
  end
3158
3208
 
3159
- desc 'remote_notebook', 'run notebook server on remote server'
3209
+ desc '', '', :hide=>true
3160
3210
  method_option :notebook_dir, :type => :string, :aliases => ["-n"], :default => "", :desc => "relative path to notebook dir from current directory"
3161
3211
  method_option :machine_type, :type => :string, :default => ""
3162
3212
  method_option :kernel, :type => :string, :aliases => ["--kernel", "-k"], :default => ""
@@ -3165,7 +3215,7 @@ module Cnvrg
3165
3215
  method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
3166
3216
 
3167
3217
 
3168
- def remote_notebook()
3218
+ def remote_notebook_old()
3169
3219
  verify_logged_in(true)
3170
3220
  log_start(__method__, args, options)
3171
3221
 
@@ -3260,6 +3310,52 @@ module Cnvrg
3260
3310
  exit(1)
3261
3311
  end
3262
3312
  end
3313
+ desc 'remote_notebook', 'run notebook server on remote server'
3314
+ method_option :machine_type, :type => :string, :default => ""
3315
+ method_option :notebook_type, :type => :string, :aliases => ["-n","--notebook_type"], :default => ""
3316
+ method_option :data, :type => :string, :aliases => ["-d", "--data"], :default => ""
3317
+ method_option :data_commit, :type => :string, :aliases => ["--data_commit"], :default => ""
3318
+ method_option :commit, :type => :string, :aliases => ["--commit"], :default => ""
3319
+
3320
+
3321
+ def remote_notebook()
3322
+ verify_logged_in(true)
3323
+ log_start(__method__, args, options)
3324
+
3325
+ working_dir = is_cnvrg_dir()
3326
+ instance_type = options["machine_type"] || nil
3327
+ data = options["data"]
3328
+ data_commit = options["data_commit"]
3329
+ commit = options["commit"]
3330
+ notebook_type = options["notebook_type"]
3331
+
3332
+
3333
+ begin
3334
+ project = Project.new(working_dir)
3335
+ exp = Experiment.new(project.owner, project.slug)
3336
+
3337
+ if !notebook_type.nil? and !notebook_type.empty?
3338
+ notebook_type = "jupyter"
3339
+ end
3340
+ invoke :sync, [false], []
3341
+ slug = ""
3342
+ res =exp.remote_notebook( instance_type, commit, data, data_commit, notebook_type)
3343
+ if Cnvrg::CLI.is_response_success(res)
3344
+ slug = res["result"]["notebook_url"]
3345
+ log_message("#{Helpers.checkmark} Notebook is ready: #{Cnvrg::Helpers.remote_url}/#{project.owner}/projects/#{project.slug}/notebook_sessions/show/#{slug}", Thor::Shell::Color::GREEN)
3346
+
3347
+ end
3348
+ rescue => e
3349
+ log_message("Error occurred, Aborting", Thor::Shell::Color::RED)
3350
+ log_error(e)
3351
+
3352
+ rescue SignalException
3353
+ log_message("Aborting", Thor::Shell::Color::BLUE)
3354
+ notebook_stop(slug) unless slug.nil? or slug.empty?
3355
+
3356
+ exit(1)
3357
+ end
3358
+ end
3263
3359
 
3264
3360
  desc 'search_libraries', 'search if libraries installed', :hide => true
3265
3361
 
@@ -3560,65 +3656,35 @@ module Cnvrg
3560
3656
  method_option :remote, :type => :boolean, :aliases => ["-r", "--r"], :default => false, :desc => "run on remote machine"
3561
3657
  method_option :verbose, :type => :boolean, :aliases => ["--v"], :default => false
3562
3658
 
3563
- def notebook_stop
3659
+ def notebook_stop(notebook_slug)
3564
3660
  begin
3565
3661
  verify_logged_in(true)
3566
3662
  log_start(__method__, args, options)
3567
- remote = options["remote"] || false
3568
3663
  project_dir = is_cnvrg_dir()
3569
3664
 
3570
3665
 
3571
- log_message('Checking for new updates from remote version', Thor::Shell::Color::BLUE, options["verbose"])
3572
- invoke :sync, [false], :verbose => options["verbose"]
3573
-
3574
- log_message("Done Syncing", Thor::Shell::Color::BLUE, options["verbose"])
3575
-
3576
-
3577
3666
  @project = Project.new(project_dir)
3578
3667
 
3579
- end_commit = @project.last_local_commit
3580
3668
 
3581
3669
  @note = Experiment.new(@project.owner, @project.slug)
3670
+ log_message("Stoping notebook session: #{notebook_slug}", Thor::Shell::Color::BLUE)
3582
3671
 
3583
- slug = get_note_url(project_dir)
3584
- @note.end_notebook_session(slug, end_commit)
3585
-
3586
-
3587
- image = is_project_with_docker(Dir.pwd)
3588
- if image and image.is_docker and !remote
3589
- container = image.get_container(true)
3590
- if !container
3591
- check = Helpers.checkmark()
3592
-
3593
- log_message("#{check} Notebook server stopped successfully", Thor::Shell::Color::GREEN)
3594
- exit(0)
3595
- end
3596
-
3597
-
3598
- log_message("Stopping notebook server...", Thor::Shell::Color::BLUE)
3599
-
3672
+ res = @note.end_notebook_session(notebook_slug)
3673
+ if res
3600
3674
  check = Helpers.checkmark()
3601
- image.remove_note_slug()
3602
- container.stop()
3603
-
3604
- log_message("#{check} Notebook server stopped successfully", Thor::Shell::Color::GREEN)
3675
+ log_message("#{check} Notebook session has stopped successfully", Thor::Shell::Color::GREEN)
3605
3676
 
3606
3677
  exit(0)
3607
- elsif remote
3608
- log_message("Stopping notebook server...", Thor::Shell::Color::BLUE)
3609
- check = Helpers.checkmark()
3678
+ else
3610
3679
 
3611
- log_message("#{check} Notebook server stopped successfully", Thor::Shell::Color::GREEN)
3612
- exit(0)
3680
+ log_message("Couldn't stop notebook session, try stopping via cnvrg web", Thor::Shell::Color::RED)
3681
+ exit(1)
3613
3682
  end
3614
3683
  rescue => e
3615
3684
  log_message("Error occurd, aborting", Thor::Shell::Color::RED)
3616
3685
  log_error(e)
3617
- if container
3618
- container.stop()
3619
- end
3620
3686
  rescue SignalException
3621
- say "Aborting"
3687
+ log_message("Aborting", Thor::Shell::Color::BLUE)
3622
3688
  exit(1)
3623
3689
  end
3624
3690
 
@@ -4413,19 +4479,25 @@ module Cnvrg
4413
4479
 
4414
4480
  desc '', '', :hide => true
4415
4481
 
4416
- def upload_cnvrg_image(image_name)
4482
+ def upload_cnvrg_image(image_path,image_name,secret)
4483
+ begin
4417
4484
  verify_logged_in(false)
4418
- log_start(__method__, args, options)
4419
- owner = Cnvrg::CLI.get_owner()
4420
4485
 
4421
- path = File.expand_path('~')+"/.cnvrg/tmp/#{image_name}.zip"
4422
4486
  @files = Cnvrg::Files.new("", "")
4423
- # python_arr = Cnvrg::Images.get_installed_packages("python")
4424
- # py = python_arr.join(",") unless python_arr.nil? or python_arr.empty?
4425
- # system_arr = Cnvrg::Images.get_installed_packages("system")
4426
- # sys = system_arr.join(",") unless system_arr.nil? or system_arr.empty?
4427
- # bash_history = Cnvrg::Images.get_bash_history
4428
- res = @files.upload_image(path, image_name, owner, true, true, "", "", "", "Image made by cnvrg.io team", "")
4487
+ say "Uploading cnvrg image file", Thor::Shell::Color::BLUE
4488
+
4489
+ res = @files.upload_cnvrg_image(image_path, image_name, secret)
4490
+ if res
4491
+ say "Successfully uploaded cnvrg image file", Thor::Shell::Color::GREEN
4492
+
4493
+ else
4494
+ say "Couldn't upload cnvrg image file", Thor::Shell::Color::RED
4495
+ end
4496
+ rescue => e
4497
+ puts e
4498
+ puts e.backtrace
4499
+ end
4500
+
4429
4501
 
4430
4502
  end
4431
4503
 
@@ -4515,7 +4587,32 @@ module Cnvrg
4515
4587
  end
4516
4588
  end
4517
4589
  end
4590
+ desc '', '', :hide => true
4591
+ def download_cnvrg_image(image_name, secret)
4592
+ verify_logged_in(false)
4593
+
4594
+ begin
4595
+ @files = Cnvrg::Files.new("", "")
4596
+
4597
+ say "Downloading image file", Thor::Shell::Color::BLUE
4598
+ begin
4599
+ if @files.download_cnvrg_image(image_name, secret)
4600
+
4601
+ say "Successfully downloaded image #{image_name}", Thor::Shell::Color::GREEN
4518
4602
 
4603
+ else
4604
+ say "Couldn't download image #{image_name}", Thor::Shell::Color::RED
4605
+ return false
4606
+ end
4607
+ rescue Interrupt
4608
+ say "The user has exited to process, aborting", Thor::Shell::Color::BLUE
4609
+ exit(1)
4610
+ end
4611
+ rescue SignalException
4612
+ say "\nAborting"
4613
+ exit(1)
4614
+ end
4615
+ end
4519
4616
 
4520
4617
  desc 'list_images', 'lists all custom images you can pull'
4521
4618
 
@@ -4855,7 +4952,7 @@ module Cnvrg
4855
4952
  end
4856
4953
 
4857
4954
  rescue => e
4858
- puts e
4955
+ puts e.backtrace
4859
4956
  end
4860
4957
  end
4861
4958
 
@@ -4885,6 +4982,7 @@ module Cnvrg
4885
4982
  end
4886
4983
 
4887
4984
  def self.is_response_success(response, should_exit=true)
4985
+ begin
4888
4986
  if response.nil?
4889
4987
  if !Cnvrg::Helpers.internet_connection?
4890
4988
  say("<%= color('Error:You seems to be offline', RED) %>")
@@ -4913,6 +5011,11 @@ module Cnvrg
4913
5011
  end
4914
5012
  end
4915
5013
  return true
5014
+ rescue => e
5015
+ puts e.message
5016
+ puts e.backtrace
5017
+ end
5018
+
4916
5019
  end
4917
5020
 
4918
5021
  def self.get_owner
@@ -201,44 +201,25 @@ module Cnvrg
201
201
 
202
202
  end
203
203
 
204
- def upload_cnvrg_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message)
205
- file_name = File.basename absolute_path
204
+ def upload_cnvrg_image(absolute_path, image_name,secret)
205
+ file_name = File.basename relative_path
206
206
  file_size = File.size(absolute_path).to_f
207
- if is_base
208
-
209
- content_type = "application/zip"
210
- else
211
- content_type = "application/gzip"
212
- end
213
- begin
214
- upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
215
- file_name: file_name,
216
- image_name: image_name,
217
- file_size: file_size,
218
- file_content_type: content_type,
219
- is_public: is_public,
220
- dpkg: dpkg,
221
- libraries: libraries,
222
- bash_history: bash,
223
- commit_message: message,
224
- is_base: is_base})
225
- # puts upload_resp
226
- if Cnvrg::CLI.is_response_success(upload_resp, false)
227
- path = upload_resp["result"]["path"]
228
- s3_res = upload_small_files_s3(path, absolute_path, content_type)
229
- if s3_res
230
- commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
231
- if Cnvrg::CLI.is_response_success(commit_resp, false)
232
- return commit_resp["result"]["image"]
233
- else
234
- return false
235
- end
236
-
237
- end
207
+ mime_type = MimeMagic.by_path(absolute_path)
208
+ content_type = !(mime_type.nil? or mime_type.text?) ? mime_type.type : "text/plain"
209
+ upload_resp = Cnvrg::API.request("images/#{image_name}/upload_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: absolute_path,
210
+ file_name: file_name,
211
+ file_size: file_size, file_content_type: content_type,
212
+ secret: secret})
213
+ if Cnvrg::CLI.is_response_success(upload_resp, false)
214
+ path = upload_resp["result"]["path"]
215
+ s3_res = upload_large_files_s3(upload_resp, absolute_path)
216
+ if s3_res
217
+ Cnvrg::API.request(@base_resource + "update_s3", 'POST', {path: path, commit_id: upload_resp["result"]["commit_id"],
218
+ blob_id: upload_resp["result"]["id"]})
219
+ return true
238
220
  end
239
- return false
240
- rescue => e
241
221
  end
222
+ return false
242
223
 
243
224
  end
244
225
 
@@ -309,7 +290,7 @@ module Cnvrg
309
290
 
310
291
  resp = s3.bucket(bucket).
311
292
  object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
312
- upload_file(file_path, {:use_accelerate_endpoint => true})
293
+ upload_file(file_path, {:use_accelerate_endpoint => true,:server_side_encryption => 'AES256'})
313
294
  # s4cmd_path = upload_resp["result"]["path_s4cmd"]
314
295
  #
315
296
  # s4cmd_uri = URI.parse(s4cmd_path)
@@ -399,6 +380,7 @@ module Cnvrg
399
380
 
400
381
  def create_dir(absolute_path, relative_path, commit_sha1)
401
382
  response = Cnvrg::API.request(@base_resource + "create_dir", 'POST', {absolute_path: absolute_path, relative_path: relative_path, commit_sha1: commit_sha1})
383
+ puts response
402
384
  return Cnvrg::CLI.is_response_success(response, false)
403
385
  end
404
386
 
@@ -34,9 +34,8 @@ module Cnvrg
34
34
 
35
35
  end
36
36
 
37
- def end_notebook_session(notebook_slug, end_commit)
38
- res = Cnvrg::API.request(@base_resource + "notebook/end_session", 'POST',
39
- {notebook_slug: notebook_slug, end_commit: end_commit})
37
+ def end_notebook_session(notebook_slug)
38
+ res = Cnvrg::API.request(@base_resource + "notebook/#{notebook_slug}/stop", 'GET')
40
39
  Cnvrg::CLI.is_response_success(res,false)
41
40
 
42
41
  return res
@@ -89,6 +88,11 @@ module Cnvrg
89
88
  dataset_commit: data_commit})
90
89
  return response
91
90
  end
91
+ def remote_notebook(instance_type, commit, data, data_commit, notebook_type)
92
+ response = Cnvrg::API.request("users/#{@owner}/projects/#{@project_slug}/notebook/remote", 'POST', {instance_type: instance_type,dataset_slug:data,
93
+ dataset_commit: data_commit,commit:commit,notebook_type:notebook_type})
94
+ return response
95
+ end
92
96
 
93
97
  def upload_temp_log(temp_log, cpu_average, memory_average)
94
98
  response = Cnvrg::API.request(@base_resource + "experiment/upload_temp_log", 'POST', {output: temp_log,
@@ -3,7 +3,6 @@ require 'aws-sdk'
3
3
  require 'URLcrypt'
4
4
  require 'tempfile'
5
5
  require 'net/http'
6
-
7
6
  module Cnvrg
8
7
  class Files
9
8
 
@@ -149,44 +148,32 @@ module Cnvrg
149
148
 
150
149
  end
151
150
 
152
- def upload_cnvrg_image(absolute_path, image_name, owner, is_public, is_base, dpkg, libraries, bash, message)
151
+ def upload_cnvrg_image(absolute_path, image_name,secret)
153
152
  file_name = File.basename absolute_path
154
153
  file_size = File.size(absolute_path).to_f
155
- if is_base
156
-
157
- content_type = "application/zip"
158
- else
159
- content_type = "application/gzip"
160
- end
154
+ content_type = MimeMagic.by_path(absolute_path)
161
155
  begin
162
- upload_resp = Cnvrg::API.request("users/#{owner}/images/" + "upload_cnvrg", 'POST_FILE', {relative_path: absolute_path,
156
+ upload_resp = Cnvrg::API.request("images/#{image_name}/upload", 'POST_FILE', {relative_path: absolute_path,
163
157
  file_name: file_name,
164
- image_name: image_name,
165
158
  file_size: file_size,
166
159
  file_content_type: content_type,
167
- is_public: is_public,
168
- dpkg: dpkg,
169
- libraries: libraries,
170
- bash_history: bash,
171
- commit_message: message,
172
- is_base: is_base})
160
+ secret:secret
161
+ })
173
162
  # puts upload_resp
174
163
  if Cnvrg::CLI.is_response_success(upload_resp, false)
175
- path = upload_resp["result"]["path"]
176
- s3_res = upload_small_files_s3(path, absolute_path, content_type)
164
+ s3_res = upload_large_files_s3(upload_resp, absolute_path)
177
165
  if s3_res
178
- commit_resp = Cnvrg::API.request("users/#{owner}/images/#{upload_resp["result"]["id"]}/" + "commit", 'GET')
179
- if Cnvrg::CLI.is_response_success(commit_resp, false)
180
- return commit_resp["result"]["image"]
181
- else
182
- return false
183
- end
184
-
166
+ return true
167
+ else
168
+ return false
185
169
  end
170
+
186
171
  end
187
- return false
188
172
  rescue => e
173
+ return false
189
174
  end
175
+ return false
176
+
190
177
 
191
178
  end
192
179
 
@@ -213,6 +200,56 @@ module Cnvrg
213
200
  end
214
201
 
215
202
 
203
+ end
204
+ def download_cnvrg_image(image_name, secret)
205
+ res =Cnvrg::API.request("images/#{image_name}/" + "download", 'POST', {secret:secret},true)
206
+ Cnvrg::CLI.is_response_success(res, true)
207
+ if res["result"]
208
+ download_resp = res
209
+ sts_path = download_resp["result"]["path_sts"]
210
+ uri = URI.parse(sts_path)
211
+ http_object = Net::HTTP.new(uri.host, uri.port)
212
+ http_object.use_ssl = true if uri.scheme == 'https'
213
+ request = Net::HTTP::Get.new(sts_path)
214
+ body = ""
215
+ http_object.start do |http|
216
+ response = http.request request
217
+ body = response.read_body
218
+ end
219
+ split = body.split("\n")
220
+ key = split[0]
221
+ iv = split[1]
222
+
223
+ access = Cnvrg::Helpers.decrypt(key, iv, download_resp["result"]["sts_a"])
224
+
225
+ secret = Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["sts_s"])
226
+
227
+ session = Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["sts_st"])
228
+ region = Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["region"])
229
+
230
+ bucket = Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["bucket"])
231
+ key = Cnvrg::Helpers.decrypt(key,iv, download_resp["result"]["key"])
232
+
233
+ client = Aws::S3::Client.new(
234
+ :access_key_id =>access,
235
+ :secret_access_key => secret,
236
+ :session_token => session,
237
+ :region => region,
238
+ :http_open_timeout => 60, :retry_limit => 20
239
+ )
240
+
241
+ File.open("/tmp/#{image_name}.tar", 'w+') do |file|
242
+ resp = client.get_object({bucket:bucket,
243
+ key:key}, target: file)
244
+ end
245
+ return true
246
+ end
247
+
248
+ rescue => e
249
+ puts e
250
+ return false
251
+
252
+
216
253
  end
217
254
 
218
255
  def upload_large_files_s3(upload_resp, file_path)
@@ -284,7 +321,7 @@ module Cnvrg
284
321
  s3 = Aws::S3::Resource.new(client: client)
285
322
  resp = s3.bucket(bucket).
286
323
  object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
287
- upload_file(file_path, {:use_accelerate_endpoint => true})
324
+ upload_file(file_path, {:use_accelerate_endpoint => true, :server_side_encryption => 'AES256'})
288
325
 
289
326
  return resp
290
327
 
@@ -349,6 +386,7 @@ module Cnvrg
349
386
  begin
350
387
  res = Cnvrg::API.request(@base_resource + "download_file", 'POST', {absolute_path: absolute_path, relative_path: relative_path,
351
388
  commit_sha1: commit_sha1,new_version:true})
389
+
352
390
  Cnvrg::CLI.is_response_success(res, false)
353
391
  if res["result"]
354
392
  download_resp = res
@@ -387,7 +425,6 @@ module Cnvrg
387
425
  :region => region,
388
426
  :http_open_timeout => 60, :retry_limit => 20
389
427
  )
390
-
391
428
  File.open(project_home+"/"+absolute_path, 'w+') do |file|
392
429
  resp = client.get_object({bucket:bucket,
393
430
  key:key}, target: file)
@@ -468,18 +505,18 @@ module Cnvrg
468
505
  return true
469
506
 
470
507
  end
471
- def start_commit(new_branch)
508
+ def start_commit(new_branch,force:false)
472
509
 
473
- response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {project_slug: @project_slug, new_branch: new_branch,
510
+ response = Cnvrg::API.request("#{base_resource}/commit/start", 'POST', {project_slug: @project_slug, new_branch: new_branch,force:force,
474
511
  username: @owner})
475
512
  Cnvrg::CLI.is_response_success(response,false)
476
513
  return response
477
514
  end
478
515
 
479
- def end_commit(commit_sha1)
480
- response = Cnvrg::API.request("#{base_resource}/commit/end", 'POST', {commit_sha1: commit_sha1})
481
- return response
482
- end
516
+ def end_commit(commit_sha1,force:false)
517
+ response = Cnvrg::API.request("#{base_resource}/commit/end", 'POST', {commit_sha1: commit_sha1,force:force})
518
+ return response
519
+ end
483
520
 
484
521
  def rollback_commit(commit_sha1)
485
522
  response = Cnvrg::API.request("#{base_resource}/commit/rollback", 'POST', {commit_sha1: commit_sha1})
@@ -351,12 +351,11 @@ module Cnvrg
351
351
  return response
352
352
  end
353
353
 
354
- def compare_idx(new_branch, commit=last_local_commit)
355
-
354
+ def compare_idx(new_branch, commit:last_local_commit,force:false)
356
355
  local_idx = self.generate_idx
357
356
  ignore_list = self.send_ignore_list()
358
357
  response = Cnvrg::API.request("users/#{self.owner}/projects/#{self.slug}/status", 'POST', {idx: local_idx, new_branch: new_branch,
359
- current_commit: commit,ignore:ignore_list})
358
+ current_commit: commit,ignore:ignore_list, force:force})
360
359
  CLI.is_response_success(response,false)
361
360
  return response
362
361
  end
@@ -1,4 +1,4 @@
1
1
  module Cnvrg
2
- VERSION = '0.2'
2
+ VERSION = '0.2.2'
3
3
  end
4
4
 
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.2'
4
+ version: 0.2.2
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-09-11 00:00:00.000000000 Z
12
+ date: 2017-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -259,6 +259,20 @@ dependencies:
259
259
  - - "~>"
260
260
  - !ruby/object:Gem::Version
261
261
  version: 1.12.0
262
+ - !ruby/object:Gem::Dependency
263
+ name: net_http_ssl_fix
264
+ requirement: !ruby/object:Gem::Requirement
265
+ requirements:
266
+ - - ">="
267
+ - !ruby/object:Gem::Version
268
+ version: '0'
269
+ type: :runtime
270
+ prerelease: false
271
+ version_requirements: !ruby/object:Gem::Requirement
272
+ requirements:
273
+ - - ">="
274
+ - !ruby/object:Gem::Version
275
+ version: '0'
262
276
  - !ruby/object:Gem::Dependency
263
277
  name: logstash-logger
264
278
  requirement: !ruby/object:Gem::Requirement
@@ -402,7 +416,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
402
416
  version: '0'
403
417
  requirements: []
404
418
  rubyforge_project:
405
- rubygems_version: 2.6.8
419
+ rubygems_version: 2.6.12
406
420
  signing_key:
407
421
  specification_version: 4
408
422
  summary: A CLI tool for interacting with cnvrg.io.