profitbricks-sdk-ruby 1.0.5 → 1.1.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: 14db6f0ee04190fb34315ac681ae64790b94eb66
4
- data.tar.gz: e33068f4eb3a3c265fc0500338808ca59cf619b5
3
+ metadata.gz: 4dcd9fb8b417625972962d592809333b2ab5b5a7
4
+ data.tar.gz: 0fd530ada738ffd0a97084c6482c8f5210f91e93
5
5
  SHA512:
6
- metadata.gz: 7713cb62f664ce285a7194c0d25fe21809099f1e85bd7ffacdf994a332c3ea84aa09c8214b763a14d143dd88ee9c86f6dccb60a5fb8d79926be71386994d6e31
7
- data.tar.gz: f0b25b5a6ef17b8e5e930ca811441213509906040be12cd45d993eed594c1126f0b30339241e32400b97b08ffdc9adf3db181b3019bda72165849660f9121c1c
6
+ metadata.gz: f69666536c3cfed17aa6ba61e788acd48ef04b604a3784fa950f7abfb0848b32de4b716c2902e07a90fff98279740d7f3c55df368743cb90570ff741254a9675
7
+ data.tar.gz: 862ecab2e7ffbbbb51a1ca1a1468670a2b0a6dfba88e8e6a925454a9e9a0325f4d4a26d6630945427fb9a803c9c03a96ffc0655723e5cdb38deb39e19092ee77
data/docs/guide.md CHANGED
@@ -147,10 +147,17 @@ Make sure the image you retrieve is in the same location as the virtual data cen
147
147
 
148
148
  ProfitBricks allows for the creation of multiple storage volumes that can be attached and detached as needed. It is useful to attach an image when creating a storage volume. The storage size is in gigabytes (GB).
149
149
 
150
- volume = datacenter.create_volume(name: 'My New Volume, size: 40, image: image.id)
150
+ volume = datacenter.create_volume(name: 'My New Volume', size: 40, image: image.id, type: 'HDD')
151
151
 
152
152
  volume.wait_for { ready? }
153
153
 
154
+ Several public images allow support for SSH authentication. This allows a list of SSH publics keys to supplied when creating a new volume.
155
+
156
+ ssh_key = 'ssh-rsa AAAAB3NzaC1yc2E...'
157
+ volume = datacenter.create_volume(name: 'Boot Volume', size: 40, image: image.id, type: 'HDD', sshKeys: [ ssh_key ])
158
+
159
+ The corresonding SSH private key can then be used when logging into a server with that boot volume.
160
+
154
161
  ## How To: Update Cores, Memory, and Disk
155
162
 
156
163
  ProfitBricks allows users to dynamically update cores, memory, and disk independently of each other. This removes the restriction of needing to upgrade to the next size available size to receive an increase in memory. You can now simply increase the instances memory keeping your costs in-line with your resource needs.
data/docs/reference.md CHANGED
@@ -205,7 +205,7 @@ Retrieve a volume:
205
205
 
206
206
  Create a volume:
207
207
 
208
- volume = datacenter.create_volume(name: "volume1", size: 20)
208
+ volume = datacenter.create_volume(name: "volume1", size: 20, type: "SSD")
209
209
 
210
210
  Update a volume:
211
211
 
data/lib/profitbricks.rb CHANGED
@@ -5,6 +5,7 @@ require 'uri'
5
5
  # Top-level module
6
6
  module ProfitBricks
7
7
  require 'profitbricks/version'
8
+ require 'profitbricks/errors'
8
9
  require 'profitbricks/config'
9
10
  require 'profitbricks/profitbricks'
10
11
  require 'profitbricks/model'
@@ -4,7 +4,7 @@ module ProfitBricks
4
4
  def delete
5
5
  response = ProfitBricks.request(
6
6
  method: :delete,
7
- path: "/datacenters/#{self.id}",
7
+ path: "/datacenters/#{id}",
8
8
  expects: 202
9
9
  )
10
10
  self.requestId = response[:requestId]
@@ -13,7 +13,7 @@ module ProfitBricks
13
13
 
14
14
  def update(options = {})
15
15
  response = ProfitBricks.request(
16
- path: "/datacenters/#{self.id}",
16
+ path: "/datacenters/#{id}",
17
17
  method: :patch,
18
18
  expects: 202,
19
19
  body: options.to_json
@@ -26,61 +26,61 @@ module ProfitBricks
26
26
  end
27
27
 
28
28
  def list_servers
29
- ProfitBricks::Server.list(self.id)
29
+ ProfitBricks::Server.list(id)
30
30
  end
31
31
 
32
32
  def get_server(server_id)
33
- ProfitBricks::Server.get(self.id, server_id)
33
+ ProfitBricks::Server.get(id, server_id)
34
34
  end
35
35
 
36
36
  def create_server(options = {})
37
- ProfitBricks::Server.create(self.id, options)
37
+ ProfitBricks::Server.create(id, options)
38
38
  end
39
39
 
40
40
  def list_volumes
41
- ProfitBricks::Volume.list(self.id)
41
+ ProfitBricks::Volume.list(id)
42
42
  end
43
43
 
44
44
  def get_volume(volume_id)
45
- ProfitBricks::Volume.get(self.id, nil, volume_id)
45
+ ProfitBricks::Volume.get(id, nil, volume_id)
46
46
  end
47
47
 
48
48
  def create_volume(options = {})
49
- ProfitBricks::Volume.create(self.id, options)
49
+ ProfitBricks::Volume.create(id, options)
50
50
  end
51
51
 
52
52
  def list_loadbalancers
53
- ProfitBricks::Loadbalancer.list(self.id)
53
+ ProfitBricks::Loadbalancer.list(id)
54
54
  end
55
55
 
56
56
  def get_loadbalancer(loadbalancer_id)
57
- ProfitBricks::Loadbalancer.get(self.id, loadbalancer_id)
57
+ ProfitBricks::Loadbalancer.get(id, loadbalancer_id)
58
58
  end
59
59
 
60
60
  def create_loadbalancer(options = {})
61
- ProfitBricks::Loadbalancer.create(self.id, options)
61
+ ProfitBricks::Loadbalancer.create(id, options)
62
62
  end
63
63
 
64
64
  def list_lans
65
- ProfitBricks::LAN.list(self.id)
65
+ ProfitBricks::LAN.list(id)
66
66
  end
67
67
 
68
68
  def get_lan(lan_id)
69
- ProfitBricks::LAN.get(self.id, lan_id)
69
+ ProfitBricks::LAN.get(id, lan_id)
70
70
  end
71
71
 
72
72
  def create_lan(options = {})
73
- ProfitBricks::LAN.create(self.id, options)
73
+ ProfitBricks::LAN.create(id, options)
74
74
  end
75
75
 
76
- alias_method :server, :get_server
77
- alias_method :servers, :list_servers
78
- alias_method :volume, :get_volume
79
- alias_method :volumes, :list_volumes
80
- alias_method :loadbalancer, :get_loadbalancer
81
- alias_method :loadbalancers, :list_loadbalancers
82
- alias_method :lan, :get_lan
83
- alias_method :lans, :list_lans
76
+ alias server get_server
77
+ alias servers list_servers
78
+ alias volume get_volume
79
+ alias volumes list_volumes
80
+ alias loadbalancer get_loadbalancer
81
+ alias loadbalancers list_loadbalancers
82
+ alias lan get_lan
83
+ alias lans list_lans
84
84
 
85
85
  class << self
86
86
  def create(options = {})
@@ -0,0 +1,6 @@
1
+ module ProfitBricks
2
+ class Errors
3
+ class Error < StandardError; end
4
+ class OperationFailure < StandardError; end
5
+ end
6
+ end
@@ -1,12 +1,11 @@
1
1
  module ProfitBricks
2
2
  # Firewall class
3
3
  class Firewall < ProfitBricks::Model
4
-
5
4
  # Delete the firewall rule.
6
5
  def delete
7
6
  response = ProfitBricks.request(
8
7
  method: :delete,
9
- path: "/datacenters/#{self.datacenterId}/servers/#{self.serverId}/nics/#{self.nicId}/firewallrules/#{self.id}",
8
+ path: "/datacenters/#{datacenterId}/servers/#{serverId}/nics/#{nicId}/firewallrules/#{id}",
10
9
  expects: 202
11
10
  )
12
11
  self.requestId = response[:requestId]
@@ -17,18 +16,15 @@ module ProfitBricks
17
16
  def update(options = {})
18
17
  response = ProfitBricks.request(
19
18
  method: :patch,
20
- path: "/datacenters/#{self.datacenterId}/servers/#{self.serverId}/nics/#{self.nicId}/firewallrules/#{self.id}",
19
+ path: "/datacenters/#{datacenterId}/servers/#{serverId}/nics/#{nicId}/firewallrules/#{id}",
21
20
  expects: 202,
22
21
  body: options.to_json
23
22
  )
24
- if response
25
- @properties = @properties.merge(response['properties'])
26
- end
23
+ @properties = @properties.merge(response['properties'])
27
24
  self
28
25
  end
29
26
 
30
27
  class << self
31
-
32
28
  # Create a new firewall rule.
33
29
  def create(datacenter_id, server_id, nic_id, options = {})
34
30
  response = ProfitBricks.request(
@@ -5,7 +5,7 @@ module ProfitBricks
5
5
  def release
6
6
  ProfitBricks.request(
7
7
  method: :delete,
8
- path: "/ipblocks/#{self.id}",
8
+ path: "/ipblocks/#{id}",
9
9
  expects: 202
10
10
  )
11
11
  end
@@ -5,7 +5,7 @@ module ProfitBricks
5
5
  def delete
6
6
  response = ProfitBricks.request(
7
7
  method: :delete,
8
- path: "/datacenters/#{self.datacenterId}/loadbalancers/#{self.id}",
8
+ path: "/datacenters/#{datacenterId}/loadbalancers/#{id}",
9
9
  expects: 202
10
10
  )
11
11
  self.requestId = response[:requestId]
@@ -16,21 +16,19 @@ module ProfitBricks
16
16
  def update(options = {})
17
17
  response = ProfitBricks.request(
18
18
  method: :patch,
19
- path: "/datacenters/#{self.datacenterId}/loadbalancers/#{self.id}",
19
+ path: "/datacenters/#{datacenterId}/loadbalancers/#{id}",
20
20
  expects: 202,
21
21
  body: options.to_json
22
22
  )
23
- if response
24
- @properties = @properties.merge(response['properties'])
25
- end
23
+ @properties = @properties.merge(response['properties'])
26
24
  self
27
25
  end
28
26
 
29
27
  def list_balanced_nics
30
28
  response = ProfitBricks.request(
31
29
  method: :get,
32
- path: "/datacenters/#{self.datacenterId}/loadbalancers/#{self.id}/balancednics",
33
- expects: 200,
30
+ path: "/datacenters/#{datacenterId}/loadbalancers/#{id}/balancednics",
31
+ expects: 200
34
32
  )
35
33
  self.class.instantiate_objects(response)
36
34
  end
@@ -38,7 +36,7 @@ module ProfitBricks
38
36
  def associate_balanced_nic(nic_id)
39
37
  response = ProfitBricks.request(
40
38
  method: :post,
41
- path: "/datacenters/#{self.datacenterId}/loadbalancers/#{self.id}/balancednics",
39
+ path: "/datacenters/#{datacenterId}/loadbalancers/#{id}/balancednics",
42
40
  expects: 202,
43
41
  body: { id: nic_id }.to_json
44
42
  )
@@ -48,7 +46,7 @@ module ProfitBricks
48
46
  def get_balanced_nic(nic_id)
49
47
  response = ProfitBricks.request(
50
48
  method: :get,
51
- path: "/datacenters/#{self.datacenterId}/loadbalancers/#{self.id}/balancednics/#{nic_id}",
49
+ path: "/datacenters/#{datacenterId}/loadbalancers/#{id}/balancednics/#{nic_id}",
52
50
  expects: 200
53
51
  )
54
52
  self.class.instantiate_objects(response)
@@ -57,7 +55,7 @@ module ProfitBricks
57
55
  def remove_balanced_nic(nic_id)
58
56
  ProfitBricks.request(
59
57
  method: :delete,
60
- path: "/datacenters/#{self.datacenterId}/loadbalancers/#{self.id}/balancednics/#{nic_id}",
58
+ path: "/datacenters/#{datacenterId}/loadbalancers/#{id}/balancednics/#{nic_id}",
61
59
  expects: 202
62
60
  )
63
61
  end
@@ -73,7 +71,8 @@ module ProfitBricks
73
71
  # * +options+<Hash>:
74
72
  # - +name+<String> - *Optional*, name of the loadbalancer
75
73
  # - +ip+<String> - *Optional*, IPv4 address of the loadbalancer
76
- # - +dhcp+<Boolean> - *Optional*, Indicates if the loadbalancer will reserve an IP using DHCP
74
+ # - +dhcp+<Boolean> - *Optional*, Indicates if the loadbalancer will
75
+ # reserve an IP using DHCP
77
76
  #
78
77
  # ==== Returns
79
78
  # * +id+<String> - Universally unique identifer of resource
@@ -19,13 +19,16 @@ module ProfitBricks
19
19
 
20
20
  def ready?
21
21
  status = ProfitBricks::Request.get(self.requestId).status
22
+ if status.metadata['status'] == 'FAILED' then
23
+ raise ProfitBricks::Errors::OperationFailure, status.metadata['message']
24
+ end
22
25
  status.metadata['status'] == 'DONE'
23
26
  end
24
27
 
25
28
  def reload
26
29
  # Remove URL host and prefix path from href.
27
30
  path = URI(self.href).path
28
- path.sub!(ProfitBricks::Config.path_prefix, '/')
31
+ path.sub!(ProfitBricks::Config.path_prefix, '')
29
32
 
30
33
  response = ProfitBricks.request(
31
34
  method: :get,
@@ -80,7 +83,7 @@ module ProfitBricks
80
83
  # Add parent resource ID's to response resources. This will provide
81
84
  # convenient ID instance variable for subsequent methods.
82
85
  def self.add_parent_identities(response)
83
- uri = URI(response['href']).path.split('/')
86
+ uri = URI(response['href']).path
84
87
  if response.key?('items') then
85
88
  response['items'].each do |item|
86
89
  item.merge!(extract_identities(uri))
@@ -92,9 +95,15 @@ module ProfitBricks
92
95
 
93
96
  def self.extract_identities(uri)
94
97
  identities = {}
95
- identities['datacenterId'] = uri[3] if uri[2] == 'datacenters'
96
- identities['serverId'] = uri[5] if uri[4] == 'servers'
97
- identities['nicId'] = uri[7] if uri[6] == 'nics'
98
+ if match = uri.match(/datacenters\/([-a-f0-9]+)/i) then
99
+ identities['datacenterId'] = match[1]
100
+ end
101
+ if match = uri.match(/servers\/([-a-f0-9]+)/i) then
102
+ identities['serverId'] = match[1]
103
+ end
104
+ if match = uri.match(/nics\/([-a-f0-9]+)/i) then
105
+ identities['nicId'] = match[1]
106
+ end
98
107
  identities
99
108
  end
100
109
 
@@ -1,12 +1,11 @@
1
1
  module ProfitBricks
2
2
  # NIC class
3
3
  class NIC < ProfitBricks::Model
4
-
5
4
  # Delete the NIC.
6
5
  def delete
7
6
  response = ProfitBricks.request(
8
7
  method: :delete,
9
- path: "/datacenters/#{self.datacenterId}/servers/#{self.serverId}/nics/#{self.id}",
8
+ path: "/datacenters/#{datacenterId}/servers/#{serverId}/nics/#{id}",
10
9
  expects: 202
11
10
  )
12
11
  self.requestId = response[:requestId]
@@ -17,39 +16,36 @@ module ProfitBricks
17
16
  def update(options = {})
18
17
  response = ProfitBricks.request(
19
18
  method: :patch,
20
- path: "/datacenters/#{self.datacenterId}/servers/#{self.serverId}/nics/#{self.id}",
19
+ path: "/datacenters/#{datacenterId}/servers/#{serverId}/nics/#{id}",
21
20
  expects: 202,
22
21
  body: options.to_json
23
22
  )
24
- if response
25
- @properties = @properties.merge(response['properties'])
26
- end
23
+ @properties = @properties.merge(response['properties'])
27
24
  self
28
25
  end
29
26
 
30
27
  # List all NIC firewall rules
31
28
  def list_firewall_rules
32
- ProfitBricks::Firewall.list(self.datacenterId, self.serverId, self.id)
29
+ ProfitBricks::Firewall.list(datacenterId, serverId, id)
33
30
  end
34
31
 
35
32
  # Retrieve NIC firewall rule
36
33
  def get_firewall_rule(fwrule_id)
37
- ProfitBricks::Firewall.get(self.datacenterId, self.serverId, self.id, fwrule_id)
34
+ ProfitBricks::Firewall.get(datacenterId, serverId, id, fwrule_id)
38
35
  end
39
36
 
40
37
  # Create NIC firewall rule
41
38
  def create_firewall_rule(options = {})
42
- ProfitBricks::Firewall.create(self.datacenterId, self.serverId, self.id, options)
43
- end
39
+ ProfitBricks::Firewall.create(datacenterId, serverId, id, options)
40
+ end
44
41
 
45
- alias_method :list_fwrules, :list_firewall_rules
46
- alias_method :fwrules, :list_firewall_rules
47
- alias_method :get_fwrule, :get_firewall_rule
48
- alias_method :fwrule, :get_firewall_rule
49
- alias_method :create_fwrule, :create_firewall_rule
42
+ alias list_fwrules list_firewall_rules
43
+ alias fwrules list_firewall_rules
44
+ alias get_fwrule get_firewall_rule
45
+ alias fwrule get_firewall_rule
46
+ alias create_fwrule create_firewall_rule
50
47
 
51
48
  class << self
52
-
53
49
  # Create a new NIC.
54
50
  def create(datacenter_id, server_id, options = {})
55
51
  response = ProfitBricks.request(
@@ -8,13 +8,13 @@ module ProfitBricks
8
8
  ProfitBricks::Config.debug = false
9
9
  ProfitBricks::Config.protocol = 'https'
10
10
  ProfitBricks::Config.port = '443'
11
- ProfitBricks::Config.path_prefix = '/rest/'
11
+ ProfitBricks::Config.path_prefix = '/rest/v2'
12
12
  yield ProfitBricks::Config
13
13
 
14
14
  if ProfitBricks::Config.host
15
15
  url = construct_url
16
16
  else
17
- url = ProfitBricks::Config.url || 'https://api.profitbricks.com/rest/'
17
+ url = ProfitBricks::Config.url || 'https://api.profitbricks.com/rest/v2'
18
18
  end
19
19
 
20
20
  params = {
@@ -69,7 +69,7 @@ module ProfitBricks
69
69
 
70
70
  def self.add_request_id(response)
71
71
  location ||= response.headers['Location']
72
- request_id ||= URI(location).path.split('/')[3] unless location.nil?
72
+ request_id ||= location.match(/requests\/([-a-f0-9]+)/i)[1] unless location.nil?
73
73
  body = parse_json(response.body)
74
74
 
75
75
  if body.nil?
@@ -1,3 +1,3 @@
1
1
  module ProfitBricks
2
- VERSION = "1.0.5"
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,12 +1,11 @@
1
1
  module ProfitBricks
2
2
  # Volume class
3
3
  class Volume < ProfitBricks::Model
4
-
5
4
  # Delete the volume.
6
5
  def delete
7
6
  response = ProfitBricks.request(
8
7
  method: :delete,
9
- path: "/datacenters/#{self.datacenterId}/volumes/#{self.id}",
8
+ path: "/datacenters/#{datacenterId}/volumes/#{id}",
10
9
  expects: 202
11
10
  )
12
11
  self.requestId = response[:requestId]
@@ -17,23 +16,21 @@ module ProfitBricks
17
16
  def update(options = {})
18
17
  response = ProfitBricks.request(
19
18
  method: :patch,
20
- path: "/datacenters/#{self.datacenterId}/volumes/#{self.id}",
19
+ path: "/datacenters/#{datacenterId}/volumes/#{id}",
21
20
  expects: 202,
22
21
  body: options.to_json
23
22
  )
24
- if response
25
- @properties = @properties.merge(response['properties'])
26
- end
23
+ @properties = @properties.merge(response['properties'])
27
24
  self
28
25
  end
29
26
 
30
27
  # Attach volume to server.
31
28
  def attach(server_id)
32
- response = ProfitBricks.request(
29
+ ProfitBricks.request(
33
30
  method: :post,
34
- path: "/datacenters/#{self.datacenterId}/servers/#{server_id}/volumes",
31
+ path: "/datacenters/#{datacenterId}/servers/#{server_id}/volumes",
35
32
  expects: 202,
36
- body: { id: self.id }.to_json
33
+ body: { id: id }.to_json
37
34
  )
38
35
  self
39
36
  end
@@ -42,7 +39,7 @@ module ProfitBricks
42
39
  def detach(server_id)
43
40
  ProfitBricks.request(
44
41
  method: :delete,
45
- path: "/datacenters/#{self.datacenterId}/servers/#{server_id}/volumes/#{self.id}",
42
+ path: "/datacenters/#{datacenterId}/servers/#{server_id}/volumes/#{id}",
46
43
  expects: 202
47
44
  )
48
45
  end
@@ -84,7 +81,7 @@ module ProfitBricks
84
81
  def create_snapshot(options = {})
85
82
  response = ProfitBricks.request(
86
83
  method: :post,
87
- path: "/datacenters/#{self.datacenterId}/volumes/#{self.id}/create-snapshot",
84
+ path: "/datacenters/#{datacenterId}/volumes/#{id}/create-snapshot",
88
85
  headers: { 'Content-Type' => 'application/x-www-form-urlencoded' },
89
86
  expects: 202,
90
87
  body: URI.encode_www_form(options)
@@ -103,7 +100,7 @@ module ProfitBricks
103
100
  def restore_snapshot(snapshot_id)
104
101
  ProfitBricks.request(
105
102
  method: :post,
106
- path: "/datacenters/#{self.datacenterId}/volumes/#{self.id}/restore-snapshot",
103
+ path: "/datacenters/#{datacenterId}/volumes/#{id}/restore-snapshot",
107
104
  headers: { 'Content-Type' => 'application/x-www-form-urlencoded' },
108
105
  expects: 202,
109
106
  body: URI.encode_www_form(snapshotId: snapshot_id)
@@ -111,17 +108,18 @@ module ProfitBricks
111
108
  end
112
109
 
113
110
  class << self
114
-
115
111
  # Create a new volume.
116
112
  #
117
113
  # ==== Parameters
118
114
  # * +options+<Hash>:
119
115
  # - +name+<String> - *Optional*, name of the volume
120
116
  # - +size+<Integer> - *Required*, size of the volume in GB
117
+ # - +type+<String> - *Required*, the volume type (HDD or SSD)
121
118
  # - +bus+<String> - *Optional*, the bus type of the volume
122
119
  # * +VIRTIO+ - *Default*
123
120
  # * +IDE+
124
121
  # - +image+<String> - *Optional*, image or snapshot ID
122
+ # - +sshKeys+<Array> - *Optional*, a list of public SSH keys
125
123
  #
126
124
  # ==== Returns
127
125
  # * +id+<String> - Universally unique identifer of resource
@@ -152,6 +150,7 @@ module ProfitBricks
152
150
  # - +discVirtioHotUnPlug+<Boolean>
153
151
  # - +discScsiHotPlug+<Boolean>
154
152
  # - +discScsiHotUnPlug+<Boolean>
153
+ # - +sshKeys+<Array>
155
154
  #
156
155
  def create(datacenter_id, options = {})
157
156
  response = ProfitBricks.request(
@@ -166,11 +165,11 @@ module ProfitBricks
166
165
 
167
166
  # List all datacenter volumes.
168
167
  def list(datacenter_id, server_id = nil)
169
- if server_id.nil?
170
- path = "/datacenters/#{datacenter_id}/volumes"
171
- else
172
- path = "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes"
173
- end
168
+ path = if server_id.nil?
169
+ "/datacenters/#{datacenter_id}/volumes"
170
+ else
171
+ "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes"
172
+ end
174
173
  response = ProfitBricks.request(
175
174
  method: :get,
176
175
  path: path,
@@ -182,11 +181,11 @@ module ProfitBricks
182
181
 
183
182
  # Retrieve a datacenter volume.
184
183
  def get(datacenter_id, server_id = nil, volume_id)
185
- if server_id.nil?
186
- path = "/datacenters/#{datacenter_id}/volumes/#{volume_id}"
187
- else
188
- path = "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes/#{volume_id}"
189
- end
184
+ path = if server_id.nil?
185
+ "/datacenters/#{datacenter_id}/volumes/#{volume_id}"
186
+ else
187
+ "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes/#{volume_id}"
188
+ end
190
189
  response = ProfitBricks.request(
191
190
  method: :get,
192
191
  path: path,
@@ -1,5 +1,8 @@
1
1
  module ProfitBricks
2
- def self.wait_for(timeout = ProfitBricks::Config.timeout, interval = ProfitBricks::Config.interval, &_block)
2
+ # Resource wait_for check
3
+ def self.wait_for(timeout = ProfitBricks::Config.timeout,
4
+ interval = ProfitBricks::Config.interval,
5
+ &_block)
3
6
  duration = 0
4
7
  start = Time.now
5
8
  retries = 0
@@ -8,9 +11,10 @@ module ProfitBricks
8
11
  duration = Time.now - start
9
12
  end
10
13
  if duration > timeout
11
- raise StandardError, "The specified wait_for timeout (#{timeout} seconds) was exceeded"
14
+ fail StandardError,
15
+ "The specified wait_for timeout (#{timeout} seconds) was exceeded."
12
16
  else
13
- { :duration => duration }
17
+ { duration: duration }
14
18
  end
15
19
  end
16
20
  end
@@ -116,7 +116,7 @@ describe ProfitBricks::Datacenter do
116
116
  expect(volumes[0].type).to eq('volume')
117
117
  expect(volumes[0].id).to match(options[:uuid])
118
118
  expect(volumes[0].properties['name']).to eq('my boot volume for server 1')
119
- expect(volumes[0].properties['size']).to eq(10)
119
+ expect(volumes[0].properties['size']).to eq(5)
120
120
  expect(volumes[0].properties['bus']).to be nil
121
121
  expect(volumes[0].properties['image']).to be nil
122
122
  expect(volumes[0].properties['imagePassword']).to be nil
@@ -131,7 +131,7 @@ describe ProfitBricks::Datacenter do
131
131
  expect(volume.type).to eq('volume')
132
132
  expect(volume.id).to match(options[:uuid])
133
133
  expect(volume.properties['name']).to eq('my boot volume for server 1')
134
- expect(volume.properties['size']).to eq(10)
134
+ expect(volume.properties['size']).to eq(5)
135
135
  expect(volume.properties['bus']).to be nil
136
136
  expect(volume.properties['image']).to be nil
137
137
  expect(volume.properties['imagePassword']).to be nil
@@ -147,7 +147,7 @@ describe ProfitBricks::Datacenter do
147
147
  expect(volume.type).to eq('volume')
148
148
  expect(volume.id).to match(options[:uuid])
149
149
  expect(volume.properties['name']).to eq('my boot volume for server 1')
150
- expect(volume.properties['size']).to eq(10)
150
+ expect(volume.properties['size']).to eq(5)
151
151
  expect(volume.properties['bus']).to be nil
152
152
  expect(volume.properties['image']).to be nil
153
153
  expect(volume.properties['imagePassword']).to be nil
data/spec/image_spec.rb CHANGED
@@ -10,9 +10,9 @@ describe ProfitBricks::Image do
10
10
  expect(@images[0].type).to eq('image')
11
11
  expect(@images[0].id).to match(options[:uuid])
12
12
  expect(@images[0].properties['name']).to be_kind_of(String)
13
- expect(@images[0].properties['description']).to be nil
13
+ expect(@images[0].properties['description']).to eq('')
14
14
  expect(@images[0].properties['location']).to match(/\w+\/\w+/)
15
- expect(@images[0].properties['size']).to be_kind_of(Integer)
15
+ expect(@images[0].properties['size']).to be > 0
16
16
  end
17
17
 
18
18
  it '#get' do
@@ -23,7 +23,7 @@ describe ProfitBricks::Image do
23
23
  expect(image.properties['name']).to be_kind_of(String)
24
24
  expect(image.properties['description']).to be nil
25
25
  expect(image.properties['location']).to match(/\w+\/\w+/)
26
- expect(image.properties['size']).to be_kind_of(Integer)
26
+ expect(image.properties['size']).to be > 0
27
27
  end
28
28
 
29
29
  # Unable to test in production due to public images.
data/spec/server_spec.rb CHANGED
@@ -68,7 +68,8 @@ describe ProfitBricks::Server do
68
68
  expect(servers[0].properties['ram']).to eq(1024)
69
69
  expect(servers[0].properties['availabilityZone']).to eq('AUTO')
70
70
  expect(servers[0].properties['vmState']).to eq('RUNNING')
71
- expect(servers[0].properties['bootVolume']).to be nil
71
+ expect(servers[0].properties['bootVolume']['type']).to eq('volume')
72
+ expect(servers[0].properties['bootVolume']['id']).to match(options[:uuid])
72
73
  expect(servers[0].properties['bootCdrom']).to be nil
73
74
  end
74
75
 
@@ -82,7 +83,8 @@ describe ProfitBricks::Server do
82
83
  expect(server.properties['ram']).to eq(1024)
83
84
  expect(server.properties['availabilityZone']).to eq('AUTO')
84
85
  expect(server.properties['vmState']).to eq('RUNNING')
85
- expect(server.properties['bootVolume']).to be nil
86
+ expect(server.properties['bootVolume']['type']).to eq('volume')
87
+ expect(server.properties['bootVolume']['id']).to match(options[:uuid])
86
88
  expect(server.properties['bootCdrom']).to be nil
87
89
  end
88
90
 
@@ -98,7 +100,8 @@ describe ProfitBricks::Server do
98
100
  expect(server.properties['ram']).to eq(1024)
99
101
  expect(server.properties['availabilityZone']).to eq('AUTO')
100
102
  expect(server.properties['vmState']).to eq('RUNNING')
101
- expect(server.properties['bootVolume']).to be nil
103
+ expect(server.properties['bootVolume']['type']).to eq('volume')
104
+ expect(server.properties['bootVolume']['id']).to match(options[:uuid])
102
105
  expect(server.properties['bootCdrom']).to be nil
103
106
  end
104
107
 
@@ -108,6 +108,8 @@ describe ProfitBricks::Snapshot do
108
108
  snapshot = @volume.create_snapshot(options[:snapshot])
109
109
  snapshot.wait_for { ready? }
110
110
 
111
- expect(snapshot.delete).to have_key(:requestId)
111
+ snapshot = snapshot.delete
112
+ expect(snapshot.type).to eq('snapshot')
113
+ expect(snapshot.delete.requestId).to match(options[:uuid])
112
114
  end
113
115
  end
@@ -16,7 +16,8 @@ module Helpers
16
16
 
17
17
  volume: {
18
18
  name: 'my boot volume for server 1',
19
- size: 10,
19
+ size: 5,
20
+ type: 'HDD',
20
21
  licenceType: 'UNKNOWN'
21
22
  },
22
23
 
@@ -27,7 +28,7 @@ module Helpers
27
28
 
28
29
  nic: {
29
30
  name: 'nic1',
30
- dhcp: 'true',
31
+ dhcp: true,
31
32
  lan: 1,
32
33
  firewallActive: true
33
34
  },
@@ -67,7 +68,8 @@ module Helpers
67
68
  volumes: [
68
69
  {
69
70
  name: 'composite-boot',
70
- size: 10,
71
+ size: 5,
72
+ type: 'HDD',
71
73
  licenceType: 'UNKNOWN'
72
74
  }
73
75
  ],
data/spec/volume_spec.rb CHANGED
@@ -28,7 +28,7 @@ describe ProfitBricks::Volume do
28
28
  expect(@volume.properties['name']).to eq('my boot volume for server 1')
29
29
  expect(@volume.properties['size']).to be_kind_of(Integer)
30
30
  expect(@volume.properties['bus']).to be nil
31
- expect(@volume.properties['type']).to be nil
31
+ expect(@volume.properties['type']).to eq('HDD')
32
32
  end
33
33
 
34
34
  it '#list' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: profitbricks-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Devenport
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-23 00:00:00.000000000 Z
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -98,6 +98,7 @@ files:
98
98
  - lib/profitbricks.rb
99
99
  - lib/profitbricks/config.rb
100
100
  - lib/profitbricks/datacenter.rb
101
+ - lib/profitbricks/errors.rb
101
102
  - lib/profitbricks/firewall.rb
102
103
  - lib/profitbricks/image.rb
103
104
  - lib/profitbricks/ipblock.rb