kontena-cli 0.0.2 → 0.5.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: 5937cedf8e64f8aee2913e0e13f84426fea8940b
4
- data.tar.gz: a422d2aeed00f845cbe6bd5e85452bf6dfbcd94d
3
+ metadata.gz: 32f7df3c75d9dd5cde332f7cf19267508230be21
4
+ data.tar.gz: ed374c9d0f1a69e216ff547d7927b67c9b09ae1b
5
5
  SHA512:
6
- metadata.gz: b469c902f707f9d7257e2205ff8b3fb33ef4416c9e28c202965574e0934124948caccc3433c272c15cec096351b92c43e01967c2dcdf07078807bf6c1653387e
7
- data.tar.gz: bd899425cfbb1b073c111ee8782cee22183180f4b9cb49f8831ad90ede1bd9732c9475590ba40b44df3982024fb4478342ea102252ada92d14eacf18d2351a5b
6
+ metadata.gz: 59b51892ecc57e51c305823aa39450a9f07970ac5aa91d23a9a7bec7682f5ec141918f70d87590071c46864e1b46a5b182f055e30bfaebce9e29be88fc548a67
7
+ data.tar.gz: 438d344f304461f7d518020125d67882e92067f2dec89a0bd0c4763ad345ff84882abf202a59e5a25a0bd1a2efe61900a8f2968b57894b929230294a612658af
data/kontena-cli.gemspec CHANGED
@@ -22,6 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_runtime_dependency 'httpclient', '~> 2.3'
24
24
  spec.add_runtime_dependency 'commander'
25
- spec.add_runtime_dependency 'inifile'
26
25
  spec.add_runtime_dependency 'colorize'
27
26
  end
@@ -1,4 +1,3 @@
1
- require 'inifile'
2
1
  require 'colorize'
3
2
 
4
3
  module Kontena
@@ -9,7 +8,7 @@ module Kontena
9
8
  end
10
9
 
11
10
  def require_token
12
- token = inifile['server']['token']
11
+ token = settings['server']['token']
13
12
  unless token
14
13
  raise ArgumentError.new("Please login first using: kontena login")
15
14
  end
@@ -29,28 +28,23 @@ module Kontena
29
28
  @client
30
29
  end
31
30
 
32
- def ini_filename
33
- File.join(Dir.home, '/.kontena_client')
31
+ def settings_filename
32
+ File.join(Dir.home, '/.kontena_client.json')
34
33
  end
35
34
 
36
- def inifile
37
- if @inifile.nil?
38
- if File.exists?(ini_filename)
39
- @inifile = IniFile.load(ini_filename)
35
+ def settings
36
+ if @settings.nil?
37
+ if File.exists?(settings_filename)
38
+ @settings = JSON.parse(File.read(settings_filename))
40
39
  else
41
- @inifile = IniFile.new
40
+ @settings = {'server' => {}}
42
41
  end
43
42
  end
44
-
45
- unless @inifile['kontena']
46
- @inifile['kontena'] = {}
47
- end
48
-
49
- @inifile
43
+ @settings
50
44
  end
51
45
 
52
46
  def api_url
53
- url = inifile['server']['url']
47
+ url = settings['server']['url']
54
48
  unless url
55
49
  raise ArgumentError.new("Please init service first using: kontena connect")
56
50
  end
@@ -58,8 +52,8 @@ module Kontena
58
52
  end
59
53
 
60
54
  def current_grid=(grid)
61
- inifile['server']['grid'] = grid['id']
62
- inifile.save(filename: ini_filename)
55
+ settings['server']['grid'] = grid['id']
56
+ save_settings
63
57
  end
64
58
 
65
59
  def require_current_grid
@@ -69,14 +63,17 @@ module Kontena
69
63
  end
70
64
 
71
65
  def clear_current_grid
72
- inifile['server'].delete('grid')
73
- inifile.save(filename: ini_filename)
66
+ settings['server'].delete('grid')
67
+ save_settings
74
68
  end
75
69
 
76
70
  def current_grid
77
- inifile['server']['grid']
71
+ settings['server']['grid']
78
72
  end
79
73
 
74
+ def save_settings
75
+ File.write(settings_filename, JSON.pretty_generate(settings))
76
+ end
80
77
  end
81
78
  end
82
79
  end
@@ -11,14 +11,14 @@ module Kontena::Cli::Nodes
11
11
  token = require_token
12
12
 
13
13
  grids = client(token).get("grids/#{current_grid}/nodes")
14
- puts "%-20s %-20s %-10s %-20s %-10s" % ['Name', 'OS', 'Driver', 'Labels', 'Status']
14
+ puts "%-30s %-20s %-15s %-30s %-10s" % ['Name', 'OS', 'Driver', 'Labels', 'Status']
15
15
  grids['nodes'].each do |node|
16
16
  if node['connected']
