haile 0.3.0 → 0.4.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: 621dd9bed5314f84e53e84a1a034d2ee7a3f5883
4
- data.tar.gz: d215682f47b347ed7c05badf06656d98c7846a4d
3
+ metadata.gz: 34e96756dc75b2ef9a5c9b9e543774571ed8e5fb
4
+ data.tar.gz: b379a6c252dda1fead8179c923ae10733294ef70
5
5
  SHA512:
6
- metadata.gz: 91f6d330486939e5da6272e33d840de4415c7a43d69de16bf20687b1dd2f4b17735a81c7588b193a9896e119cc7df10f88035b619c491c00bd84b44cd6f0787d
7
- data.tar.gz: 774672fdaa5ef6bbf9b9957dc53ab34fdd45e2e9cf278908de90c88b3978d741c700fdf0c869ae560797564a01df2179b7b5ac4a01ae7c6583750f973db040bd
6
+ metadata.gz: c82ef99476bf387e6d77804ef41880c38151cd73344ddb9b9705ca48f0df883e534f57907b731ede634b593705cc1666aca80bda5f5d7a1a2eb8528699be6502
7
+ data.tar.gz: 65018902d2629d32fd3afd2a5f56c031dc3303be18121c4ca6ecbf663370903c5bf37099f0954ad5d3aa97fee38165aabe80cba78cca92bb777f9f2929c60d62
data/bin/haile CHANGED
@@ -1,29 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'marathon'))
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'haile'))
4
4
  require 'trollop'
5
5
 
6
- SUB_COMMANDS = %w[endpoints kill kill_tasks start scale list list_tasks search]
6
+ SUB_COMMANDS = %w[endpoints kill kill_tasks start scale list list_tasks search docker_deploy]
7
7
 
8
8
  global_opts = Trollop.options do
9
- version Marathon::VERSION
9
+ version Haile::VERSION
10
10
  banner <<-EOS
11
- Usage: marathon [global options] [command] [options]
11
+ Usage: haile [global options] [command] [options]
12
12
 
13
13
  Available commands:
14
14
 
15
- kill Kill an app and remove it from Marathon.
16
- kill_tasks Kill a task or tasks belonging to a specified app.
17
- list Show a list of running apps and their options.
18
- list_tasks Show a list of an app's running tasks.
19
- scale Scale the number of app instances.
20
- search Search the current list of apps.
21
- start Start a new app.
15
+ kill Kill an app and remove it from Marathon.
16
+ kill_tasks Kill a task or tasks belonging to a specified app.
17
+ list Show a list of running apps and their options.
18
+ list_tasks Show a list of an app's running tasks.
19
+ scale Scale the number of app instances.
20
+ search Search the current list of apps.
21
+ start Start a new app.
22
+ docker_deploy Update the docker image tag of an app.
22
23
 
23
24
  Global options:
24
25
  EOS
25
26
 
26
- opt :marathon_host, 'Marathon host (default http://localhost:8080, or MARATHON_HOST)', :short => '-H', :type => String
27
+ opt :marathon_url, 'Marathon URL (default http://localhost:8080, or MARATHON_URL)', :short => '-R', :type => String
27
28
  opt :marathon_user, 'User name to authenticate against Marathon (optional).', :short => '-U', :type => String
28
29
  opt :marathon_pass, 'Password to authenticate against Marathon (optional).', :short => '-P', :type => String
29
30
  stop_on SUB_COMMANDS
@@ -73,12 +74,17 @@ cmd_opts = case cmd
73
74
  opt :id, 'A unique identifier for the app.', :short => '-i', :type => String, :default => nil
74
75
  opt :command, 'The command for the app.', :short => '-C', :type => String, :default => nil
75
76
  end
77
+ when 'docker_deploy'
78
+ Trollop.options do
79
+ opt :id, 'A unique identifier for the app.', :required => true, :short => '-i', :type => String
80
+ opt :docker_image, 'The docker image:tag to update to.', :required => true, :short => '-d', :type => String
81
+ end
76
82
  else
77
83
  {}
78
84
  end
79
85
 
