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
@@ -103,23 +103,20 @@ module Fog
103
103
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#retrieve-a-server]
104
104
  def get_server(datacenter_id, server_id)
105
105
  request(
106
- :expects => [200],
107
- :method => "GET",
108
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}?depth=5"
106
+ :expects => [200],
107
+ :method => "GET",
108
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}?depth=5"
109
109
  )
110
- rescue => error
111
- Fog::Errors::NotFound.new(error)
112
110
  end
113
111
  end
114
112
 
115
113
  class Mock
116
114
  def get_server(datacenter_id, server_id)
117
-
118
- if server = self.data[:servers]['items'].find {
119
- |serv| serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
120
- }
115
+ if server = data[:servers]['items'].find do |serv|
116
+ serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
117
+ end
121
118
  else
122
- raise Fog::Errors::NotFound.new("The server resource could not be found")
119
+ raise Fog::Errors::NotFound, "The server resource could not be found"
123
120
  end
124
121
 
125
122
  response = Excon::Response.new
@@ -41,22 +41,20 @@ module Fog
41
41
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#get-snapshot]
42
42
  def get_snapshot(snapshot_id)
43
43
  request(
44
- :expects => [200],
45
- :method => "GET",
46
- :path => "/snapshots/#{snapshot_id}"
44
+ :expects => [200],
45
+ :method => "GET",
46
+ :path => "/snapshots/#{snapshot_id}"
47
47
  )
48
- rescue => error
49
- Fog::Errors::NotFound.new(error)
50
48
  end
51
49
  end
52
50
 
53
51
  class Mock
54
52
  def get_snapshot(snapshot_id)
55
- if snapshot = self.data[:snapshots]['items'].find {
56
- |attrib| attrib["id"] == snapshot_id
57
- }
53
+ if snapshot = data[:snapshots]['items'].find do |attrib|
54
+ attrib["id"] == snapshot_id
55
+ end
58
56
  else
59
- raise Fog::Errors::NotFound.new("The requested resource could not be found")
57
+ raise Excon::Error::HTTPStatus, "The requested resource could not be found"
60
58
  end
61
59
 
62
60
  response = Excon::Response.new
@@ -44,22 +44,20 @@ module Fog
44
44
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#get-volume]
45
45
  def get_volume(datacenter_id, volume_id)
46
46
  request(
47
- :expects => [200],
48
- :method => "GET",
49
- :path => "/datacenters/#{datacenter_id}/volumes/#{volume_id}"
47
+ :expects => [200],
48
+ :method => "GET",
49
+ :path => "/datacenters/#{datacenter_id}/volumes/#{volume_id}"
50
50
  )
51
- rescue => error
52
- Fog::Errors::NotFound.new(error)
53
51
  end
54
52
  end
55
53
 
56
54
  class Mock
57
55
  def get_volume(datacenter_id, volume_id)
58
- if volume = self.data[:volumes]['items'].find {
59
- |vlm| vlm["id"] == volume_id && vlm["datacenter_id"] == datacenter_id
60
- }
56
+ if volume = data[:volumes]['items'].find do |vlm|
57
+ vlm["id"] == volume_id && vlm["datacenter_id"] == datacenter_id
58
+ end
61
59
  else
62
- raise Fog::Errors::NotFound.new("The requested resource could not be found")
60
+ raise Excon::Error::HTTPStatus, "The requested resource could not be found"
63
61
  end
64
62
 
65
63
  response = Excon::Response.new
@@ -47,25 +47,25 @@ module Fog
47
47
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#list-attached-cd-roms]
48
48
  def list_attached_cdroms(datacenter_id, server_id)
49
49
  request(
50
- :expects => [200],
51
- :method => 'GET',
52
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms?depth=1"
50
+ :expects => [200],
51
+ :method => 'GET',
52
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms?depth=1"
53
53
  )
54
54
  end
55
55
  end
56
56
 
57
57
  class Mock
58
58
  def list_attached_cdroms(datacenter_id, server_id)
59
- if server = self.data[:servers]['items'].find {
60
- |serv| serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
61
- }
59
+ if server = data[:servers]['items'].find do |serv|
60
+ serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
61
+ end
62
62
  else
63
- raise Fog::Errors::NotFound.new("The server resource could not be found")
63
+ raise Fog::Errors::NotFound, "The server resource could not be found"
64
64
  end
65
65
 
66
66
  response = Excon::Response.new
67
67
  response.status = 200
68
- response.body = server['entities']['cdroms']
68
+ response.body = data[:images]
69
69
  response
70
70
  end
71
71
  end
@@ -48,25 +48,35 @@ module Fog
48
48
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#list-attached-volumes]
49
49
  def list_attached_volumes(datacenter_id, server_id)
50
50
  request(
51
- :expects => [200],
52
- :method => 'GET',
53
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes?depth=1"
51
+ :expects => [200],
52
+ :method => 'GET',
53
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/volumes?depth=1"
54
54
  )
55
55
  end
56
56
  end
57
57
 
58
58
  class Mock
59
59
  def list_attached_volumes(datacenter_id, server_id)
60
- if server = self.data[:servers]['items'].find {
61
- |serv| serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
62
- }
60
+ if server = data[:servers]['items'].find do |serv|
61
+ serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
62
+ end
63
63
  else
64
- raise Fog::Errors::NotFound.new("The server resource could not be found")
64
+ raise Fog::Errors::NotFound, "The server resource could not be found"
65
65
  end
66
66
 
67
67
  response = Excon::Response.new
68
68
  response.status = 200
69
- response.body = server['entities']['volumes']
69
+ response.body = if server['entities'] && server['entities']['volumes']
70
+ server['entities']['volumes']
71
+ else
72
+ {
73
+ 'id' => "#{server_id}/volumes",
74
+ 'type' => 'collection',
75
+ 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/volumes",
76
+ 'items' => []
77
+ }
78
+ end
79
+
70
80
  response
71
81
  end
72
82
  end
@@ -17,24 +17,20 @@ module Fog
17
17
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#reboot-a-server]
18
18
  def reboot_server(datacenter_id, server_id)
19
19
  request(
20
- :expects => [202],
21
- :method => 'POST',
22
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/reboot"
20
+ :expects => [202],
21
+ :method => 'POST',
22
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/reboot"
23
23
  )
24
- rescue => error
25
- Fog::Errors::NotFound.new(error)
26
24
  end
27
25
  end
28
26
 
29
27
  class Mock
30
28
  def reboot_server(datacenter_id, server_id)
31
- if server = self.data[:servers]['items'].find {
32
- |attrib| attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
33
- }
29
+ if server = data[:servers]['items'].find do |attrib|
30
+ attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
31
+ end
34
32
  else
35
- raise Fog::Errors::NotFound.new(
36
- 'The requested server resource could not be found'
37
- )
33
+ raise Fog::Errors::NotFound, 'The requested server resource could not be found'
38
34
  end
39
35
 
40
36
  response = Excon::Response.new
@@ -16,22 +16,20 @@ module Fog
16
16
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#remove-a-nic-association]
17
17
  def remove_nic_association(datacenter_id, load_balancer_id, nic_id)
18
18
  request(
19
- :expects => [202],
20
- :method => 'DELETE',
21
- :path => "/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}/balancednics/#{nic_id}"
19
+ :expects => [202],
20
+ :method => 'DELETE',
21
+ :path => "/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}/balancednics/#{nic_id}"
22
22
  )
23
- rescue => error
24
- Fog::Errors::NotFound.new(error)
25
23
  end
26
24
  end
27
25
 
28
26
  class Mock
29
- def remove_nic_association(datacenter_id, load_balancer_id, nic_id)
30
- if load_balancer = self.data[:load_balancers]['items'].find {
31
- |lb| lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
32
- }
27
+ def remove_nic_association(datacenter_id, load_balancer_id, _nic_id)
28
+ if load_balancer = data[:load_balancers]['items'].find do |lb|
29
+ lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
30
+ end
33
31
  else
34
- raise Fog::Errors::NotFound.new("The requested resource could not be found")
32
+ raise Fog::Errors::NotFound, "The requested resource could not be found"
35
33
  end
36
34
 
37
35
  response = Excon::Response.new
@@ -41,4 +39,4 @@ module Fog
41
39
  end
42
40
  end
43
41
  end
44
- end
42
+ end
@@ -21,36 +21,34 @@ module Fog
21
21
  # * Connection<~String>
