mescal-cli 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a16c71e8eb82bf60dc70d432fd07e0cedfb3ab4
4
- data.tar.gz: e4a445b4b3590395a4f569ce8e060a4f3a566448
3
+ metadata.gz: 07931eb74112fd608cd4672c38a63f96b7250783
4
+ data.tar.gz: 84bef31d4fc88d3f288490d44d318c3787800140
5
5
  SHA512:
6
- metadata.gz: c5d369481d3440d4b1578c2b4d9e77ae22cd435c3e686677b13d2a874225371efca55eb41fa7b96bf8935630497ced402587ee54ced6cbe20446fbdd5684b26f
7
- data.tar.gz: 8f4f64231d9a43868b834ea20ca66cf2f2aec9955892489e50064d0031f690740f0a4cc8bb5a1e9c56ce924fb1d2f0e6e7d43dd61ff91c6b2673af2896a694a5
6
+ metadata.gz: 97ee7777a69991f85c6e73c7405728b5650d8e88ffc91fb84e8306a4dc03664f24d21fda2b381130c1f03208a106dbb856142dc2bae6eb595c8025a529922655
7
+ data.tar.gz: ec6f2e4c03aa65c52d8c92642437401361e582d95f402d8d7268d44bdba5cb89991935db93614a3416a66d3b90dd945afd3ef82491e0170e1c219b2fbcf0587d
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .mescal.json
2
2
  *.swp
3
+ *.gem
@@ -9,8 +9,9 @@ module MescalCli
9
9
  @config = config
10
10
  @client = Client.new(config['mescal'])
11
11
  @image = config['image']
12
- @cmd = ARGV[1] || config['cmd']
13
12
  @sshCmd = config['sshCmd']
13
+ @cpus = config['cpus']
14
+ @mem = config['mem']
14
15
  end
15
16
 
16
17
  def usage
@@ -22,6 +23,7 @@ module MescalCli
22
23
  when "run" then run
23
24
  when "ssh" then ssh
24
25
  when "list" then list
26
+ when "kill" then kill
25
27
  end
26
28
  end
27
29
 
@@ -30,8 +32,9 @@ module MescalCli
30
32
  end
31
33
 
32
34
  def run
35
+ @cmd = ARGV[1] || @config['cmd']
33
36
  puts "Sending task to Mescal..."
34
- task = Task.create(@client, @image, @cmd)
37
+ task = Task.create(@client, @image, @cmd, @cpus, @mem)
35
38
  run = true
36
39
  threads = []
37
40
  pailer_started = false
@@ -56,15 +59,18 @@ module MescalCli
56
59
  end
57
60
 
58
61
  def ssh
59
- task = Task.create(@client, @image, @sshCmd)
62
+ @cmd = ARGV[1] || @config['cmd']
63
+ task = Task.create(@client, @image, @sshCmd, @cpus, @mem)
60
64
  run = true
61
65
  while(run) do
62
66
  sleep(2)
63
67
  state = task.state
64
68
  task.update!
65
69
  if state != task.state
66
- if task.state != "TASK_PENDING"
70
+ if task.state == "TASK_RUNNING"
67
71
  Ssh.new(task).run!
72
+ elsif task.state != "TASK_PENDING"
73
+ puts "Task exited with state #{task.state} before ssh could connect"
68
74
  end
69
75
  end
70
76
 
@@ -72,5 +78,14 @@ module MescalCli
72
78
  end
73
79
  end
74
80
 
81
+ def kill
82
+ @id = ARGV[1]
83
+ if(killed = Task.kill(@client, @id))
84
+ puts "Killed #{killed}"
85
+ else
86
+ puts "Failed to kill #{@id}"
87
+ end
88
+ end
89
+
75
90
  end
76
91
  end
@@ -28,8 +28,8 @@ module MescalCli
28
28
  @base_url = base_url + "tasks"
29
29
  end
30
30
 
31
- def create(image, cmd)
32
- RestClient.post @base_url, image: image, cmd: cmd, port: 22
31
+ def create(image, cmd, cpus, mem)
32
+ RestClient.post @base_url, image: image, cmd: cmd, cpus: cpus, mem: mem, port: 22
33
33
  end
34
34
 
35
35
  def get(id)
@@ -39,5 +39,9 @@ module MescalCli
39
39
  def list
40
40
  RestClient.get "#{@base_url}"
41
41
  end
42
+
43
+ def kill(id)
44
+ RestClient.delete "#{@base_url}/#{id}"
45
+ end
42
46
  end
43
47
  end
@@ -7,7 +7,8 @@ module MescalCli
7
7
  def run!
8
8
  ip = @task.slave_ip
9
9
  port = @task.ssh_port
10
- exec "ssh -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@#{ip} -p #{port}"
10
+ killer = "#{$0} kill #{@task.id}"
11
+ "ssh -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@#{ip} -p #{port}; #{killer}"
11
12
  end
12
13
  end
13
14
  end
@@ -3,8 +3,8 @@ module MescalCli
3
3
  attr_reader :id, :image, :cmd, :slave_id
4
4
  attr_accessor :state
5
5
 
6
- def self.create(client, image, cmd)
7
- resp = client.task.create(image, cmd)
6
+ def self.create(client, image, cmd, cpus, mem)
7
+ resp = client.task.create(image, cmd, cpus, mem)
8
8
  obj = MultiJson.load(resp)
9
9
  Task.new(client, obj['id'], image, cmd)
10
10
  end
@@ -19,6 +19,15 @@ module MescalCli
19
19
  end
20
20
  end
21
21
 
22
+ def self.kill(client, id)
23
+ resp = client.task.kill(id) rescue nil
24
+ if(resp && obj = MultiJson.load(resp))
25
+ obj['id']
26
+ else
27
+ nil
28
+ end
29
+ end
30
+
22
31
  def initialize(client, id, image, cmd)
23
32
  @client, @id, @image, @cmd = client, id, image, cmd
24
33
  end
@@ -1,3 +1,3 @@
1
1
  module MescalCli
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mescal-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Kite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-13 00:00:00.000000000 Z
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler