mescal-cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/mescal-cli/cli.rb +19 -4
- data/lib/mescal-cli/client.rb +6 -2
- data/lib/mescal-cli/ssh.rb +2 -1
- data/lib/mescal-cli/task.rb +11 -2
- data/lib/mescal-cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07931eb74112fd608cd4672c38a63f96b7250783
|
4
|
+
data.tar.gz: 84bef31d4fc88d3f288490d44d318c3787800140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ee7777a69991f85c6e73c7405728b5650d8e88ffc91fb84e8306a4dc03664f24d21fda2b381130c1f03208a106dbb856142dc2bae6eb595c8025a529922655
|
7
|
+
data.tar.gz: ec6f2e4c03aa65c52d8c92642437401361e582d95f402d8d7268d44bdba5cb89991935db93614a3416a66d3b90dd945afd3ef82491e0170e1c219b2fbcf0587d
|
data/.gitignore
CHANGED
data/lib/mescal-cli/cli.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
data/lib/mescal-cli/client.rb
CHANGED
@@ -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
|
data/lib/mescal-cli/ssh.rb
CHANGED
@@ -7,7 +7,8 @@ module MescalCli
|
|
7
7
|
def run!
|
8
8
|
ip = @task.slave_ip
|
9
9
|
port = @task.ssh_port
|
10
|
-
|
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
|
data/lib/mescal-cli/task.rb
CHANGED
@@ -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
|
data/lib/mescal-cli/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|