From 5d10b3b30e303f153842b72bfd2879a87e1c3c2e Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Tue, 14 Mar 2017 16:04:32 -0500 Subject: [PATCH 01/18] deploy fills release now --- lib/singularity/request.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index f1f6c74..67dfb6f 100644 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -32,6 +32,7 @@ def deploy else @data['requestId'] = @data['id'] @data['id'] = "#{@release}.#{Time.now.to_i}" + @data['containerInfo']['docker']['image'] = "#{JSON.parse(File.read('.mescal.json'))['image'].split(':').first}:#{@release}" @deploy = { 'deploy' => @data, 'user' => `whoami`.chomp, From af48365401a0ac647f86c5462585a2aa67085c1e Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Mon, 27 Mar 2017 14:33:26 -0500 Subject: [PATCH 02/18] added list-ssh command, not finished --- bin/singularity | 3 +++ lib/singularity/util.rb | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/bin/singularity b/bin/singularity index 90dd0d8..28d3209 100755 --- a/bin/singularity +++ b/bin/singularity @@ -75,6 +75,9 @@ case action end Singularity::Runner.new(ARGV, uri).run + when "list-ssh" + Singularity::Util.new.list_ssh + when "help" print_usage diff --git a/lib/singularity/util.rb b/lib/singularity/util.rb index f029fb4..1150a5f 100644 --- a/lib/singularity/util.rb +++ b/lib/singularity/util.rb @@ -3,6 +3,7 @@ module Singularity module Util + def self.port_open?(ip, port, seconds=1) Timeout::timeout(seconds) do begin @@ -15,5 +16,11 @@ def self.port_open?(ip, port, seconds=1) rescue Timeout::Error false end + + def self.list_ssh() + + + end + end end From 78853acf9e6930323d25c8570cf7d6a4fc4e192e Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Mon, 10 Apr 2017 11:01:02 -0500 Subject: [PATCH 03/18] progresses --- bin/singularity | 2 +- lib/singularity/request.rb | 4 ++++ lib/singularity/util.rb | 5 ----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/singularity b/bin/singularity index 28d3209..801ab58 100755 --- a/bin/singularity +++ b/bin/singularity @@ -76,7 +76,7 @@ case action Singularity::Runner.new(ARGV, uri).run when "list-ssh" - Singularity::Util.new.list_ssh + Singularity::Request.new(nil, uri, nil).list_ssh when "help" print_usage diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index 67dfb6f..b7b2f0f 100644 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -24,6 +24,10 @@ def delete puts ' Deleted request: '.red + "#{@data['requestId']||@data['id']}".light_blue end + def list_ssh + RestClient.get "#{@uri}/api/tasks/active", @data.to_json, :content_type => :json + end + # deploys a request in singularity def deploy if is_paused diff --git a/lib/singularity/util.rb b/lib/singularity/util.rb index 1150a5f..698dd93 100644 --- a/lib/singularity/util.rb +++ b/lib/singularity/util.rb @@ -17,10 +17,5 @@ def self.port_open?(ip, port, seconds=1) false end - def self.list_ssh() - - - end - end end From 8d1a3799d28a2f7ba1e1bced1b7ffcc2722e79cf Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Wed, 12 Apr 2017 15:46:28 -0500 Subject: [PATCH 04/18] list ssh working, needs pretty --- bin/singularity | 2 +- lib/singularity/request.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/singularity b/bin/singularity index 801ab58..2b5059c 100755 --- a/bin/singularity +++ b/bin/singularity @@ -70,7 +70,7 @@ case action end else - puts "Your ~/.ssh directory did not successfully mount in the docker image that this command runs." + puts "Your ~/.ssh directory did not successfully mount in the docker image that this command runs in." exit end Singularity::Runner.new(ARGV, uri).run diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index b7b2f0f..43889a9 100644 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -25,7 +25,18 @@ def delete end def list_ssh - RestClient.get "#{@uri}/api/tasks/active", @data.to_json, :content_type => :json + tasks = JSON.parse(RestClient.get "#{@uri}/api/tasks/active", :content_type => :json) + + tasks.each do |entry| + taskId = entry['taskRequest']['request']['id'] + if taskId.include?("SSH") + ip = entry['offer']['url']['address']['ip'] + port = entry['mesosTask']['container']['docker']['portMappings'][0]['hostPort'] + + puts "#{taskId}: ".light_blue + "root".yellow + " @ ".light_blue + "#{ip}".light_magenta + " : ".light_blue + "#{port}".light_cyan + end + end + end # deploys a request in singularity From 36b72af847ff753207b9ae03c2eeab000b5d7877 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Wed, 12 Apr 2017 16:34:53 -0500 Subject: [PATCH 05/18] list ssh working, needs more pretty --- lib/singularity/request.rb | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index 43889a9..ef6916e 100644 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -27,16 +27,58 @@ def delete def list_ssh tasks = JSON.parse(RestClient.get "#{@uri}/api/tasks/active", :content_type => :json) + count = 1 tasks.each do |entry| taskId = entry['taskRequest']['request']['id'] if taskId.include?("SSH") ip = entry['offer']['url']['address']['ip'] port = entry['mesosTask']['container']['docker']['portMappings'][0]['hostPort'] - puts "#{taskId}: ".light_blue + "root".yellow + " @ ".light_blue + "#{ip}".light_magenta + " : ".light_blue + "#{port}".light_cyan + puts "#{count}: ".light_green + "#{taskId}: ".light_blue + "root".yellow + " @ ".light_blue + "#{ip}".light_magenta + " : ".light_blue + "#{port}".light_cyan + count = count + 1 end end + puts "Would you like to (k)ill or (c)onnect to any of these sessions? (n or Ctrl+C to exit) " + resp = 'x' + + while !['n','k','kill','c','con','conn','connect'].include?(resp) + resp = gets + end + + case resp + when 'n' + message = RestClient.get "http://bit.ly/2p9K3sI" + message = message.chop.chop.chop + "\"" + puts RestClient.get "http://bit.ly/2otyRsW", :message => "#{message}", :format => "text" + when 'k','kill' + + when 'c','con','conn','connect' + # please enter the session number + + # # wrap the below in error checking + # num = gets.to_i + + + # while resp != (y|n) + # puts "SSH into <> (y/n)?" + # resp = getc + # end + # if resp == "y" + # Singularity::Runner ->ssh + # else + # end + + # if (k) + # please enter a comma-separated list of which numbers you'd like to kill + # list = gets + # list = list.remove(" ").split(",") + # list.each do |process_index| + # tasks[process_index-1] + # "!!".red + " Are you sure you want to KILL " + "#{taskId}}".red + "?" + "!!".red + # end + # end + end # deploys a request in singularity From 7aa4287b6c1921621960504955cbbc4fb4f0a885 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Thu, 13 Apr 2017 15:12:52 -0500 Subject: [PATCH 06/18] still prettying --- bin/singularity | 5 ++++ lib/singularity/request.rb | 61 +++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/bin/singularity b/bin/singularity index 2b5059c..88c3a70 100755 --- a/bin/singularity +++ b/bin/singularity @@ -76,6 +76,11 @@ case action Singularity::Runner.new(ARGV, uri).run when "list-ssh" + # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + # + # this has to change, need @data for ssh? + # + # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Singularity::Request.new(nil, uri, nil).list_ssh when "help" diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index ef6916e..2212b6a 100644 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -25,10 +25,10 @@ def delete end def list_ssh - tasks = JSON.parse(RestClient.get "#{@uri}/api/tasks/active", :content_type => :json) + activeTasksList = JSON.parse(RestClient.get "#{@uri}/api/tasks/active", :content_type => :json) count = 1 - tasks.each do |entry| + activeTasksList.each do |entry| taskId = entry['taskRequest']['request']['id'] if taskId.include?("SSH") ip = entry['offer']['url']['address']['ip'] @@ -39,45 +39,50 @@ def list_ssh end end - puts "Would you like to (k)ill or (c)onnect to any of these sessions? (n or Ctrl+C to exit) " - resp = 'x' + puts "Would you like to (k)ill or (c)onnect to any of these sessions? (x to exit) " + resp = ' ' - while !['n','k','kill','c','con','conn','connect'].include?(resp) - resp = gets + while !['x','k','kill','c','con','conn','connect'].include?(resp) + resp = gets.chomp end case resp - when 'n' - message = RestClient.get "http://bit.ly/2p9K3sI" - message = message.chop.chop.chop + "\"" - puts RestClient.get "http://bit.ly/2otyRsW", :message => "#{message}", :format => "text" + when 'x' + exit 0 when 'k','kill' - + puts 'Please enter a comma-separated list of which numbers from the above list you would like to kill (or x to exit)' + killList = gets.chomp + if killList == 'x' + exit 0 + end + killList = killList.delete(' ').split(',') + killList.each do |task_index| + thisTask = activeTasksList[task_index.to_i-1] + puts '!! '.red + 'Are you sure you want to KILL ' + "#{taskId}}".red + '? (y/n)' + ' !!'.red + if gets.chomp == 'y' + RestClient.delete "#{@uri}/api/requests/request/#{thisTask['taskId']['requestId']}" + puts ' KILLED and DELETED: '.red + "#{thisTask['taskId']['requestId']}".light_blue + end + end when 'c','con','conn','connect' - # please enter the session number - - # # wrap the below in error checking - # num = gets.to_i - - + num = 0 + while num <= 0 + puts 'Please enter session number from the above list (or x to exit)' + num = gets.chomp + num == 'x' ? (exit 0) : (num = Integer(num)) + end + puts "SSH into #{activeTasksList[num-1]['taskId']['requestId']} (y/n)?" + if gets.chomp == 'y' + Singularity::Runner.new() # while resp != (y|n) - # puts "SSH into <> (y/n)?" - # resp = getc + # resp = gets.chomp # end # if resp == "y" # Singularity::Runner ->ssh # else # end - # if (k) - # please enter a comma-separated list of which numbers you'd like to kill - # list = gets - # list = list.remove(" ").split(",") - # list.each do |process_index| - # tasks[process_index-1] - # "!!".red + " Are you sure you want to KILL " + "#{taskId}}".red + "?" + "!!".red - # end - # end + end From 754e353f4ed0ca27b3ccdebdba45eeb7fe79faa5 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Tue, 18 Apr 2017 13:01:24 -0500 Subject: [PATCH 07/18] auto connect & kill pretest --- .dope.json | 0 Dockerfile | 0 docker-compose.yml | 0 lib/singularity/request.rb | 121 ++++++++++++++++++++++--------------- lib/singularity/runner.rb | 15 +++-- lib/singularity/util.rb | 0 6 files changed, 83 insertions(+), 53 deletions(-) mode change 100644 => 100755 .dope.json mode change 100644 => 100755 Dockerfile mode change 100644 => 100755 docker-compose.yml mode change 100644 => 100755 lib/singularity/request.rb mode change 100644 => 100755 lib/singularity/util.rb diff --git a/.dope.json b/.dope.json old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile old mode 100644 new mode 100755 diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb old mode 100644 new mode 100755 index 2212b6a..a67d4be --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -47,64 +47,87 @@ def list_ssh end case resp - when 'x' + when 'x' + puts 'Exiting...' + exit 0 + when 'k','kill' + puts 'Please enter a comma-separated list of which numbers from the above list you would like to kill (or x to exit)' + killList = gets.chomp + if killList == 'x' exit 0 - when 'k','kill' - puts 'Please enter a comma-separated list of which numbers from the above list you would like to kill (or x to exit)' - killList = gets.chomp - if killList == 'x' - exit 0 - end - killList = killList.delete(' ').split(',') - killList.each do |task_index| - thisTask = activeTasksList[task_index.to_i-1] - puts '!! '.red + 'Are you sure you want to KILL ' + "#{taskId}}".red + '? (y/n)' + ' !!'.red - if gets.chomp == 'y' - RestClient.delete "#{@uri}/api/requests/request/#{thisTask['taskId']['requestId']}" - puts ' KILLED and DELETED: '.red + "#{thisTask['taskId']['requestId']}".light_blue - end + end + killList = killList.delete(' ').split(',') + killList.each do |task_index| + thisTask = activeTasksList[task_index.to_i-1] + puts '!! '.red + 'Are you sure you want to KILL ' + "#{taskId}}".red + '? (y/n)' + ' !!'.red + if gets.chomp == 'y' + RestClient.delete "#{@uri}/api/requests/request/#{thisTask['taskId']['requestId']}" + puts ' KILLED and DELETED: '.red + "#{thisTask['taskId']['requestId']}".light_blue end - when 'c','con','conn','connect' - num = 0 - while num <= 0 - puts 'Please enter session number from the above list (or x to exit)' - num = gets.chomp - num == 'x' ? (exit 0) : (num = Integer(num)) + end + when 'c','con','conn','connect' + taskIndex = -1 + + def getTaskIndex + n = 0 + while n <= 0 + puts 'Please enter session number to SSH into from the above list (or x to exit)' + n = gets.chomp + n == 'x' ? (puts "Exiting..."; exit 0) : (n = Integer(n)) end - puts "SSH into #{activeTasksList[num-1]['taskId']['requestId']} (y/n)?" - if gets.chomp == 'y' - Singularity::Runner.new() - # while resp != (y|n) - # resp = gets.chomp - # end - # if resp == "y" - # Singularity::Runner ->ssh - # else - # end + return n-1 + end + def pickTask + taskIndex = getTaskIndex + puts "SSH into #{activeTasksList[taskIndex]['taskId']['requestId']}? (y = yes, p = pick another task number, or x = exit)" + input = gets.chomp - end + case input + when 'x' + puts "Exiting..." + exit 0 + when 'p' + pickTask + when 'y' + puts "Just a moment... connecting you to the instance." + else + puts "Please enter: y, p, or x" + end + end - # deploys a request in singularity - def deploy - if is_paused - puts ' PAUSED, SKIPPING.' - return - else - @data['requestId'] = @data['id'] - @data['id'] = "#{@release}.#{Time.now.to_i}" - @data['containerInfo']['docker']['image'] = "#{JSON.parse(File.read('.mescal.json'))['image'].split(':').first}:#{@release}" - @deploy = { - 'deploy' => @data, - 'user' => `whoami`.chomp, - 'unpauseOnSuccessfulDeploy' => false - } - # deploy the request - RestClient.post "#{@uri}/api/deploys", @deploy.to_json, :content_type => :json - puts ' Deploy succeeded: '.green + @data['requestId'].light_blue + pickTask + + # create fresh Runner, which normally creates a new request when it runs + # so we assign values to it to "turn it into" our currently running SSH task + runner = Singularity::Runner.new('ssh', @uri) + runner.thisIsANewRequest = false # so that we don't create & deploy a new request + runner.thisTask = activeTasksList[taskIndex] + runner.projectName = activeTasksList[taskIndex]['taskId']['requestId'] + # then run it + runner.run end end + end + # deploys a request in singularity + def deploy + if is_paused + puts ' PAUSED, SKIPPING.' + return + else + @data['requestId'] = @data['id'] + @data['id'] = "#{@release}.#{Time.now.to_i}" + @data['containerInfo']['docker']['image'] = "#{JSON.parse(File.read('.mescal.json'))['image'].split(':').first}:#{@release}" + @deploy = { + 'deploy' => @data, + 'user' => `whoami`.chomp, + 'unpauseOnSuccessfulDeploy' => false + } + # deploy the request + RestClient.post "#{@uri}/api/deploys", @deploy.to_json, :content_type => :json + puts ' Deploy succeeded: '.green + @data['requestId'].light_blue + end end end diff --git a/lib/singularity/runner.rb b/lib/singularity/runner.rb index f3940d4..cda6fc6 100644 --- a/lib/singularity/runner.rb +++ b/lib/singularity/runner.rb @@ -1,6 +1,6 @@ module Singularity class Runner - attr_accessor :request, :ip, :port + attr_accessor :request, :ip, :port, :thisIsANewRequest, :thisTask, :projectName def initialize(commands, uri) @commands = commands @@ -8,6 +8,7 @@ def initialize(commands, uri) @ip = 0 @port = 0 @thisTask = '' + @thisIsANewRequest = true mescaljson = JSON.parse(File.read('.mescal.json')) @cpus = mescaljson['cpus'] @@ -75,9 +76,12 @@ def initialize(commands, uri) def run exit_code = 0 - @request.create - @request.deploy - waitForTaskToShowUp() + if @thisIsANewRequest + @request.create + @request.deploy + waitForTaskToShowUp + end + getIPAndPort if @commands[0] == 'ssh' runSsh @@ -105,6 +109,9 @@ def waitForTaskToShowUp end end end until @thisTask != '' + end + + def getIPAndPort @ip = @thisTask['offer']['url']['address']['ip'] @port = @thisTask['mesosTask']['container']['docker']['portMappings'][0]['hostPort'] end diff --git a/lib/singularity/util.rb b/lib/singularity/util.rb old mode 100644 new mode 100755 From f12dbebbf9b7c613ab73b4fd7e5386d3b3339674 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Thu, 20 Apr 2017 14:09:12 -0500 Subject: [PATCH 08/18] just another push --- bin/singularity | 7 +--- lib/singularity/request.rb | 65 ++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/bin/singularity b/bin/singularity index 88c3a70..a79e815 100755 --- a/bin/singularity +++ b/bin/singularity @@ -76,18 +76,13 @@ case action Singularity::Runner.new(ARGV, uri).run when "list-ssh" - # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - # - # this has to change, need @data for ssh? - # - # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Singularity::Request.new(nil, uri, nil).list_ssh when "help" print_usage else - puts "Invalid subcommand '#{action}'" + puts "Invalid subcommand \'#{action}\'" print_usage end diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index a67d4be..6650766 100755 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -24,31 +24,58 @@ def delete puts ' Deleted request: '.red + "#{@data['requestId']||@data['id']}".light_blue end + # deploys a request in singularity + def deploy + if is_paused + puts ' PAUSED, SKIPPING.' + return + else + @data['requestId'] = @data['id'] + @data['id'] = "#{@release}.#{Time.now.to_i}" + @data['containerInfo']['docker']['image'] = "#{JSON.parse(File.read('.mescal.json'))['image'].split(':').first}:#{@release}" + @deploy = { + 'deploy' => @data, + 'user' => `whoami`.chomp, + 'unpauseOnSuccessfulDeploy' => false + } + # deploy the request + RestClient.post "#{@uri}/api/deploys", @deploy.to_json, :content_type => :json + puts ' Deploy succeeded: '.green + @data['requestId'].light_blue + end + end + def list_ssh activeTasksList = JSON.parse(RestClient.get "#{@uri}/api/tasks/active", :content_type => :json) - count = 1 + count = 0 activeTasksList.each do |entry| taskId = entry['taskRequest']['request']['id'] if taskId.include?("SSH") ip = entry['offer']['url']['address']['ip'] port = entry['mesosTask']['container']['docker']['portMappings'][0]['hostPort'] - puts "#{count}: ".light_green + "#{taskId}: ".light_blue + "root".yellow + " @ ".light_blue + "#{ip}".light_magenta + " : ".light_blue + "#{port}".light_cyan + puts "#{count+1}: ".light_green + "#{taskId}: ".light_blue + "root".yellow + " @ ".light_blue + "#{ip}".light_magenta + " : ".light_blue + "#{port}".light_cyan count = count + 1 end end - puts "Would you like to (k)ill or (c)onnect to any of these sessions? (x to exit) " + if !count + puts "There were no running SSH sessions on #{@uri}" + exit 0 + end + resp = ' ' + puts "Would you like to (k)ill or (c)onnect to any of these sessions? (x to exit)" + resp = gets.chomp while !['x','k','kill','c','con','conn','connect'].include?(resp) + puts "Incorrect input, please enter c, k, or x" resp = gets.chomp end case resp when 'x' - puts 'Exiting...' + puts 'Exiting...'.light_magenta exit 0 when 'k','kill' puts 'Please enter a comma-separated list of which numbers from the above list you would like to kill (or x to exit)' @@ -84,6 +111,11 @@ def pickTask puts "SSH into #{activeTasksList[taskIndex]['taskId']['requestId']}? (y = yes, p = pick another task number, or x = exit)" input = gets.chomp + while !["x","y","p"].include?(input) + puts "Please enter: y, p, or x" + input = gets.chomp + end + case input when 'x' puts "Exiting..." @@ -92,9 +124,8 @@ def pickTask pickTask when 'y' puts "Just a moment... connecting you to the instance." - else - puts "Please enter: y, p, or x" end + end pickTask @@ -105,29 +136,9 @@ def pickTask runner.thisIsANewRequest = false # so that we don't create & deploy a new request runner.thisTask = activeTasksList[taskIndex] runner.projectName = activeTasksList[taskIndex]['taskId']['requestId'] - # then run it + # then run it, which only does getIPAndPort and runSsh runner.run end end end - - # deploys a request in singularity - def deploy - if is_paused - puts ' PAUSED, SKIPPING.' - return - else - @data['requestId'] = @data['id'] - @data['id'] = "#{@release}.#{Time.now.to_i}" - @data['containerInfo']['docker']['image'] = "#{JSON.parse(File.read('.mescal.json'))['image'].split(':').first}:#{@release}" - @deploy = { - 'deploy' => @data, - 'user' => `whoami`.chomp, - 'unpauseOnSuccessfulDeploy' => false - } - # deploy the request - RestClient.post "#{@uri}/api/deploys", @deploy.to_json, :content_type => :json - puts ' Deploy succeeded: '.green + @data['requestId'].light_blue - end - end end From dda337e9ffee7686763b0dabc671c35caaaaec4c Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Thu, 20 Apr 2017 14:16:19 -0500 Subject: [PATCH 09/18] just another pushq --- lib/singularity/request.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index 6650766..321ee81 100755 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -66,11 +66,11 @@ def list_ssh resp = ' ' puts "Would you like to (k)ill or (c)onnect to any of these sessions? (x to exit)" - resp = gets.chomp + resp = STDIN.gets.chomp while !['x','k','kill','c','con','conn','connect'].include?(resp) puts "Incorrect input, please enter c, k, or x" - resp = gets.chomp + resp = STDIN.gets.chomp end case resp @@ -79,7 +79,7 @@ def list_ssh exit 0 when 'k','kill' puts 'Please enter a comma-separated list of which numbers from the above list you would like to kill (or x to exit)' - killList = gets.chomp + killList = STDIN.gets.chomp if killList == 'x' exit 0 end @@ -87,7 +87,7 @@ def list_ssh killList.each do |task_index| thisTask = activeTasksList[task_index.to_i-1] puts '!! '.red + 'Are you sure you want to KILL ' + "#{taskId}}".red + '? (y/n)' + ' !!'.red - if gets.chomp == 'y' + if STDIN.gets.chomp == 'y' RestClient.delete "#{@uri}/api/requests/request/#{thisTask['taskId']['requestId']}" puts ' KILLED and DELETED: '.red + "#{thisTask['taskId']['requestId']}".light_blue end @@ -99,7 +99,7 @@ def getTaskIndex n = 0 while n <= 0 puts 'Please enter session number to SSH into from the above list (or x to exit)' - n = gets.chomp + n = STDIN.gets.chomp n == 'x' ? (puts "Exiting..."; exit 0) : (n = Integer(n)) end return n-1 @@ -109,11 +109,11 @@ def pickTask taskIndex = getTaskIndex puts "SSH into #{activeTasksList[taskIndex]['taskId']['requestId']}? (y = yes, p = pick another task number, or x = exit)" - input = gets.chomp + input = STDIN.gets.chomp while !["x","y","p"].include?(input) puts "Please enter: y, p, or x" - input = gets.chomp + input = STDIN.gets.chomp end case input From 4aa0c1252330909faea265735b73e533832a55cd Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Thu, 20 Apr 2017 14:34:03 -0500 Subject: [PATCH 10/18] just another pushqq --- lib/singularity/request.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index 321ee81..17a4efb 100755 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -47,6 +47,8 @@ def deploy def list_ssh activeTasksList = JSON.parse(RestClient.get "#{@uri}/api/tasks/active", :content_type => :json) + taskId = '' + count = 0 activeTasksList.each do |entry| taskId = entry['taskRequest']['request']['id'] @@ -59,12 +61,11 @@ def list_ssh end end - if !count - puts "There were no running SSH sessions on #{@uri}" + if count == 0 + puts "There were no running SSH sessions on #{@uri.split("/")[1]}" exit 0 end - resp = ' ' puts "Would you like to (k)ill or (c)onnect to any of these sessions? (x to exit)" resp = STDIN.gets.chomp @@ -86,7 +87,7 @@ def list_ssh killList = killList.delete(' ').split(',') killList.each do |task_index| thisTask = activeTasksList[task_index.to_i-1] - puts '!! '.red + 'Are you sure you want to KILL ' + "#{taskId}}".red + '? (y/n)' + ' !!'.red + puts '!! '.red + 'Are you sure you want to KILL ' + "#{thisTask['taskId']['requestId']}".red + '? (y/n)' + ' !!'.red if STDIN.gets.chomp == 'y' RestClient.delete "#{@uri}/api/requests/request/#{thisTask['taskId']['requestId']}" puts ' KILLED and DELETED: '.red + "#{thisTask['taskId']['requestId']}".light_blue From 5d79911a87993ed8ef7c8e9cea982c48ec78b2ee Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Thu, 20 Apr 2017 14:36:27 -0500 Subject: [PATCH 11/18] just another pushqqq --- lib/singularity/request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index 17a4efb..67b8c2f 100755 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -62,7 +62,7 @@ def list_ssh end if count == 0 - puts "There were no running SSH sessions on #{@uri.split("/")[1]}" + puts "There were no running SSH sessions on #{@uri}" exit 0 end From 7791c69a72f799821306e125208fd037d92b2e4c Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Mon, 24 Apr 2017 14:24:05 -0500 Subject: [PATCH 12/18] mostly done with listssh, needs more testing --- .dope.json | 0 .gitignore | 0 .rspec | 0 Dockerfile | 0 docker-compose.yml | 0 lib/singularity/request.rb | 4 +- lib/singularity/util.rb | 0 nohup.out | 5 ++ spec/request_spec.rb | 174 ++++++++++++++++++------------------- spec/runner_spec.rb | 0 spec/spec_helper.rb | 0 11 files changed, 94 insertions(+), 89 deletions(-) mode change 100755 => 100644 .dope.json mode change 100755 => 100644 .gitignore mode change 100755 => 100644 .rspec mode change 100755 => 100644 Dockerfile mode change 100755 => 100644 docker-compose.yml mode change 100755 => 100644 lib/singularity/request.rb mode change 100755 => 100644 lib/singularity/util.rb create mode 100644 nohup.out mode change 100755 => 100644 spec/request_spec.rb mode change 100755 => 100644 spec/runner_spec.rb mode change 100755 => 100644 spec/spec_helper.rb diff --git a/.dope.json b/.dope.json old mode 100755 new mode 100644 diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.rspec b/.rspec old mode 100755 new mode 100644 diff --git a/Dockerfile b/Dockerfile old mode 100755 new mode 100644 diff --git a/docker-compose.yml b/docker-compose.yml old mode 100755 new mode 100644 diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb old mode 100755 new mode 100644 index 67b8c2f..4ad43f2 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -101,7 +101,7 @@ def getTaskIndex while n <= 0 puts 'Please enter session number to SSH into from the above list (or x to exit)' n = STDIN.gets.chomp - n == 'x' ? (puts "Exiting..."; exit 0) : (n = Integer(n)) + n == 'x' ? (puts "Exiting...".light_magenta; exit 0) : (n = Integer(n)) end return n-1 end @@ -119,7 +119,7 @@ def pickTask case input when 'x' - puts "Exiting..." + puts "Exiting...".light_magenta exit 0 when 'p' pickTask diff --git a/lib/singularity/util.rb b/lib/singularity/util.rb old mode 100755 new mode 100644 diff --git a/nohup.out b/nohup.out new file mode 100644 index 0000000..9ff9da7 --- /dev/null +++ b/nohup.out @@ -0,0 +1,5 @@ +Command "daemon" is deprecated, and will be removed in Docker 1.16. Please run `dockerd` directly. +time="2017-04-20T18:54:29.679030400Z" level=warning msg="[!] DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING [!]" +time="2017-04-20T18:54:29.680782000Z" level=info msg="libcontainerd: new containerd process, pid: 420" +time="2017-04-20T18:54:30.689019600Z" level=error msg="[graphdriver] prior storage driver aufs failed: operation not permitted" +Error starting daemon: error initializing graphdriver: operation not permitted diff --git a/spec/request_spec.rb b/spec/request_spec.rb old mode 100755 new mode 100644 index 9fd793b..1768cac --- a/spec/request_spec.rb +++ b/spec/request_spec.rb @@ -1,87 +1,87 @@ -require 'spec_helper' - -module Singularity - describe Request do - before { - @request = Request.new(@data, @uri, @release) - } - - describe '#is_paused' do - before { - stub_is_paused(@request, "PAUSED") - @request.is_paused - } - it "should check if the request is paused" do - expect(WebMock).to have_requested(:get, @uri+'/api/requests/request/'+@id) - end - end - - describe '#create' do - before { - WebMock.stub_request(:post, /.*/) - @request.create - } - - it 'should have created a request' do - expect(WebMock).to have_requested(:post, @uri+'/api/requests'). - with(body: hash_including({'id' => @id})) - end - end - - describe '#delete' do - before { - WebMock.stub_request(:delete, /.*/) - @request.delete - } - it 'should delete the request' do - expect(WebMock).to have_requested(:delete, @uri+'/api/requests/request/'+@id) - end - end - - context 'when paused' do - before { - stub_is_paused(@request, "PAUSED") - WebMock.stub_request(:post, /.*/) - @response = @request.is_paused - @request.deploy - } - - it "should check if the request is paused" do - expect(WebMock).to have_requested(:get, @uri+'/api/requests/request/'+@id).twice - end - - it "should find PAUSED == true" do - expect(@response).to equal(true) - end - - it "should not have deployed the request" do - expect(WebMock).not_to have_requested(:post, /.*/) - end - - end - - context 'when not paused' do - before { - stub_is_paused(@request, "RUNNING") - WebMock.stub_request(:post, /.*/) - @response = @request.is_paused - @request.deploy - } - - it "should check if the request is paused" do - expect(WebMock).to have_requested(:get, @uri+'/api/requests/request/'+@id).twice - end - - it "should find PAUSED == false" do - expect(@response).to equal(false) - end - - it 'should deploy the request' do - expect(WebMock).to have_requested(:post, @uri+'/api/deploys'). - with(body: hash_including({'user' => `whoami`.chomp})) - end - - end - - end -end +require 'spec_helper' + +module Singularity + describe Request do + before { + @request = Request.new(@data, @uri, @release) + } + + describe '#is_paused' do + before { + stub_is_paused(@request, "PAUSED") + @request.is_paused + } + it "should check if the request is paused" do + expect(WebMock).to have_requested(:get, @uri+'/api/requests/request/'+@id) + end + end + + describe '#create' do + before { + WebMock.stub_request(:post, /.*/) + @request.create + } + + it 'should have created a request' do + expect(WebMock).to have_requested(:post, @uri+'/api/requests'). + with(body: hash_including({'id' => @id})) + end + end + + describe '#delete' do + before { + WebMock.stub_request(:delete, /.*/) + @request.delete + } + it 'should delete the request' do + expect(WebMock).to have_requested(:delete, @uri+'/api/requests/request/'+@id) + end + end + + context 'when paused' do + before { + stub_is_paused(@request, "PAUSED") + WebMock.stub_request(:post, /.*/) + @response = @request.is_paused + @request.deploy + } + + it "should check if the request is paused" do + expect(WebMock).to have_requested(:get, @uri+'/api/requests/request/'+@id).twice + end + + it "should find PAUSED == true" do + expect(@response).to equal(true) + end + + it "should not have deployed the request" do + expect(WebMock).not_to have_requested(:post, /.*/) + end + + end + + context 'when not paused' do + before { + stub_is_paused(@request, "RUNNING") + WebMock.stub_request(:post, /.*/) + @response = @request.is_paused + @request.deploy + } + + it "should check if the request is paused" do + expect(WebMock).to have_requested(:get, @uri+'/api/requests/request/'+@id).twice + end + + it "should find PAUSED == false" do + expect(@response).to equal(false) + end + + it 'should deploy the request' do + expect(WebMock).to have_requested(:post, @uri+'/api/deploys'). + with(body: hash_including({'user' => `whoami`.chomp})) + end + + end + + end +end diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb old mode 100755 new mode 100644 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb old mode 100755 new mode 100644 From 3922ea3bc791fe5bf71554116b5c153289589adc Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Wed, 26 Apr 2017 15:40:42 -0500 Subject: [PATCH 13/18] ssh probably needs to use bootstrap script --- lib/singularity/request.rb | 18 +++++++++--------- nohup.out | 5 ----- 2 files changed, 9 insertions(+), 14 deletions(-) delete mode 100644 nohup.out diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index 4ad43f2..084c699 100644 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -46,7 +46,7 @@ def deploy def list_ssh activeTasksList = JSON.parse(RestClient.get "#{@uri}/api/tasks/active", :content_type => :json) - + mySshTaskList = [] taskId = '' count = 0 @@ -55,7 +55,7 @@ def list_ssh if taskId.include?("SSH") ip = entry['offer']['url']['address']['ip'] port = entry['mesosTask']['container']['docker']['portMappings'][0]['hostPort'] - + mySshTaskList.push(entry) puts "#{count+1}: ".light_green + "#{taskId}: ".light_blue + "root".yellow + " @ ".light_blue + "#{ip}".light_magenta + " : ".light_blue + "#{port}".light_cyan count = count + 1 end @@ -106,10 +106,10 @@ def getTaskIndex return n-1 end - def pickTask + def pickTask(fromList) taskIndex = getTaskIndex - puts "SSH into #{activeTasksList[taskIndex]['taskId']['requestId']}? (y = yes, p = pick another task number, or x = exit)" + puts "SSH into #{fromList[taskIndex]['taskId']['requestId']}? (y = yes, p = pick another task number, or x = exit)" input = STDIN.gets.chomp while !["x","y","p"].include?(input) @@ -122,21 +122,21 @@ def pickTask puts "Exiting...".light_magenta exit 0 when 'p' - pickTask + pickTask(fromList) when 'y' puts "Just a moment... connecting you to the instance." end end - pickTask + pickTask(mySshTaskList) # create fresh Runner, which normally creates a new request when it runs # so we assign values to it to "turn it into" our currently running SSH task - runner = Singularity::Runner.new('ssh', @uri) + runner = Singularity::Runner.new(['ssh'], @uri) runner.thisIsANewRequest = false # so that we don't create & deploy a new request - runner.thisTask = activeTasksList[taskIndex] - runner.projectName = activeTasksList[taskIndex]['taskId']['requestId'] + runner.thisTask = mySshTaskList[taskIndex] + runner.projectName = mySshTaskList[taskIndex]['taskId']['requestId'] # then run it, which only does getIPAndPort and runSsh runner.run end diff --git a/nohup.out b/nohup.out deleted file mode 100644 index 9ff9da7..0000000 --- a/nohup.out +++ /dev/null @@ -1,5 +0,0 @@ -Command "daemon" is deprecated, and will be removed in Docker 1.16. Please run `dockerd` directly. -time="2017-04-20T18:54:29.679030400Z" level=warning msg="[!] DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF YOU DON'T KNOW WHAT YOU'RE DOING [!]" -time="2017-04-20T18:54:29.680782000Z" level=info msg="libcontainerd: new containerd process, pid: 420" -time="2017-04-20T18:54:30.689019600Z" level=error msg="[graphdriver] prior storage driver aufs failed: operation not permitted" -Error starting daemon: error initializing graphdriver: operation not permitted From 31a5b84407916effbf9bd6a0b63292ff31d774b9 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Mon, 1 May 2017 14:19:14 -0500 Subject: [PATCH 14/18] list-ssh done, need to write tests --- bin/singularity | 51 +++++++++++++++++++++----------------- lib/singularity/request.rb | 2 +- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/bin/singularity b/bin/singularity index a79e815..6515cf9 100755 --- a/bin/singularity +++ b/bin/singularity @@ -16,6 +16,32 @@ def print_usage END end +def prepare_ssh + # copy the docker mounted ssh files and chown them to work inside the container + if Dir.exists?('/ssh') + FileUtils.copy_entry '/ssh', '/root/.ssh' + FileUtils.chown_R 'root', 'root', '/root/.ssh' + + # create & populate ssh config file + Dir.chdir('/root/.ssh') do + identities = (Dir['*'] - ['.', '..']).select do |entry| + open(entry).read.include?('BEGIN RSA PRIVATE KEY') + end + + File.open('config', 'w') do |config| + identities.each do |i| + config.write('IdentityFile /root/.ssh/' + i + "\n") + end + config.write("Host *\n\tServerAliveInterval 60\n\tTCPKeepAlive yes") + end + + end + else + puts "Your ~/.ssh directory did not successfully mount in the docker image that this command runs in." + exit + end +end + action = ARGV[0] unless File.exist?('mesos-deploy.yml') and File.exist?('.mescal.json') @@ -50,32 +76,11 @@ case action Singularity::Runner.new(ARGV, uri).run when "ssh" - # copy the docker mounted ssh files and chown them to work inside the container - if Dir.exists?('/ssh') - FileUtils.copy_entry '/ssh', '/root/.ssh' - FileUtils.chown_R 'root', 'root', '/root/.ssh' - - # create & populate ssh config file - Dir.chdir('/root/.ssh') do - identities = (Dir['*'] - ['.', '..']).select do |entry| - open(entry).read.include?('BEGIN RSA PRIVATE KEY') - end - - File.open('config', 'w') do |config| - identities.each do |i| - config.write('IdentityFile /root/.ssh/' + i + "\n") - end - config.write("Host *\n\tServerAliveInterval 60\n\tTCPKeepAlive yes") - end - - end - else - puts "Your ~/.ssh directory did not successfully mount in the docker image that this command runs in." - exit - end + prepare_ssh Singularity::Runner.new(ARGV, uri).run when "list-ssh" + prepare_ssh Singularity::Request.new(nil, uri, nil).list_ssh when "help" diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index 084c699..76663ad 100644 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -86,7 +86,7 @@ def list_ssh end killList = killList.delete(' ').split(',') killList.each do |task_index| - thisTask = activeTasksList[task_index.to_i-1] + thisTask = mySshTaskList[task_index.to_i-1] puts '!! '.red + 'Are you sure you want to KILL ' + "#{thisTask['taskId']['requestId']}".red + '? (y/n)' + ' !!'.red if STDIN.gets.chomp == 'y' RestClient.delete "#{@uri}/api/requests/request/#{thisTask['taskId']['requestId']}" From a264825d9d71dc94fc8bf5664726ae9d2791dc38 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Tue, 9 May 2017 11:40:35 -0500 Subject: [PATCH 15/18] added some blank tests --- spec/request_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/request_spec.rb b/spec/request_spec.rb index 1768cac..413b908 100644 --- a/spec/request_spec.rb +++ b/spec/request_spec.rb @@ -83,5 +83,24 @@ module Singularity end + describe '#list_ssh' do + it 'should list SSH sessions on the correct singularity url' do + end + + it 'should tell us there are no SSH sessions when there are none' do + end + + it 'should kill the correct SSH sessions when told to' do + end + + it 'should connect us to the correct SSH session when told to' do + end + + # new functionality to be added + it 'should ask us if we want to kill the SSH session when we exit from it' do + end + + end + end end From 669f36413bf223f7a9c423bfc82b0556be9d8088 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Tue, 9 May 2017 16:26:37 -0500 Subject: [PATCH 16/18] fixed runner spec --- spec/runner_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index 289fe97..aa71248 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -23,6 +23,7 @@ module Singularity stub_get_tasks(@runner) @runner.request.data['requestId'] = @runner.request.data['id'] @runner.send(:waitForTaskToShowUp) + @runner.send(:getIPAndPort) } it "should get the task list" do expect(WebMock).to have_requested(:get, @uri+'/api/tasks/active') From 5c1ea938a6fd2df2093b29a540f0756f77dcbeb7 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Tue, 9 May 2017 16:27:48 -0500 Subject: [PATCH 17/18] revert request spec --- spec/request_spec.rb | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/spec/request_spec.rb b/spec/request_spec.rb index 413b908..1768cac 100644 --- a/spec/request_spec.rb +++ b/spec/request_spec.rb @@ -83,24 +83,5 @@ module Singularity end - describe '#list_ssh' do - it 'should list SSH sessions on the correct singularity url' do - end - - it 'should tell us there are no SSH sessions when there are none' do - end - - it 'should kill the correct SSH sessions when told to' do - end - - it 'should connect us to the correct SSH session when told to' do - end - - # new functionality to be added - it 'should ask us if we want to kill the SSH session when we exit from it' do - end - - end - end end From 72dec1c3976553f7d2dbb3c955e3aad5cb86c613 Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Wed, 10 May 2017 11:17:06 -0500 Subject: [PATCH 18/18] working list-ssh complete --- lib/singularity/request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/singularity/request.rb b/lib/singularity/request.rb index 76663ad..1c0a093 100644 --- a/lib/singularity/request.rb +++ b/lib/singularity/request.rb @@ -32,7 +32,7 @@ def deploy else @data['requestId'] = @data['id'] @data['id'] = "#{@release}.#{Time.now.to_i}" - @data['containerInfo']['docker']['image'] = "#{JSON.parse(File.read('.mescal.json'))['image'].split(':').first}:#{@release}" + # @data['containerInfo']['docker']['image'] = "#{JSON.parse(File.read('.mescal.json'))['image'].split(':').first}:#{@release}" @deploy = { 'deploy' => @data, 'user' => `whoami`.chomp,