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
@@ -36,47 +36,88 @@ module Fog
36
36
  # See the NIC section for attribute definitions
37
37
  #
38
38
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-load-balancer]
39
- def create_load_balancer(datacenter_id, properties={}, entities={})
39
+ def create_load_balancer(datacenter_id, properties = {}, entities = {})
40
40
  load_balancer = {
41
- :properties => properties,
42
- :entities => entities
41
+ :properties => properties,
42
+ :entities => entities
43
43
  }
44
44
 
45
45
  request(
46
- :expects => [202],
47
- :method => 'POST',
48
- :path => "/datacenters/#{datacenter_id}/loadbalancers",
49
- :body => Fog::JSON.encode(load_balancer)
46
+ :expects => [202],
47
+ :method => 'POST',
48
+ :path => "/datacenters/#{datacenter_id}/loadbalancers",
49
+ :body => Fog::JSON.encode(load_balancer)
50
50
  )
51
- rescue => error
52
- Fog::Errors::NotFound.new(error)
53
51
  end
54
52
  end
55
53
 
56
54
  class Mock
57
- def create_load_balancer(datacenter_id, properties={}, entities={})
55
+ def create_load_balancer(datacenter_id, properties = {}, _entities = {})
58
56
  response = Excon::Response.new
59
57
  response.status = 202
60
58
 
61
- load_balancer_id = Fog::UUID.uuid
59
+ load_balancer_id = Fog::UUID.uuid
60
+ nic_1_id = Fog::UUID.uuid
61
+ serv_1_id = Fog::UUID.uuid
62
+
62
63
  load_balancer = {
63
- 'id' => load_balancer_id,
64
- 'type' => 'nic',
65
- 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}",
66
- 'metadata' => {
67
- 'createdDate' => '2015-03-18T19:00:51Z',
68
- 'createdBy' => 'test@stackpointcloud.com',
69
- 'etag' => 'faa67fbacb1c0e2e02cf9650657251f2',
70
- 'lastModifiedDate' => '2015-03-18T19:00:51Z',
71
- 'lastModifiedBy' => 'test@stackpointcloud.com',
72
- 'state' => 'AVAILABLE'
73
- },
74
- 'properties' => properties,
75
- 'entities' => entities,
76
- 'datacenter_id' => datacenter_id
64
+ 'id' => load_balancer_id,
65
+ 'type' => 'nic',
66
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}",
67
+ 'metadata' => {
68
+ 'createdDate' => '2015-03-18T19:00:51Z',
69
+ 'createdBy' => 'test@stackpointcloud.com',
70
+ 'etag' => 'faa67fbacb1c0e2e02cf9650657251f2',
71
+ 'lastModifiedDate' => '2015-03-18T19:00:51Z',
72
+ 'lastModifiedBy' => 'test@stackpointcloud.com',
73
+ 'state' => 'AVAILABLE'
74
+ },
75
+ 'properties' => properties,
76
+ 'entities' => {
77
+ 'balancednics' => {
78
+ 'id' => "#{load_balancer_id}/balancednics",
79
+ 'type' => 'collection',
80
+ 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}/balancednics",
81
+ 'items' =>
82
+ [
83
+ {
84
+ 'id' => nic_1_id,
85
+ 'type' => 'nic',
86
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{serv_1_id}/nics/#{nic_1_id}",
87
+ 'metadata' => {
88
+ 'createdDate' => '2015-03-18T19:00:51Z',
89
+ 'createdBy' => 'test@stackpointcloud.com',
90
+ 'etag' => 'faa67fbacb1c0e2e02cf9650657251f1',
91
+ 'lastModifiedDate' => '2015-03-18T19:00:51Z',
92
+ 'lastModifiedBy' => 'test@stackpointcloud.com',
93
+ 'state' => 'AVAILABLE'
94
+ },
95
+ 'properties' => {
96
+ 'name' => 'FogTestLoadBalancedNIC_1',
97
+ 'mac' => '02:01:36:5f:09:da',
98
+ 'ips' => ['10.9.194.12'],
99
+ 'dhcp' => 'true',
100
+ 'lan' => 2,
101
+ 'firewallActive' => 'false'
102
+ },
103
+ 'entities' => {
104
+ 'firewallrules' => {
105
+ 'id' => "#{nic_1_id}/firewallrules",
106
+ 'type' => 'collection',
107
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{serv_1_id}/nics/#{nic_1_id}/firewallrules",
108
+ 'items' => []
109
+ }
110
+ },
111
+ 'datacenter_id' => datacenter_id,
112
+ 'load_balancer_id' => load_balancer_id
113
+ }
114
+ ]
115
+ }
116
+ },
117
+ 'datacenter_id' => datacenter_id
77
118
  }
78
119
 
79
- self.data[:load_balancers]['items'] << load_balancer
120
+ data[:load_balancers]['items'] << load_balancer
80
121
  response.body = load_balancer
81
122
 
82
123
  response
@@ -72,48 +72,46 @@ module Fog
72
72
  # portRangeEnd value null to allow all ports
73
73
  #
74
74
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-a-nic]
75
- def create_nic(datacenter_id, server_id, options={}, entities={})
75
+ def create_nic(datacenter_id, server_id, options = {}, entities = {})
76
76
  nic = {
77
- :properties => options,
78
- :entities => entities
77
+ :properties => options,
78
+ :entities => entities
79
79
  }
80
80
 
81
81
  request(
82
- :expects => [202],
83
- :method => 'POST',
84
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/nics",
85
- :body => Fog::JSON.encode(nic)
82
+ :expects => [202],
83
+ :method => 'POST',
84
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/nics",
85
+ :body => Fog::JSON.encode(nic)
86
86
  )
87
- rescue => error
88
- Fog::Errors::NotFound.new(error)
89
87
  end
90
88
  end
91
89
 
92
90
  class Mock
93
- def create_nic(datacenter_id, server_id, options={}, entities={})
91
+ def create_nic(datacenter_id, server_id, options = {}, entities = {})
94
92
  response = Excon::Response.new
95
93
  response.status = 202
96
94
 
97
95
  nic_id = Fog::UUID.uuid
98
96
  nic = {
99
- 'id' => nic_id,
100
- 'type' => 'nic',
101
- 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}",
102
- 'metadata' => {
103
- 'createdDate' => '2015-03-18T19:00:51Z',
104
- 'createdBy' => 'test@stackpointcloud.com',
105
- 'etag' => 'faa67fbacb1c0e2e02cf9650657251f2',
106
- 'lastModifiedDate' => '2015-03-18T19:00:51Z',
107
- 'lastModifiedBy' => 'test@stackpointcloud.com',
108
- 'state' => 'AVAILABLE'
109
- },
110
- 'properties' => options,
111
- 'entities' => entities,
112
- 'datacenter_id' => datacenter_id,
113
- 'server_id' => server_id
97
+ 'id' => nic_id,
98
+ 'type' => 'nic',
99
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}",
100
+ 'metadata' => {
101
+ 'createdDate' => '2015-03-18T19:00:51Z',
102
+ 'createdBy' => 'test@stackpointcloud.com',
103
+ 'etag' => 'faa67fbacb1c0e2e02cf9650657251f2',
104
+ 'lastModifiedDate' => '2015-03-18T19:00:51Z',
105
+ 'lastModifiedBy' => 'test@stackpointcloud.com',
106
+ 'state' => 'AVAILABLE'
107
+ },
108
+ 'properties' => options,
109
+ 'entities' => entities,
110
+ 'datacenter_id' => datacenter_id,
111
+ 'server_id' => server_id
114
112
  }
115
113
 
116
- self.data[:nics]['items'] << nic
114
+ data[:nics]['items'] << nic
117
115
  response.body = nic
118
116
 
119
117
  response
@@ -116,33 +116,37 @@ module Fog
116
116
  # * items<~Array> - An array of individual firewall rules associated to the NIC
117
117
  #
118
118
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-a-server]
119
- def create_server(datacenter_id, properties={}, entities={})
119
+ def create_server(datacenter_id, properties = {}, entities = {})
120
120
  server = {
121
- :properties => properties,
122
- :entities => entities
121
+ :properties => properties,
122
+ :entities => entities
123
123
  }
