marathon_client 0.0.6 → 0.0.7

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: 6764ad6e988acf5e3744c22312b145a8dd3b268a
4
- data.tar.gz: fbe55345264c3fdf746d1230d3736d973c1ab548
3
+ metadata.gz: 6c9e596d1d9a22eed7059f0abcb32e19a5f09bf3
4
+ data.tar.gz: f454fed66fad61cc4aa9c3a20564c014ca2c3e75
5
5
  SHA512:
6
- metadata.gz: cd9f91dd8cf433da91477b328a7537540b58dbc8e4ba73d39f7d204ac80156a671f9a7073fb365b1a757570f61bee7526ac9e2a943d6fed9c721643021d6acc6
7
- data.tar.gz: db9f41bc1a3dd5a661e11208284460787e74136beae7ab4adaa53b690e564a13ae476a5e0b5625a9df9f729627a0590b1ecd01b5a9fc9cd903842720305043f3
6
+ metadata.gz: aaee3ee5f3221bddcce683faf3f4aee1afbc1946c7f149160d15661a29394eb9d35eb337c432026a3852bda70edc313df4de94f473ca1eac7dbf4e39565e84b6
7
+ data.tar.gz: 9e0aaf7370257182cf9062f94b650a4490d4da57d88c45738d92dd1e580d636a1d44cd539d6e70c80083ec1c0fdd01da20a840303d79e73fae4c6119e72afa76
data/bin/marathon CHANGED
@@ -1,99 +1,109 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'marathon'))
4
- require 'slop'
5
-
6
-
7
- opts = Slop.parse(:help => true) do
8
- on :v, 'Print the version' do
9
- puts "Version #{Marathon::VERSION}"
10
- end
11
-
12
-
13
- command 'start' do
14
- description 'Start a new app.'
15
-
16
- on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
17
- on :i=, :id=, 'A unique identifier for the app.'
18
- on :C=, :command=, 'The command to start the app.'
19
- on :n=, :num_instances=, 'The number of instances to run (default 1).', :as => Integer
20
- on :c=, :cpus=, 'The number of CPUs to give to this app, can be a fraction (default 1.0).', :as => Float
21
- on :m=, :mem=, 'The memory limit for this app, in MB, can be a fraction (default 10.0).', :as => Float
22
- on :u=, :uri=, 'URIs to download and unpack into the working directory.', :as => Array
23
- on :e=, :env=, 'Environment variables to add to the process, as NAME=VALUE.', :as => Array
24
-
25
- run do |opts, args|
26
- app_opts = {
27
- :instances => opts[:num_instances] || 1,
28
- :uris => opts[:uri] || [],
29
- :cmd => opts[:command],
30
- :env => opts[:env].nil? ? {} : Hash[opts[:env].map { |e| e.split('=', 2) }],
31
- :cpus => opts[:cpus] || 1.0,
32
- :mem => opts[:mem] || 10.0
33
- }
34
-
35
- puts "Starting app '#{opts[:id]}'"
36
- res = Marathon::Client.new(opts[:marathon_host]).start(opts[:id], app_opts)
37
- puts res
4
+ require 'trollop'
5
+
6
+ SUB_COMMANDS = %w[start stop scale list]
7
+
8
+ global_opts = Trollop.options do
9
+ version Marathon::VERSION
10
+ banner <<-EOS
11
+ Usage: marathon [command] [options]
12
+
13
+ Available commands:
14
+
15
+ start Start a new app.
16
+ scale Scale the number of app instances.
17
+ stop Stop an app and remove it from Marathon.
18
+ list Show a list of running apps and their options.
19
+
20
+ Global options:
21
+ EOS
22
+
23
+ opt :marathon_host, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)', :short => '-H', :type => String
24
+ opt :marathon_user, 'User name to authenticate against Marathon (optional).', :short => '-U', :type => String
25
+ opt :marathon_pass, 'Password to authenticate against Marathon (optional).', :short => '-P', :type => String
26
+ stop_on SUB_COMMANDS
27
+ end
28
+
29
+ cmd = ARGV.shift # get the subcommand
30
+
31
+ cmd_opts = case cmd
32
+ when 'start'
33
+ Trollop.options do
34
+ opt :id, 'A unique identifier for the app.', :short => '-i', :type => String
35
+ opt :command, 'The command to start the app.', :short => '-C', :type => String
36
+ opt :num_instances, 'The number of instances to run (default 1).', :short => '-n', :type => Integer
37
+ opt :cpus, 'The number of CPUs to give to this app, can be a fraction (default 1.0).', :short => '-c', :type => Float
38
+ opt :mem, 'The memory limit for this app, in MB, can be a fraction (default 10.0).', :short => '-m', :type => Float
39
+ opt :uri, 'URIs to download and unpack into the working directory.', :short => '-u', :type => Array
40
+ opt :env, 'Environment variables to add to the process, as NAME=VALUE.', :short => '-e', :type => Array
38
41
  end
39
- end
40
-
41
- command 'scale' do
42
- description 'Scale the number of app instances.'
43
-
44
- on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
45
- on :i=, :id=, 'A unique identifier for the app.'
46
- on :n=, :num_instances=, 'The number of instances to run.', :as => Integer
47
-
48
- run do |opts, args|
49
- puts "Scaling app '#{opts[:id]}' to #{opts[:num_instances]} instances"
50
- res = Marathon::Client.new(opts[:marathon_host]).scale(opts[:id], opts[:num_instances])
51
- puts res
42
+ when 'scale'
43
+ Trollop.options do
44
+ opt :id, 'A unique identifier for the app.', :short => '-i', :type => String
45
+ opt :num_instances, 'The number of instances to run (default 1).', :short => '-n', :type => Integer
52
46
  end
53
- end
54
-
55
- command 'stop' do
56
- description 'Stop an app and remove it from Marathon.'
57
-
58
- on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
59
- on :i=, :id=, 'A unique identifier for the app.'
60
-
61
- run do |opts, args|
62
- puts "Stopping app '#{opts[:id]}'"
63
- res = Marathon::Client.new(opts[:marathon_host]).stop(opts[:id])
64
- puts res
47
+ when 'stop'
48
+ Trollop.options do
49
+ opt :id, 'A unique identifier for the app.', :short => '-i', :type => String
65
50
  end
51
+ else
52
+ {}
66
53
  end
67
54
 
68
- command 'list' do
69
- description 'Show a list of running apps and their options.'
70
-
71
- on :H=, :marathon_host=, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)'
72
-
73
- run do |opts, args|
74
- res = Marathon::Client.new(opts[:marathon_host]).list
75
- if res.success?
76
- res.parsed_response.each do |app|
77
- puts "App ID: #{app['id']}"
78
- puts "Command: #{app['cmd']}"
79
- puts "Instances: #{app['instances']}"
80
- puts "CPUs: #{app['cpus']}"
81
- puts "Memory: #{app['mem']} MB"
82
- app['uris'].each do |uri|
83
- puts "URI: #{uri}"
84
- end
85
- app['env'].each do |k, v|
86
- puts "ENV: #{k}=#{v}"
87
- end
88
- puts
89
- end
90
-
91
- if res.parsed_response.empty?
92
- puts "No apps are currently running"
93
- end
94
- else
95
- puts res
55
+ marathon = Marathon::Client.new(
56
+ global_opts[:marathon_host],
57
+ global_opts[:marathon_user],
58
+ global_opts[:marathon_pass]
59
+ )
60
+
61
+ # Run
62
+ case cmd
63
+ when 'start'
64
+ app_opts = {
65
+ :instances => cmd_opts[:num_instances] || 1,
66
+ :uris => cmd_opts[:uri] || [],
67
+ :cmd => cmd_opts[:command],
68
+ :env => cmd_opts[:env].nil? ? {} : Hash[cmd_opts[:env].map { |e| e.split('=', 2) }],
69
+ :cpus => cmd_opts[:cpus] || 1.0,
70
+ :mem => cmd_opts[:mem] || 10.0
71
+ }
72
+ puts "Starting app '#{cmd_opts[:id]}'"
73
+ res = marathon.start(cmd_opts[:id], app_opts)
74
+ puts res
75
+ when 'scale'
76
+ puts "Scaling app '#{cmd_opts[:id]}' to #{cmd_opts[:num_instances]} instances"
77
+ res = marathon.scale(cmd_opts[:id], cmd_opts[:num_instances])
78
+ puts res
79
+ when 'stop'
80
+ puts "Stopping app '#{cmd_opts[:id]}'"
81
+ res = marathon.stop(cmd_opts[:id])
82
+ puts res
83
+ when 'list'
84
+ res = marathon.list
85
+ if res.success?
86
+ res.parsed_response.each do |app|
87
+ puts "App ID: #{app['id']}"
88
+ puts "Command: #{app['cmd']}"
89
+ puts "Instances: #{app['instances']}"
90
+ puts "CPUs: #{app['cpus']}"
91
+ puts "Memory: #{app['mem']} MB"
92
+ app['uris'].each do |uri|
93
+ puts "URI: #{uri}"
94
+ end
95
+ app['env'].each do |k, v|
96
+ puts "ENV: #{k}=#{v}"
96
97
  end
98
+ puts
99
+ end
100
+
101
+ if res.parsed_response.empty?
102
+ puts "No apps are currently running"
97
103
  end
104
+ else
105
+ puts res
98
106
  end
99
- end
107
+ else
108
+ Trollop.die "unknown subcommand #{cmd.inspect}"
109
+ end
@@ -8,8 +8,13 @@ module Marathon
8
8
  default_timeout 5
9
9
 
10
10
 
11
- def initialize(host = nil)
11
+ def initialize(host = nil, user = nil, pass = nil)
12
12
  @host = host || ENV['MARATHON_HOST'] || 'http://localhost:8080'
13
+ @default_options = {}
14
+
15
+ if user && pass
16
+ @default_options[:basic_auth] = {:username => user, :password => pass}
17
+ end
13
18
  end
14
19
 
15
20
  def list
@@ -35,11 +40,11 @@ module Marathon
35
40
  private
36
41
 
37
42
  def wrap_request(method, url, options = {})
43
+ options = @default_options.merge(options)
38
44
  http = self.class.send(method, @host + url, options)
39
45
  Marathon::Response.new(http)
40
46
  rescue => e
41
47
  Marathon::Response.error(e.message)
42
48
  end
43
-
44
49
  end
45
50
  end
@@ -1,3 +1,3 @@
1
1
  module Marathon
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "slop", "~> 3.4.5"
21
+ spec.add_dependency "trollop", "~> 2.0"
22
22
  spec.add_dependency "httparty", "~> 0.11.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marathon_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobi Knaup
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-19 00:00:00.000000000 Z
11
+ date: 2013-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: slop
14
+ name: trollop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 3.4.5
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 3.4.5
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement