fog-brightbox 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/lib/fog/brightbox/compute.rb +10 -0
  4. data/lib/fog/brightbox/compute/resource_locking.rb +27 -0
  5. data/lib/fog/brightbox/models/compute/database_server.rb +3 -0
  6. data/lib/fog/brightbox/models/compute/database_snapshot.rb +3 -0
  7. data/lib/fog/brightbox/models/compute/image.rb +3 -0
  8. data/lib/fog/brightbox/models/compute/load_balancer.rb +2 -0
  9. data/lib/fog/brightbox/models/compute/server.rb +2 -2
  10. data/lib/fog/brightbox/requests/compute/lock_resource_database_server.rb +19 -0
  11. data/lib/fog/brightbox/requests/compute/lock_resource_database_snapshot.rb +19 -0
  12. data/lib/fog/brightbox/requests/compute/lock_resource_image.rb +19 -0
  13. data/lib/fog/brightbox/requests/compute/lock_resource_load_balancer.rb +19 -0
  14. data/lib/fog/brightbox/requests/compute/lock_resource_server.rb +19 -0
  15. data/lib/fog/brightbox/requests/compute/unlock_resource_database_server.rb +19 -0
  16. data/lib/fog/brightbox/requests/compute/unlock_resource_database_snapshot.rb +19 -0
  17. data/lib/fog/brightbox/requests/compute/unlock_resource_image.rb +19 -0
  18. data/lib/fog/brightbox/requests/compute/unlock_resource_load_balancer.rb +19 -0
  19. data/lib/fog/brightbox/requests/compute/unlock_resource_server.rb +19 -0
  20. data/lib/fog/brightbox/version.rb +1 -1
  21. data/spec/fog/compute/brightbox/database_server_spec.rb +1 -0
  22. data/spec/fog/compute/brightbox/database_snapshot_spec.rb +1 -0
  23. data/spec/fog/compute/brightbox/image_spec.rb +1 -0
  24. data/spec/fog/compute/brightbox/load_balancer_spec.rb +1 -0
  25. data/spec/fog/compute/brightbox/server_spec.rb +1 -0
  26. data/spec/model_setup.rb +22 -0
  27. data/spec/spec_helper.rb +1 -0
  28. data/spec/supports_resource_locking.rb +41 -0
  29. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 436790875e6a2537f3df4c8eb055433d587a4698
4
- data.tar.gz: a4bd9e31309af1881961aac487d3731fc0007d82
3
+ metadata.gz: 3ba0fd5a2af49de6bfd1c985302496ca96f0368c
4
+ data.tar.gz: 59f4dec412be2a7f9bd2f77585e4c045f62741a0
5
5
  SHA512:
6
- metadata.gz: 037b0733e2c70416434de4396101e13ab9aede47ae11ee6d6b3ea54e149fdfa2bfe3c056479e6a28ae9d0d6d96344c17497ecd7ebac0f2647788848703fbf0e9
7
- data.tar.gz: cea10f7f2d5756b10d31f4b406445d57f05990111ce1e16d698625e3f301927c2c799edfab294b17f5759dbbb0abf237d3ae4c8835ff6cc949db3f1037988554
6
+ metadata.gz: 6df22c1e489650cbf363a0c12f1a382235293108dc145ca089fb996d1720fed5a0e0de11e0120374102d75c4980541db203f681169f8af40ec0aa0729250017a
7
+ data.tar.gz: 8c186b06909f62c6d395a4ce85bfaa190ece428d761859dee413bc1b883ae4145282e15bb114d330bdadbad57ef495d30dde860d68c98b520b0915af371c929b
@@ -1,3 +1,14 @@
1
+ ### 0.2.0 / 2014-08-07
2
+
3
+ Enhancements:
4
+
5
+ * Add resource locks to prevent accidental deleting of the following resources:
6
+ * Database servers
7
+ * Database snapshots
8
+ * Images
9
+ * Load balancers
10
+ * Servers
11
+
1
12
  ### 0.1.1 / 2014-06-26
2
13
 
3
14
  Bug fixes:
@@ -137,6 +137,11 @@ module Fog
137
137
  request :list_users
138
138
  request :list_user_collaborations
139
139
  request :list_zones