124
124
 
125
125
  request(
126
- :expects => [202],
127
- :method => 'POST',
128
- :path => "/datacenters/#{datacenter_id}/servers",
129
- :body => Fog::JSON.encode(server)
126
+ :expects => [202],
127
+ :method => 'POST',
128
+ :path => "/datacenters/#{datacenter_id}/servers",
129
+ :body => Fog::JSON.encode(server)
130
130
  )
131
- rescue => error
132
- Fog::Errors::NotFound.new(error)
133
131
  end
134
132
  end
135
133
 
136
134
  class Mock
137
- def create_server(datacenter_id, properties={}, entities={})
135
+ def create_server(datacenter_id, properties = {}, entities = {})
138
136
  server_id = Fog::UUID.uuid
139
- volume_id = entities[:volumes]['items'][0]['id']
140
-
137
+
138
+ volume_id = if entities[:volumes] && entities[:volumes]['items'] && entities[:volumes]['items'][0] && entities[:volumes]['items'][0]['id']
139
+ entities[:volumes]['items'][0]['id']
140
+ else
141
+ Fog::UUID.uuid
142
+ end
143
+
141
144
  server = {
142
145
  'id' => server_id,
143
146
  'type' => 'server',
144
147
  'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}",
145
- 'metadata' => {
148
+ 'datacenter_id' => datacenter_id,
149
+ 'metadata' => {
146
150
  'createdDate' => '2014-10-20T21:20:46Z',
147
151
  'createdBy' => 'test@stackpointcloud.com',
148
152
  'etag' => '0018832d7a7ba455db74ac41ae9f11fe',
@@ -150,15 +154,18 @@ module Fog
150
154
  'lastModifiedBy' => 'test@stackpointcloud.com',
151
155
  'state' => 'AVAILABLE'
152
156
  },
153
- 'properties' => {
157
+ 'properties' => {
154
158
  'name' => properties[:name],
155
159
  'cores' => properties[:cores],
156
160
  'ram' => properties[:ram],
157
161
  'availabilityZone' => properties[:availabilityZone],
158
162
  'vmState' => 'RUNNING',
159
163
  'cpuFamily' => properties[:cpuFamily]
160
- },
161
- 'entities' => {
164
+ }
165
+ }
166
+
167
+ if entities[:volumes]
168
+ server['entities'] = {
162
169
  'volumes' => {
163
170
  'id' => "#{server_id}/volumes",
164
171
  'type' => 'collection',
@@ -177,7 +184,7 @@ module Fog
177
184
  'lastModifiedBy' => 'test@stackpointcloud.com',
178
185
  'state' => 'AVAILABLE'
179
186
  },
180
- 'properties' => {
187
+ 'properties' => {
181
188
  'name' => 'FogRestTestVolume',
182
189
  'type' => 'HDD',
183
190
  'size' => 5,
@@ -198,52 +205,54 @@ module Fog
198
205
  }
199
206
  }
200
207
  ]
201
- },
202
- 'cdroms' => {
203
- 'id' => "#{server_id}/cdroms",
204
- 'type' => 'collection',
205
- 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms",
206
- 'items' =>
207
- [
208
- {
209
- 'id' => 'dfcb40db-28b5-11e6-9336-52540005ab80',
210
- 'type' => 'image',
211
- 'href' => 'https=>//api.profitbricks.com/rest/v2/images/dfcb40db-28b5-11e6-9336-52540005ab80',
212
- 'metadata' => {
213
- 'createdDate' => '2016-06-02T11:33:49Z',
214
- 'createdBy' => 'System',
215
- 'etag' => '9909709d99655c6f31aca789998d7d89',
216
- 'lastModifiedDate' => '2016-06-02T11:33:49Z',
217
- 'lastModifiedBy' => 'System',
218
- 'state' => 'AVAILABLE'
219
- },
220
- 'properties' => {
221
- 'name' => 'CentOS-6.8-x86_64-netinstall.iso',
222
- 'description' => '',
223
- 'location' => 'us/las',
224
- 'size' => 0.23,
225
- 'cpuHotPlug' => 'true',
226
- 'cpuHotUnplug' => 'false',
227
- 'ramHotPlug' => 'true',
228
- 'ramHotUnplug' => 'false',
229
- 'nicHotPlug' => 'true',
230
- 'nicHotUnplug' => 'true',
231
- 'discVirtioHotPlug' => 'true',
232
- 'discVirtioHotUnplug' => 'true',
233
- 'discScsiHotPlug' => 'false',
234
- 'discScsiHotUnplug' => 'false',
235
- 'licenceType' => 'LINUX',
236
- 'imageType' => 'CDROM',
237
- 'public' => 'true'
238
- }
239
- }
240
- ]
241
208
  }
242
- },
243
- 'datacenter_id' => datacenter_id
244
- }
209
+ }
210
+ end
211
+
212
+ if entities[:cdroms]
213
+ server['entities']['cdroms'] = {
214
+ 'id' => "#{server_id}/cdroms",
215
+ 'type' => 'collection',
216
+ 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms",
217
+ 'items' =>
218
+ [
219
+ {
220
+ 'id' => 'dfcb40db-28b5-11e6-9336-52540005ab80',
221
+ 'type' => 'image',
222
+ 'href' => 'https=>//api.profitbricks.com/rest/v2/images/dfcb40db-28b5-11e6-9336-52540005ab80',
223
+ 'metadata' => {
224
+ 'createdDate' => '2016-06-02T11:33:49Z',
225
+ 'createdBy' => 'System',
226
+ 'etag' => '9909709d99655c6f31aca789998d7d89',
227
+ 'lastModifiedDate' => '2016-06-02T11:33:49Z',
228
+ 'lastModifiedBy' => 'System',
229
+ 'state' => 'AVAILABLE'
230
+ },
231
+ 'properties' => {
232
+ 'name' => 'CentOS-6.8-x86_64-netinstall.iso',
233
+ 'description' => '',
234
+ 'location' => 'us/las',
235
+ 'size' => 0.23,
236
+ 'cpuHotPlug' => 'true',
237
+ 'cpuHotUnplug' => 'false',
238
+ 'ramHotPlug' => 'true',
239
+ 'ramHotUnplug' => 'false',
240
+ 'nicHotPlug' => 'true',
241
+ 'nicHotUnplug' => 'true',
242
+ 'discVirtioHotPlug' => 'true',
243
+ 'discVirtioHotUnplug' => 'true',
244
+ 'discScsiHotPlug' => 'false',
245
+ 'discScsiHotUnplug' => 'false',
246
+ 'licenceType' => 'LINUX',
247
+ 'imageType' => 'CDROM',
248
+ 'public' => 'true'
249
+ }
250
+ }
251
+ ]
252
+ }
253
+ end
245
254
 
246
- self.data[:servers]['items'] << server
255
+ data[:servers]['items'] << server
247
256
 
248
257
  response = Excon::Response.new
249
258
  response.status = 202
@@ -1,133 +1,133 @@
1
1
  module Fog
2
- module Compute
3
- class ProfitBricks
4
- class Real
5
- # Creates a volume within the data center. This will NOT attach the volume to a server.
6
- #
7
- # ==== Parameters
8
- # * datacenter_id<~String> - Required, UUID of virtual data center
9
- # * options<~Hash>:
10
- # * name<~String> - The name of the volume
11
- # * size<~Integer> - Required, the size of the volume in GB
12
- # * bus<~String> - The bus type of the volume (VIRTIO or IDE). Default: VIRTIO.
13
- # * image<~String> - Required**, the image or snapshot ID
14
- # * type<~String> - The volume type, HDD or SSD
15
- # * licenceType<~String> - Required**, the licence type of the volume. Options: LINUX, WINDOWS, UNKNOWN, OTHER
16
- # * imagePassword<~String> - One-time password is set on the Image for the appropriate account.
17
- # This field may only be set in creation requests. When reading, it always returns null.
18
- # Password has to contain 8-50 characters.
19
- # Only these characters are allowed: [abcdefghjkmnpqrstuvxABCDEFGHJKLMNPQRSTUVX23456789]
20
- # * sshKeys<~String> - SSH keys to allow access to the volume via SSH
21
- #
22
- # ** Either the image or the licenceType parameters need to be provided.
23
- # licenceType is required, but if image is supplied, it will already have a licenceType set.
24
- #
25
- # ==== Returns
26
- # * response<~Excon::Response>:
27
- # * body<~Hash>:
28
- # * id<~String> - The resource's unique identifier
29
- # * type<~String> - The type of the created resource
30
- # * href<~String> - URL to the object's representation (absolute path)
31
- # * metadata<~Hash> - Hash containing the volume metadata
32
- # * createdDate<~String> - The date the resource was created
33
- # * createdBy<~String> - The user who created the resource
34
- # * etag<~String> - The etag for the resource
35
- # * lastModifiedDate<~String> - The last time the resource has been modified
36
- # * lastModifiedBy<~String> - The user who last modified the resource
37
- # * state<~String> - Volume state
38
- # * properties<~Hash> - Hash containing the volume properties
39
- # * name<~String> - The name of the volume.
40
- # * type<~String> - The volume type, HDD or SSD.
41
- # * size<~Integer> - The size of the volume in GB.
42
- # * image<~String> - The image or snapshot ID.
43
- # * imagePassword<~String> - Indicates if a password is set on the image.
44
- # * sshKeys<~String> - SSH keys
45
- # * bus<~String> - The bus type of the volume (VIRTIO or IDE). Default: VIRTIO.
46
- # * licenceType<~String> - Volume licence type. ( WINDOWS, LINUX, OTHER, UNKNOWN)
47
- # * cpuHotPlug<~Boolean> - This volume is capable of CPU hot plug (no reboot required)
48
- # * cpuHotUnplug<~Boolean> - This volume is capable of CPU hot unplug (no reboot required)
49
- # * ramHotPlug<~Boolean> - This volume is capable of memory hot plug (no reboot required)
50
- # * ramHotUnplug<~Boolean> - This volume is capable of memory hot unplug (no reboot required)
51
- # * nicHotPlug<~Boolean> - This volume is capable of nic hot plug (no reboot required)
52
- # * nicHotUnplug<~Boolean> - This volume is capable of nic hot unplug (no reboot required)
53
- # * discVirtioHotPlug<~Boolean> - This volume is capable of Virt-IO drive hot plug (no reboot required)
54
- # * discVirtioHotPlug<~Boolean> - This volume is capable of Virt-IO drive hot unplug (no reboot required)
55
- # * discScsiHotPlug<~Boolean> - This volume is capable of Scsi drive hot plug (no reboot required)
56
- # * discScsiHotUnplug<~Boolean> - This volume is capable of Scsi drive hot unplug (no reboot required)
57
- # * deviceNumber<~Integer> - The LUN ID of the volume volume
58
- #
59
- # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-volume]
60
- def create_volume(datacenter_id, options={})
61
- volume = {
62
- :properties => options
63
- }
2
+ module Compute
3
+ class ProfitBricks
4
+ class Real
5
+ # Creates a volume within the data center. This will NOT attach the volume to a server.
6
+ #
7
+ # ==== Parameters
8
+ # * datacenter_id<~String> - Required, UUID of virtual data center
9
+ # * options<~Hash>:
10
+ # * name<~String> - The name of the volume
11
+ # * size<~Integer> - Required, the size of the volume in GB
12
+ # * bus<~String> - The bus type of the volume (VIRTIO or IDE). Default: VIRTIO.
13
+ # * image<~String> - Required**, the image or snapshot ID
14
+ # * type<~String> - The volume type, HDD or SSD
15
+ # * licenceType<~String> - Required**, the licence type of the volume. Options: LINUX, WINDOWS, UNKNOWN, OTHER
16
+ # * imagePassword<~String> - One-time password is set on the Image for the appropriate account.
17
+ # This field may only be set in creation requests. When reading, it always returns null.
18
+ # Password has to contain 8-50 characters.
19
+ # Only these characters are allowed: [abcdefghjkmnpqrstuvxABCDEFGHJKLMNPQRSTUVX23456789]
20
+ # * sshKeys<~String> - SSH keys to allow access to the volume via SSH
21
+ #
22
+ # ** Either the image or the licenceType parameters need to be provided.
23
+ # licenceType is required, but if image is supplied, it will already have a licenceType set.
24
+ #
25
+ # ==== Returns
26
+ # * response<~Excon::Response>:
27
+ # * body<~Hash>:
28
+ # * id<~String> - The resource's unique identifier
29
+ # * type<~String> - The type of the created resource
30
+ # * href<~String> - URL to the object's representation (absolute path)
31
+ # * metadata<~Hash> - Hash containing the volume metadata
32
+ # * createdDate<~String> - The date the resource was created
33
+ # * createdBy<~String> - The user who created the resource
34
+ # * etag<~String> - The etag for the resource
35
+ # * lastModifiedDate<~String> - The last time the resource has been modified
36
+ # * lastModifiedBy<~String> - The user who last modified the resource
37
+ # * state<~String> - Volume state
38
+ # * properties<~Hash> - Hash containing the volume properties
39
+ # * name<~String> - The name of the volume.
40
+ # * type<~String> - The volume type, HDD or SSD.
41
+ # * size<~Integer> - The size of the volume in GB.
42
+ # * image<~String> - The image or snapshot ID.
43
+ # * imagePassword<~String> - Indicates if a password is set on the image.
44
+ # * sshKeys<~String> - SSH keys
45
+ # * bus<~String> - The bus type of the volume (VIRTIO or IDE). Default: VIRTIO.
46
+ # * licenceType<~String> - Volume licence type. ( WINDOWS, LINUX, OTHER, UNKNOWN)
47
+ # * cpuHotPlug<~Boolean> - This volume is capable of CPU hot plug (no reboot required)
48
+ # * cpuHotUnplug<~Boolean> - This volume is capable of CPU hot unplug (no reboot required)
49
+ # * ramHotPlug<~Boolean> - This volume is capable of memory hot plug (no reboot required)
50
+ # * ramHotUnplug<~Boolean> - This volume is capable of memory hot unplug (no reboot required)
51
+ # * nicHotPlug<~Boolean> - This volume is capable of nic hot plug (no reboot required)
52
+ # * nicHotUnplug<~Boolean> - This volume is capable of nic hot unplug (no reboot required)
53
+ # * discVirtioHotPlug<~Boolean> - This volume is capable of Virt-IO drive hot plug (no reboot required)
54
+ # * discVirtioHotPlug<~Boolean> - This volume is capable of Virt-IO drive hot unplug (no reboot required)
55
+ # * discScsiHotPlug<~Boolean> - This volume is capable of Scsi drive hot plug (no reboot required)
56
+ # * discScsiHotUnplug<~Boolean> - This volume is capable of Scsi drive hot unplug (no reboot required)
57
+ # * deviceNumber<~Integer> - The LUN ID of the volume volume
58
+ #
59
+ # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-volume]
60
+ def create_volume(datacenter_id, options = {})
61
+ volume = {
62
+ :properties => options
63
+ }
64
64
 
