kontena-cli 0.7.2 → 0.7.3

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: 783db978846f2562ae4376aafaf2cc331e3c2335
4
- data.tar.gz: 8bf9cf6feb781b34997c5805d93739cce03002ab
3
+ metadata.gz: 3373d4421b6f61fd8e141235ecc1c00d98ff9953
4
+ data.tar.gz: 577e0ebe31f0536ac54376be8154278651ee2caa
5
5
  SHA512:
6
- metadata.gz: e9b55c7c46b7feafe97f4ef835584545bdfcf6d8cf44a31b2870468da4a8c372d72d1192d126986bb9ed453ce6e4cbb581bab92405c9b06b52ce0d8fed3eec12
7
- data.tar.gz: 9aac40ace507b5ac790652cb003ad1e51142303ede988e0f8133df68d3a9e8192a5e1f2ee6861b87b46ee31cd19023594020dc60b090a89b6a1d911e356dd130
6
+ metadata.gz: 10a7dff3ac50b99808ca0754e8de9a77740f2535801dc304574d2c25082e79c32a5503765c6c39f15f7b66ed9fa70b6026c851e7ac9bd78ef0d6f9ec4b9c4e50
7
+ data.tar.gz: 54af8670055cbeac319144712d3add58bd1a334b385d48cab3a35acab0f5b324f70eb98557589e0ebfbeeeefd04b95e6ec3366c6f07058595371e56e92e08ca1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
1
+ 0.7.3
@@ -15,7 +15,7 @@ module Kontena::Cli::Services
15
15
  puts "%-30.30s %-40.40s %-10s %-8s" % ['NAME', 'IMAGE', 'INSTANCES', 'STATEFUL']
16
16
  grids['services'].each do |service|
17
17
  state = service['stateful'] ? 'yes' : 'no'
18
- puts "%-30.30s %-40.40s %-10.10s %-8s" % [service['id'], service['image'], service['container_count'], state]
18
+ puts "%-30.30s %-40.40s %-10.10s %-8s" % [service['name'], service['image'], service['container_count'], state]
19
19
  end
20
20
  end
21
21
 
@@ -50,7 +50,7 @@ module Kontena::Cli::Services
50
50
  end
51
51
  end
52
52
  puts " containers:"
53
- result = client(token).get("services/#{current_grid}/#{service_id}/containers")
53
+ result = client(token).get("services/#{parse_service_id(service_id)}/containers")
54
54
  result['containers'].each do |container|
55
55
  puts " #{container['name']}:"
56
56
  puts " rev: #{container['deploy_rev']}"
@@ -67,7 +67,7 @@ module Kontena::Cli::Services
67
67
  end
68
68
 
69
69
  def scale(service_id, count, options)
70
- client(require_token).put("services/#{current_grid}/#{service_id}", {container_count: count})
70
+ client(require_token).put("services/#{parse_service_id(service_id)}", {container_count: count})
71
71
  self.deploy(service_id, options)
72
72
  end
73
73
 
@@ -85,20 +85,20 @@ module Kontena::Cli::Services
85
85
  def restart(service_id)
86
86
  require_api_url
87
87
  token = require_token
88
- result = client(token).post("services/#{current_grid}/#{service_id}/restart", {})
88
+ result = client(token).post("services/#{parse_service_id(service_id)}/restart", {})
89
89
  end
90
90
 
91
91
  def stop(service_id)
92
92
  require_api_url
93
93
  token = require_token
94
- result = client(token).post("services/#{current_grid}/#{service_id}/stop", {})
94
+ result = client(token).post("services/#{parse_service_id(service_id)}/stop", {})
95
95
  end
96
96
 
97
97
  def start(service_id)
98
98
  require_api_url
99
99
  token = require_token
100
100
 
101
- result = client(token).post("services/#{current_grid}/#{service_id}/start", {})
101
+ result = client(token).post("services/#{parse_service_id(service_id)}/start", {})
102
102
  end
103
103
 
104
104
  def create(name, image, options)
@@ -126,7 +126,7 @@ module Kontena::Cli::Services
126
126
  require_api_url
127
127
  token = require_token
128
128
 
129
- result = client(token).delete("services/#{current_grid}/#{service_id}")
129
+ result = client(token).delete("services/#{parse_service_id(service_id)}")
130
130
  end
131
131
 
132
132
  private
@@ -7,22 +7,36 @@ module Kontena
7
7
  module ServicesHelper
8
8
  include Kontena::Cli::Common
9
9
 
10
+ # @param [String] token
11
+ # @param [String] grid_id
12
+ # @param [Hash] data
10
13
  def create_service(token, grid_id, data)
11
14
  client(token).post("grids/#{grid_id}/services", data)
12
15
  end
13
16
 
17
+ # @param [String] token
18
+ # @param [String] service_id
19
+ # @param [Hash] data
14
20
  def update_service(token, service_id, data)