17
17
  status = 'online'
18
18
  else
19
19
  status = 'offline'
20
20
  end
21
- puts "%-20.20s %-20.20s %-10s %-20.20s %-10s" % [
21
+ puts "%-30.30s %-20.20s %-15s %-30.30s %-10s" % [
22
22
  node['name'],
23
23
  node['os'],
24
24
  node['driver'],
@@ -9,8 +9,8 @@ module Kontena::Cli::Server
9
9
  until !api_url.nil? && !api_url.empty?
10
10
  api_url = ask('Kontena server url: ')
11
11
  end
12
- inifile['server']['url'] = api_url
13
- inifile.save(filename: ini_filename)
12
+ settings['server']['url'] = api_url
13
+ save_settings
14
14
 
15
15
  sleep 0.1
16
16
  if client.get('ping') # test server connection
@@ -22,8 +22,8 @@ module Kontena::Cli::Server
22
22
  end
23
23
 
24
24
  def disconnect
25
- inifile['server'].delete('url')
26
- inifile.save(filename: ini_filename)
25
+ settings['server'].delete('url')
26
+ save_settings
27
27
  end
28
28
 
29
29
  private
@@ -19,8 +19,8 @@ module Kontena::Cli::Server
19
19
  response = client.post('auth', params)
20
20
 
21
21
  if response
22
- inifile['server']['token'] = response['access_token']
23
- inifile.save(filename: ini_filename)
22
+ settings['server']['token'] = response['access_token']
23
+ save_settings
24
24
  print color('Login Successful', :green)
25
25
  true
26
26
  else
@@ -30,13 +30,13 @@ module Kontena::Cli::Server
30
30
  end
31
31
 
32
32
  def logout
33
- inifile['server'].delete('token')
34
- inifile.save(filename: ini_filename)
33
+ settings['server'].delete('token')
34
+ save_settings
35
35
  end
36
36
 
37
37
  def whoami
38
38
  require_api_url
39
- puts "Server: #{inifile['server']['url']}"
39
+ puts "Server: #{settings['server']['url']}"
40
40
  token = require_token
41
41
  response = client(token).get('user')
42
42
  puts "User: #{response['email']}"
@@ -24,8 +24,10 @@ end
24
24
  command 'service deploy' do |c|
25
25
  c.syntax = 'kontena service deploy <service_id>'
26
26
  c.description = 'Deploy service to nodes'
27
+ c.option '--strategy String', String, 'Define deploy strategy (ha / random)'
28
+ c.option '--wait-for-port String', String, 'Wait for given container port before deploying next container'
27
29
  c.action do |args, options|
28
- Kontena::Cli::Services::Services.new.deploy(args[0])
30
+ Kontena::Cli::Services::Services.new.deploy(args[0], options)
29
31
  end
30
32
  end
31
33
 
@@ -69,6 +71,8 @@ command 'service create' do |c|
69
71
  c.option '--instances INTEGER', Integer, 'How many instances should be deployed'
70
72
  c.option '-u', '--user String', String, 'Username who executes first process inside container'
71
73
  c.option '--stateful', 'Set service as stateful'
74
+ c.option '--cap-add Array', Array, 'Add capabilities'
75
+ c.option '--cap-drop Array', Array, 'Drop capabilities'
72
76
 
73
77
  c.action do |args, options|
74
78
  Kontena::Cli::Services::Services.new.create(args[0], args[1], options)
@@ -83,6 +87,8 @@ command 'service update' do |c|
83
87
  c.option '--image STRING', String, 'Service image'
84
88
  c.option '--instances INTEGER', Integer, 'How many instances should be deployed'
85
89
  c.option '--cmd STRING', String, 'Command to execute'
90
+ c.option '--cap-add Array', Array, 'Add capabilities'
91
+ c.option '--cap-drop Array', Array, 'Drop capabilities'
86
92
  c.action do |args, options|
87
93
  Kontena::Cli::Services::Services.new.update(args[0], options)
88
94
  end
@@ -91,8 +97,9 @@ end
91
97
  command 'service scale' do |c|
92
98
  c.syntax = 'kontena service scale <service_id> <instances>'
93
99
  c.description = 'Scale service horizontally'
100
+ c.option '--strategy String', String, 'Define deploy strategy (ha / random)'
94
101
  c.action do |args, options|
95
- Kontena::Cli::Services::Services.new.scale(args[0], args[1])
102
+ Kontena::Cli::Services::Services.new.scale(args[0], args[1], options)
96
103
  end
97
104
  end
98
105
 
@@ -10,10 +10,10 @@ module Kontena::Cli::Services
10
10
  token = require_token
11
11
 
12
12
  grids = client(token).get("grids/#{current_grid}/services")
13
- puts "%-30.30s %-40.40s %-15s %-8s" % ['NAME', 'IMAGE', 'INSTANCES', 'STATE?']
13
+ puts "%-30.30s %-40.40s %-10s %-8s" % ['NAME', 'IMAGE', 'INSTANCES', 'STATEFUL']
14
14
  grids['services'].each do |service|
15
15
  state = service['stateful'] ? 'yes' : 'no'
16
- puts "%-30.30s %-40.40s %-15.15s %-8s" % [service['id'], service['image'], service['container_count'], state]
16
+ puts "%-30.30s %-40.40s %-10.10s %-8s" % [service['id'], service['image'], service['container_count'], state]
17
17
  end
18
18
  end
19
19
 
@@ -63,16 +63,19 @@ module Kontena::Cli::Services
63
63
  end
64
64
  end
65
65
 
66
- def scale(service_id, count)
66
+ def scale(service_id, count, options)
67
67
  client(require_token).put("services/#{service_id}", {container_count: count})
68
- self.deploy(service_id)
68
+ self.deploy(service_id, options)
69
69
  end
70
70
 
71
- def deploy(service_id)
71
+ def deploy(service_id, options)
72
72
  require_api_url
73
73
  token = require_token
74
74
 
75
- result = client(token).post("services/#{service_id}/deploy", {})
75
+ data = {}
76
+ data[:strategy] = options.strategy if options.strategy
77
+ data[:wait_for_port] = options.wait_for_port if options.wait_for_port
78
+ result = client(token).post("services/#{service_id}/deploy", data)
76
79
 
77
80
  print 'deploying '
78
81
  until client(token).get("services/#{service_id}")['state'] != 'deploying' do
@@ -132,6 +135,8 @@ module Kontena::Cli::Services
132
135
  data[:cmd] = options.cmd.split(" ") if options.cmd
133
136
  data[:user] = options.user if options.user
134
137
  data[:cpu] = options.cpu if options.cpu
138
+ data[:cap_add] = options.cap_add if options.cap_add
139
+ data[:cap_drop] = options.cap_drop if options.cap_drop
135
140
  if options.memory
136
141
  memory = human_size_to_number(options.memory)
137
142
  raise ArgumentError.new('Invalid --memory')
@@ -151,6 +156,8 @@ module Kontena::Cli::Services
151
156
  data[:cmd] = options.cmd.split(" ") if options.cmd
152
157
  data[:ports] = parse_ports(options.ports) if options.ports
153
158
  data[:image] = options.image if options.image
159
+ data[:cap_add] = options.cap_add if options.cap_add
160
+ data[:cap_drop] = options.cap_drop if options.cap_drop
154
161
 
155
162
  client(require_token).put("services/#{service_id}", data)
156
163
  end
@@ -163,19 +170,17 @@ module Kontena::Cli::Services
163
170
  end
164
171
 
165
172
  private
166
- def current_grid
167
- inifile['server']['grid']
168
- end
169
173
 
170
174
  def parse_ports(port_options)
171
175
  port_options.map{|p|
172
- node_port, container_port = p.split(':')
176
+ node_port, container_port, protocol = p.split(':')
173
177
  if node_port.nil? || container_port.nil?
174
178
  raise ArgumentError.new("Invalid port value #{p}")
175
179
  end
176
180
  {
177
181
  container_port: container_port,
178
- node_port: node_port
182
+ node_port: node_port,
183
+ protocol: protocol || 'tcp'
179
184
  }
180
185
  }
181
186
  end
@@ -1,5 +1,5 @@
1
1
  module Kontena
2
2
  module Cli
3
- VERSION = "0.0.2"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,97 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2015-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: httpclient
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: commander
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: inifile
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: colorize
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - '>='
73
+ - - ">="
88
74
  - !ruby/object:Gem::Version
89
75
  version: '0'
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - '>='
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  description: Kontena command line tool
@@ -102,7 +88,7 @@ executables:
102
88
  extensions: []
103
89
  extra_rdoc_files: []
104
90
  files:
105
- - .gitignore
91
+ - ".gitignore"
106
92
  - Gemfile
107
93
  - LICENSE.txt
108
94
  - README.md
@@ -140,17 +126,17 @@ require_paths:
140
126
  - lib
141
127
  required_ruby_version: !ruby/object:Gem::Requirement
142
128
  requirements:
143
- - - '>='
129
+ - - ">="
144
130
  - !ruby/object:Gem::Version
145
131
  version: '0'
146
132
  required_rubygems_version: !ruby/object:Gem::Requirement
147
133
  requirements:
148
- - - '>='
134
+ - - ">="
149
135
  - !ruby/object:Gem::Version
150
136
  version: '0'
151
137
  requirements: []
152
138
  rubyforge_project:
153
- rubygems_version: 2.4.3
139
+ rubygems_version: 2.2.2
154
140
  signing_key:
155
141
  specification_version: 4
156
142
  summary: Kontena command line tool