65
- request(
66
- :expects => [202],
67
- :method => 'POST',
68
- :path => "/datacenters/#{datacenter_id}/volumes",
69
- :body => Fog::JSON.encode(volume)
70
- )
71
- rescue => error
72
- Fog::Errors::NotFound.new(error)
73
- end
74
- end
65
+ request(
66
+ :expects => [202],
67
+ :method => 'POST',
68
+ :path => "/datacenters/#{datacenter_id}/volumes",
69
+ :body => Fog::JSON.encode(volume)
70
+ )
71
+ end
72
+ end
73
+
74
+ class Mock
75
+ def create_volume(datacenter_id, options = {})
76
+ response = Excon::Response.new
77
+ response.status = 202
75
78
 
76
- class Mock
77
- def create_volume(datacenter_id, options={})
78
- response = Excon::Response.new
79
- response.status = 202
79
+ if datacenter = data[:datacenters]['items'].find do |attrib|
80
+ attrib['id'] == datacenter_id
81
+ end
80
82
 
81
- if datacenter = self.data[:datacenters]['items'].find {
82
- |attrib| attrib['id'] == datacenter_id
83
- }
84
- datacenter['properties']['version'] += 1
85
- else
86
- raise Fog::Errors::NotFound.new('Data center resource could not be found')
87
- end
83
+ datacenter['version'] += 1 if datacenter['version']
84
+ else
85
+ raise Fog::Errors::NotFound, 'Data center resource could not be found'
86
+ end
88
87
 
89
- volume_id = Fog::UUID.uuid
88
+ volume_id = Fog::UUID.uuid
90
89
 
91
- volume = {
92
- 'id' => volume_id,
93
- 'type' => 'volume',
94
- 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter['id']}/volumes/#{volume_id}",
95
- 'metadata' => {
96
- 'createdDate' => '2015-03-18T19=>00=>51Z',
97
- 'createdBy' => 'test@stackpointcloud.com',
98
- 'etag' => 'c4a2fde6ba91a038ff953b939cc21efe',
99
- 'lastModifiedDate' => '2015-03-18T19=>00=>51Z',
100
- 'lastModifiedBy' => 'test@stackpointcloud.com',
101
- 'state' => 'AVAILABLE'
102
- },
103
- 'properties' => {
104
- 'name' => options[:name],
105
- 'type' => options[:type],
106
- 'size' => options[:size],
107
- 'image' => options[:image],
108
- 'bus' => 'VIRTIO',
109
- 'licenceType' => 'OTHER',
110
- 'cpuHotPlug' => 'true',
111
- 'cpuHotUnplug' => 'false',
112
- 'ramHotPlug' => 'false',
113
- 'ramHotUnplug' => 'false',
114
- 'nicHotPlug' => 'true',
115
- 'nicHotUnplug' => 'true',
116
- 'discVirtioHotPlug' => 'true',
117
- 'discVirtioHotUnplug' => 'true',
118
- 'discScsiHotPlug' => 'false',
119
- 'discScsiHotUnplug' => 'false',
120
- 'deviceNumber' => 1
121
- },
122
- 'datacenter_id' => datacenter['id']
123
- }
90
+ volume = {
91
+ 'id' => volume_id,
92
+ 'type' => 'volume',
93
+ 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter['id']}/volumes/#{volume_id}",
94
+ 'metadata' => {
95
+ 'createdDate' => '2015-03-18T19=>00=>51Z',
96
+ 'createdBy' => 'test@stackpointcloud.com',
97
+ 'etag' => 'c4a2fde6ba91a038ff953b939cc21efe',
98
+ 'lastModifiedDate' => '2015-03-18T19=>00=>51Z',
99
+ 'lastModifiedBy' => 'test@stackpointcloud.com',
100
+ 'state' => 'AVAILABLE'
101
+ },
102
+ 'properties' => {
103
+ 'name' => options[:name],
104
+ 'type' => options[:type],
105
+ 'size' => options[:size],
106
+ 'image' => options[:image],
107
+ 'availabilityZone' => options[:availabilityZone],
108
+ 'bus' => 'VIRTIO',
109
+ 'licenceType' => 'OTHER',
110
+ 'cpuHotPlug' => 'true',
111
+ 'cpuHotUnplug' => 'false',
112
+ 'ramHotPlug' => 'false',
113
+ 'ramHotUnplug' => 'false',
114
+ 'nicHotPlug' => 'true',
115
+ 'nicHotUnplug' => 'true',
116
+ 'discVirtioHotPlug' => 'true',
117
+ 'discVirtioHotUnplug' => 'true',
118
+ 'discScsiHotPlug' => 'false',
119
+ 'discScsiHotUnplug' => 'false',
120
+ 'deviceNumber' => 1
121
+ },
122
+ 'datacenter_id' => datacenter['id']
123
+ }
124
124
 
125
- self.data[:volumes]['items'] << volume
125
+ data[:volumes]['items'] << volume
126
126
 
127
- response.body = volume
128
- response
129
- end
130
- end
127
+ response.body = volume
128
+ response
131
129
  end
130
+ end
132
131
  end
132
+ end
133
133
  end