140
+ request :lock_resource_database_server
141
+ request :lock_resource_database_snapshot
142
+ request :lock_resource_image
143
+ request :lock_resource_load_balancer
144
+ request :lock_resource_server
140
145
  request :map_cloud_ip
141
146
  request :move_servers_server_group
142
147
  request :reject_user_collaboration
@@ -156,6 +161,11 @@ module Fog
156
161
  request :snapshot_server
157
162
  request :start_server
158
163
  request :stop_server
164
+ request :unlock_resource_database_server
165
+ request :unlock_resource_database_snapshot
166
+ request :unlock_resource_image
167
+ request :unlock_resource_load_balancer
168
+ request :unlock_resource_server
159
169
  request :unmap_cloud_ip
160
170
  request :update_account
161
171
  request :update_api_client
@@ -0,0 +1,27 @@
1
+ module ResourceLocking
2
+ def locked?
3
+ if attributes.key?("locked") || attributes.key?(:locked)
4
+ attributes["locked"] || attributes[:locked] || false
5
+ else
6
+ false
7
+ end
8
+ end
9
+
10
+ def lock!
11
+ locking_request(:lock)
12
+ end
13
+
14
+ def unlock!
15
+ locking_request(:unlock)
16
+ end
17
+
18
+ private
19
+
20
+ def locking_request(lock_setting)
21
+ requires :identity
22
+
23
+ data = service.send(:"#{lock_setting}_resource_#{resource_name}", identity)
24
+ merge_attributes(data)
25
+ true
26
+ end
27
+ end
@@ -1,9 +1,12 @@
1
1
  require "fog/brightbox/model"
2
+ require "fog/brightbox/compute/resource_locking"
2
3
 
3
4
  module Fog
4
5
  module Compute
5
6
  class Brightbox
6
7
  class DatabaseServer < Fog::Brightbox::Model
8
+ include ResourceLocking
9
+
7
10
  identity :id
8
11
  attribute :url
9
12
  attribute :resource_type
@@ -1,9 +1,12 @@
1
1
  require "fog/brightbox/model"
2
+ require "fog/brightbox/compute/resource_locking"
2
3
 
3
4
  module Fog
4
5
  module Compute
5
6
  class Brightbox
6
7
  class DatabaseSnapshot < Fog::Brightbox::Model
8
+ include ResourceLocking
9
+
7
10
  identity :id
8
11
  attribute :url
9
12
  attribute :resource_type
@@ -1,9 +1,12 @@
1
1
  require "fog/brightbox/model"
2
+ require "fog/brightbox/compute/resource_locking"
2
3
 
3
4
  module Fog
4
5
  module Compute
5
6
  class Brightbox
6
7
  class Image < Fog::Brightbox::Model
8
+ include ResourceLocking
9
+
7
10
  identity :id
8
11
  attribute :url
9
12
  attribute :resource_type
@@ -1,9 +1,11 @@
1
1
  require "fog/brightbox/model"
2
+ require "fog/brightbox/compute/resource_locking"
2
3
 
3
4
  module Fog
4
5
  module Compute
5
6
  class Brightbox
6
7
  class LoadBalancer < Fog::Brightbox::Model
8
+ include ResourceLocking
7
9
 
8
10
  identity :id
9
11
  attribute :url
@@ -1,11 +1,12 @@
1
1
  require "fog/compute/models/server"
2
- require "fog/brightbox/model_helper"
2
+ require "fog/brightbox/compute/resource_locking"
3
3
 
4
4
  module Fog
5
5
  module Compute
6
6
  class Brightbox
7
7
  class Server < Fog::Compute::Server
8
8
  include Fog::Brightbox::ModelHelper
9
+ include ResourceLocking
9
10
 
10
11
  identity :id
11
12
  attribute :resource_type
@@ -212,7 +213,6 @@ module Fog
212
213
  end
213
214
  end
214
215
  end
215
-
216
216
  end
217
217
  end
218
218
  end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#database_server_lock_resource_database_server
