aptible-cli 0.9.0 → 0.10.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: 5e3e03cae11a2a3bab84c225df322c9fe8c75ab6
4
- data.tar.gz: aafef516b5c3bc4996317cf977e3cb403d3f7496
3
+ metadata.gz: 5d0afaea6319a0ba8278d83dc1de979778dd5842
4
+ data.tar.gz: 6d087bb9b0de9c1da3855e4ea85c38a18f48820d
5
5
  SHA512:
6
- metadata.gz: 0ef871ee863e4f5e49a82acd02b7062e20c93c11138e3aa3eae2918c82090b0991a198c5166f765b8d75b576a71ac5508ec014774bded52518d9008448dc4597
7
- data.tar.gz: 6f40a10270be6929ad61c11a42fb11bc3d68dc3a5d62a3d4713a7101fb4eb065005816ed93f7ad2bc561dc0285fadd4f5ca0991b01efde892da59cde25a5da16
6
+ metadata.gz: 12d928e9a1fc0266a38e81052132759873220f6ecdc60d4c93a3769a651a39b40ba350efc5140365da88b2ccc25175d63b73c0c7f8d1d0797f8a56128247a48f
7
+ data.tar.gz: 634e77e72b255e67b2ecff6df9391d16b2d06052ecfc92f582247e650ee8e81d457a2de55d92635f04f130dc287b241472e1be4e1c0bcc4554346b9e5ece1456
@@ -35,7 +35,7 @@ module Aptible
35
35
  end
36
36
 
37
37
  desc 'apps:scale SERVICE ' \
38
- '[--container-count COUNT] [--container-size SIZE]',
38
+ '[--container-count COUNT] [--container-size SIZE_MB]',
39
39
  'Scale a service'
40
40
  app_options
41
41
  option :container_count, type: :numeric
@@ -7,9 +7,11 @@ module Aptible
7
7
  include Helpers::Token
8
8
  include Helpers::Database
9
9
 
10
- desc 'backup:restore [--handle HANDLE] [--size SIZE_GB]',
10
+ desc 'backup:restore BACKUP_ID [--handle HANDLE] ' \
11
+ '[--container-size SIZE_MB] [--size SIZE_GB]',
11
12
  'Restore a backup'
12
13
  option :handle
14
+ option :container_size, type: :numeric
13
15
  option :size, type: :numeric
14
16
  define_method 'backup:restore' do |backup_id|
15
17
  backup = Aptible::Api::Backup.find(backup_id, token: fetch_token)
@@ -23,6 +25,7 @@ module Aptible
23
25
  opts = {
24
26
  type: 'restore',
25
27
  handle: handle,
28
+ container_size: options[:container_size],
26
29
  disk_size: options[:size]
27
30
  }.delete_if { |_, v| v.nil? }
28
31
 
@@ -20,23 +20,42 @@ module Aptible
20
20
  end
21
21
  end
22
22
 
23
- desc 'db:create HANDLE', 'Create a new database'
23
+ desc 'db:create HANDLE' \
24
+ '[--type TYPE] [--container-size SIZE_MB] [--size SIZE_GB]',
25
+ 'Create a new database'
24
26
  option :type, default: 'postgresql'
27
+ option :container_size, type: :numeric
25
28
  option :size, default: 10, type: :numeric
26
29
  option :environment
27
30
  define_method 'db:create' do |handle|
28
31
  environment = ensure_environment(options)
29
- database = environment.create_database(handle: handle,
30
- type: options[:type])
31
-
32
- if database.errors.any?
33
- raise Thor::Error, database.errors.full_messages.first
34
- else
35
- op = database.create_operation!(type: 'provision',
36
- disk_size: options[:size])
37
- attach_to_operation_logs(op)
38
- say database.reload.connection_url
32
+
33
+ db_opts = {
34
+ handle: handle,
35
+ type: options[:type],
36
+ initial_container_size: options[:container_size],
37
+ initial_disk_size: options[:size]
38
+ }.delete_if { |_, v| v.nil? }
39
+ database = environment.create_database!(db_opts)
40
+
41
+ op_opts = {
42
+ type: 'provision',
43
+ container_size: options[:container_size],
44
+ disk_size: options[:size]
45
+ }.delete_if { |_, v| v.nil? }
46
+ op = database.create_operation(op_opts)
47
+
48
+ if op.errors.any?
49
+ # NOTE: If we fail to provision the database, we should try and
50
+ # clean it up immediately. Note that this will not be possible
51
+ # if we have an account that's not activated, but that's
52
+ # arguably the desired UX here.
53
+ database.create_operation!(type: 'deprovision')
54
+ raise Thor::Error, op.errors.full_messages.first
39
55
  end
