fog-profitbricks 2.0.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.travis.yml +11 -4
  4. data/README.md +8 -5
  5. data/Rakefile +1 -1
  6. data/examples/pb_demo.rb +49 -49
  7. data/fog-profitbricks.gemspec +4 -5
  8. data/gemfiles/Gemfile.1.9.2+ +1 -0
  9. data/lib/fog/bin/profitbricks.rb +5 -5
  10. data/lib/fog/profitbricks.rb +3 -3
  11. data/lib/fog/profitbricks/compute.rb +209 -204
  12. data/lib/fog/profitbricks/helpers/compute/data_helper.rb +1 -1
  13. data/lib/fog/profitbricks/models/compute/datacenter.rb +1 -1
  14. data/lib/fog/profitbricks/models/compute/datacenters.rb +6 -7
  15. data/lib/fog/profitbricks/models/compute/firewall_rule.rb +2 -2
  16. data/lib/fog/profitbricks/models/compute/firewall_rules.rb +5 -8
  17. data/lib/fog/profitbricks/models/compute/flavors.rb +1 -4
  18. data/lib/fog/profitbricks/models/compute/image.rb +4 -0
  19. data/lib/fog/profitbricks/models/compute/images.rb +2 -5
  20. data/lib/fog/profitbricks/models/compute/ip_block.rb +1 -1
  21. data/lib/fog/profitbricks/models/compute/ip_blocks.rb +3 -8
  22. data/lib/fog/profitbricks/models/compute/lan.rb +1 -1
  23. data/lib/fog/profitbricks/models/compute/lans.rb +4 -7
  24. data/lib/fog/profitbricks/models/compute/load_balancer.rb +6 -7
  25. data/lib/fog/profitbricks/models/compute/load_balancers.rb +5 -9
  26. data/lib/fog/profitbricks/models/compute/locations.rb +2 -5
  27. data/lib/fog/profitbricks/models/compute/nic.rb +6 -3
  28. data/lib/fog/profitbricks/models/compute/nics.rb +2 -5
  29. data/lib/fog/profitbricks/models/compute/regions.rb +1 -4
  30. data/lib/fog/profitbricks/models/compute/request.rb +0 -1
  31. data/lib/fog/profitbricks/models/compute/requests.rb +2 -4
  32. data/lib/fog/profitbricks/models/compute/server.rb +10 -13
  33. data/lib/fog/profitbricks/models/compute/servers.rb +3 -6
  34. data/lib/fog/profitbricks/models/compute/snapshot.rb +2 -2
  35. data/lib/fog/profitbricks/models/compute/snapshots.rb +3 -6
  36. data/lib/fog/profitbricks/models/compute/volume.rb +11 -9
  37. data/lib/fog/profitbricks/models/compute/volumes.rb +3 -6
  38. data/lib/fog/profitbricks/requests/compute/associate_nic_to_load_balancer.rb +26 -13
  39. data/lib/fog/profitbricks/requests/compute/attach_cdrom.rb +25 -16
  40. data/lib/fog/profitbricks/requests/compute/attach_volume.rb +25 -16
  41. data/lib/fog/profitbricks/requests/compute/create_datacenter.rb +22 -23
  42. data/lib/fog/profitbricks/requests/compute/create_firewall_rule.rb +24 -26
  43. data/lib/fog/profitbricks/requests/compute/create_flavor.rb +34 -34
  44. data/lib/fog/profitbricks/requests/compute/create_ip_block.rb +18 -20
  45. data/lib/fog/profitbricks/requests/compute/create_lan.rb +151 -150
  46. data/lib/fog/profitbricks/requests/compute/create_load_balancer.rb +67 -26
  47. data/lib/fog/profitbricks/requests/compute/create_nic.rb +24 -26
  48. data/lib/fog/profitbricks/requests/compute/create_server.rb +70 -61
  49. data/lib/fog/profitbricks/requests/compute/create_volume.rb +122 -122
  50. data/lib/fog/profitbricks/requests/compute/create_volume_snapshot.rb +42 -45
  51. data/lib/fog/profitbricks/requests/compute/delete_datacenter.rb +34 -36
  52. data/lib/fog/profitbricks/requests/compute/delete_firewall_rule.rb +8 -11
  53. data/lib/fog/profitbricks/requests/compute/delete_image.rb +7 -9
  54. data/lib/fog/profitbricks/requests/compute/delete_ip_block.rb +8 -10
  55. data/lib/fog/profitbricks/requests/compute/delete_lan.rb +7 -9
  56. data/lib/fog/profitbricks/requests/compute/delete_load_balancer.rb +8 -10
  57. data/lib/fog/profitbricks/requests/compute/delete_nic.rb +7 -10
  58. data/lib/fog/profitbricks/requests/compute/delete_server.rb +6 -10
  59. data/lib/fog/profitbricks/requests/compute/delete_snapshot.rb +7 -10
  60. data/lib/fog/profitbricks/requests/compute/delete_volume.rb +36 -38
  61. data/lib/fog/profitbricks/requests/compute/detach_cdrom.rb +11 -13
  62. data/lib/fog/profitbricks/requests/compute/detach_volume.rb +16 -13
  63. data/lib/fog/profitbricks/requests/compute/get_all_datacenters.rb +1 -1
  64. data/lib/fog/profitbricks/requests/compute/get_all_firewall_rules.rb +6 -7
  65. data/lib/fog/profitbricks/requests/compute/get_all_flavors.rb +72 -72
  66. data/lib/fog/profitbricks/requests/compute/get_all_images.rb +62 -62
  67. data/lib/fog/profitbricks/requests/compute/get_all_ip_blocks.rb +5 -5
  68. data/lib/fog/profitbricks/requests/compute/get_all_lans.rb +113 -113
  69. data/lib/fog/profitbricks/requests/compute/get_all_load_balanced_nics.rb +15 -9
  70. data/lib/fog/profitbricks/requests/compute/get_all_load_balancers.rb +9 -9
  71. data/lib/fog/profitbricks/requests/compute/get_all_locations.rb +6 -6
  72. data/lib/fog/profitbricks/requests/compute/get_all_nic.rb +94 -94
  73. data/lib/fog/profitbricks/requests/compute/get_all_requests.rb +38 -38
  74. data/lib/fog/profitbricks/requests/compute/get_all_servers.rb +8 -9
  75. data/lib/fog/profitbricks/requests/compute/get_all_snapshots.rb +4 -4
  76. data/lib/fog/profitbricks/requests/compute/get_all_volumes.rb +71 -71
  77. data/lib/fog/profitbricks/requests/compute/get_attached_cdrom.rb +11 -11
  78. data/lib/fog/profitbricks/requests/compute/get_attached_volume.rb +16 -11
  79. data/lib/fog/profitbricks/requests/compute/get_datacenter.rb +4 -6
  80. data/lib/fog/profitbricks/requests/compute/get_firewall_rule.rb +8 -11
  81. data/lib/fog/profitbricks/requests/compute/get_flavor.rb +9 -9
  82. data/lib/fog/profitbricks/requests/compute/get_image.rb +7 -9
  83. data/lib/fog/profitbricks/requests/compute/get_ip_block.rb +8 -10
  84. data/lib/fog/profitbricks/requests/compute/get_lan.rb +7 -10
  85. data/lib/fog/profitbricks/requests/compute/get_load_balanced_nic.rb +16 -12
  86. data/lib/fog/profitbricks/requests/compute/get_load_balancer.rb +7 -9
  87. data/lib/fog/profitbricks/requests/compute/get_location.rb +7 -9
  88. data/lib/fog/profitbricks/requests/compute/get_nic.rb +8 -11
  89. data/lib/fog/profitbricks/requests/compute/get_request.rb +55 -57
  90. data/lib/fog/profitbricks/requests/compute/get_request_status.rb +44 -46
  91. data/lib/fog/profitbricks/requests/compute/get_server.rb +7 -10
  92. data/lib/fog/profitbricks/requests/compute/get_snapshot.rb +7 -9
  93. data/lib/fog/profitbricks/requests/compute/get_volume.rb +7 -9
  94. data/lib/fog/profitbricks/requests/compute/list_attached_cdroms.rb +8 -8
  95. data/lib/fog/profitbricks/requests/compute/list_attached_volumes.rb +18 -8
  96. data/lib/fog/profitbricks/requests/compute/reboot_server.rb +7 -11
  97. data/lib/fog/profitbricks/requests/compute/remove_nic_association.rb +9 -11
  98. data/lib/fog/profitbricks/requests/compute/restore_volume_snapshot.rb +15 -17
  99. data/lib/fog/profitbricks/requests/compute/start_server.rb +7 -11
  100. data/lib/fog/profitbricks/requests/compute/stop_server.rb +7 -11
  101. data/lib/fog/profitbricks/requests/compute/update_datacenter.rb +20 -15
  102. data/lib/fog/profitbricks/requests/compute/update_firewall_rule.rb +9 -11
  103. data/lib/fog/profitbricks/requests/compute/update_image.rb +15 -15
  104. data/lib/fog/profitbricks/requests/compute/update_lan.rb +6 -8
  105. data/lib/fog/profitbricks/requests/compute/update_load_balancer.rb +10 -12
  106. data/lib/fog/profitbricks/requests/compute/update_nic.rb +10 -12
  107. data/lib/fog/profitbricks/requests/compute/update_server.rb +10 -13
  108. data/lib/fog/profitbricks/requests/compute/update_snapshot.rb +10 -13
  109. data/lib/fog/profitbricks/requests/compute/update_volume.rb +10 -13
  110. data/lib/fog/profitbricks/version.rb +1 -1
  111. data/spec/minitest_helper.rb +1 -3
  112. data/tests/helpers/formats_helper.rb +8 -8
  113. data/tests/profitbricks/models/compute/compute_tests.rb +529 -0
  114. data/tests/profitbricks/requests/compute/composite_create_tests.rb +16 -83
  115. data/tests/profitbricks/requests/compute/flavor_tests.rb +1 -4
  116. data/tests/profitbricks/requests/compute/location_tests.rb +14 -17
  117. data/tests/profitbricks/requests/compute/nic_tests.rb +60 -70
  118. data/tests/profitbricks/requests/compute/request_tests.rb +1 -3
  119. data/tests/profitbricks/requests/compute/server_tests.rb +163 -161
  120. metadata +5 -18
@@ -1,5 +1,5 @@
1
1
  # require "fog/compute/models/server"
2
- require File.expand_path('../../helpers/compute/data_helper', __dir__)
2
+ require File.expand_path('../../../helpers/compute/data_helper', __FILE__)
3
3
 
4
4
  module Fog
5
5
  module Compute
@@ -54,13 +54,9 @@ module Fog
54
54
  properties[:cpuFamily] = cpu_family if cpu_family
55
55
 
56
56
  entities = {}
57
- if volumes
58
- entities[:volumes] = get_volumes(volumes)
59
- end
57
+ entities[:volumes] = get_volumes(volumes) if volumes
60
58
 
61
- if nics
62
- entities[:nics] = get_nics(nics)
63
- end
59
+ entities[:nics] = get_nics(nics) if nics
64
60
 
65
61
  data = service.create_server(datacenter_id, properties, entities)
66
62
  merge_attributes(flatten(data.body))
@@ -110,6 +106,7 @@ module Fog
110
106
  requires :datacenter_id, :id
111
107
 
112
108
  data = service.attach_cdrom(datacenter_id, id, cdrom_image_id)
109
+
113
110
  flatten(data.body)
114
111
  end
115
112
 
@@ -216,9 +213,9 @@ module Fog
216
213
  item[:imagePassword] = volume[:image_password]
217
214
  item[:sshKeys] = volume[:ssh_keys]
218
215
  item[:licenceType] = volume[:licence_type]
219
- items << { properties: item }
216
+ items << { :properties => item }
220
217
  end
221
- { items: items }
218
+ { :items => items }
222
219
  end
223
220
 
224
221
  def get_nics(nics)
@@ -235,9 +232,9 @@ module Fog
235
232
  firewall_rules = get_firewall_rules(nic[:firewall_rules])
236
233
  item[:firewallActive] = true
237
234
  end
238
- items << { properties: item, entities: firewall_rules }
235
+ items << { :properties => item, :entities => firewall_rules }
239
236
  end
240
- { items: items }
237
+ { :items => items }
241
238
  end
242
239
 
243
240
  def get_firewall_rules(firewall_rules)
@@ -253,9 +250,9 @@ module Fog
253
250
  item[:portRangeEnd] = firewall_rule[:port_range_end] if firewall_rule.key?(:port_range_end)
254
251
  item[:icmpType] = firewall_rule[:icmp_type] if firewall_rule.key?(:icmp_type)
255
252
  item[:icmpCode] = firewall_rule[:icmp_code] if firewall_rule.key?(:icmp_code)
256
- items << { properties: item }
253
+ items << { :properties => item }
257
254
  end
258
- { firewallrules: { items: items } }
255
+ { :firewallrules => { :items => items } }
259
256
  end
260
257
  end
261
258
  end
@@ -1,5 +1,5 @@
1
1
  require File.expand_path('../server', __FILE__)
2
- require File.expand_path('../../helpers/compute/data_helper', __dir__)
2
+ require File.expand_path('../../../helpers/compute/data_helper', __FILE__)
3
3
 
4
4
  module Fog
5
5
  module Compute
@@ -11,20 +11,17 @@ module Fog
11
11
  def all(datacenter_id)
12
12
  result = service.get_all_servers(datacenter_id)
13
13
 
14
- servers = result.body['items'].each {|server| server['datacenter_id'] = datacenter_id}
14
+ servers = result.body['items'].each { |server| server['datacenter_id'] = datacenter_id }
15
15
  result.body['items'] = servers
16
16
 
17
- load(result.body['items'].each {|dc| flatten(dc)})
17
+ load(result.body['items'].each { |dc| flatten(dc) })
18
18
  end
19
19
 
20
20
  def get(datacenter_id, server_id)
21
21
  server = service.get_server(datacenter_id, server_id).body
22
22
  server['datacenter_id'] = datacenter_id
23
23
 
24
- Excon::Errors
25
24
  new(flatten(server))
26
- rescue Excon::Errors::NotFound
27
- nil
28
25
  end
29
26
  end
30
27
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../helpers/compute/data_helper', __dir__)
1
+ require File.expand_path('../../../helpers/compute/data_helper', __FILE__)
2
2
 
3
3
  module Fog
4
4
  module Compute
@@ -55,7 +55,7 @@ module Fog
55
55
  options[:discVirtioHotUnplug] = disc_virtio_hot_unplug if disc_virtio_hot_unplug
56
56
  options[:discScsiHotPlug] = disc_scsi_hot_plug if disc_scsi_hot_plug
57
57
  options[:discScsiHotUnplug] = disc_scsi_hot_unplug if disc_scsi_hot_unplug
58
- options[:licenceType] = license_type if license_type
58
+ options[:licenceType] = licence_type if licence_type
59
59
 
60
60
  data = service.update_snapshot(id, options)
61
61
  merge_attributes(flatten(data.body))
@@ -1,5 +1,5 @@
1
1
  require File.expand_path('../snapshot', __FILE__)
2
- require File.expand_path('../../helpers/compute/data_helper', __dir__)
2
+ require File.expand_path('../../../helpers/compute/data_helper', __FILE__)
3
3
 
4
4
  module Fog
5
5
  module Compute
@@ -11,18 +11,15 @@ module Fog
11
11
  def all
12
12
  result = service.get_all_snapshots
13
13
 
14
- load(result.body['items'].each {|snapshot| flatten(snapshot)})
14
+ load(result.body['items'].each { |snapshot| flatten(snapshot) })
15
15
  end
16
16
 
17
17
  def get(id)
18
18
  snapshot = service.get_snapshot(id).body
19
19
 
20
- Excon::Errors
21
20
  new(flatten(snapshot))
22
- rescue Excon::Errors::NotFound
23
- nil
24
21
  end
25
22
  end
26
23
  end
27
24
  end
28
- end
25
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../../helpers/compute/data_helper', __dir__)
1
+ require File.expand_path('../../../helpers/compute/data_helper', __FILE__)
2
2
 
3
3
  module Fog
4
4
  module Compute
@@ -14,6 +14,7 @@ module Fog
14
14
  attribute :image
15
15
  attribute :bus
16
16
  attribute :type
17
+ attribute :availability_zone, :aliases => 'availabilityZone'
17
18
  attribute :image_password, :aliases => 'imagePassword'
18
19
  attribute :ssh_keys, :aliases => 'sshKeys'
19
20
  attribute :licence_type, :aliases => 'licenceType'
@@ -49,14 +50,15 @@ module Fog
49
50
  requires :datacenter_id, :size, :type
50
51
 
51
52
  options = {}
52
- options[:name] = name if name
53
- options[:size] = size
54
- options[:bus] = bus if bus
55
- options[:image] = image if image
56
- options[:type] = type
57
- options[:licenceType] = licence_type if licence_type
58
- options[:imagePassword] = image_password if image_password
59
- options[:sshKeys] = ssh_keys if ssh_keys
53
+ options[:name] = name if name
54
+ options[:size] = size
55
+ options[:bus] = bus if bus
56
+ options[:image] = image if image
57
+ options[:type] = type
58
+ options[:licenceType] = licence_type if licence_type
59
+ options[:imagePassword] = image_password if image_password
60
+ options[:sshKeys] = ssh_keys if ssh_keys
61
+ options[:availabilityZone] = availability_zone if availability_zone
60
62
 
61
63
  data = service.create_volume(datacenter_id, options)
62
64
  merge_attributes(flatten(data.body))
@@ -1,5 +1,5 @@
1
1
  require File.expand_path('../volume', __FILE__)
2
- require File.expand_path('../../helpers/compute/data_helper', __dir__)
2
+ require File.expand_path('../../../helpers/compute/data_helper', __FILE__)
3
3
 
4
4
  module Fog
5
5
  module Compute
@@ -11,21 +11,18 @@ module Fog
11
11
  def all(datacenter_id)
12
12
  result = service.get_all_volumes(datacenter_id)
13
13
 
14
- volumes = result.body['items'].each {|volume| volume['datacenter_id'] = datacenter_id}
14
+ volumes = result.body['items'].each { |volume| volume['datacenter_id'] = datacenter_id }
15
15
  result.body['items'] = volumes
16
16
 
17
- load(result.body['items'].each {|volume| flatten(volume)})
17
+ load(result.body['items'].each { |volume| flatten(volume) })
18
18
  end
19
19
 
20
20
  def get(datacenter_id, volume_id)
21
21
  response = service.get_volume(datacenter_id, volume_id)
22
22
  volume = response.body
23
23
 
24
- Excon::Errors
25
24
  volume['datacenter_id'] = datacenter_id
26
25
  new(flatten(volume))
27
- rescue Excon::Errors::NotFound
28
- nil
29
26
  end
30
27
  end
31
28
  end
@@ -68,30 +68,43 @@ module Fog
68
68
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#associate-nic-to-load-balancer]
69
69
  def associate_nic_to_load_balancer(datacenter_id, load_balancer_id, nic_id)
70
70
  nic = {
71
- :id => nic_id
71
+ :id => nic_id
72
72
  }
73
73
 
74
74
  request(
75
- :expects => [202],
76
- :method => 'POST',
77
- :path => "/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}/balancednics",
78
- :body => Fog::JSON.encode(nic)
75
+ :expects => [202],
76
+ :method => 'POST',
77
+ :path => "/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}/balancednics",
78
+ :body => Fog::JSON.encode(nic)
79
79
  )
80
- rescue => error
81
- Fog::Errors::NotFound.new(error)
82
80
  end
83
81
  end
84
82
 
85
83
  class Mock
86
84
  def associate_nic_to_load_balancer(datacenter_id, load_balancer_id, nic_id)
87
- if load_balancer = self.data[:load_balancers]['items'].find {
88
- |lb| lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
89
- }
85
+ if load_balancer = data[:load_balancers]['items'].find do |lb|
86
+ lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
87
+ end
90
88
  else
91
- raise Fog::Errors::NotFound.new("The requested resource could not be found")
89
+ raise Fog::Errors::NotFound, "The requested resource could not be found"
90
+ end
91
+
92
+ unless load_balancer['entities'] && load_balancer['entities']['balancednics'] && load_balancer['entities']['balancednics']['items']
93
+ nic = data[:nics]['items'].find do |nic|
94
+ nic["datacenter_id"] == datacenter_id && nic["id"] == nic_id
95
+ end
96
+
97
+ load_balancer['entities'] = {
98
+ 'balancednics' => {
99
+ 'id' => "#{load_balancer_id}/balancednics",
100
+ 'type' => "collection",
101
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}/balancednics",
102
+ 'items' => [nic]
103
+ }
104
+ }
92
105
  end
93
106
 
94
- data = load_balancer['entities'][:balancednics][0]
107
+ data = load_balancer['entities']['balancednics']['items'][0]
95
108
 
96
109
  response = Excon::Response.new
97
110
  response.status = 202
@@ -101,4 +114,4 @@ module Fog
101
114
  end
102
115
  end
103
116
  end
104
- end
117
+ end
@@ -44,37 +44,46 @@ module Fog
44
44
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#attach-a-cd-rom]
45
45
  def attach_cdrom(datacenter_id, server_id, cdrom_image_id)
46
46
  volume = {
47
- :id => cdrom_image_id
47
+ :id => cdrom_image_id
48
48
  }
49
49
 
50
50
  request(
51
- :expects => [202],
52
- :method => 'POST',
53
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms",
54
- :body => Fog::JSON.encode(volume)
51
+ :expects => [202],
52
+ :method => 'POST',
53
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms",
54
+ :body => Fog::JSON.encode(volume)
55
55
  )
56
- rescue => error
57
- Fog::Errors::NotFound.new(error)
58
56
  end
59
57
  end
60
58
 
61
59
  class Mock
62
60
  def attach_cdrom(datacenter_id, server_id, cdrom_image_id)
63
- if cdrom = self.data[:images]['items'].find {
64
- |cd| cd["id"] == cdrom_image_id
65
- }
61
+ if cdrom = data[:images]['items'].find do |cd|
62
+ cd["id"] == cdrom_image_id
63
+ end
66
64
  else
67
- raise Fog::Errors::NotFound.new("The requested resource could not be found")
65
+ raise Fog::Errors::NotFound, "The requested resource could not be found"
68
66
  end
69
67
 
70
- if server = self.data[:servers]['items'].find {
71
- |serv| serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
72
- }
68
+ if server = data[:servers]['items'].find do |serv|
69
+ serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
70
+ end
73
71
  else
74
- raise Fog::Errors::NotFound.new("The server resource could not be found")
72
+ raise Fog::Errors::NotFound, "The server resource could not be found"
75
73
  end
76
74
 
77
- server['entities']['cdroms']['items'] << cdrom
75
+ if server['entities'] && server['entities']['cdroms'] && server['entities']['cdroms']['items']
76
+ server['entities']['cdroms']['items'] << cdrom
77
+ else
78
+ server['entities'] = {
79
+ 'cdroms' => {
80
+ 'id' => "#{server['id']}/cdroms",
81
+ 'type' => 'collection',
82
+ 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{server['datacenter_id']}/servers/#{server['id']}/cdroms",
83
+ 'items' => [cdrom]
84
+ }
85
+ }
86
+ end
78
87
 
79
88
  response = Excon::Response.new
80
89
  response.status = 202
@@ -45,37 +45,46 @@ module Fog
45
45
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#attach-a-volume]
46
46
  def attach_volume(datacenter_id, server_id, storage_id)
47
47
  volume = {
48
- :id => storage_id
48
+ :id => storage_id
49
49
  }
50
50
 
51
51
  request(
52
- :expects => [202],
53
- :method => 'POST',
54
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes",
55
- :body => Fog::JSON.encode(volume)
52
+ :expects => [202],
53
+ :method => 'POST',
54
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes",
55
+ :body => Fog::JSON.encode(volume)
56
56
  )
57
- rescue => error
58
- Fog::Errors::NotFound.new(error)
59
57
  end
60
58
  end
61
59
 
62
60
  class Mock
63
61
  def attach_volume(datacenter_id, server_id, storage_id)
64
- if volume = self.data[:volumes]['items'].find {
65
- |vlm| vlm["id"] == storage_id && vlm["datacenter_id"] == datacenter_id
66
- }
62
+ if volume = data[:volumes]['items'].find do |vlm|
63
+ vlm["id"] == storage_id && vlm["datacenter_id"] == datacenter_id
64
+ end
67
65
  else
68
- raise Fog::Errors::NotFound.new("The requested resource could not be found")
66
+ raise Fog::Errors::NotFound, "The requested resource could not be found"
69
67
  end
70
68
 
71
- if server = self.data[:servers]['items'].find {
72
- |serv| serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
73
- }
69
+ if server = data[:servers]['items'].find do |serv|
70
+ serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
71
+ end
74
72
  else
75
- raise Fog::Errors::NotFound.new("The server resource could not be found")
73
+ raise Fog::Errors::NotFound, "The server resource could not be found"
76
74
  end
77
75
 
78
- server['entities']['volumes']['items'] << volume
76
+ if server['entities'] && server['entities']['volumes'] && server['entities']['volumes']['items']
77
+ server['entities']['volumes']['items'] << volume
78
+ else
79
+ server['entities'] = {
80
+ 'volumes' => {
81
+ 'id' => "#{server_id}/volumes",
82
+ 'type' => 'collection',
83
+ 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/volumes",
84
+ 'items' => [volume]
85
+ }
86
+ }
87
+ end
79
88
 
80
89
  response = Excon::Response.new
81
90
  response.status = 202
@@ -38,7 +38,7 @@ module Fog
38
38
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-a-data-center]
39
39
  def create_datacenter(options)
40
40
  datacenter = {
41
- :properties => options
41
+ :properties => options
42
42
  }
43
43
 
44
44
  request(
@@ -51,39 +51,38 @@ module Fog
51
51
  end
52
52
 
53
53
  class Mock
54
- def create_datacenter(options)
54
+ def create_datacenter(_options)
55
55
  dc_3_id = Fog::UUID.uuid
56
56
  datacenter = {
57
- 'id'=>dc_3_id,
58
- 'type'=>'datacenter',
59
- 'href'=>"https://api.profitbricks.com/rest/v2/datacenters/#{dc_3_id}",
60
- 'metadata'=>{
61
- 'createdDate'=>'2016-07-31T15:41:27Z',
62
- 'createdBy'=>'test@stackpointcloud.com',
63
- 'etag'=>'5b91832ee85a758568d4523a86bd8702',
64
- 'lastModifiedDate'=>'2016-07-31T15:41:27Z',
65
- 'lastModifiedBy'=>'test@stackpointcloud.com',
66
- 'state'=>'AVAILABLE'
67
- },
68
- 'properties'=>{
69
- 'name'=>'dc_3',
70
- 'description'=>'testing fog rest implementation',
71
- 'location'=>'de/fra',
72
- 'version'=>1,
73
- 'features'=>[
57
+ 'id' => dc_3_id,
58
+ 'type' => 'datacenter',
59
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{dc_3_id}",
60
+ 'metadata' => {
61
+ 'createdDate' => '2016-07-31T15:41:27Z',
62
+ 'createdBy' => 'test@stackpointcloud.com',
63
+ 'etag' => '5b91832ee85a758568d4523a86bd8702',
64
+ 'lastModifiedDate' => '2016-07-31T15:41:27Z',
65
+ 'lastModifiedBy' => 'test@stackpointcloud.com',
66
+ 'state' => 'AVAILABLE'
67
+ },
68
+ 'properties' => {
69
+ 'name' => 'fog-demo',
70
+ 'description' => 'testing fog rest implementation',
71
+ 'location' => 'de/fra',
72
+ 'version' => 1,
73
+ 'features' => [
74
74
 
75
- ]
76
- }
75
+ ]
76
+ }
77
77
  }
78
78
 
79
- self.data[:datacenters]['items'] << datacenter
79
+ data[:datacenters]['items'] << datacenter
80
80
  response = Excon::Response.new
81
81
  response.status = 202
82
82
  response.body = datacenter
83
83
  response
84
84
  end
85
85
  end
86
-
87
86
  end
88
87
  end
89
88
  end