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,18 @@
1
+ module Fog
2
+ module ProfitBricks
3
+ def self.construct_envelope(&block)
4
+ namespaces = {
5
+ "xmlns" => "",
6
+ "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/",
7
+ "xmlns:ws" => "http://ws.api.profitbricks.com/"
8
+ }
9
+
10
+ Nokogiri::XML::Builder.new do |xml|
11
+ xml[:soapenv].Envelope(namespaces) do
12
+ xml[:soapenv].Header
13
+ xml[:soapenv].Body(&block)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,59 @@
1
+ module Fog
2
+ module Compute
3
+ class ProfitBricks
4
+ class Datacenter < Fog::Model
5
+ identity :id, :aliases => 'dataCenterId'
6
+ attribute :name, :aliases => 'dataCenterName'
7
+ attribute :version, :aliases => 'dataCenterVersion'
8
+ attribute :state, :aliases => 'provisioningState'
9
+ attribute :request_id, :aliases => 'requestId'
10
+ attribute :region
11
+
12
+ attr_accessor :options
13
+
14
+ def initialize(attributes={})
15
+ super
16
+ end
17
+
18
+ def save
19
+ requires :name, :region
20
+
21
+ data = service.create_data_center(name, region)
22
+ merge_attributes(data.body['createDataCenterResponse'])
23
+ true
24
+ end
25
+
26
+ def update
27
+ requires :id
28
+ data = service.update_data_center(id, options)
29
+ merge_attributes(data.body['updateDataCenterResponse'])
30
+ true
31
+ end
32
+
33
+ def destroy
34
+ requires :id
35
+ service.delete_data_center(id)
36
+ true
37
+ end
38
+
39
+ def clear(confirm = false)
40
+ requires :id
41
+ if confirm == true
42
+ service.clear_data_center(id)
43
+ true
44
+ else
45
+ raise ArgumentError.new('Confirm with true boolean to clear datacenter')
46
+ end
47
+ end
48
+
49
+ def ready?
50
+ self.state == 'AVAILABLE'
51
+ end
52
+
53
+ def failed?
54
+ self.state == 'ERROR'
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,24 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/profitbricks/models/compute/datacenter'
3
+
4
+ module Fog
5
+ module Compute
6
+ class ProfitBricks
7
+ class Datacenters < Fog::Collection
8
+ model Fog::Compute::ProfitBricks::Datacenter
9
+
10
+ def all
11
+ load (service.get_all_data_centers.body['getAllDataCentersResponse'])
12
+ end
13
+
14
+ def get(id)
15
+ datacenter = service.get_data_center(id).body['getDataCenterResponse']
16
+ Excon::Errors
17
+ new(datacenter)
18
+ rescue Excon::Errors::NotFound
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Compute
3
+ class ProfitBricks
4
+ class Flavor < Fog::Model
5
+ identity :id, :aliases => 'flavorId'
6
+ attribute :name, :aliases => 'flavorName'
7
+ attribute :cores
8
+ attribute :ram
9
+
10
+ def initialize(attributes={})
11
+ super
12
+ end
13
+
14
+ def save
15
+ requires :name, :ram, :cores
16
+ data = service.create_flavor(name, cores, ram)
17
+ merge_attributes(data.body['createFlavorResponse'])
18
+ true
19
+ end
20
+
21
+ def update
22
+ Fog::Mock.not_implemented
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/profitbricks/models/compute/flavor'
3
+
4
+ module Fog
5
+ module Compute
6
+ class ProfitBricks
7
+ class Flavors < Fog::Collection
8
+ model Fog::Compute::ProfitBricks::Flavor
9
+
10
+ def all()
11
+ load (service.get_all_flavors.body['getAllFlavorsResponse'])
12
+ end
13
+
14
+ def get(id)
15
+ flavor = service.get_flavor(id).body['getFlavorResponse']
16
+ Excon::Errors
17
+ new(flavor)
18
+ rescue Excon::Errors::NotFound
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Compute
3
+ class ProfitBricks
4
+ class Image < Fog::Model
5
+ identity :id, :aliases => 'imageId'
6
+ attribute :name, :aliases => 'imageName'
7
+ attribute :type, :aliases => 'imageType'
8
+ attribute :size, :aliases => 'imageSize'
9
+ attribute :cpu_hotplug, :aliases => 'cpuHotPlug'
10
+ attribute :cpu_hotunplug, :aliases => 'cpuHotUnplug'
11
+ attribute :ram_hotplug, :aliases => 'memoryHotPlug'
12
+ attribute :ram_hotunplug, :aliases => 'memoryHotUnPlug'
13
+ attribute :disc_hotplug, :aliases => 'discVirtioHotPlug'
14
+ attribute :disc_hotunplug, :aliases => 'discVirtioUnHotPlug'
15
+ attribute :nic_hotplug, :aliases => 'nicHotPlug'
16
+ attribute :nic_hotunplug, :aliases => 'nicHotUnPlug'
17
+ attribute :server_ids, :aliases => 'serverIds'
18
+ attribute :os_type, :aliases => 'osType'
19
+ attribute :region, :aliases => 'location'
20
+ attribute :bootable
21
+ attribute :writeable
22
+ attribute :public
23
+
24
+ def initialize(attributes={})
25
+ super
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/profitbricks/models/compute/image'
3
+
4
+ module Fog
5
+ module Compute
6
+ class ProfitBricks
7
+ class Images < Fog::Collection
8
+ model Fog::Compute::ProfitBricks::Image
9
+
10
+ def all
11
+ load (service.get_all_images.body['getAllImagesResponse'])
12
+ end
13
+
14
+ def get(id)
15
+ image = service.get_image(id).body['getImageResponse']
16
+ new(image)
17
+ rescue Fog::Errors::NotFound
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,64 @@
1
+ module Fog
2
+ module Compute
3
+ class ProfitBricks
4
+ class Interface < Fog::Model
5
+ identity :id, :aliases => 'nicId'
6
+ attribute :name, :aliases => 'nicName'
7
+ attribute :mac_address, :aliases => 'macAddress'
8
+ attribute :lan_id, :aliases => 'lanId'
9
+ attribute :dhcp_active, :aliases => 'dhcpActive'
10
+ attribute :ips, :aliases => 'ips'
11
+ attribute :server_id, :aliases => 'serverId'
12
+ attribute :internet_access, :aliases => 'internetAccess'
13
+ attribute :state, :aliases => 'provisioningState'
14
+ attribute :firewall
15
+ attribute :data_center_id, :aliases => 'dataCenterId'
16
+ attribute :data_center_version, :aliases => 'dataCenterVersion'
17
+ attribute :request_id, :aliases => 'requestId'
18
+
19
+ attr_accessor :options
20
+
21
+ def initialize(attributes={})
22
+ super
23
+ end
24
+
25
+ def save
26
+ requires :server_id, :lan_id
27
+
28
+ data = service.create_nic(server_id, lan_id, options={})
29
+ merge_attributes(data.body['createNicResponse'])
30
+ true
31
+ end
32
+
33
+ def update
34
+ requires :id
35
+
36
+ data = service.update_nic(id, options)
37
+ merge_attributes(data.body['updateNicResponse'])
38
+ true
39
+ end
40
+
41
+ def destroy
42
+ requires :id
43
+ service.delete_nic(id)
44
+ true
45
+ end
46
+
47
+ def set_internet_access(options={})
48
+ service.set_internet_access(
49
+ options[:data_center_id], options[:lan_id], options[:internet_access]
50
+ )
51
+ true
52
+ end
53
+
54
+ def ready?
55
+ self.state == 'AVAILABLE'
56
+ end
57
+
58
+ def failed?
59
+ self.state == 'ERROR'
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/profitbricks/models/compute/interface'
3
+
4
+ module Fog
5
+ module Compute
6
+ class ProfitBricks
7
+ class Interfaces < Fog::Collection
8
+ model Fog::Compute::ProfitBricks::Interface
9
+
10
+ def all
11
+ load(service.get_all_nic.body['getAllNicResponse'])
12
+ end
13
+
14
+ def get(id)
15
+ interface = service.get_nic(id).body['getNicResponse']
16
+ Excon::Errors
17
+ new(interface)
18
+ rescue Excon::Errors::NotFound
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module Fog
2
+ module Compute
3
+ class ProfitBricks
4
+ class Region < Fog::Model
5
+ identity :id, :aliases => 'locationId'
6
+ attribute :name, :aliases => 'locationName'
7
+ attribute :country, :aliases => 'country'
8
+
9
+ def initialize(attributes={})
10
+ super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/profitbricks/models/compute/region'
3
+
4
+ module Fog
5
+ module Compute
6
+ class ProfitBricks
7
+ class Regions < Fog::Collection
8
+ model Fog::Compute::ProfitBricks::Region
9
+
10
+ def all()
11
+ load (service.get_all_locations.body['getAllLocationsResponse'])
12
+ end
13
+
14
+ def get(id)
15
+ region = service.get_location(id).body['getLocationResponse']
16
+ Excon::Errors
17
+ new(region)
18
+ rescue Excon::Errors::NotFound
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,107 @@
1
+ require 'fog/compute/models/server'
2
+
3
+ module Fog
4
+ module Compute
5
+ class ProfitBricks
6
+ class Server < Fog::Compute::Server
7
+ identity :id, :aliases => 'serverId'
8
+ attribute :name, :aliases => 'serverName'
9
+ attribute :cores
10
+ attribute :ram
11
+ attribute :attached_volumes, :aliases => 'connectedStorages'
12
+ attribute :interfaces, :aliases => 'nics'
13
+ attribute :internet_access, :aliases => 'internetAccess'
14
+ attribute :zone, :aliases => 'availabilityZone'
15
+ attribute :creation_time, :aliases => 'creationTime'
16
+ attribute :modification_time, :aliases => 'lastModificationTime'
17
+ attribute :machine_state, :aliases => 'virtualMachineState'
18
+ attribute :state, :aliases => 'provisioningState'
19
+ attribute :os_type, :aliases => 'osType'
20
+ attribute :cpu_hotplug, :aliases => 'cpuHotPlug'
21
+ attribute :ram_hotplug, :aliases => 'ramHotPlug'
22
+ attribute :nic_hotplug, :aliases => 'nicHotPlug'
23
+ attribute :nic_hotunplug, :aliases => 'nicHotUnPlug'
24
+ attribute :disc_hotplug, :aliases => 'discVirtioHotPlug'
25
+ attribute :disc_hotunplug, :aliases => 'discVirtioHotUnPlug'
26
+ attribute :data_center_id, :aliases => 'dataCenterId'
27
+ attribute :data_center_version, :aliases => 'dataCenterVersion'
28
+ attribute :request_id, :aliases => 'requestId'
29
+
30
+ attr_accessor :options
31
+ attr_accessor :flavor_id
32
+
33
+ def initialize(attributes={})
34
+ super
35
+ end
36
+
37
+ def save
38
+ requires :data_center_id
39
+
40
+ if (cores and ram)
41
+ data = service.create_server(data_center_id, cores, ram, options || {})
42
+ elsif flavor_id
43
+ flavor = service.flavors.get(flavor_id)
44
+ data = service.create_server(data_center_id, flavor.cores, flavor.ram, options || {})
45
+ else
46
+ raise ArgumentError, 'cores/ram or flavor_id is required for this operation'
47
+ end
48
+
49
+ merge_attributes(data.body['createServerResponse'])
50
+ true
51
+ end
52
+
53
+ def update
54
+ requires :id
55
+
56
+ data = service.update_server(id, options)
57
+ merge_attributes(data.body['updateServerResponse'])
58
+ true
59
+ end
60
+
61
+ def reset
62
+ requires :id
63
+ service.reset_server(id)
64
+ true
65
+ end
66
+
67
+ def start
68
+ requires :id
69
+ service.start_server(id)
70
+ true
71
+ end
72
+
73
+ def stop
74
+ requires :id
75
+ service.stop_server(id)
76
+ true
77
+ end
78
+
79
+ def destroy
80
+ requires :id
81
+ service.delete_server(id)
82
+ true
83
+ end
84
+
85
+ def volumes
86
+ service.volumes.find_all do |volume|
87
+ volume.server_ids =~ /#{id}/
88
+ end
89
+ end
90
+
91
+ def interfaces
92
+ service.interfaces.find_all do |nic|
93
+ nic.server_id == id
94
+ end
95
+ end
96
+
97
+ def ready?
98
+ self.state == 'AVAILABLE'
99
+ end
100
+
101
+ def failed?
102
+ self.state == 'ERROR'
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end