15
- client(token).put("services/#{current_grid}/#{service_id}", data)
21
+ param = parse_service_id(service_id)
22
+ client(token).put("services/#{param}", data)
16
23
  end
17
24
 
25
+ # @param [String] token
26
+ # @param [String] service_id
18
27
  def get_service(token, service_id)
19
- client(token).get("services/#{current_grid}/#{service_id}")
28
+ param = parse_service_id(service_id)
29
+ client(token).get("services/#{param}")
20
30
  end
21
31
 
32
+ # @param [String] token
33
+ # @param [String] service_id
34
+ # @param [Hash] data
22
35
  def deploy_service(token, service_id, data)
23
- client(token).post("services/#{current_grid}/#{service_id}/deploy", data)
36
+ param = parse_service_id(service_id)
37
+ client(token).post("services/#{param}/deploy", data)
24
38
  print 'deploying '
25
- until client(token).get("services/#{current_grid}/#{service_id}")['state'] != 'deploying' do
39
+ until client(token).get("services/#{param}")['state'] != 'deploying' do
26
40
  print '.'
27
41
  sleep 1
28
42
  end
@@ -30,6 +44,18 @@ module Kontena
30
44
  puts ''
31
45
  end
32
46
 
47
+ # @param [String] service_id
48
+ # @return [String]
49
+ def parse_service_id(service_id)
50
+ if service_id.to_s.include?('/')
51
+ param = service_id
52
+ else
53
+ param = "#{current_grid}/#{service_id}"
54
+ end
55
+ end
56
+
57
+ # @param [Array<String>] port_options
58
+ # @return [Array<Hash>]
33
59
  def parse_ports(port_options)
34
60
  port_options.map{|p|
35
61
  node_port, container_port, protocol = p.split(':')
@@ -44,6 +70,8 @@ module Kontena
44
70
  }
45
71
  end
46
72
 
73
+ # @param [Array<String>] link_options
74
+ # @return [Array<Hash>]
47
75
  def parse_links(link_options)
48
76
  link_options.map{|l|
49
77
  service_name, alias_name = l.split(':')
@@ -58,6 +86,8 @@ module Kontena
58
86
  }
59
87
  end
60
88
 
89
+ # @param [String] memory
90
+ # @return [Integer]
61
91
  def parse_memory(memory)
62
92
  if memory.end_with?('k')
63
93
  memory.to_i * 1000
@@ -44,7 +44,7 @@ module Kontena::Cli::Stacks
44
44
  data[:strategy] = service['deploy']['strategy'] if service['deploy']['strategy']
45
45
  data[:wait_for_port] = service['deploy']['wait_for_port'] if service['deploy']['wait_for_port']
46
46
  end
47
- deploy_service(token, service['id'], data)
47
+ deploy_service(token, service['id'].split('/').last, data)
48
48
  end
49
49
  end
50
50
 
@@ -35,7 +35,6 @@ class Helper
35
35
  services = client.get("grids/#{current_grid}/services")['services']
36
36
  results = []
37
37
  results.push services.map{|s| s['name']}
38
- results.push services.map{|s| s['id']}
39
38
 
40
39
  results
41
40
  rescue
@@ -76,9 +76,7 @@ module Kontena::Cli::Services
76
76
  protocol: 'tcp'
77
77
  }]
78
78
  port_options = subject.parse_ports(['80:80'])
79
-
80
79
  expect(port_options).to eq(valid_result)
81
-
82
80
  end
83
81
  end
84
82
 
@@ -91,13 +89,21 @@ module Kontena::Cli::Services
91
89
 
92
90
  it 'returns hash of link options' do
93
91
  valid_result = [{
94
- name: 'db',
95
- alias: 'mysql',
96
- }]
92
+ name: 'db',
93
+ alias: 'mysql',
94
+ }]
97
95
  link_options = subject.parse_links(['db:mysql'])
98
-
99
96
  expect(link_options).to eq(valid_result)
97
+ end
98
+ end
99
+
100
+ describe '#parse_service_id' do
101
+ it 'adds current_grid if service_id is missing prefix' do
102
+ expect(subject.parse_service_id('mysql')).to eq('test-grid/mysql')
103
+ end
100
104
 
105
+ it 'does not add current_grid if service id includes prefix' do
106
+ expect(subject.parse_service_id('second-grid/mysql')).to eq('second-grid/mysql')
101
107
  end
102
108
  end
103
109
  end
@@ -198,6 +198,7 @@ content
198
198
  it 'deploys only given services' do
199
199
  allow(subject).to receive(:current_dir).and_return("kontena-test")
200
200
  allow(options).to receive(:service).and_return(['wordpress'])
201
+ allow(subject).to receive(:deploy_services).and_return({})
201
202
  expect(subject).to receive(:create).once.with('wordpress', anything).and_return({})
202
203
  expect(subject).not_to receive(:create).with('mysql', services['mysql'])
203
204
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
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-07-25 00:00:00.000000000 Z
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler