fog-profitbricks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rubocop.yml +21 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +25 -0
  7. data/CONTRIBUTING.md +18 -0
  8. data/CONTRIBUTORS.md +2 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.md +20 -0
  11. data/README.md +29 -0
  12. data/Rakefile +21 -0
  13. data/examples/pb_demo.rb +53 -0
  14. data/fog-profitbricks.gemspec +31 -0
  15. data/gemfiles/Gemfile.1.8.7 +7 -0
  16. data/gemfiles/Gemfile.1.9.2+ +6 -0
  17. data/lib/fog/bin/profitbricks.rb +29 -0
  18. data/lib/fog/profitbricks.rb +13 -0
  19. data/lib/fog/profitbricks/compute.rb +215 -0
  20. data/lib/fog/profitbricks/core.rb +18 -0
  21. data/lib/fog/profitbricks/models/compute/datacenter.rb +59 -0
  22. data/lib/fog/profitbricks/models/compute/datacenters.rb +24 -0
  23. data/lib/fog/profitbricks/models/compute/flavor.rb +27 -0
  24. data/lib/fog/profitbricks/models/compute/flavors.rb +24 -0
  25. data/lib/fog/profitbricks/models/compute/image.rb +30 -0
  26. data/lib/fog/profitbricks/models/compute/images.rb +23 -0
  27. data/lib/fog/profitbricks/models/compute/interface.rb +64 -0
  28. data/lib/fog/profitbricks/models/compute/interfaces.rb +24 -0
  29. data/lib/fog/profitbricks/models/compute/region.rb +15 -0
  30. data/lib/fog/profitbricks/models/compute/regions.rb +24 -0
  31. data/lib/fog/profitbricks/models/compute/server.rb +107 -0
  32. data/lib/fog/profitbricks/models/compute/servers.rb +23 -0
  33. data/lib/fog/profitbricks/models/compute/volume.rb +74 -0
  34. data/lib/fog/profitbricks/models/compute/volumes.rb +24 -0
  35. data/lib/fog/profitbricks/parsers/base.rb +49 -0
  36. data/lib/fog/profitbricks/parsers/compute/clear_data_center.rb +22 -0
  37. data/lib/fog/profitbricks/parsers/compute/connect_storage_to_server.rb +22 -0
  38. data/lib/fog/profitbricks/parsers/compute/create_data_center.rb +22 -0
  39. data/lib/fog/profitbricks/parsers/compute/create_nic.rb +22 -0
  40. data/lib/fog/profitbricks/parsers/compute/create_server.rb +22 -0
  41. data/lib/fog/profitbricks/parsers/compute/create_storage.rb +22 -0
  42. data/lib/fog/profitbricks/parsers/compute/delete_data_center.rb +20 -0
  43. data/lib/fog/profitbricks/parsers/compute/delete_nic.rb +22 -0
  44. data/lib/fog/profitbricks/parsers/compute/delete_server.rb +22 -0
  45. data/lib/fog/profitbricks/parsers/compute/delete_storage.rb +22 -0
  46. data/lib/fog/profitbricks/parsers/compute/disconnect_storage_from_server.rb +22 -0
  47. data/lib/fog/profitbricks/parsers/compute/get_all_data_centers.rb +26 -0
  48. data/lib/fog/profitbricks/parsers/compute/get_all_images.rb +30 -0
  49. data/lib/fog/profitbricks/parsers/compute/get_all_nic.rb +30 -0
  50. data/lib/fog/profitbricks/parsers/compute/get_all_servers.rb +56 -0
  51. data/lib/fog/profitbricks/parsers/compute/get_all_storages.rb +33 -0
  52. data/lib/fog/profitbricks/parsers/compute/get_data_center.rb +23 -0
  53. data/lib/fog/profitbricks/parsers/compute/get_data_center_state.rb +20 -0
  54. data/lib/fog/profitbricks/parsers/compute/get_image.rb +26 -0
  55. data/lib/fog/profitbricks/parsers/compute/get_nic.rb +27 -0
  56. data/lib/fog/profitbricks/parsers/compute/get_server.rb +55 -0
  57. data/lib/fog/profitbricks/parsers/compute/get_storage.rb +30 -0
  58. data/lib/fog/profitbricks/parsers/compute/reset_server.rb +20 -0
  59. data/lib/fog/profitbricks/parsers/compute/set_internet_access.rb +22 -0
  60. data/lib/fog/profitbricks/parsers/compute/update_data_center.rb +22 -0
  61. data/lib/fog/profitbricks/parsers/compute/update_nic.rb +22 -0
  62. data/lib/fog/profitbricks/parsers/compute/update_server.rb +22 -0
  63. data/lib/fog/profitbricks/parsers/compute/update_storage.rb +22 -0
  64. data/lib/fog/profitbricks/requests/compute/clear_data_center.rb +53 -0
  65. data/lib/fog/profitbricks/requests/compute/connect_storage_to_server.rb +85 -0
  66. data/lib/fog/profitbricks/requests/compute/create_data_center.rb +64 -0
  67. data/lib/fog/profitbricks/requests/compute/create_flavor.rb +40 -0
  68. data/lib/fog/profitbricks/requests/compute/create_nic.rb +81 -0
  69. data/lib/fog/profitbricks/requests/compute/create_server.rb +107 -0
  70. data/lib/fog/profitbricks/requests/compute/create_storage.rb +98 -0
  71. data/lib/fog/profitbricks/requests/compute/delete_data_center.rb +62 -0
  72. data/lib/fog/profitbricks/requests/compute/delete_nic.rb +66 -0
  73. data/lib/fog/profitbricks/requests/compute/delete_server.rb +66 -0
  74. data/lib/fog/profitbricks/requests/compute/delete_storage.rb +66 -0
  75. data/lib/fog/profitbricks/requests/compute/disconnect_storage_from_server.rb +78 -0
  76. data/lib/fog/profitbricks/requests/compute/get_all_data_centers.rb +32 -0
  77. data/lib/fog/profitbricks/requests/compute/get_all_flavors.rb +77 -0
  78. data/lib/fog/profitbricks/requests/compute/get_all_images.rb +67 -0
  79. data/lib/fog/profitbricks/requests/compute/get_all_locations.rb +44 -0
  80. data/lib/fog/profitbricks/requests/compute/get_all_nic.rb +55 -0
  81. data/lib/fog/profitbricks/requests/compute/get_all_servers.rb +58 -0
  82. data/lib/fog/profitbricks/requests/compute/get_all_storages.rb +58 -0
  83. data/lib/fog/profitbricks/requests/compute/get_data_center.rb +40 -0
  84. data/lib/fog/profitbricks/requests/compute/get_data_center_state.rb +43 -0
  85. data/lib/fog/profitbricks/requests/compute/get_flavor.rb +82 -0
  86. data/lib/fog/profitbricks/requests/compute/get_image.rb +71 -0
  87. data/lib/fog/profitbricks/requests/compute/get_location.rb +48 -0
  88. data/lib/fog/profitbricks/requests/compute/get_nic.rb +65 -0
  89. data/lib/fog/profitbricks/requests/compute/get_server.rb +100 -0
  90. data/lib/fog/profitbricks/requests/compute/get_storage.rb +65 -0
  91. data/lib/fog/profitbricks/requests/compute/reset_server.rb +51 -0
  92. data/lib/fog/profitbricks/requests/compute/set_internet_access.rb +61 -0
  93. data/lib/fog/profitbricks/requests/compute/start_server.rb +59 -0
  94. data/lib/fog/profitbricks/requests/compute/stop_server.rb +59 -0
  95. data/lib/fog/profitbricks/requests/compute/update_data_center.rb +55 -0
  96. data/lib/fog/profitbricks/requests/compute/update_nic.rb +76 -0
  97. data/lib/fog/profitbricks/requests/compute/update_server.rb +81 -0
  98. data/lib/fog/profitbricks/requests/compute/update_storage.rb +75 -0
  99. data/lib/fog/profitbricks/version.rb +5 -0
  100. data/spec/minitest_helper.rb +33 -0
  101. data/tests/helper.rb +19 -0
  102. data/tests/helpers/formats_helper.rb +23 -0
  103. data/tests/helpers/mock_helper.rb +8 -0
  104. data/tests/profitbricks/requests/compute/flavor_tests.rb +43 -0
  105. data/tests/profitbricks/requests/compute/image_tests.rb +50 -0
  106. data/tests/profitbricks/requests/compute/interface_tests.rb +101 -0
  107. data/tests/profitbricks/requests/compute/location_tests.rb +33 -0
  108. data/tests/profitbricks/requests/compute/server_tests.rb +246 -0
  109. metadata +293 -0
@@ -0,0 +1,23 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/profitbricks/models/compute/server'
3
+
4
+ module Fog
5
+ module Compute
6
+ class ProfitBricks
7
+ class Servers < Fog::Collection
8
+ model Fog::Compute::ProfitBricks::Server
9
+
10
+ def all
11
+ load (service.get_all_servers.body['getAllServersResponse'])
12
+ end
13
+
14
+ def get(id)
15
+ server = service.get_server(id).body['getServerResponse']
16
+ new(server)
17
+ rescue Excon::Errors::NotFound
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,74 @@
1
+ module Fog
2
+ module Compute
3
+ class ProfitBricks
4
+ class Volume < Fog::Model
5
+ identity :id, :aliases => 'storageId'
6
+ attribute :name, :aliases => 'storageName'
7
+ attribute :size
8
+ attribute :creation_time, :aliases => 'creationTime'
9
+ attribute :modification_time, :aliases => 'lastModificationTime'
10
+ attribute :server_ids, :aliases => 'serverIds'
11
+ attribute :mount_image, :aliases => 'mountImage'
12
+ attribute :state, :aliases => 'provisioningState'
13
+ attribute :data_center_id, :aliases => 'dataCenterId'
14
+ attribute :data_center_version, :aliases => 'dataCenterVersion'
15
+ attribute :request_id, :aliases => 'requestId'
16
+
17
+ attr_accessor :options
18
+
19
+ def initialize(attributes={})
20
+ super
21
+ end
22
+
23
+ def save
24
+ requires :data_center_id, :size
25
+
26
+ data = service.create_storage(data_center_id, size, options)
27
+ merge_attributes(data.body['createStorageResponse'])
28
+ true
29
+ end
30
+
31
+ def update
32
+ requires :id
33
+
34
+ data = service.update_storage(id, options)
35
+ merge_attributes(data.body['updateStorageResponse'])
36
+ true
37
+ end
38
+
39
+ def attach(server_id, options={})
40
+ requires :id
41
+
42
+ options = {
43
+ 'busType' => options[:bus_type],
44
+ 'deviceNumber' => options[:device_number]
45
+ }
46
+
47
+ data = service.connect_storage_to_server(id, server_id, options)
48
+ reload
49
+ end
50
+
51
+ def detach(server_id)
52
+ requires :id
53
+
54
+ data = service.disconnect_storage_from_server(id, server_id)
55
+ reload
56
+ end
57
+
58
+ def destroy
59
+ requires :id
60
+ service.delete_storage(id)
61
+ true
62
+ end
63
+
64
+ def ready?
65
+ self.state == 'AVAILABLE'
66
+ end
67
+
68
+ def failed?
69
+ self.state == 'ERROR'
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,24 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/profitbricks/models/compute/volume'
3
+
4
+ module Fog
5
+ module Compute
6
+ class ProfitBricks
7
+ class Volumes < Fog::Collection
8
+ model Fog::Compute::ProfitBricks::Volume
9
+
10
+ def all
11
+ load(service.get_all_storages.body['getAllStoragesResponse'])
12
+ end
13
+
14
+ def get(id)
15
+ volume = service.get_storage(id).body['getStorageResponse']
16
+ Excon::Errors
17
+ new(volume)
18
+ rescue Excon::Errors::NotFound
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,49 @@
1
+ require "nokogiri"
2
+
3
+ module Fog
4
+ module Parsers
5
+ module ProfitBricks
6
+ class Base < Nokogiri::XML::SAX::Document
7
+ attr_reader :response
8
+
9
+ def initialize
10
+ reset
11
+ end
12
+
13
+ def attr_value(name, attrs)
14
+ (entry = attrs.find {|a, v| a == name }) && entry.last
15
+ end
16
+
17
+ def reset
18
+ @response = {}
19
+ end
20
+
21
+ def characters(string)
22
+ @value ||= ''
23
+ @value << string
24
+ end
25
+
26
+ # ###############################################################################
27
+ # This is a workaround. Original implementation from Nokogiri is overwritten with
28
+ # one that does not join namespace prefix with local name.
29
+ def start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = []
30
+ start_element name, attrs
31
+ end
32
+
33
+ def end_element_namespace name, prefix = nil, uri = nil
34
+ end_element name
35
+ end
36
+
37
+ # ###############################################################################
38
+
39
+ def start_element(name, attrs = [])
40
+ @value = nil
41
+ end
42
+
43
+ def value
44
+ @value && @value.dup
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class ClearDataCenter < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'clearDataCenterResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId'
13
+ @response['clearDataCenterResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['clearDataCenterResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class ConnectStorageToServer < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'connectStorageToServerResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId'
13
+ @response['connectStorageToServerResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['connectStorageToServerResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class CreateDataCenter < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'createDataCenterResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId', 'location'
13
+ @response['createDataCenterResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['createDataCenterResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class CreateNic < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'createNicResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId', 'nicId'
13
+ @response['createNicResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['createNicResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class CreateServer < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'createServerResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId', 'serverId'
13
+ @response['createServerResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['createServerResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class CreateStorage < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'createStorageResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId', 'storageId'
13
+ @response['createStorageResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['createStorageResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class DeleteDataCenter < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'deleteDataCenterResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId'
13
+ @response['deleteDataCenterResponse'][name] = value
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class DeleteNic < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'deleteNicResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId'
13
+ @response['deleteNicResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['deleteNicResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class DeleteServer < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'deleteServerResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId'
13
+ @response['deleteServerResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['deleteServerResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class DeleteStorage < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'deleteStorageResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId'
13
+ @response['deleteStorageResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['deleteStorageResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class DisconnectStorageFromServer < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @response = { 'disconnectStorageFromServerResponse' => {} }
8
+ end
9
+
10
+ def end_element(name)
11
+ case name
12
+ when 'requestId', 'dataCenterId'
13
+ @response['disconnectStorageFromServerResponse'][name] = value
14
+ when 'dataCenterVersion'
15
+ @response['disconnectStorageFromServerResponse'][name] = value.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Parsers
3
+ module Compute
4
+ module ProfitBricks
5
+ class GetAllDataCenters < Fog::Parsers::ProfitBricks::Base
6
+ def reset
7
+ @datacenter = {}
8
+ @response = { 'getAllDataCentersResponse' => [] }
9
+ end
10
+
11
+ def end_element(name)
12
+ case name
13
+ when 'dataCenterId', 'dataCenterName'
14
+ @datacenter[name] = value
15
+ when 'dataCenterVersion'
16
+ @datacenter[name] = value.to_i
17
+ when 'return'
18
+ @response['getAllDataCentersResponse'] << @datacenter
19
+ @datacenter = {}
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end