brightbox-cli 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -2
  3. data/Gemfile.lock +6 -6
  4. data/brightbox-cli.gemspec +1 -1
  5. data/lib/brightbox-cli/api.rb +3 -1
  6. data/lib/brightbox-cli/commands/sql/instances_create.rb +12 -16
  7. data/lib/brightbox-cli/commands/sql/instances_update.rb +13 -11
  8. data/lib/brightbox-cli/database_server.rb +61 -0
  9. data/lib/brightbox-cli/version.rb +1 -1
  10. data/locales/en.yml +12 -0
  11. data/spec/cassettes/{brightbox_database-servers → brightbox_sql_instances}/create/--allow-access_10_0_0_0/correctly_sends_API_parameters.yml +0 -0
  12. data/spec/cassettes/{brightbox_database-servers → brightbox_sql_instances}/create/--allow-access_srv-12345_grp-12345/correctly_sends_API_parameters.yml +0 -0
  13. data/spec/cassettes/{brightbox_database-servers → brightbox_sql_instances}/create/--engine_mysql/correctly_sends_API_parameters.yml +0 -0
  14. data/spec/cassettes/{brightbox_database-servers → brightbox_sql_instances}/create/--engine_mysql_--engine-version_5_6/correctly_sends_API_parameters.yml +0 -0
  15. data/spec/cassettes/{brightbox_database-servers → brightbox_sql_instances}/create/without_arguments/reports_the_new_admin_password.yml +0 -0
  16. data/spec/cassettes/{brightbox_database-servers → brightbox_sql_instances}/create/without_arguments/reports_the_new_admin_username.yml +0 -0
  17. data/spec/cassettes/{brightbox_database-servers → brightbox_sql_instances}/snapshot/when_database_server_active/correctly_sends_API_parameters.yml +0 -0
  18. data/spec/cassettes/{brightbox_database-servers → brightbox_sql_instances}/snapshot/when_database_server_can_not_be_snapshotted/reports_an_error_to_the_user.yml +0 -0
  19. data/spec/cassettes/{brightbox_database-snapshots → brightbox_sql_snapshots}/list/when_resources_are_available/does_not_output_to_stderr.yml +0 -0
  20. data/spec/cassettes/{brightbox_database-snapshots → brightbox_sql_snapshots}/list/when_resources_are_available/outputs_table_details_to_stdout.yml +0 -0
  21. data/spec/cassettes/{brightbox_database-snapshots → brightbox_sql_snapshots}/show/when_resource_exists/does_not_output_to_stderr.yml +0 -0
  22. data/spec/commands/sql/instances/create_spec.rb +66 -1
  23. data/spec/commands/sql/instances/show_spec.rb +79 -0
  24. data/spec/commands/sql/instances/snapshot_spec.rb +1 -1
  25. data/spec/commands/sql/instances/update_spec.rb +84 -0
  26. data/spec/commands/sql/snapshots/list_spec.rb +1 -1
  27. data/spec/commands/sql/snapshots/show_spec.rb +1 -1
  28. data/spec/unit/brightbox/api/created_on_spec.rb +22 -0
  29. data/spec/unit/brightbox/database_server/clean_arguments_spec.rb +45 -0
  30. data/spec/unit/brightbox/database_server/cloud_ips_spec.rb +23 -0
  31. data/spec/unit/brightbox/database_server/maintenance_window_spec.rb +44 -0
  32. metadata +38 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bbdbad8470b9de08cb4f12df141a2cedd6e39f4
4
- data.tar.gz: a629a8cdf9a0bbfe851763bb0e7f51dc4a73b265
3
+ metadata.gz: 96fa4d23d9ae155d8bed3923b2008147d5f02e5d
4
+ data.tar.gz: 8e2c0fc64b410dc6f62e35b7e3f5636fa02db1bc
5
5
  SHA512:
6
- metadata.gz: 3be96e1fea686cb9512a86c144405a3970ac66679aa481ce3c4c513298934d7793ac2073bf1f4d4e5592a01f50dc46c77694107b212cf243748d5ed6a6f2290d
7
- data.tar.gz: c9cf607d8de69355b24a441343942e315868349c817bcadf54931589c31629d09cce1a2ebafa74e3197735b5e0593d0190478a1000456fca01618956c0815621
6
+ metadata.gz: 75b51b5235e6a878194476c16eef375e65b538fc35e7fae7741f2d021b846b54cdf23c80d3040d9d5a583aa61b2ea9b0f2375e69010ae394f33e45f17ffed44c
7
+ data.tar.gz: 413d50665c92d89d79fc2256cc2dc98811158954d404ba5bbe420c7bff6377989a9f2aa23bb52911a20f98349214be48ea92b53f45fd276762f7136fc0467d64
data/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
- ### v2.5.0 / 2016-06-20
1
+ ### v2.6.0 / 2016-07-07
2
2
 
3
- [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v2.4.1...v2.5.0)
3
+ [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v2.5.0...v2.6.0)
4
4
 
5
5
  Enhancements:
6
6
 
@@ -9,6 +9,26 @@ Enhancements:
9
9
  between 06:00-06:59 UTC does not suit for your application.
10
10
  The maintenance window is used to automatically apply security updates to the
11
11
  instance.
12
+ * Add args `snapshots-schedule` and `remove-snapshots-schedule` to `sql instance`
13
+ command to enable setting up schedules for automatic snapshots of data. The
14
+ argument to set takes a crontab format string (e.g. "0 5 * * 0") to specify
15
+ when it should occur. Schedules must be at hourly or more.
16
+
17
+ Bug fixes:
18
+
19
+ * Fix handling of creation time to not error if excluded from JSON.
20
+ * Fix handling of SQL instance's cloud IP is excluded from JSON.
21
+
22
+ Changes:
23
+
24
+ * Update `fog-brightbox` to v0.11.0
25
+ * Corrected naming of a number of VCR recordings.
26
+
27
+ ### v2.5.0 / 2016-06-20
28
+
29
+ [Full Changelog](https://github.com/brightbox/brightbox-cli/compare/v2.4.1...v2.5.0)
30
+
31
+ Released in error with only version bump.
12
32
 
13
33
  ### v2.4.1 / 2016-06-06
14
34
 
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brightbox-cli (2.5.0)
5
- fog-brightbox (>= 0.10.1)
4
+ brightbox-cli (2.6.0)
5
+ fog-brightbox (>= 0.11.0)
6
6
  gli (~> 2.12.0)
7
7
  highline (~> 1.6.0)
8
8
  hirb (~> 0.6)
@@ -20,12 +20,12 @@ GEM
20
20
  crack (0.4.2)
21
21
  safe_yaml (~> 1.0.0)
22
22
  diff-lcs (1.2.5)
23
- excon (0.49.0)
24
- fog-brightbox (0.10.1)
23
+ excon (0.50.1)
24
+ fog-brightbox (0.11.0)
25
25
  fog-core (~> 1.22)
26
26
  fog-json
27
27
  inflecto (~> 0.0.2)
28
- fog-core (1.39.0)
28
+ fog-core (1.42.0)
29
29
  builder
30
30
  excon (~> 0.49)
31
31
  formatador (~> 0.2)
@@ -40,7 +40,7 @@ GEM
40
40
  inflecto (0.0.2)
41
41
  metaclass (0.0.1)
42
42
  method_source (0.8.1)
43
- mime-types (2.99.1)
43
+ mime-types (2.99.2)
44
44
  mocha (0.14.0)
45
45
  metaclass (~> 0.0.1)
46
46
  multi_json (1.11.3)
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_dependency "fog-brightbox", ">= 0.10.1"
24
+ s.add_dependency "fog-brightbox", ">= 0.11.0"
25
25
  s.add_dependency "gli", "~> 2.12.0"
26
26
  s.add_dependency "i18n", "~> 0.6.0"
27
27
  s.add_dependency "mime-types", "~> 2.6"
@@ -186,7 +186,9 @@ module Brightbox
186
186
  # Displays creation date in ISO 8601 Complete date format
187
187
  #
188
188
  def created_on
189
- fog_model.created_at.strftime("%Y-%m-%d")
189
+ if fog_model.created_at
190
+ fog_model.created_at.strftime("%Y-%m-%d")
191
+ end
190
192
  end
191
193
  end
192
194
  end
@@ -27,6 +27,16 @@ module Brightbox
27
27
  c.desc I18n.t("sql.instances.options.engine_version.desc")
28
28
  c.flag ["engine-version"]
29
29
 
30
+ # Maintenance window options
31
+ c.desc I18n.t("sql.instances.options.maintenance_weekday.desc")
32
+ c.flag ["maintenance-weekday"]
33
+ c.desc I18n.t("sql.instances.options.maintenance_hour.desc")
34
+ c.flag ["maintenance-hour"]
35
+
36
+ # Snapshots schedule
37
+ c.desc I18n.t("sql.instances.options.snapshots_schedule.desc")
38
+ c.flag [:"snapshots-schedule"]
39
+
30
40
  # Snapshot
31
41
  c.desc I18n.t("sql.instances.options.snapshot.desc")
32
42
  c.flag [:snapshot]
@@ -35,22 +45,8 @@ module Brightbox
35
45
  c.desc I18n.t("sql.instances.options.zone.desc")
36
46
  c.flag [:z, "zone"]
37
47
 
38
- c.action do |global_options, options, _args|
39
- params = {}
40
-
41
- params[:name] = options[:n] if options[:n]
42
- params[:description] = options[:d] if options[:d]
43
-
44
- if options[:"allow-access"]
45
- access_items = options[:"allow-access"].split(",")
46
- params[:allow_access] = access_items
47
- end
48
-
49
- params[:database_engine] = options[:engine] if options[:engine]
50
- params[:database_version] = options["engine-version"] if options["engine-version"]
51
- params[:snapshot_id] = options[:snapshot] if options[:snapshot]
52
- params[:flavor_id] = options[:type] if options[:type]
53
- params[:zone_id] = options[:zone] if options[:zone]
48
+ c.action do |global_options, options, args|
49
+ params = DatabaseServer.clean_arguments(options)
54
50
 
55
51
  server = DatabaseServer.create(params)
56
52
  table_options = global_options.merge(
@@ -15,6 +15,18 @@ module Brightbox
15
15
  c.desc I18n.t("sql.instances.options.allow_access.desc")
16
16
  c.flag [:"allow-access"]
17
17
 
18
+ # Maintenance window options
19
+ c.desc I18n.t("sql.instances.options.maintenance_weekday.desc")
20
+ c.flag ["maintenance-weekday"]
21
+ c.desc I18n.t("sql.instances.options.maintenance_hour.desc")
22
+ c.flag ["maintenance-hour"]
23
+
24
+ # Snapshots schedule
25
+ c.desc I18n.t("sql.instances.options.snapshots_schedule.desc")
26
+ c.flag [:"snapshots-schedule"]
27
+ c.desc I18n.t("sql.instances.options.remove_snapshots_schedule.desc")
28
+ c.switch [:"remove-snapshots-schedule"], :negatable => false
29
+
18
30
  c.action do |global_options, options, args|
19
31
  dbs_id = args.shift
20
32
  unless dbs_id =~ /^dbs-/
@@ -22,17 +34,7 @@ module Brightbox
22
34
  end
23
35
 
24
36
  server = DatabaseServer.find dbs_id
25
-
26
- params = NilableHash.new
27
- params[:name] = options[:n] if options[:n]
28
- params[:description] = options[:d] if options[:d]
29
-
30
- if options[:"allow-access"]
31
- access_items = options[:"allow-access"].split(",")
32
- params[:allow_access] = access_items
33
- end
34
-
35
- params.nilify_blanks
37
+ params = DatabaseServer.clean_arguments(options)
36
38
 
37
39
  info "Updating #{server}"
38
40
  server.update params
@@ -1,3 +1,5 @@
1
+ require "date"
2
+
1
3
  module Brightbox
2
4
  class DatabaseServer < Api
3
5
  def self.require_account?
@@ -51,6 +53,9 @@ module Brightbox
51
53
  :zone,
52
54
  :created_on,
53
55
  :admin_username, :admin_password,
56
+ :maintenance_window,
57
+ :snapshots_schedule,
58
+ :snapshots_schedule_next_at,
54
59
  :allow_access,
55
60
  :cloud_ip_ids, :cloud_ips
56
61
  ]
@@ -76,6 +81,9 @@ module Brightbox
76
81
  a[:db_engine] = engine_version
77
82
  a[:engine] = database_engine
78
83
  a[:version] = database_version
84
+ a[:maintenance_weekday] = maintenance_weekday
85
+ a[:maintenance_hour] = maintenance_hour
86
+ a[:maintenance_window] = maintenance_window
79
87
  a[:zone] = zone_handle
80
88
  a[:created_on] = created_on
81
89
  a[:allow_access] = allow_access
@@ -88,6 +96,17 @@ module Brightbox
88
96
  [database_engine, database_version].join("-")
89
97
  end
90
98
 
99
+ # A more humanised version of the maintenance window
100
+ def maintenance_window
101
+ return nil if maintenance_weekday.nil?
102
+ weekday = Date::DAYNAMES[maintenance_weekday]
103
+ sprintf("%s %02d:00 UTC", weekday, maintenance_hour)
104
+ end
105
+
106
+ def cloud_ips
107
+ super.nil? ? [] : super
108
+ end
109
+
91
110
  # Lists the CIP identifiers (cip-12345)
92
111
  def cloud_ip_ids
93
112
  cloud_ips.map { |cip| cip["id"] }
@@ -97,5 +116,47 @@ module Brightbox
97
116
  def cloud_ip_addresses
98
117
  cloud_ips.map { |cip| cip["public_ip"] }
99
118
  end
119
+
120
+ # Converts GLI's arguments to fog based parameters
121
+ def self.clean_arguments(args)
122
+ params = NilableHash.new
123
+
124
+ params[:name] = args[:n] if args[:n]
125
+ params[:description] = args[:d] if args[:d]
126
+
127
+ if args["allow-access"]
128
+ params[:allow_access] = args["allow-access"].split(",")
129
+ end
130
+
131
+ if args["maintenance-weekday"]
132
+ params[:maintenance_weekday] = weekday_index(args["maintenance-weekday"])
133
+ end
134
+ params[:maintenance_hour] = args["maintenance-hour"] if args["maintenance-hour"]
135
+
136
+ params[:snapshots_schedule] = args["snapshots-schedule"] if args["snapshots-schedule"]
137
+ if args["remove-snapshots-schedule"]
138
+ params[:snapshots_schedule] = nil
139
+ end
140
+
141
+ params[:database_engine] = args[:engine] if args[:engine]
142
+ params[:database_version] = args["engine-version"] if args["engine-version"]
143
+
144
+ params[:snapshot_id] = args[:snapshot] if args[:snapshot]
145
+ params[:flavor_id] = args[:type] if args[:type]
146
+ params[:zone_id] = args[:zone] if args[:zone]
147
+
148
+ params.nilify_blanks
149
+ params
150
+ end
151
+
152
+ private
153
+
154
+ # @param [String] user_input either a day or it's index ('sunday' or '0')
155
+ # @returns [String] The index
156
+ def self.weekday_index(user_input)
157
+ DateTime.parse(user_input).wday.to_s
158
+ rescue ArgumentError
159
+ user_input.to_s
160
+ end
100
161
  end
101
162
  end
@@ -1,3 +1,3 @@
1
1
  module Brightbox
2
- VERSION = "2.5.0" unless defined?(Brightbox::VERSION)
2
+ VERSION = "2.6.0" unless defined?(Brightbox::VERSION)
3
3
  end
data/locales/en.yml CHANGED
@@ -171,12 +171,24 @@ en:
171
171
  options:
172
172
  allow_access:
173
173
  desc: Comma separated list of IPs or IDs for servers or groups to allow access
174
+ default_maintenance:
175
+ desc: Use default settings for instance's maintenance window
174
176
  engine:
175
177
  desc: The database engine to use for the SQL instance (e.g. 'mysql')
176
178
  engine_version:
177
179
  desc: The version of the engine to use (e.g. '5.6')
180
+ maintenance_hour:
181
+ desc: Number representing the hour for the instance's maintenance
182
+ window (0-24 based on 24hr clock)
183
+ maintenance_weekday:
184
+ desc: Number representing the weekday to set for the instance's
185
+ maintenance window (0-6 where 0=Sunday)
178
186
  snapshot:
179
187
  desc: ID of a Cloud SQL snapshot to create new instance from
188
+ snapshots_schedule:
189
+ desc: Create or reschedule automatic snapshots using crontab format (e.g. "0 5 * * *"). May not be more than hourly.
190
+ remove_snapshots_schedule:
191
+ desc: Clear an existing snapshots schedule
180
192
  type:
181
193
  desc: ID of a Cloud SQL type
182
194
  zone:
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "brightbox database-servers" do
3
+ describe "brightbox sql instances" do
4
4
  describe "create" do
5
5
  let(:output) { FauxIO.new { Brightbox.run(argv) } }
6
6
  let(:stdout) { output.stdout }
@@ -65,5 +65,70 @@ describe "brightbox database-servers" do
65
65
  expect(stderr).to eql("")
66
66
  end
67
67
  end
68
+
69
+ context "--maintenance-weekday=5 --maintenance_hour=11" do
70
+ let(:argv) { %w(sql instances create --maintenance-weekday=5 --maintenance-hour=11) }
71
+ let(:expected_args) { { :maintenance_weekday => "5", :maintenance_hour => "11" } }
72
+
73
+ before do
74
+ stub_request(:post, "http://api.brightbox.dev/token").to_return(
75
+ :status => 200,
76
+ :body => '{"access_token":"44320b29286077c44f14c4efdfed70f63f4a8361","token_type":"Bearer","refresh_token":"759b2b28c228948a0ba5d07a89f39f9e268a95c0","scope":"infrastructure orbit","expires_in":7200}')
77
+
78
+ stub_request(:post, "http://api.brightbox.dev/1.0/database_servers?account_id=acc-12345")
79
+ .with(:body => "{\"name\":null,\"description\":null,\"maintenance_weekday\":\"5\",\"maintenance_hour\":\"11\"}")
80
+ end
81
+
82
+ it "correctly sends API parameters" do
83
+ expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
84
+ expect(stderr).to eql("")
85
+ end
86
+ end
87
+
88
+ context "--maintenance-weekday=thursday" do
89
+ let(:argv) { %w(sql instances create --maintenance-weekday=thursday) }
90
+ let(:expected_args) { { :maintenance_weekday => "4" } }
91
+
92
+ before do
93
+ stub_request(:post, "http://api.brightbox.dev/token").to_return(
94
+ :status => 200,
95
+ :body => '{"access_token":"44320b29286077c44f14c4efdfed70f63f4a8361","token_type":"Bearer","refresh_token":"759b2b28c228948a0ba5d07a89f39f9e268a95c0","scope":"infrastructure orbit","expires_in":7200}')
96
+
97
+ stub_request(:post, "http://api.brightbox.dev/1.0/database_servers?account_id=acc-12345")
98
+ .with(:body => "{\"name\":null,\"description\":null,\"maintenance_weekday\":\"4\",\"maintenance_hour\":null}")
99
+ end
100
+
101
+ it "correctly sends API parameters" do
102
+ expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
103
+ expect(stderr).to eql("")
104
+ end
105
+ end
106
+
107
+ context "--snapshots-schedule='0 12 * * 4'" do
108
+ let(:argv) { ["sql", "instances", "create", "--snapshots-schedule=0 12 * * 4"] }
109
+ let(:expected_args) { { :snapshots_schedule => "0 12 * * 4" } }
110
+
111
+ let(:json_response) do
112
+ <<-EOS
113
+ {
114
+ "id":"dbs-12345",
115
+ "snapshots_schedule":"0 12 * * 4",
116
+ "snapshots_schedule_next_at":"2016-07-07T12:00:00Z"
117
+ }
118
+ EOS
119
+ end
120
+
121
+ before do
122
+ stub_request(:post, "http://api.brightbox.dev/1.0/database_servers?account_id=acc-12345")
123
+ .and_return(:status => 202, :body => json_response)
124
+ end
125
+
126
+ it "includes schedule fields in response" do
127
+ expect(Brightbox::DatabaseServer).to receive(:create).with(expected_args).and_call_original
128
+ expect(stdout).to include("snapshots_schedule: 0 12 * * 4")
129
+ expect(stdout).to include("snapshots_schedule_next_at: 2016-07-07T12:00Z")
130
+ expect(stderr).to eql("")
131
+ end
132
+ end
68
133
  end
69
134
  end
@@ -0,0 +1,79 @@
1
+ require "spec_helper"
2
+
3
+ describe "brghtbox sql instances" do
4
+ describe "show" do
5
+ let(:output) { FauxIO.new { Brightbox.run(argv) } }
6
+ let(:stdout) { output.stdout }
7
+ let(:stderr) { output.stderr }
8
+
9
+ before do
10
+ config = config_from_contents(USER_APP_CONFIG_CONTENTS)
11
+ cache_access_token(config, "1234567890")
12
+ end
13
+
14
+ context "when id does not exist" do
15
+ let(:argv) { %w(sql instances show dbs-12345) }
16
+ let(:json_response) do
17
+ "{\"error_name\":\"missing_resource\",\"errors\":[\"Resource not found using supplied identifier\"]}"
18
+ end
19
+
20
+ before do
21
+ stub_request(:get, "http://api.brightbox.dev/1.0/database_servers/dbs-12345?account_id=acc-12345").
22
+ to_return(:status => 404, :body => json_response, :headers => { "Content-Type" => "" })
23
+ end
24
+
25
+ it "reports error" do
26
+ expect(stderr).to include("ERROR: Couldn't find an SQL instance with ID dbs-12345")
27
+ expect(stdout).to be_empty
28
+ end
29
+ end
30
+
31
+ context "when id exists" do
32
+ let(:argv) { %w(sql instances show dbs-12345) }
33
+
34
+ let(:json_response) do
35
+ <<-EOS
36
+ {
37
+ "id":"dbs-12345",
38
+ "resource_type":"database_server",
39
+ "url":"https://api.gb1.brightbox.com/1.0/database_servers/dbs-12345",
40
+ "name":"",
41
+ "description":"",
42
+ "admin_username":"admin",
43
+ "admin_password":null,
44
+ "allow_access":[],
45
+ "database_engine":"mysql",
46
+ "database_version":"5.5",
47
+ "status":"active",
48
+ "maintenance_weekday":0,
49
+ "maintenance_hour":6,
50
+ "snapshots_schedule":"0 16 * * 0",
51
+ "snapshots_schedule_next_at":"2016-07-10T16:00:00Z",
52
+ "created_at":"2016-07-07T12:34:56Z",
53
+ "updated_at":"2016-07-07T12:34:56Z",
54
+ "deleted_at":null,
55
+ "account":{},
56
+ "database_server_type":{},
57
+ "cloud_ips":[],
58
+ "zone":{}
59
+ }
60
+ EOS
61
+ end
62
+
63
+ before do
64
+ stub_request(:get, "http://api.brightbox.dev/1.0/database_servers/dbs-12345?account_id=acc-12345").
65
+ to_return(:status => 200, :body => json_response, :headers => { "Content-Type" => "" })
66
+ end
67
+
68
+ it "simplifies the maintenance window" do
69
+ expect(stdout).to include("maintenance_window: Sunday 06:00 UTC")
70
+ expect(stderr).to be_empty
71
+ end
72
+
73
+ it "includes snapshots schedule fields" do
74
+ expect(stdout).to include("snapshots_schedule: 0 16 * * 0")
75
+ expect(stdout).to include("snapshots_schedule_next_at: 2016-07-10T16:00Z")
76
+ end
77
+ end
78
+ end
79
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "brightbox database-servers" do
3
+ describe "brightbox sql instances" do
4
4
  describe "snapshot" do
5
5
  let(:output) { FauxIO.new { Brightbox.run(argv) } }
6
6
  let(:stdout) { output.stdout }
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+ require "fog/brightbox/models/compute/database_server"
3
+
4
+ describe "brightbox sql instances" do
5
+ describe "update" do
6
+ let(:output) { FauxIO.new { Brightbox.run(argv) } }
7
+ let(:stdout) { output.stdout }
8
+ let(:stderr) { output.stderr }
9
+
10
+ before do
11
+ config = config_from_contents(USER_APP_CONFIG_CONTENTS)
12
+ cache_access_token(config, "44320b29286077c44f14c4efdfed70f63f4a8361")
13
+ end
14
+
15
+ context "--maintenance-weekday=Monday" do
16
+ let(:argv) { %w(sql instances update --maintenance-weekday=Monday dbs-12345) }
17
+ let(:expected_args) { { :maintenance_weekday => "1" } }
18
+
19
+ before do
20
+ stub_request(:get, "http://api.brightbox.dev/1.0/database_servers/dbs-12345?account_id=acc-12345")
21
+ .to_return(:status => 200, :body => '{"id":"dbs-12345","maintenance_weekday":0, "maintenance_hour":6}')
22
+ .to_return(:status => 200,
23
+ :body => '{
24
+ "id":"dbs-12345",
25
+ "maintenance_weekday":1,
26
+ "maintenance_hour":6}')
27
+
28
+ stub_request(:put, "http://api.brightbox.dev/1.0/database_servers/dbs-12345?account_id=acc-12345")
29
+ .with(:body => "{\"maintenance_weekday\":\"1\"}")
30
+ end
31
+
32
+ it "sets custom maintenance window settings" do
33
+ expect(stderr).to eql("Updating dbs-12345\n")
34
+ expect(stdout).to include("dbs-12345")
35
+ end
36
+ end
37
+
38
+ context "--snapshots-schedule='0 12 * * 4'" do
39
+ let(:dbs) { Brightbox::DatabaseServer.find("dbs-12345") }
40
+ let(:argv) { ["sql", "instances", "update", "--snapshots-schedule=0 12 * * 4", "dbs-12345"] }
41
+ let(:expected_args) { { :snapshots_schedule => "0 12 * * 4" } }
42
+
43
+ before do
44
+ stub_request(:get, "http://api.brightbox.dev/1.0/database_servers/dbs-12345?account_id=acc-12345")
45
+ .to_return(:status => 200, :body => '{"id":"dbs-12345","snapshots_schedule":null,"snapshots_schedule_next_at":null}')
46
+ .to_return(:status => 200, :body => '{"id":"dbs-12345","snapshots_schedule":"34 12 * * 4","snapshots_schedule_next_at":"2016-07-07T12:34:56Z"}')
47
+
48
+ stub_request(:put, "http://api.brightbox.dev/1.0/database_servers/dbs-12345?account_id=acc-12345")
49
+ .to_return(:status => 200, :body => '{"id":"dbs-12345","snapshots_schedule":"34 12 * * 4","snapshots_schedule_next_at":"2016-07-07T12:34:56Z"}')
50
+ end
51
+
52
+ it "sets snapshots schedule" do
53
+ expect(Brightbox::DatabaseServer).to receive(:find).and_return(dbs)
54
+ expect(dbs).to receive(:update).with(expected_args).and_call_original
55
+
56
+ expect(stderr).to eq("Updating dbs-12345\n")
57
+ expect(stdout).to include("dbs-12345")
58
+ end
59
+ end
60
+
61
+ context "--remove-snapshots-schedule" do
62
+ let(:dbs) { Brightbox::DatabaseServer.find("dbs-12345") }
63
+ let(:argv) { %w(sql instances update --remove-snapshots-schedule dbs-12345) }
64
+ let(:expected_args) { { :snapshots_schedule => nil } }
65
+
66
+ before do
67
+ stub_request(:get, "http://api.brightbox.dev/1.0/database_servers/dbs-12345?account_id=acc-12345")
68
+ .to_return(:status => 200, :body => '{"id":"dbs-12345","snapshots_schedule":"34 12 * * 4","snapshots_schedule_next_at":"2016-07-07T12:34:56Z"}')
69
+ .to_return(:status => 200, :body => '{"id":"dbs-12345","snapshots_schedule":null,"snapshots_schedule_next_at":null}')
70
+
71
+ stub_request(:put, "http://api.brightbox.dev/1.0/database_servers/dbs-12345?account_id=acc-12345")
72
+ .to_return(:status => 200, :body => '{"id":"dbs-12345","snapshots_schedule":null,"snapshots_schedule_next_at":null}')
73
+ end
74
+
75
+ it "clears snapshots schedule" do
76
+ expect(Brightbox::DatabaseServer).to receive(:find).and_return(dbs)
77
+ expect(dbs).to receive(:update).with(expected_args).and_call_original
78
+
79
+ expect(stderr).to eq("Updating dbs-12345\n")
80
+ expect(stdout).to include("dbs-12345")
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "brightbox database-snapshots" do
3
+ describe "brightbox sql snapshots" do
4
4
  describe "list" do
5
5
  let(:output) { FauxIO.new { Brightbox.run(argv) } }
6
6
  let(:stdout) { output.stdout }
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "brightbox database-snapshots" do
3
+ describe "brightbox sql snapshots" do
4
4
  describe "show" do
5
5
  let(:output) { FauxIO.new { Brightbox.run(argv) } }
6
6
  let(:stdout) { output.stdout }
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe Brightbox::Api, "#created_on" do
4
+ subject(:api_model) { described_class.new(fog_model) }
5
+ let(:fog_model) do
6
+ double id: nil,
7
+ attributes: attrs,
8
+ created_at: attrs[:created_at]
9
+ end
10
+
11
+ context "when initialised with no attributes" do
12
+ let(:attrs) { {} }
13
+
14
+ it { expect(api_model.created_on).to be_nil }
15
+ end
16
+
17
+ context "when initialised with created_at" do
18
+ let(:attrs) { { created_at: Time.utc(2016, 7, 7, 12, 34, 56) } }
19
+
20
+ it { expect(api_model.created_on).to eq("2016-07-07") }
21
+ end
22
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+ require "fog/brightbox/models/compute/database_server"
3
+
4
+ describe Brightbox::DatabaseServer do
5
+
6
+ describe ".clean_arguments" do
7
+ let(:parameters) { Brightbox::DatabaseServer.clean_arguments(arguments) }
8
+
9
+ context "when no arguments" do
10
+ let(:arguments) { {} }
11
+
12
+ it { expect(parameters.keys).to be_empty }
13
+ end
14
+
15
+ context "when --allow-access=10.0.0.0" do
16
+ let(:arguments) { { "allow-access" => "10.0.0.0" } }
17
+
18
+ it { expect(parameters[:allow_access]).to eql(["10.0.0.0"]) }
19
+ end
20
+
21
+ context "when --allow-access=10.0.0.0,11.0.0.0" do
22
+ let(:arguments) { { "allow-access" => "10.0.0.0,11.0.0.0" } }
23
+
24
+ it { expect(parameters[:allow_access]).to eql(%w(10.0.0.0 11.0.0.0)) }
25
+ end
26
+
27
+ context "when --maintenance-weekday=4" do
28
+ let(:arguments) { { "maintenance-weekday" => "4" } }
29
+
30
+ it { expect(parameters[:maintenance_weekday]).to eql("4") }
31
+ end
32
+
33
+ context "when --maintenance-weekday=wednesday" do
34
+ let(:arguments) { { "maintenance-weekday" => "3" } }
35
+
36
+ it { expect(parameters[:maintenance_weekday]).to eql("3") }
37
+ end
38
+
39
+ context "when --maintenance-weekday=" do
40
+ let(:arguments) { { "maintenance-weekday" => "" } }
41
+
42
+ it { expect(parameters[:maintenance_weekday]).to be_nil }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+ require "fog/brightbox/models/compute/database_server"
3
+
4
+ describe Brightbox::DatabaseServer, "#cloud_ips" do
5
+ let(:fog_model) { Fog::Compute::Brightbox::DatabaseServer.new(fog_settings) }
6
+ let(:dbs) { described_class.new(fog_model) }
7
+
8
+ context "when attribute is missing" do
9
+ let(:fog_settings) { {} }
10
+ it { expect(dbs.cloud_ips).to be_empty }
11
+ end
12
+
13
+ context "when attribute is empty" do
14
+ let(:fog_settings) { { cloud_ips: [] } }
15
+ it { expect(dbs.cloud_ips).to be_empty }
16
+ end
17
+
18
+ context "when attribute contains data" do
19
+ let(:cloud_ip) { { id: "cip-12345", public_ip: "10.0.0.10" } }
20
+ let(:fog_settings) { { cloud_ips: [cloud_ip] } }
21
+ it { expect(dbs.cloud_ips).to include(cloud_ip) }
22
+ end
23
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+ require "fog/brightbox/models/compute/database_server"
3
+
4
+ describe Brightbox::DatabaseServer do
5
+
6
+ describe "#maintenance_window" do
7
+ let(:fog_model) { Fog::Compute::Brightbox::DatabaseServer.new(fog_settings) }
8
+ let(:dbs) { Brightbox::DatabaseServer.new(fog_model) }
9
+
10
+ context "when default values" do
11
+ let(:fog_settings) do
12
+ {
13
+ "maintenance_weekday" => 0,
14
+ "maintenance_hour" => 6
15
+ }
16
+ end
17
+
18
+ it "returns 'Sunday 06:00 UTC'" do
19
+ expect(dbs.maintenance_window).to eql("Sunday 06:00 UTC")
20
+ end
21
+ end
22
+
23
+ context "when non standard values" do
24
+ let(:fog_settings) do
25
+ {
26
+ "maintenance_weekday" => 6,
27
+ "maintenance_hour" => 23
28
+ }
29
+ end
30
+
31
+ it "returns 'Saturday 23:00 UTC'" do
32
+ expect(dbs.maintenance_window).to eql("Saturday 23:00 UTC")
33
+ end
34
+ end
35
+
36
+ context "when not initialised" do
37
+ let(:fog_settings) { {} }
38
+
39
+ it "returns nil" do
40
+ expect(dbs.maintenance_window).to be_nil
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightbox-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Leach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-brightbox
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.1
19
+ version: 0.11.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: 0.10.1
26
+ version: 0.11.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: gli
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -482,17 +482,6 @@ files:
482
482
  - spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/does_not_error.yml
483
483
  - spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/requests_access_tokens.yml
484
484
  - spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/sets_up_the_config.yml
485
- - spec/cassettes/brightbox_database-servers/create/--allow-access_10_0_0_0/correctly_sends_API_parameters.yml
486
- - spec/cassettes/brightbox_database-servers/create/--allow-access_srv-12345_grp-12345/correctly_sends_API_parameters.yml
487
- - spec/cassettes/brightbox_database-servers/create/--engine_mysql/correctly_sends_API_parameters.yml
488
- - spec/cassettes/brightbox_database-servers/create/--engine_mysql_--engine-version_5_6/correctly_sends_API_parameters.yml
489
- - spec/cassettes/brightbox_database-servers/create/without_arguments/reports_the_new_admin_password.yml
490
- - spec/cassettes/brightbox_database-servers/create/without_arguments/reports_the_new_admin_username.yml
491
- - spec/cassettes/brightbox_database-servers/snapshot/when_database_server_active/correctly_sends_API_parameters.yml
492
- - spec/cassettes/brightbox_database-servers/snapshot/when_database_server_can_not_be_snapshotted/reports_an_error_to_the_user.yml
493
- - spec/cassettes/brightbox_database-snapshots/list/when_resources_are_available/does_not_output_to_stderr.yml
494
- - spec/cassettes/brightbox_database-snapshots/list/when_resources_are_available/outputs_table_details_to_stdout.yml
495
- - spec/cassettes/brightbox_database-snapshots/show/when_resource_exists/does_not_output_to_stderr.yml
496
485
  - spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/does_not_error.yml
497
486
  - spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/does_not_prompt_to_rerun_the_command.yml
498
487
  - spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/prompts_for_the_password.yml
@@ -517,6 +506,17 @@ files:
517
506
  - spec/cassettes/brightbox_login/when_no_password_is_given/prompts_for_the_password.yml
518
507
  - spec/cassettes/brightbox_login/when_no_password_is_given/requests_access_tokens.yml
519
508
  - spec/cassettes/brightbox_login/when_no_password_is_given/sets_up_the_config.yml
509
+ - spec/cassettes/brightbox_sql_instances/create/--allow-access_10_0_0_0/correctly_sends_API_parameters.yml
510
+ - spec/cassettes/brightbox_sql_instances/create/--allow-access_srv-12345_grp-12345/correctly_sends_API_parameters.yml
511
+ - spec/cassettes/brightbox_sql_instances/create/--engine_mysql/correctly_sends_API_parameters.yml
512
+ - spec/cassettes/brightbox_sql_instances/create/--engine_mysql_--engine-version_5_6/correctly_sends_API_parameters.yml
513
+ - spec/cassettes/brightbox_sql_instances/create/without_arguments/reports_the_new_admin_password.yml
514
+ - spec/cassettes/brightbox_sql_instances/create/without_arguments/reports_the_new_admin_username.yml
515
+ - spec/cassettes/brightbox_sql_instances/snapshot/when_database_server_active/correctly_sends_API_parameters.yml
516
+ - spec/cassettes/brightbox_sql_instances/snapshot/when_database_server_can_not_be_snapshotted/reports_an_error_to_the_user.yml
517
+ - spec/cassettes/brightbox_sql_snapshots/list/when_resources_are_available/does_not_output_to_stderr.yml
518
+ - spec/cassettes/brightbox_sql_snapshots/list/when_resources_are_available/outputs_table_details_to_stdout.yml
519
+ - spec/cassettes/brightbox_sql_snapshots/show/when_resource_exists/does_not_output_to_stderr.yml
520
520
  - spec/commands/accounts/default_spec.rb
521
521
  - spec/commands/accounts/list_spec.rb
522
522
  - spec/commands/accounts/reset_ftp_password_spec.rb
@@ -584,7 +584,9 @@ files:
584
584
  - spec/commands/servers/update_spec.rb
585
585
  - spec/commands/sql/instances/create_spec.rb
586
586
  - spec/commands/sql/instances/locking_spec.rb
587
+ - spec/commands/sql/instances/show_spec.rb
587
588
  - spec/commands/sql/instances/snapshot_spec.rb
589
+ - spec/commands/sql/instances/update_spec.rb
588
590
  - spec/commands/sql/snapshots/list_spec.rb
589
591
  - spec/commands/sql/snapshots/locking_spec.rb
590
592
  - spec/commands/sql/snapshots/show_spec.rb
@@ -612,6 +614,7 @@ files:
612
614
  - spec/unit/brightbox/account/get_spec.rb
613
615
  - spec/unit/brightbox/account_spec.rb
614
616
  - spec/unit/brightbox/api/conn_spec.rb
617
+ - spec/unit/brightbox/api/created_on_spec.rb
615
618
  - spec/unit/brightbox/api/find_spec.rb
616
619
  - spec/unit/brightbox/api/fog_model_spec.rb
617
620
  - spec/unit/brightbox/api/klass_name_spec.rb
@@ -663,6 +666,9 @@ files:
663
666
  - spec/unit/brightbox/config/user_application/valid_spec.rb
664
667
  - spec/unit/brightbox/config/user_application_spec.rb
665
668
  - spec/unit/brightbox/connection_manager/fetch_connection_spec.rb
669
+ - spec/unit/brightbox/database_server/clean_arguments_spec.rb
670
+ - spec/unit/brightbox/database_server/cloud_ips_spec.rb
671
+ - spec/unit/brightbox/database_server/maintenance_window_spec.rb
666
672
  - spec/unit/brightbox/database_server_spec.rb
667
673
  - spec/unit/brightbox/database_snapshot_spec.rb
668
674
  - spec/unit/brightbox/database_type_spec.rb
@@ -834,17 +840,6 @@ test_files:
834
840
  - spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/does_not_error.yml
835
841
  - spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/requests_access_tokens.yml
836
842
  - spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/sets_up_the_config.yml
837
- - spec/cassettes/brightbox_database-servers/create/--allow-access_10_0_0_0/correctly_sends_API_parameters.yml
838
- - spec/cassettes/brightbox_database-servers/create/--allow-access_srv-12345_grp-12345/correctly_sends_API_parameters.yml
839
- - spec/cassettes/brightbox_database-servers/create/--engine_mysql/correctly_sends_API_parameters.yml
840
- - spec/cassettes/brightbox_database-servers/create/--engine_mysql_--engine-version_5_6/correctly_sends_API_parameters.yml
841
- - spec/cassettes/brightbox_database-servers/create/without_arguments/reports_the_new_admin_password.yml
842
- - spec/cassettes/brightbox_database-servers/create/without_arguments/reports_the_new_admin_username.yml
843
- - spec/cassettes/brightbox_database-servers/snapshot/when_database_server_active/correctly_sends_API_parameters.yml
844
- - spec/cassettes/brightbox_database-servers/snapshot/when_database_server_can_not_be_snapshotted/reports_an_error_to_the_user.yml
845
- - spec/cassettes/brightbox_database-snapshots/list/when_resources_are_available/does_not_output_to_stderr.yml
846
- - spec/cassettes/brightbox_database-snapshots/list/when_resources_are_available/outputs_table_details_to_stdout.yml
847
- - spec/cassettes/brightbox_database-snapshots/show/when_resource_exists/does_not_output_to_stderr.yml
848
843
  - spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/does_not_error.yml
849
844
  - spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/does_not_prompt_to_rerun_the_command.yml
850
845
  - spec/cassettes/brightbox_login/when_alternative_client_credentials_are_given/prompts_for_the_password.yml
@@ -869,6 +864,17 @@ test_files:
869
864
  - spec/cassettes/brightbox_login/when_no_password_is_given/prompts_for_the_password.yml
870
865
  - spec/cassettes/brightbox_login/when_no_password_is_given/requests_access_tokens.yml
871
866
  - spec/cassettes/brightbox_login/when_no_password_is_given/sets_up_the_config.yml
867
+ - spec/cassettes/brightbox_sql_instances/create/--allow-access_10_0_0_0/correctly_sends_API_parameters.yml
868
+ - spec/cassettes/brightbox_sql_instances/create/--allow-access_srv-12345_grp-12345/correctly_sends_API_parameters.yml
869
+ - spec/cassettes/brightbox_sql_instances/create/--engine_mysql/correctly_sends_API_parameters.yml
870
+ - spec/cassettes/brightbox_sql_instances/create/--engine_mysql_--engine-version_5_6/correctly_sends_API_parameters.yml
871
+ - spec/cassettes/brightbox_sql_instances/create/without_arguments/reports_the_new_admin_password.yml
872
+ - spec/cassettes/brightbox_sql_instances/create/without_arguments/reports_the_new_admin_username.yml
873
+ - spec/cassettes/brightbox_sql_instances/snapshot/when_database_server_active/correctly_sends_API_parameters.yml
874
+ - spec/cassettes/brightbox_sql_instances/snapshot/when_database_server_can_not_be_snapshotted/reports_an_error_to_the_user.yml
875
+ - spec/cassettes/brightbox_sql_snapshots/list/when_resources_are_available/does_not_output_to_stderr.yml
876
+ - spec/cassettes/brightbox_sql_snapshots/list/when_resources_are_available/outputs_table_details_to_stdout.yml
877
+ - spec/cassettes/brightbox_sql_snapshots/show/when_resource_exists/does_not_output_to_stderr.yml
872
878
  - spec/commands/accounts/default_spec.rb
873
879
  - spec/commands/accounts/list_spec.rb
874
880
  - spec/commands/accounts/reset_ftp_password_spec.rb
@@ -936,7 +942,9 @@ test_files:
936
942
  - spec/commands/servers/update_spec.rb
937
943
  - spec/commands/sql/instances/create_spec.rb
938
944
  - spec/commands/sql/instances/locking_spec.rb
945
+ - spec/commands/sql/instances/show_spec.rb
939
946
  - spec/commands/sql/instances/snapshot_spec.rb
947
+ - spec/commands/sql/instances/update_spec.rb
940
948
  - spec/commands/sql/snapshots/list_spec.rb
941
949
  - spec/commands/sql/snapshots/locking_spec.rb
942
950
  - spec/commands/sql/snapshots/show_spec.rb
@@ -964,6 +972,7 @@ test_files:
964
972
  - spec/unit/brightbox/account/get_spec.rb
965
973
  - spec/unit/brightbox/account_spec.rb
966
974
  - spec/unit/brightbox/api/conn_spec.rb
975
+ - spec/unit/brightbox/api/created_on_spec.rb
967
976
  - spec/unit/brightbox/api/find_spec.rb
968
977
  - spec/unit/brightbox/api/fog_model_spec.rb
969
978
  - spec/unit/brightbox/api/klass_name_spec.rb
@@ -1015,6 +1024,9 @@ test_files:
1015
1024
  - spec/unit/brightbox/config/user_application/valid_spec.rb
1016
1025
  - spec/unit/brightbox/config/user_application_spec.rb
1017
1026
  - spec/unit/brightbox/connection_manager/fetch_connection_spec.rb
1027
+ - spec/unit/brightbox/database_server/clean_arguments_spec.rb
1028
+ - spec/unit/brightbox/database_server/cloud_ips_spec.rb
1029
+ - spec/unit/brightbox/database_server/maintenance_window_spec.rb
1018
1030
  - spec/unit/brightbox/database_server_spec.rb
1019
1031
  - spec/unit/brightbox/database_snapshot_spec.rb
1020
1032
  - spec/unit/brightbox/database_type_spec.rb