10
+ #
11
+ def lock_resource_database_server(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/database_servers/#{identifier}/lock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#database_snapshot_lock_resource_database_snapshot
10
+ #
11
+ def lock_resource_database_snapshot(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/database_snapshots/#{identifier}/lock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#image_lock_resource_image
10
+ #
11
+ def lock_resource_image(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/images/#{identifier}/lock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#load_balancer_lock_resource_load_balancer
10
+ #
11
+ def lock_resource_load_balancer(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/load_balancers/#{identifier}/lock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#server_lock_resource_server
10
+ #
11
+ def lock_resource_server(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/servers/#{identifier}/lock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#database_server_unlock_resource_database_server
10
+ #
11
+ def unlock_resource_database_server(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/database_servers/#{identifier}/unlock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#database_snapshot_unlock_resource_database_snapshot
10
+ #
11
+ def unlock_resource_database_snapshot(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/database_snapshots/#{identifier}/unlock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#image_unlock_resource_image
10
+ #
11
+ def unlock_resource_image(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/images/#{identifier}/unlock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#load_balancer_unlock_resource_load_balancer
10
+ #
11
+ def unlock_resource_load_balancer(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/load_balancers/#{identifier}/unlock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Brightbox
4
+ class Real
5
+ # @param [String] identifier Unique reference to identify the resource
6
+ #
7
+ # @return [Hash] if successful Hash version of JSON object
8
+ #
9
+ # @see https://api.gb1.brightbox.com/1.0/#server_unlock_resource_server
10
+ #
11
+ def unlock_resource_server(identifier)
12
+ return nil if identifier.nil? || identifier == ""
13
+ wrapped_request("put", "/1.0/servers/#{identifier}/unlock_resource", [200])
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Brightbox
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require "fog/brightbox/models/compute/database_server"
3
3
 
4
4
  describe Fog::Compute::Brightbox::DatabaseServer do
5
5
  include ModelSetup
6
+ include SupportsResourceLocking
6
7
 
7
8
  subject { service.database_servers.new }
8
9
 
@@ -3,6 +3,7 @@ require "fog/brightbox/models/compute/database_snapshot"
3
3
 
4
4
  describe Fog::Compute::Brightbox::DatabaseSnapshot do
5
5
  include ModelSetup
6
+ include SupportsResourceLocking
6
7
 
7
8
  subject { service.database_snapshots.new }
8
9
 
@@ -3,6 +3,7 @@ require "fog/brightbox/models/compute/image"
3
3
 
4
4
  describe Fog::Compute::Brightbox::Image do
5
5
  include ModelSetup
6
+ include SupportsResourceLocking
6
7
 
7
8
  subject { service.images.new }
8
9
 
@@ -3,6 +3,7 @@ require "fog/brightbox/models/compute/load_balancer"
3
3
 
4
4
  describe Fog::Compute::Brightbox::LoadBalancer do
5
5
  include ModelSetup
6
+ include SupportsResourceLocking
6
7
 
7
8
  subject { service.load_balancers.new }
8
9
 
@@ -3,6 +3,7 @@ require "fog/brightbox/models/compute/server"
3
3
 
4
4
  describe Fog::Compute::Brightbox::Server do
5
5
  include ModelSetup
6
+ include SupportsResourceLocking
6
7
 
7
8
  subject { service.servers.new }
8
9
 
@@ -0,0 +1,22 @@
1
+ module ModelSetup
2
+ def self.included(base)
3
+ base.class_eval do
4
+ let(:configuration) do
5
+ {
6
+ :brightbox_auth_url => "http://localhost",
7
+ :brightbox_api_url => "http://localhost",
8
+ :brightbox_client_id => "",
9
+ :brightbox_secret => "",
10
+ :brightbox_username => "",
11
+ :brightbox_password => "",
12
+ :brightbox_account => "",
13
+ :brightbox_default_image => "img-test",
14
+ :brightbox_access_token => "FAKECACHEDTOKEN"
15
+ }
16
+ end
17
+
18
+ let(:config) { Fog::Brightbox::Config.new(configuration) }
19
+ let(:service) { Fog::Compute::Brightbox.new(config) }
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,4 @@
1
1
  require "minitest/autorun"
2
2
  require "fog/brightbox"
3
3
  require "model_helper"
4
+ require "supports_resource_locking"
@@ -0,0 +1,41 @@
1
+ require "webmock/minitest"
2
+
3
+ module SupportsResourceLocking
4
+ def self.included(base)
5
+ base.class_eval do
6
+ let(:collection_name) { subject.collection_name }
7
+
8
+ def test_responds_to_locked
9
+ assert_respond_to subject, :locked?
10
+ end
11
+
12
+ def test_responds_to_lock
13
+ assert_respond_to subject, :lock!
14
+ end
15
+
16
+ def test_lock_makes_request
17
+ skip if RUBY_VERSION < "1.9"
18
+
19
+ subject.id = "tst-12345"
20
+
21
+ stub_request(:put, "http://localhost/1.0/#{collection_name}/tst-12345/lock_resource?account_id=").to_return(:status => 200, :body => "{}", :headers => {})
22
+
23
+ subject.lock!
24
+ end
25
+
26
+ def test_responds_to_unlock
27
+ assert_respond_to subject, :unlock!
28
+ end
29
+
30
+ def test_unlock_makes_request
31
+ skip if RUBY_VERSION < "1.9"
32
+
33
+ subject.id = "tst-12345"
34
+
35
+ stub_request(:put, "http://localhost/1.0/#{collection_name}/tst-12345/unlock_resource?account_id=").to_return(:status => 200, :body => "{}", :headers => {})
36
+
37
+ subject.unlock!
38
+ end
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-brightbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Thornthwaite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -142,6 +142,7 @@ files:
142
142
  - lib/fog/brightbox/compute.rb
143
143
  - lib/fog/brightbox/compute/config.rb
144
144
  - lib/fog/brightbox/compute/image_selector.rb
145
+ - lib/fog/brightbox/compute/resource_locking.rb
145
146
  - lib/fog/brightbox/compute/shared.rb
146
147
  - lib/fog/brightbox/config.rb
147
148
  - lib/fog/brightbox/core.rb
@@ -255,6 +256,11 @@ files:
255
256
  - lib/fog/brightbox/requests/compute/list_user_collaborations.rb
256
257
  - lib/fog/brightbox/requests/compute/list_users.rb
257
258
  - lib/fog/brightbox/requests/compute/list_zones.rb
259
+ - lib/fog/brightbox/requests/compute/lock_resource_database_server.rb
260
+ - lib/fog/brightbox/requests/compute/lock_resource_database_snapshot.rb
261
+ - lib/fog/brightbox/requests/compute/lock_resource_image.rb
262
+ - lib/fog/brightbox/requests/compute/lock_resource_load_balancer.rb
263
+ - lib/fog/brightbox/requests/compute/lock_resource_server.rb
258
264
  - lib/fog/brightbox/requests/compute/map_cloud_ip.rb
259
265
  - lib/fog/brightbox/requests/compute/move_servers_server_group.rb
260
266
  - lib/fog/brightbox/requests/compute/reject_user_collaboration.rb
@@ -273,6 +279,11 @@ files:
273
279
  - lib/fog/brightbox/requests/compute/snapshot_server.rb
274
280
  - lib/fog/brightbox/requests/compute/start_server.rb
275
281
  - lib/fog/brightbox/requests/compute/stop_server.rb
282
+ - lib/fog/brightbox/requests/compute/unlock_resource_database_server.rb
283
+ - lib/fog/brightbox/requests/compute/unlock_resource_database_snapshot.rb
284
+ - lib/fog/brightbox/requests/compute/unlock_resource_image.rb
285
+ - lib/fog/brightbox/requests/compute/unlock_resource_load_balancer.rb
286
+ - lib/fog/brightbox/requests/compute/unlock_resource_server.rb
276
287
  - lib/fog/brightbox/requests/compute/unmap_cloud_ip.rb
277
288
  - lib/fog/brightbox/requests/compute/update_account.rb
278
289
  - lib/fog/brightbox/requests/compute/update_api_client.rb
@@ -311,7 +322,9 @@ files:
311
322
  - spec/fog/compute/brightbox/zone_spec.rb
312
323
  - spec/fog/compute/brightbox_spec.rb
313
324
  - spec/model_helper.rb
325
+ - spec/model_setup.rb
314
326
  - spec/spec_helper.rb
327
+ - spec/supports_resource_locking.rb
315
328
  homepage: ''
316
329
  licenses:
317
330
  - MIT
@@ -360,4 +373,7 @@ test_files:
360
373
  - spec/fog/compute/brightbox/zone_spec.rb
361
374
  - spec/fog/compute/brightbox_spec.rb
362
375
  - spec/model_helper.rb
376
+ - spec/model_setup.rb
363
377
  - spec/spec_helper.rb
378
+ - spec/supports_resource_locking.rb
379
+ has_rdoc: