droplet_kit 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/droplet_kit.gemspec +1 -1
- data/lib/droplet_kit.rb +4 -0
- data/lib/droplet_kit/mappings/droplet_mapping.rb +1 -0
- data/lib/droplet_kit/mappings/volume_mapping.rb +21 -0
- data/lib/droplet_kit/models/droplet.rb +1 -0
- data/lib/droplet_kit/models/volume.rb +11 -0
- data/lib/droplet_kit/resources/volume_action_resource.rb +44 -0
- data/lib/droplet_kit/resources/volume_resource.rb +30 -0
- data/lib/droplet_kit/version.rb +1 -1
- data/spec/fixtures/volume_actions/all.json +41 -0
- data/spec/fixtures/volume_actions/attach.json +34 -0
- data/spec/fixtures/volume_actions/detach.json +34 -0
- data/spec/fixtures/volume_actions/find.json +34 -0
- data/spec/fixtures/volumes/all.json +41 -0
- data/spec/fixtures/volumes/create.json +34 -0
- data/spec/fixtures/volumes/find.json +34 -0
- data/spec/lib/droplet_kit/resources/volume_action_resource_spec.rb +126 -0
- data/spec/lib/droplet_kit/resources/volume_resource_spec.rb +79 -0
- metadata +26 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d84cca0ff01969f160664546b907f2751a96d8b
|
4
|
+
data.tar.gz: ddc4e60f97ce4f43568f8138cbe5eca43eddf446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2405189c82ef1c755d6afe508b90eab21b65df3c504c19c68b7ea19974b00126ae5efa57519689608a1d0b44f609749fa57d874889b5312145d31ea8bc0d4148
|
7
|
+
data.tar.gz: d986af0561cf005c41a6a11f902020785c895c8d3414275b8c7d476da83844db15e6d094637875490b98575d110feab10c19db82ab525e831c4118851c9b1029
|
data/README.md
CHANGED
@@ -272,6 +272,27 @@ Actions supported:
|
|
272
272
|
* `client.floating_ip_actions.assign(ip: floating_ip.ip, droplet_id: droplet.id)`
|
273
273
|
* `client.floating_ip_actions.unassign(ip: floating_ip.ip)`
|
274
274
|
|
275
|
+
## Volume resource
|
276
|
+
|
277
|
+
client = DropletKit::Client.new(access_token: 'TOKEN')
|
278
|
+
client.volumes #=> DropletKit::VolumeResource
|
279
|
+
|
280
|
+
Actions supported:
|
281
|
+
|
282
|
+
* `client.volumes.all()`
|
283
|
+
* `client.volumes.find(id: 'id')`
|
284
|
+
* `client.volumes.create(volume)`
|
285
|
+
* `client.volumes.delete(id: 'id')`
|
286
|
+
|
287
|
+
## Volume Action resource
|
288
|
+
|
289
|
+
client = DropletKit::Client.new(access_token: 'TOKEN')
|
290
|
+
client.volume_actions #=> DropletKit::VolumeActionResource
|
291
|
+
|
292
|
+
Actions supported:
|
293
|
+
|
294
|
+
* `client.volume_actions.attach(volume_id: volume.id, droplet_id: droplet.id, region: droplet.region.slug)`
|
295
|
+
* `client.volume_actions.detach(volume_id: volume.id, droplet_id: droplet.id, region: droplet.region.slug)`
|
275
296
|
|
276
297
|
## Contributing
|
277
298
|
|
data/droplet_kit.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency "activesupport", '> 3.0', '< 5.1'
|
27
27
|
spec.add_dependency "faraday", '~> 0.9.1'
|
28
28
|
|
29
|
-
spec.add_development_dependency "bundler", "
|
29
|
+
spec.add_development_dependency "bundler", ">= 1.11.0"
|
30
30
|
spec.add_development_dependency "rake"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0.0"
|
32
32
|
spec.add_development_dependency "pry"
|
data/lib/droplet_kit.rb
CHANGED
@@ -29,6 +29,7 @@ module DropletKit
|
|
29
29
|
autoload :Tag, 'droplet_kit/models/tag'
|
30
30
|
autoload :TaggedResources, 'droplet_kit/models/tagged_resources'
|
31
31
|
autoload :TaggedDropletsResources, 'droplet_kit/models/tagged_droplets_resources'
|
32
|
+
autoload :Volume, 'droplet_kit/models/volume'
|
32
33
|
|
33
34
|
# Resources
|
34
35
|
autoload :DropletResource, 'droplet_kit/resources/droplet_resource'
|
@@ -46,6 +47,8 @@ module DropletKit
|
|
46
47
|
autoload :FloatingIpResource, 'droplet_kit/resources/floating_ip_resource'
|
47
48
|
autoload :FloatingIpActionResource, 'droplet_kit/resources/floating_ip_action_resource'
|
48
49
|
autoload :TagResource, 'droplet_kit/resources/tag_resource'
|
50
|
+
autoload :VolumeResource, 'droplet_kit/resources/volume_resource'
|
51
|
+
autoload :VolumeActionResource, 'droplet_kit/resources/volume_action_resource'
|
49
52
|
|
50
53
|
# JSON Maps
|
51
54
|
autoload :DropletMapping, 'droplet_kit/mappings/droplet_mapping'
|
@@ -69,6 +72,7 @@ module DropletKit
|
|
69
72
|
autoload :TagMapping, 'droplet_kit/mappings/tag_mapping'
|
70
73
|
autoload :TaggedResourcesMapping, 'droplet_kit/mappings/tagged_resources_mapping'
|
71
74
|
autoload :TaggedDropletsResourcesMapping, 'droplet_kit/mappings/tagged_droplets_resources_mapping'
|
75
|
+
autoload :VolumeMapping, 'droplet_kit/mappings/volume_mapping'
|
72
76
|
|
73
77
|
# Utils
|
74
78
|
autoload :PaginatedResource, 'droplet_kit/paginated_resource'
|
@@ -29,6 +29,7 @@ module DropletKit
|
|
29
29
|
# Create properties arent quite the same
|
30
30
|
property :name, scopes: [:create] # "Regular" create
|
31
31
|
property :names, scopes: [:create] # Multiple create
|
32
|
+
property :volumes, scopes: [:create] # Create with volumes
|
32
33
|
property :region, scopes: [:create]
|
33
34
|
property :size, scopes: [:create]
|
34
35
|
property :image, scopes: [:create]
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DropletKit
|
2
|
+
class VolumeMapping
|
3
|
+
include Kartograph::DSL
|
4
|
+
|
5
|
+
kartograph do
|
6
|
+
mapping Volume
|
7
|
+
root_key plural: 'volumes', singular: 'volume', scopes: [:read]
|
8
|
+
|
9
|
+
property :id, scopes: [:read]
|
10
|
+
property :region, scopes: [:read], include: RegionMapping
|
11
|
+
property :droplet_ids, scopes: [:read]
|
12
|
+
property :name, scopes: [:read, :create]
|
13
|
+
property :description, scopes: [:read, :create]
|
14
|
+
property :size_gigabytes, scopes: [:read, :create]
|
15
|
+
property :created_at, scopes: [:read]
|
16
|
+
|
17
|
+
property :region, scopes: [:create]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module DropletKit
|
2
|
+
class VolumeActionResource < ResourceKit::Resource
|
3
|
+
resources do
|
4
|
+
default_handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
|
5
|
+
|
6
|
+
action :attach, 'POST /v2/volumes/:volume_id/actions' do
|
7
|
+
body do |hash|
|
8
|
+
{
|
9
|
+
type: 'attach',
|
10
|
+
droplet_id: hash[:droplet_id],
|
11
|
+
volume_id: hash[:volume_id], # seems redundant to the id in the url?
|
12
|
+
region: hash[:region], # seems redundant - inferred from the droplet?
|
13
|
+
}.to_json
|
14
|
+
end
|
15
|
+
handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
|
16
|
+
end
|
17
|
+
|
18
|
+
action :detach, 'POST /v2/volumes/:volume_id/actions' do
|
19
|
+
body do |hash|
|
20
|
+
{
|
21
|
+
type: 'detach',
|
22
|
+
droplet_id: hash[:droplet_id],
|
23
|
+
volume_id: hash[:volume_id], # seems redundant to the id in the url?
|
24
|
+
region: hash[:region], # seems redundant - inferred from the droplet?
|
25
|
+
}.to_json
|
26
|
+
end
|
27
|
+
handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
|
28
|
+
end
|
29
|
+
|
30
|
+
action :find, 'GET /v2/volumes/:volume_id/actions/:id' do
|
31
|
+
handler(200) { |response| ActionMapping.extract_single(response.body, :read) }
|
32
|
+
end
|
33
|
+
|
34
|
+
action :all, 'GET /v2/volumes/:volume_id/actions' do
|
35
|
+
query_keys :per_page, :page
|
36
|
+
handler(200) { |response| ActionMapping.extract_collection(response.body, :read) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def all(*args)
|
41
|
+
PaginatedResource.new(action(:all), self, *args)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module DropletKit
|
2
|
+
class VolumeResource < ResourceKit::Resource
|
3
|
+
include ErrorHandlingResourcable
|
4
|
+
|
5
|
+
resources do
|
6
|
+
action :all, 'GET /v2/volumes' do
|
7
|
+
query_keys :per_page, :page
|
8
|
+
handler(200) { |response| VolumeMapping.extract_collection(response.body, :read) }
|
9
|
+
end
|
10
|
+
|
11
|
+
action :create, 'POST /v2/volumes' do
|
12
|
+
body { |object| VolumeMapping.representation_for(:create, object) }
|
13
|
+
handler(201) { |response| VolumeMapping.extract_single(response.body, :read) }
|
14
|
+
handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
|
15
|
+
end
|
16
|
+
|
17
|
+
action :find, 'GET /v2/volumes/:id' do
|
18
|
+
handler(200) { |response| VolumeMapping.extract_single(response.body, :read) }
|
19
|
+
end
|
20
|
+
|
21
|
+
action :delete, 'DELETE /v2/volumes/:id' do
|
22
|
+
handler(204) { |response| true }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def all(*args)
|
27
|
+
PaginatedResource.new(action(:all), self, *args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/droplet_kit/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
{
|
2
|
+
"actions": [
|
3
|
+
{
|
4
|
+
"id": 72531856,
|
5
|
+
"status": "in-progress",
|
6
|
+
"type": "attach_volume",
|
7
|
+
"started_at": "2015-11-12T17:51:03Z",
|
8
|
+
"completed_at": null,
|
9
|
+
"resource_id": null,
|
10
|
+
"resource_type": "volume",
|
11
|
+
"region": {
|
12
|
+
"name": "New York 1",
|
13
|
+
"slug": "nyc1",
|
14
|
+
"sizes": [
|
15
|
+
"1gb",
|
16
|
+
"2gb",
|
17
|
+
"4gb",
|
18
|
+
"8gb",
|
19
|
+
"32gb",
|
20
|
+
"64gb",
|
21
|
+
"512mb",
|
22
|
+
"48gb",
|
23
|
+
"16gb"
|
24
|
+
],
|
25
|
+
"features": [
|
26
|
+
"private_networking",
|
27
|
+
"backups",
|
28
|
+
"ipv6",
|
29
|
+
"metadata"
|
30
|
+
],
|
31
|
+
"available": true
|
32
|
+
},
|
33
|
+
"region_slug": "nyc1"
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"links": {
|
37
|
+
},
|
38
|
+
"meta": {
|
39
|
+
"total": 1
|
40
|
+
}
|
41
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"action": {
|
3
|
+
"id": 72531856,
|
4
|
+
"status": "in-progress",
|
5
|
+
"type": "attach_volume",
|
6
|
+
"started_at": "2015-11-12T17:51:03Z",
|
7
|
+
"completed_at": null,
|
8
|
+
"resource_id": null,
|
9
|
+
"resource_type": "volume",
|
10
|
+
"region": {
|
11
|
+
"name": "New York 1",
|
12
|
+
"slug": "nyc1",
|
13
|
+
"sizes": [
|
14
|
+
"1gb",
|
15
|
+
"2gb",
|
16
|
+
"4gb",
|
17
|
+
"8gb",
|
18
|
+
"32gb",
|
19
|
+
"64gb",
|
20
|
+
"512mb",
|
21
|
+
"48gb",
|
22
|
+
"16gb"
|
23
|
+
],
|
24
|
+
"features": [
|
25
|
+
"private_networking",
|
26
|
+
"backups",
|
27
|
+
"ipv6",
|
28
|
+
"metadata"
|
29
|
+
],
|
30
|
+
"available": true
|
31
|
+
},
|
32
|
+
"region_slug": "nyc1"
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"action": {
|
3
|
+
"id": 72531856,
|
4
|
+
"status": "in-progress",
|
5
|
+
"type": "detach_volume",
|
6
|
+
"started_at": "2015-11-12T17:51:03Z",
|
7
|
+
"completed_at": null,
|
8
|
+
"resource_id": null,
|
9
|
+
"resource_type": "volume",
|
10
|
+
"region": {
|
11
|
+
"name": "New York 1",
|
12
|
+
"slug": "nyc1",
|
13
|
+
"sizes": [
|
14
|
+
"512mb",
|
15
|
+
"1gb",
|
16
|
+
"2gb",
|
17
|
+
"4gb",
|
18
|
+
"8gb",
|
19
|
+
"16gb",
|
20
|
+
"32gb",
|
21
|
+
"48gb",
|
22
|
+
"64gb"
|
23
|
+
],
|
24
|
+
"features": [
|
25
|
+
"private_networking",
|
26
|
+
"backups",
|
27
|
+
"ipv6",
|
28
|
+
"metadata"
|
29
|
+
],
|
30
|
+
"available": true
|
31
|
+
},
|
32
|
+
"region_slug": "nyc1"
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"action": {
|
3
|
+
"id": 72531856,
|
4
|
+
"status": "in-progress",
|
5
|
+
"type": "attach_volume",
|
6
|
+
"started_at": "2015-11-12T17:51:03Z",
|
7
|
+
"completed_at": null,
|
8
|
+
"resource_id": null,
|
9
|
+
"resource_type": "volume",
|
10
|
+
"region": {
|
11
|
+
"name": "New York 1",
|
12
|
+
"slug": "nyc1",
|
13
|
+
"sizes": [
|
14
|
+
"1gb",
|
15
|
+
"2gb",
|
16
|
+
"4gb",
|
17
|
+
"8gb",
|
18
|
+
"32gb",
|
19
|
+
"64gb",
|
20
|
+
"512mb",
|
21
|
+
"48gb",
|
22
|
+
"16gb"
|
23
|
+
],
|
24
|
+
"features": [
|
25
|
+
"private_networking",
|
26
|
+
"backups",
|
27
|
+
"ipv6",
|
28
|
+
"metadata"
|
29
|
+
],
|
30
|
+
"available": true
|
31
|
+
},
|
32
|
+
"region_slug": "nyc1"
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
{
|
2
|
+
"volumes": [
|
3
|
+
{
|
4
|
+
"id": "7724db7c-e098-11e5-b522-000f53304e51",
|
5
|
+
"region": {
|
6
|
+
"name": "New York 1",
|
7
|
+
"slug": "nyc1",
|
8
|
+
"sizes": [
|
9
|
+
"512mb",
|
10
|
+
"1gb",
|
11
|
+
"2gb",
|
12
|
+
"4gb",
|
13
|
+
"8gb",
|
14
|
+
"16gb",
|
15
|
+
"32gb",
|
16
|
+
"48gb",
|
17
|
+
"64gb"
|
18
|
+
],
|
19
|
+
"features": [
|
20
|
+
"private_networking",
|
21
|
+
"backups",
|
22
|
+
"ipv6",
|
23
|
+
"metadata"
|
24
|
+
],
|
25
|
+
"available": true
|
26
|
+
},
|
27
|
+
"droplet_ids": [
|
28
|
+
|
29
|
+
],
|
30
|
+
"name": "Example",
|
31
|
+
"description": "Block store for examples",
|
32
|
+
"size_gigabytes": 10,
|
33
|
+
"created_at": "2016-03-02T17:00:49Z"
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"links": {
|
37
|
+
},
|
38
|
+
"meta": {
|
39
|
+
"total": 1
|
40
|
+
}
|
41
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"volume": {
|
3
|
+
"id": "7724db7c-e098-11e5-b522-000f53304e51",
|
4
|
+
"region": {
|
5
|
+
"name": "New York 1",
|
6
|
+
"slug": "nyc1",
|
7
|
+
"sizes": [
|
8
|
+
"512mb",
|
9
|
+
"1gb",
|
10
|
+
"2gb",
|
11
|
+
"4gb",
|
12
|
+
"8gb",
|
13
|
+
"16gb",
|
14
|
+
"32gb",
|
15
|
+
"48gb",
|
16
|
+
"64gb"
|
17
|
+
],
|
18
|
+
"features": [
|
19
|
+
"private_networking",
|
20
|
+
"backups",
|
21
|
+
"ipv6",
|
22
|
+
"metadata"
|
23
|
+
],
|
24
|
+
"available": true
|
25
|
+
},
|
26
|
+
"droplet_ids": [
|
27
|
+
|
28
|
+
],
|
29
|
+
"name": "Example",
|
30
|
+
"description": "Block store for examples",
|
31
|
+
"size_gigabytes": 10,
|
32
|
+
"created_at": "2016-03-02T17:00:49Z"
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"volume": {
|
3
|
+
"id": "7724db7c-e098-11e5-b522-000f53304e51",
|
4
|
+
"region": {
|
5
|
+
"name": "New York 1",
|
6
|
+
"slug": "nyc1",
|
7
|
+
"sizes": [
|
8
|
+
"512mb",
|
9
|
+
"1gb",
|
10
|
+
"2gb",
|
11
|
+
"4gb",
|
12
|
+
"8gb",
|
13
|
+
"16gb",
|
14
|
+
"32gb",
|
15
|
+
"48gb",
|
16
|
+
"64gb"
|
17
|
+
],
|
18
|
+
"features": [
|
19
|
+
"private_networking",
|
20
|
+
"backups",
|
21
|
+
"ipv6",
|
22
|
+
"metadata"
|
23
|
+
],
|
24
|
+
"available": true
|
25
|
+
},
|
26
|
+
"droplet_ids": [
|
27
|
+
|
28
|
+
],
|
29
|
+
"name": "Example",
|
30
|
+
"description": "Block store for examples",
|
31
|
+
"size_gigabytes": 10,
|
32
|
+
"created_at": "2016-03-02T17:00:49Z"
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe DropletKit::VolumeActionResource do
|
4
|
+
subject(:resource) { described_class.new(connection: connection) }
|
5
|
+
include_context 'resources'
|
6
|
+
|
7
|
+
RSpec::Matchers.define :match_volume_action_fixture do |type|
|
8
|
+
match do |action|
|
9
|
+
expect(action).to be_kind_of(DropletKit::Action)
|
10
|
+
expect(action.id).to eq(72531856)
|
11
|
+
expect(action.status).to eq("in-progress")
|
12
|
+
expect(action.type).to eq(type) if type
|
13
|
+
expect(action.started_at).to eq("2015-11-12T17:51:03Z")
|
14
|
+
expect(action.completed_at).to eq(nil)
|
15
|
+
expect(action.resource_id).to eq(nil)
|
16
|
+
expect(action.resource_type).to eq("volume")
|
17
|
+
expect(action.region_slug).to eq("nyc1")
|
18
|
+
|
19
|
+
expect(action.region).to be_kind_of(DropletKit::Region)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#attach' do
|
24
|
+
let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
|
25
|
+
let(:droplet_id) { 123 }
|
26
|
+
let(:region) { 'nyc1' }
|
27
|
+
let(:path) { "/v2/volumes/#{volume_id}/actions" }
|
28
|
+
let(:action) { 'attach' }
|
29
|
+
let(:fixture) { api_fixture("volume_actions/#{action}") }
|
30
|
+
|
31
|
+
it 'sends an attach request for a volume' do
|
32
|
+
request = stub_do_api(path).with(
|
33
|
+
body: {
|
34
|
+
type: action,
|
35
|
+
droplet_id: droplet_id,
|
36
|
+
volume_id: volume_id,
|
37
|
+
region: region
|
38
|
+
}.to_json
|
39
|
+
).to_return(body: fixture, status: 201)
|
40
|
+
|
41
|
+
action = resource.attach(
|
42
|
+
volume_id: volume_id,
|
43
|
+
droplet_id: droplet_id,
|
44
|
+
region: region
|
45
|
+
)
|
46
|
+
|
47
|
+
expect(request).to have_been_made
|
48
|
+
expect(action).to match_volume_action_fixture('attach_volume')
|
49
|
+
end
|
50
|
+
|
51
|
+
it_behaves_like 'an action that handles invalid parameters' do
|
52
|
+
let(:arguments) { { volume_id: volume_id, droplet_id: droplet_id } }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#detach' do
|
57
|
+
let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
|
58
|
+
let(:droplet_id) { 123 }
|
59
|
+
let(:region) { 'nyc1' }
|
60
|
+
let(:path) { "/v2/volumes/#{volume_id}/actions" }
|
61
|
+
let(:action) { 'detach' }
|
62
|
+
let(:fixture) { api_fixture("volume_actions/#{action}") }
|
63
|
+
|
64
|
+
it 'sends an detach request for a volume' do
|
65
|
+
request = stub_do_api(path).with(
|
66
|
+
body: {
|
67
|
+
type: action,
|
68
|
+
droplet_id: droplet_id,
|
69
|
+
volume_id: volume_id,
|
70
|
+
region: region
|
71
|
+
}.to_json
|
72
|
+
).to_return(body: fixture, status: 201)
|
73
|
+
|
74
|
+
action = resource.detach(
|
75
|
+
volume_id: volume_id,
|
76
|
+
droplet_id: droplet_id,
|
77
|
+
region: region
|
78
|
+
)
|
79
|
+
|
80
|
+
expect(request).to have_been_made
|
81
|
+
expect(action).to match_volume_action_fixture('detach_volume')
|
82
|
+
end
|
83
|
+
|
84
|
+
it_behaves_like 'an action that handles invalid parameters' do
|
85
|
+
let(:arguments) { { volume_id: volume_id } }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#all' do
|
90
|
+
let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
|
91
|
+
|
92
|
+
it 'returns all of the volume actions via a paginated resources' do
|
93
|
+
request = stub_do_api("/v2/volumes/#{volume_id}/actions", :get).to_return(
|
94
|
+
body: api_fixture('volume_actions/all'),
|
95
|
+
status: 200
|
96
|
+
)
|
97
|
+
|
98
|
+
actions = resource.all(volume_id: volume_id).take(20)
|
99
|
+
|
100
|
+
expect(request).to have_been_made
|
101
|
+
|
102
|
+
expect(actions.size).to be(1)
|
103
|
+
|
104
|
+
action = actions.first
|
105
|
+
expect(action).to match_volume_action_fixture
|
106
|
+
end
|
107
|
+
|
108
|
+
it_behaves_like 'a paginated index' do
|
109
|
+
let(:fixture_path) { 'volume_actions/all' }
|
110
|
+
let(:api_path) { "/v2/volumes/#{volume_id}/actions" }
|
111
|
+
let(:parameters) { { volume_id: volume_id } }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#find' do
|
116
|
+
let(:id) { 72531856 }
|
117
|
+
let(:volume_id) { '7724db7c-e098-11e5-b522-000f53304e51' }
|
118
|
+
|
119
|
+
it 'returns a single action' do
|
120
|
+
stub_do_api("/v2/volumes/#{volume_id}/actions/#{id}", :get).to_return(body: api_fixture('volume_actions/find'))
|
121
|
+
action = resource.find(id: id, volume_id: volume_id)
|
122
|
+
|
123
|
+
expect(action).to match_volume_action_fixture
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe DropletKit::VolumeResource do
|
4
|
+
subject(:resource) { described_class.new(connection: connection) }
|
5
|
+
include_context 'resources'
|
6
|
+
|
7
|
+
RSpec::Matchers.define :match_volume_fixture do
|
8
|
+
match do |volume|
|
9
|
+
expect(volume).to be_kind_of(DropletKit::Volume)
|
10
|
+
|
11
|
+
expect(volume.region).to be_kind_of(DropletKit::Region)
|
12
|
+
expect(volume.id).to eq("7724db7c-e098-11e5-b522-000f53304e51")
|
13
|
+
expect(volume.droplet_ids).to eq([])
|
14
|
+
expect(volume.name).to eq("Example")
|
15
|
+
expect(volume.description).to eq("Block store for examples")
|
16
|
+
expect(volume.size_gigabytes).to eq(10)
|
17
|
+
expect(volume.created_at).to eq("2016-03-02T17:00:49Z")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#all' do
|
22
|
+
it 'returns all of the volumes' do
|
23
|
+
stub_do_api('/v2/volumes', :get).to_return(body: api_fixture('volumes/all'))
|
24
|
+
volumes = resource.all
|
25
|
+
|
26
|
+
expect(volumes).to all(be_kind_of(DropletKit::Volume))
|
27
|
+
expect(volumes.first).to match_volume_fixture
|
28
|
+
end
|
29
|
+
|
30
|
+
it_behaves_like 'a paginated index' do
|
31
|
+
let(:fixture_path) { 'volumes/all' }
|
32
|
+
let(:api_path) { '/v2/volumes' }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#find' do
|
37
|
+
it 'returns a singular volume' do
|
38
|
+
stub_do_api('/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51', :get).to_return(body: api_fixture('volumes/find'))
|
39
|
+
volume = resource.find(id: "7724db7c-e098-11e5-b522-000f53304e51")
|
40
|
+
|
41
|
+
expect(volume).to match_volume_fixture
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#create' do
|
46
|
+
let(:path) { '/v2/volumes' }
|
47
|
+
|
48
|
+
context 'for a successful create' do
|
49
|
+
it 'returns the created volume' do
|
50
|
+
volume = DropletKit::Volume.new(
|
51
|
+
size_gigabytes: 10,
|
52
|
+
name: "Example",
|
53
|
+
description: "Block store for examples",
|
54
|
+
region: "nyc1"
|
55
|
+
)
|
56
|
+
|
57
|
+
as_string = DropletKit::VolumeMapping.representation_for(:create, volume)
|
58
|
+
stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('volumes/create'), status: 201)
|
59
|
+
created_volume = resource.create(volume)
|
60
|
+
|
61
|
+
expect(created_volume).to match_volume_fixture
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it_behaves_like 'an action that handles invalid parameters' do
|
66
|
+
let(:action) { 'create' }
|
67
|
+
let(:arguments) { DropletKit::Volume.new }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#delete' do
|
72
|
+
it 'sends a delete request for the volume' do
|
73
|
+
request = stub_do_api('/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51', :delete)
|
74
|
+
resource.delete(id: "7724db7c-e098-11e5-b522-000f53304e51")
|
75
|
+
|
76
|
+
expect(request).to have_been_made
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: droplet_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Ross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -90,14 +90,14 @@ dependencies:
|
|
90
90
|
name: bundler
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: 1.11.0
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - "
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 1.11.0
|
103
103
|
- !ruby/object:Gem::Dependency
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- lib/droplet_kit/mappings/tag_mapping.rb
|
211
211
|
- lib/droplet_kit/mappings/tagged_droplets_resources_mapping.rb
|
212
212
|
- lib/droplet_kit/mappings/tagged_resources_mapping.rb
|
213
|
+
- lib/droplet_kit/mappings/volume_mapping.rb
|
213
214
|
- lib/droplet_kit/models/account.rb
|
214
215
|
- lib/droplet_kit/models/action.rb
|
215
216
|
- lib/droplet_kit/models/backup.rb
|
@@ -233,6 +234,7 @@ files:
|
|
233
234
|
- lib/droplet_kit/models/tag.rb
|
234
235
|
- lib/droplet_kit/models/tagged_droplets_resources.rb
|
235
236
|
- lib/droplet_kit/models/tagged_resources.rb
|
237
|
+
- lib/droplet_kit/models/volume.rb
|
236
238
|
- lib/droplet_kit/paginated_resource.rb
|
237
239
|
- lib/droplet_kit/resources/account_resource.rb
|
238
240
|
- lib/droplet_kit/resources/action_resource.rb
|
@@ -249,6 +251,8 @@ files:
|
|
249
251
|
- lib/droplet_kit/resources/size_resource.rb
|
250
252
|
- lib/droplet_kit/resources/ssh_key_resource.rb
|
251
253
|
- lib/droplet_kit/resources/tag_resource.rb
|
254
|
+
- lib/droplet_kit/resources/volume_action_resource.rb
|
255
|
+
- lib/droplet_kit/resources/volume_resource.rb
|
252
256
|
- lib/droplet_kit/version.rb
|
253
257
|
- lib/tasks/resource_doc.rake
|
254
258
|
- spec/fixtures/account/info.json
|
@@ -316,6 +320,13 @@ files:
|
|
316
320
|
- spec/fixtures/tags/all_empty.json
|
317
321
|
- spec/fixtures/tags/create.json
|
318
322
|
- spec/fixtures/tags/find.json
|
323
|
+
- spec/fixtures/volume_actions/all.json
|
324
|
+
- spec/fixtures/volume_actions/attach.json
|
325
|
+
- spec/fixtures/volume_actions/detach.json
|
326
|
+
- spec/fixtures/volume_actions/find.json
|
327
|
+
- spec/fixtures/volumes/all.json
|
328
|
+
- spec/fixtures/volumes/create.json
|
329
|
+
- spec/fixtures/volumes/find.json
|
319
330
|
- spec/lib/droplet_kit/client_spec.rb
|
320
331
|
- spec/lib/droplet_kit/models/base_model_spec.rb
|
321
332
|
- spec/lib/droplet_kit/models/droplet_spec.rb
|
@@ -335,6 +346,8 @@ files:
|
|
335
346
|
- spec/lib/droplet_kit/resources/size_resource_spec.rb
|
336
347
|
- spec/lib/droplet_kit/resources/ssh_key_resource_spec.rb
|
337
348
|
- spec/lib/droplet_kit/resources/tag_resource_spec.rb
|
349
|
+
- spec/lib/droplet_kit/resources/volume_action_resource_spec.rb
|
350
|
+
- spec/lib/droplet_kit/resources/volume_resource_spec.rb
|
338
351
|
- spec/spec_helper.rb
|
339
352
|
- spec/support/fake_server.rb
|
340
353
|
- spec/support/request_stub_helpers.rb
|
@@ -432,6 +445,13 @@ test_files:
|
|
432
445
|
- spec/fixtures/tags/all_empty.json
|
433
446
|
- spec/fixtures/tags/create.json
|
434
447
|
- spec/fixtures/tags/find.json
|
448
|
+
- spec/fixtures/volume_actions/all.json
|
449
|
+
- spec/fixtures/volume_actions/attach.json
|
450
|
+
- spec/fixtures/volume_actions/detach.json
|
451
|
+
- spec/fixtures/volume_actions/find.json
|
452
|
+
- spec/fixtures/volumes/all.json
|
453
|
+
- spec/fixtures/volumes/create.json
|
454
|
+
- spec/fixtures/volumes/find.json
|
435
455
|
- spec/lib/droplet_kit/client_spec.rb
|
436
456
|
- spec/lib/droplet_kit/models/base_model_spec.rb
|
437
457
|
- spec/lib/droplet_kit/models/droplet_spec.rb
|
@@ -451,6 +471,8 @@ test_files:
|
|
451
471
|
- spec/lib/droplet_kit/resources/size_resource_spec.rb
|
452
472
|
- spec/lib/droplet_kit/resources/ssh_key_resource_spec.rb
|
453
473
|
- spec/lib/droplet_kit/resources/tag_resource_spec.rb
|
474
|
+
- spec/lib/droplet_kit/resources/volume_action_resource_spec.rb
|
475
|
+
- spec/lib/droplet_kit/resources/volume_resource_spec.rb
|
454
476
|
- spec/spec_helper.rb
|
455
477
|
- spec/support/fake_server.rb
|
456
478
|
- spec/support/request_stub_helpers.rb
|