56
+
57
+ attach_to_operation_logs(op)
58
+ say database.reload.connection_url
40
59
  end
41
60
 
42
61
  desc 'db:clone SOURCE DEST', 'Clone a database to create a new one'
@@ -138,6 +157,26 @@ module Aptible
138
157
  op = database.create_operation!(type: 'reload')
139
158
  attach_to_operation_logs(op)
140
159
  end
160
+
161
+ desc 'db:restart HANDLE ' \
162
+ '[--container-size SIZE_MB] [--size SIZE_GB]',
163
+ 'Restart a database'
164
+ option :environment
165
+ option :container_size, type: :numeric
166
+ option :disk_size, type: :numeric
167
+ define_method 'db:restart' do |handle|
168
+ database = ensure_database(options.merge(db: handle))
169
+
170
+ opts = {
171
+ type: 'restart',
172
+ container_size: options[:container_size],
173
+ disk_size: options[:size]
174
+ }.delete_if { |_, v| v.nil? }
175
+
176
+ say "Restarting #{database.handle}..."
177
+ op = database.create_operation!(opts)
178
+ attach_to_operation_logs(op)
179
+ end
141
180
  end
142
181
  end
143
182
  end
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.9.0'.freeze
3
+ VERSION = '0.10.0'.freeze
4
4
  end
5
5
  end
@@ -47,20 +47,48 @@ describe Aptible::CLI::Agent do
47
47
  expect(messages).to eq(["Restoring backup into #{h}"])
48
48
  end
49
49
 
50
- it 'accepts a custom handle and disk size' do
50
+ it 'accepts a handle' do
51
51
  h = 'some-handle'
52
- s = 40
53
52
 
54
53
  expect(backup).to receive(:create_operation!) do |options|
55
54
  expect(options[:handle]).to eq(h)
56
- expect(options[:disk_size]).to eq(s)
55
+ expect(options[:container_size]).to be_nil
56
+ expect(options[:disk_size]).to be_nil
57
57
  op
58
58
  end
59
59
 
60
- subject.options = { handle: h, size: s }
60
+ subject.options = { handle: h }
61
61
  subject.send('backup:restore', 1)
62
62
  expect(messages).to eq(["Restoring backup into #{h}"])
63
63
  end
64
+
65
+ it 'accepts a container size' do
66
+ s = 40
67
+
68
+ expect(backup).to receive(:create_operation!) do |options|
69
+ expect(options[:handle]).to be_present
70
+ expect(options[:container_size]).to eq(s)
71
+ expect(options[:disk_size]).to be_nil
72
+ op
73
+ end
74
+
75
+ subject.options = { container_size: s }
76
+ subject.send('backup:restore', 1)
77
+ end
78
+
79
+ it 'accepts a disk size' do
80
+ s = 40
81
+
82
+ expect(backup).to receive(:create_operation!) do |options|
83
+ expect(options[:handle]).to be_present
84
+ expect(options[:container_size]).to be_nil
85
+ expect(options[:disk_size]).to eq(s)
86
+ op
87
+ end
88
+
89
+ subject.options = { size: s }
90
+ subject.send('backup:restore', 1)
91
+ end
64
92
  end
65
93
  end
66
94
 
@@ -12,6 +12,82 @@ describe Aptible::CLI::Agent do
12
12
  let(:database) { Fabricate(:database, handle: handle) }
13
13
  let(:socat_helper) { SocatHelperMock.new(port: 4242) }
14
14
 
15
+ describe '#db:create' do
16
+ let(:db) { Fabricate(:database) }
17
+ let(:op) { Fabricate(:operation) }
18
+ let(:account) { Fabricate(:account) }
19
+
20
+ before do
21
+ allow(Aptible::Api::Account).to receive(:all).and_return([account])
22
+ allow(db).to receive(:reload).and_return(db)
23
+ op.stub(errors: Aptible::Resource::Errors.new)
24
+ end
25
+
26
+ it 'creates a new DB' do
27
+ expect(account).to receive(:create_database!)
28
+ .with(handle: 'foo', type: 'postgresql')
29
+ .and_return(db)
30
+
31
+ expect(db).to receive(:create_operation)
32
+ .with(type: 'provision')
33
+ .and_return(op)
34
+
35
+ expect(subject).to receive(:attach_to_operation_logs)
36
+ .with(op)
37
+
38
+ subject.options = { type: 'postgresql' }
39
+ subject.send('db:create', 'foo')
40
+ end
41
+
42
+ it 'creates a new DB with a container size' do
43
+ expect(account).to receive(:create_database!)
44
+ .with(handle: 'foo', type: 'postgresql', initial_container_size: 1024)
45
+ .and_return(db)
46
+
47
+ expect(db).to receive(:create_operation)
48
+ .with(type: 'provision', container_size: 1024)
49
+ .and_return(op)
50
+
51
+ expect(subject).to receive(:attach_to_operation_logs)
52
+ .with(op)
53
+
54
+ subject.options = { type: 'postgresql', container_size: 1024 }
55
+ subject.send('db:create', 'foo')
56
+ end
57
+
58
+ it 'creates a new DB with a disk size' do
59
+ expect(account).to receive(:create_database!)
60
+ .with(handle: 'foo', type: 'postgresql', initial_disk_size: 200)
61
+ .and_return(db)
62
+
63
+ expect(db).to receive(:create_operation)
64
+ .with(type: 'provision', disk_size: 200)
65
+ .and_return(op)
66
+
67
+ expect(subject).to receive(:attach_to_operation_logs)
68
+ .with(op)
69
+
70
+ subject.options = { type: 'postgresql', size: 200 }
71
+ subject.send('db:create', 'foo')
72
+ end
73
+
74
+ it 'deprovisions the database if the operation cannot be created' do
75
+ op.errors.full_messages << 'oops!'
76
+
77
+ expect(account).to receive(:create_database!).and_return(db)
78
+
79
+ expect(db).to receive(:create_operation)
80
+ .with(type: 'provision')
81
+ .once.ordered.and_return(op)
82
+
83
+ expect(db).to receive(:create_operation!)
84
+ .with(type: 'deprovision')
85
+ .once.ordered
86
+
87
+ expect { subject.send('db:create', 'foo') }.to raise_error(/oops/im)
88
+ end
89
+ end
90
+
15
91
  describe '#db:tunnel' do
16
92
  it 'should fail if database is non-existent' do
17
93
  allow(Aptible::Api::Database).to receive(:all) { [] }
@@ -233,4 +309,48 @@ describe Aptible::CLI::Agent do
233
309
  .to raise_error(Thor::Error, 'Could not find database nope')
234
310
  end
235
311
  end
312
+
313
+ describe '#db:restart' do
314
+ before { allow(Aptible::Api::Account).to receive(:all) { [account] } }
315
+ before { allow(Aptible::Api::Database).to receive(:all) { [database] } }
316
+
317
+ let(:op) { Fabricate(:operation) }
318
+
319
+ it 'allows restarting a database' do
320
+ expect(database).to receive(:create_operation!)
321
+ .with(type: 'restart').and_return(op)
322
+
323
+ expect(subject).to receive(:say).with('Restarting foobar...')
324
+ expect(subject).to receive(:attach_to_operation_logs).with(op)
325
+
326
+ subject.send('db:restart', handle)
327
+ end
328
+
329
+ it 'allows restarting a database with a container size' do
330
+ expect(database).to receive(:create_operation!)
331
+ .with(type: 'restart', container_size: 40).and_return(op)
332
+
333
+ expect(subject).to receive(:say).with('Restarting foobar...')
334
+ expect(subject).to receive(:attach_to_operation_logs).with(op)
335
+
336
+ subject.options = { container_size: 40 }
337
+ subject.send('db:restart', handle)
338
+ end
339
+
340
+ it 'allows restarting a database with a disk size' do
341
+ expect(database).to receive(:create_operation!)
342
+ .with(type: 'restart', disk_size: 40).and_return(op)
343
+
344
+ expect(subject).to receive(:say).with('Restarting foobar...')
345
+ expect(subject).to receive(:attach_to_operation_logs).with(op)
346
+
347
+ subject.options = { size: 40 }
348
+ subject.send('db:restart', handle)
349
+ end
350
+
351
+ it 'fails if the DB is not found' do
352
+ expect { subject.send('db:restart', 'nope') }
353
+ .to raise_error(Thor::Error, 'Could not find database nope')
354
+ end
355
+ end
236
356
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-12 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api