22
22
  #
23
23
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-volume-snapshot]
24
- def restore_volume_snapshot(datacenter_id, volume_id, options={})
24
+ def restore_volume_snapshot(datacenter_id, volume_id, options = {})
25
25
  request(
26
- :expects => [202],
27
- :method => 'POST',
28
- :path => "/datacenters/#{datacenter_id}/volumes/#{volume_id}/restore-snapshot",
29
- :headers => { "Content-Type" => "application/x-www-form-urlencoded" },
30
- :body => URI.encode_www_form("snapshotId" => options[:snapshot_id])
26
+ :expects => [202],
27
+ :method => 'POST',
28
+ :path => "/datacenters/#{datacenter_id}/volumes/#{volume_id}/restore-snapshot",
29
+ :headers => { "Content-Type" => "application/x-www-form-urlencoded" },
30
+ :body => URI.encode_www_form("snapshotId" => options[:snapshot_id])
31
31
  )
32
- rescue => error
33
- Fog::Errors::NotFound.new(error)
34
32
  end
35
33
  end
36
34
 
37
35
  class Mock
38
- def restore_volume_snapshot(datacenter_id, volume_id, options={})
36
+ def restore_volume_snapshot(datacenter_id, volume_id, _options = {})
39
37
  response = Excon::Response.new
40
38
  response.status = 202
41
39
 
42
- if datacenter = self.data[:datacenters]['items'].find {
43
- |attrib| attrib['id'] == datacenter_id
44
- }
40
+ if datacenter = data[:datacenters]['items'].find do |attrib|
41
+ attrib['id'] == datacenter_id
42
+ end
45
43
  else
46
- raise Fog::Errors::NotFound.new('Data center resource could not be found')
44
+ raise Excon::Error::HTTPStatus, 'Data center resource could not be found'
47
45
  end
48
46
 
49
- if volume = self.data[:volumes]['items'].find {
50
- |attrib| attrib['id'] == volume_id && attrib['datacenter_id'] == datacenter_id
51
- }
47
+ if volume = data[:volumes]['items'].find do |attrib|
48
+ attrib['id'] == volume_id && attrib['datacenter_id'] == datacenter_id
49
+ end
52
50
  else
53
- raise Fog::Errors::NotFound.new('Volume resource could not be found')
51
+ raise Excon::Error::HTTPStatus, 'Volume resource could not be found'
54
52
  end
55
53
 
56
54
  response
@@ -16,24 +16,20 @@ module Fog
16
16
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#start-a-server]
17
17
  def start_server(datacenter_id, server_id)
18
18
  request(
19
- :expects => [202],
20
- :method => 'POST',
21
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/start"
19
+ :expects => [202],
20
+ :method => 'POST',
21
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/start"
22
22
  )
23
- rescue Excon::Errors::InternalServerError => error
24
- Fog::Errors::NotFound.new(error)
25
23
  end
26
24
  end
27
25
 
28
26
  class Mock
29
27
  def start_server(datacenter_id, server_id)
30
- if server = self.data[:servers]['items'].find {
31
- |attrib| attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
32
- }
28
+ if server = data[:servers]['items'].find do |attrib|
29
+ attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
30
+ end
33
31
  else
34
- raise Fog::Errors::NotFound.new(
35
- 'The requested server resource could not be found'
36
- )
32
+ raise Fog::Errors::NotFound, 'The requested server resource could not be found'
37
33
  end
38
34
 
39
35
  server['vm_state'] = 'RUNNING'
@@ -17,24 +17,20 @@ module Fog
17
17
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#stop-a-server]
18
18
  def stop_server(datacenter_id, server_id)
19
19
  request(
20
- :expects => [202],
21
- :method => 'POST',
22
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/stop"
20
+ :expects => [202],
21
+ :method => 'POST',
22
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/stop"
23
23
  )
24
- rescue Excon::Errors::InternalServerError => error
25
- Fog::Errors::NotFound.new(error)
26
24
  end
27
25
  end
28
26
 
29
27
  class Mock
30
28
  def stop_server(datacenter_id, server_id)
31
- if server = self.data[:servers]['items'].find {
32
- |attrib| attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
33
- }
29
+ if server = data[:servers]['items'].find do |attrib|
30
+ attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
31
+ end
34
32
  else
35
- raise Fog::Errors::NotFound.new(
36
- 'The requested server resource could not be found'
37
- )
33
+ raise Fog::Errors::NotFound, 'The requested server resource could not be found'
38
34
  end
39
35
 
40
36
  server['vm_state'] = 'SHUTOFF'
@@ -35,30 +35,35 @@ module Fog
35
35
  # * lans<~Hash> - A collection that represents the LANs in a data center
36
36
  #
37
37
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#update-a-data-center]
38
- def update_datacenter(datacenter_id, options={})
39
- request(
40
- :expects => [202],
41
- :method => 'PATCH',
42
- :path => "/datacenters/#{datacenter_id}",
43
- :body => Fog::JSON.encode(options)
44
- )
45
- rescue => error
46
- Fog::Errors::NotFound.new(error)
38
+ def update_datacenter(datacenter_id, options = {})
39
+ request(
40
+ :expects => [202],
41
+ :method => 'PATCH',
42
+ :path => "/datacenters/#{datacenter_id}",
43
+ :body => Fog::JSON.encode(options)
44
+ )
47
45
  end
48
46
  end
49
47
 
50
48
  class Mock
51
- def update_datacenter(datacenter_id, options={})
52
- if dc = self.data[:datacenters]["items"].find {
53
- |datacenter| datacenter["id"] == datacenter_id
54
- }
49
+ def update_datacenter(datacenter_id, options = {})
50
+ if dc = data[:datacenters]["items"].find do |datacenter|
51
+ datacenter["id"] == datacenter_id
52
+ end
55
53
  options.each do |key, value|
56
54
  dc[key] = value
57
55
  end
58
56
 
59
- dc['properties']['version'] += 1
57
+ dc['properties']['version'] += 1 if dc['properties']
58
+ dc['version'] += 1 if dc['version']
59
+
60
+ dc['properties']['name'] += ' - updated' if dc['properties']
61
+ dc['name'] += ' - updated' if dc['name']
62
+ dc['properties']['description'] += ' - updated' if dc['properties']
63
+ dc['description'] += ' - updated' if dc['description']
64
+
60
65
  else
61
- raise Fog::Errors::NotFound.new("The requested resource could not be found")
66
+ raise Excon::Error::HTTPStatus, "The requested resource could not be found"
62
67
  end
63
68
 
64
69
  response = Excon::Response.new
@@ -53,26 +53,24 @@ module Fog
53
53
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#update-firewall-rule]
54
54
  def update_firewall_rule(datacenter_id, server_id, nic_id, firewall_rule_id, options = {})
55
55
  request(
56
- :expects => [202],
57
- :method => 'PATCH',
58
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules/#{firewall_rule_id}",
59
- :body => Fog::JSON.encode(options)
56
+ :expects => [202],
57
+ :method => 'PATCH',
58
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules/#{firewall_rule_id}",
59
+ :body => Fog::JSON.encode(options)
60
60
  )
61
- rescue => error
62
- Fog::Errors::NotFound.new(error)
63
61
  end
64
62
  end
65
63
 
66
64
  class Mock
67
65
  def update_firewall_rule(datacenter_id, server_id, nic_id, firewall_rule_id, options = {})
68
- if firewall_rule = self.data[:firewall_rules]['items'].find {
69
- |attribute| attribute["datacenter_id"] == datacenter_id && attribute["server_id"] == server_id && attribute["nic_id"] == nic_id && attribute["id"] == firewall_rule_id
70
- }
66
+ if firewall_rule = data[:firewall_rules]['items'].find do |attribute|
67
+ attribute["datacenter_id"] == datacenter_id && attribute["server_id"] == server_id && attribute["nic_id"] == nic_id && attribute["id"] == firewall_rule_id
68
+ end
71
69
  options.each do |key, value|
72
70
  firewall_rule[key] = value
73
71
  end
74
72
  else
75
- raise Fog::Errors::NotFound.new('The requested resource could not be found')
73
+ raise Fog::Errors::NotFound, 'The requested resource could not be found'
76
74
  end
77
75
 
78
76
  response = Excon::Response.new
@@ -84,4 +82,4 @@ module Fog
84
82
  end
85
83
  end
86
84
  end
87
- end
85
+ end