80
- marathon = Marathon::Client.new(
81
- global_opts[:marathon_host],
86
+ haile = Haile::Client.new(
87
+ global_opts[:marathon_url],
82
88
  global_opts[:marathon_user],
83
89
  global_opts[:marathon_pass]
84
90
  )
@@ -117,7 +123,7 @@ end
117
123
  # Run
118
124
  case cmd
119
125
  when 'endpoints'
120
- puts marathon.endpoints(cmd_opts[:id]).parsed_response
126
+ puts haile.endpoints(cmd_opts[:id]).parsed_response
121
127
  when 'start'
122
128
  app_opts = {
123
129
  :instances => cmd_opts[:num_instances] || 1,
@@ -130,27 +136,31 @@ when 'start'
130
136
  }
131
137
  app_opts[:executor] = cmd_opts[:executor] unless cmd_opts[:executor] == nil
132
138
  puts "Starting app '#{cmd_opts[:id]}'"
133
- puts marathon.start(cmd_opts[:id], app_opts)
139
+ puts haile.start(cmd_opts[:id], app_opts)
134
140
  when 'scale'
135
141
  puts "Scaling app '#{cmd_opts[:id]}' to #{cmd_opts[:num_instances]} instances"
136
- res = marathon.scale(cmd_opts[:id], cmd_opts[:num_instances])
142
+ res = haile.scale(cmd_opts[:id], cmd_opts[:num_instances])
143
+ puts res
144
+ when 'docker_deploy'
145
+ puts "Deploying app '#{cmd_opts[:id]}' to #{cmd_opts[:docker_image]}"
146
+ res = haile.docker_deploy(cmd_opts[:id], cmd_opts[:docker_image])
137
147
  puts res
138
148
  when 'kill'
139
149
  puts "Killing app '#{cmd_opts[:id]}'"
140
- puts marathon.kill(cmd_opts[:id])
150
+ puts haile.kill(cmd_opts[:id])
141
151
  when 'kill_tasks'
142
152
  KILL_TASKS_KEYS = [:host, :scale, :task_id]
143
153
 
144
154
  opts = cmd_opts.clone
145
155
  opts.select! {|k, v| KILL_TASKS_KEYS.include?(k)}
146
156
 
147
- puts marathon.kill_tasks(cmd_opts[:id], opts).parsed_response
157
+ puts haile.kill_tasks(cmd_opts[:id], opts).parsed_response
148
158
  when 'list'
149
- handle_listing(marathon.list)
159
+ handle_listing(haile.list)
150
160
  when 'list_tasks'
151
- puts marathon.list_tasks(cmd_opts[:id]).parsed_response
161
+ puts haile.list_tasks(cmd_opts[:id]).parsed_response
152
162
  when 'search'
153
- handle_listing(marathon.search(cmd_opts[:id], cmd_opts[:command]))
163
+ handle_listing(haile.search(cmd_opts[:id], cmd_opts[:command]))
154
164
  else
155
165
  Trollop.die "unknown subcommand #{cmd.inspect}"
156
166
  end
data/lib/haile/client.rb CHANGED
@@ -13,9 +13,9 @@ module Haile
13
13
  maintain_method_across_redirects
14
14
  default_timeout 5
15
15
 
16
- EDITABLE_APP_ATTRIBUTES = [
17
- :cmd, :constraints, :container, :cpus, :env, :executor, :id, :instances,
18
- :mem, :ports, :uris]
16
+ EDITABLE_APP_ATTRIBUTES = %w(
17
+ cmd constraints container cpus env executor id instances mem ports uris
18
+ )
19
19
 
20
20
  def initialize(url = nil, user = nil, pass = nil, proxy = nil)
21
21
  @host = url || ENV['MARATHON_URL'] || 'http://localhost:8080'
@@ -65,6 +65,25 @@ module Haile
65
65
  wrap_request(:post, '/v2/apps/', :body => body)
66
66
  end
67
67
 
68
+ def docker_deploy(id, image)
69
+ # Fetch current state and update only the 'container['docker']['image']'
70
+ # attribute. Since the API only supports PUT, the full representation
71
+ # of the app must be supplied to update even just a single attribute.
72
+
73
+ app = wrap_request(:get, "/v2/apps/#{id}").parsed_response['app']
74
+ app.select! {|k, v| EDITABLE_APP_ATTRIBUTES.include?(k)}
75
+
76
+ begin
77
+ app['container']['docker']['image'] = image
78
+ rescue
79
+ msg = "App doesn't have a docker image configured. Make sure " \
80
+ "the ID is correct and that this app is already configured " \
81
+ "with a docker image."
82
+ return Haile::Response.error(msg)
83
+ end
84
+ wrap_request(:put, "/v2/apps/#{id}", :body => app)
85
+ end
86
+
68
87
  def scale(id, num_instances)
69
88
  # Fetch current state and update only the 'instances' attribute. Since the
70
89
  # API only supports PUT, the full representation of the app must be
@@ -72,7 +91,7 @@ module Haile
72
91
  app = wrap_request(:get, "/v2/apps/#{id}").parsed_response['app']
73
92
  app.select! {|k, v| EDITABLE_APP_ATTRIBUTES.include?(k)}
74
93
 
75
- app[:instances] = num_instances
94
+ app['instances'] = num_instances
76
95
  wrap_request(:put, "/v2/apps/#{id}", :body => app)
77
96
  end
78
97
 
@@ -96,10 +115,16 @@ module Haile
96
115
 
97
116
  def wrap_request(method, url, options = {})
98
117
  options = @default_options.merge(options)
99
- http = self.class.send(method, @host + url, options)
100
- Marathon::Response.new(http)
118
+ if method == :get
119
+ puts "GET"
120
+ http = self.class.send(method, @host + url, options)
121
+ return Haile::Response.new(http)
122
+ else
123
+ puts "#{method} #{@host + url} #{options}"
124
+ return
125
+ end
101
126
  rescue => e
102
- Marathon::Response.error(e.message)
127
+ Haile::Response.error(e.message)
103
128
  end
104
129
 
105
130
  def query_params(hash)
data/lib/haile/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Haile
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobi Knaup