fog-scaleway 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b2994d73da388c40b6d946002f2f353be48e729
4
- data.tar.gz: c93b69bf568fd17acd1a245df2592f29ec657d78
3
+ metadata.gz: db12bf5472f63d0a82967f353364b030d692aa52
4
+ data.tar.gz: 0b9b420db0de3ae446a3a8b849de10cc06ed7bec
5
5
  SHA512:
6
- metadata.gz: 274dcd37918039e53cda8b9fdef4f4e4f06a8a0775212039528320d205188a8c7247118335c39378b217cc885627607da7c792e2ca33fb7fb5824a9ffef533a9
7
- data.tar.gz: 2c99fcf8985b593c74aeab7011936751c352bc5d771e52ea16e8d47c6831a57e2f1eb643b990aac302dcb64d1b30d9f26c211b54b6be5926a18bd89da4de99f8
6
+ metadata.gz: c7c53503be5dbea85781e6d2a4ac210fb7e95c533c0fa1a721736cc38e0ac9e5b5c9224bed40d5b9c4f8a288c1a5fad7be2d46e70f0a975e07555c6871db913e
7
+ data.tar.gz: 548432aeeaa06b08871bade39ba2561a47f4c17b09ec6d298ae51405b42d62e45ec498d4db3d0bc72ab90e58ac7829f1b028b2fc42de07e22509009b02fdd1aa
data/Rakefile CHANGED
@@ -21,4 +21,4 @@ task test: ['test:units', 'test:integration']
21
21
 
22
22
  RuboCop::RakeTask.new(:rubocop)
23
23
 
24
- task default: [:test, :rubocop]
24
+ task default: %i[test rubocop]
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'fog/scaleway/version'
@@ -37,6 +37,8 @@ module Fog
37
37
  collection :bootscripts
38
38
  model :task
39
39
  collection :tasks
40
+ model :product_server
41
+ collection :product_servers
40
42
 
41
43
  request_path 'fog/scaleway/requests/compute'
42
44
 
@@ -106,6 +108,9 @@ module Fog
106
108
  request :list_containers
107
109
  request :get_container
108
110
 
111
+ # Products
112
+ request :list_product_servers
113
+
109
114
  # Dashboard
110
115
  request :get_dashboard
111
116
 
@@ -209,6 +214,48 @@ module Fog
209
214
  'public' => true
210
215
  }].freeze
211
216
 
217
+ PRODUCTS = {
218
+ 'servers' => {
219
+ 'VC1S' => {
220
+ 'volumes_constraint' => {
221
+ 'min_size' => nil,
222
+ 'max_size' => 50_000_000_000
223
+ },
224
+ 'network' => {
225
+ 'interfaces' => [{
226
+ 'internal_bandwidth' => nil,
227
+ 'internet_bandwidth' => 209_715_200
228
+ }],
229
+ 'sum_internal_bandwidth' => nil,
230
+ 'sum_internet_bandwidth' => 209_715_200,
231
+ 'ipv6_support' => true
232
+ },
233
+ 'ncpus' => 2,
234
+ 'ram' => 2_147_483_648,
235
+ 'alt_names' => ['X64-2GB'],
236
+ 'baremetal' => false,
237
+ 'arch' => 'x86_64'
238
+ },
239
+ 'C1' => {
240
+ 'volumes_constraint' => nil,
241
+ 'network' => {
242
+ 'interfaces' => [{
243
+ 'internal_bandwidth' => 1_073_741_824,
244
+ 'internet_bandwidth' => 209_715_200
245
+ }],
246
+ 'sum_internal_bandwidth' => 1_073_741_824,
247
+ 'sum_internet_bandwidth' => 209_715_200,
248
+ 'ipv6_support' => false
249
+ },
250
+ 'ncpus' => 4,
251
+ 'ram' => 2_147_483_648,
252
+ 'alt_names' => [],
253
+ 'baremetal' => true,
254
+ 'arch' => 'arm'
255
+ }
256
+ }
257
+ }.freeze
258
+
212
259
  def self.data
213
260
  @data ||= Hash.new do |hash, token|
214
261
  hash[token] = {
@@ -225,7 +272,7 @@ module Fog
225
272
  end],
226
273
  tasks: {},
227
274
  containers: {},
228
- server_actions: Hash.new(%w(poweron poweroff reboot terminate))
275
+ server_actions: Hash.new(%w[poweron poweroff reboot terminate])
229
276
  }
230
277
  end
231
278
  end
@@ -248,6 +295,10 @@ module Fog
248
295
  data[type][id] || raise_unknown_resource(id)
249
296
  end
250
297
 
298
+ def lookup_product_server(name)
299
+ PRODUCTS['servers'].find { |n, s| n == name || s['alt_names'].include?(name) }
300
+ end
301
+
251
302
  def default_security_group
252
303
  data[:security_groups].values.find { |s| s['organization_default'] }
253
304
  end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class ProductServer < Fog::Model
5
+ identity :name
6
+
7
+ attribute :volumes_constraint
8
+ attribute :network
9
+ attribute :ncpus
10
+ attribute :ram
11
+ attribute :alt_names
12
+ attribute :baremetal
13
+ attribute :arch
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class ProductServers < Fog::Collection
5
+ model Fog::Scaleway::Compute::ProductServer
6
+
7
+ def all
8
+ product_servers = service.list_product_servers.body['servers'] || {}
9
+ product_servers = product_servers.map do |name, product_server|
10
+ product_server.merge(name: name)
11
+ end
12
+ load(product_servers)
13
+ end
14
+
15
+ def get(name)
16
+ product_servers = service.list_product_servers.body['servers'] || {}
17
+ name, product_server = product_servers.find do |n, s|
18
+ n == name || s['alt_names'].include?(name)
19
+ end
20
+ new(product_server.merge(name: name)) if product_server
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -16,7 +16,7 @@ module Fog
16
16
 
17
17
  user = lookup(:users, user_id)
18
18
 
19
- %w(firstname lastname).each do |attr|
19
+ %w[firstname lastname].each do |attr|
20
20
  user[attr] = options[attr] if options.key?(attr)
21
21
  end
22
22
 
@@ -31,6 +31,14 @@ module Fog
31
31
 
32
32
  image = lookup(:images, body['image'])
33
33
 
34
+ commercial_type, product_server = lookup_product_server(body.fetch('commercial_type', 'VC1S'))
35
+ raise_invalid_request_error('Validation Error') unless commercial_type
36
+
37
+ unless image['arch'] == product_server['arch']
38
+ message = "Image '#{image['id']}' arch is not '#{product_server['arch']}'"
39
+ raise_invalid_request_error(message)
40
+ end
41
+
34
42
  creation_date = now
35
43
 
36
44
  volumes = {}
@@ -69,12 +77,17 @@ module Fog
69
77
  }
70
78
  end
71
79
 
72
- dynamic_ip_required = !public_ip && body.fetch('dynamic_ip_required', true)
73
-
74
80
  default_bootscript_id = image['default_bootscript']['id']
75
81
  bootscript_id = body.fetch('bootscript', default_bootscript_id)
76
82
  bootscript = lookup(:bootscripts, bootscript_id)
77
83
 
84
+ dynamic_ip_required = !public_ip && body.fetch('dynamic_ip_required', true)
85
+
86
+ enable_ipv6 = body.fetch('enable_ipv6', false)
87
+ if enable_ipv6 && !product_server['network']['ipv6_support']
88
+ raise_invalid_request_error("Cannot enable ipv6 on #{commercial_type}")
89
+ end
90
+
78
91
  if body['security_group']
79
92
  security_group = lookup(:security_groups, body['security_group'])
80
93
  else
@@ -85,10 +98,10 @@ module Fog
85
98
  server = {
86
99
  'arch' => image['arch'],
87
100
  'bootscript' => bootscript,
88
- 'commercial_type' => body.fetch('commercial_type', 'C1'),
101
+ 'commercial_type' => commercial_type,
89
102
  'creation_date' => creation_date,
90
103
  'dynamic_ip_required' => dynamic_ip_required,
91
- 'enable_ipv6' => body.fetch('enable_ipv6', false),
104
+ 'enable_ipv6' => enable_ipv6,
92
105
  'extra_networks' => [],
93
106
  'hostname' => body['name'],
94
107
  'id' => Fog::UUID.uuid,
@@ -33,6 +33,26 @@ module Fog
33
33
  raise_invalid_request_error('server should be stopped')
34
34
  end
35
35
 
36
+ total_volume_size = server['volumes'].values.map { |v| v['size'] }.reduce(&:+)
37
+ commercial_type, product_server = lookup_product_server(server['commercial_type'])
38
+ # rubocop:disable Metrics/BlockNesting
39
+ if (constraint = product_server['volumes_constraint'])
40
+ min_size = constraint['min_size'] || -Float::INFINITY
41
+ max_size = constraint['max_size'] || Float::INFINITY
42
+ if total_volume_size < min_size || total_volume_size > max_size
43
+ message = "The total volume size of #{commercial_type} instances must be "
44
+ message << if min_size == -Float::INFINITY
45
+ "equal or below #{max_size / 10**9}GB"
46
+ elsif max_size == Float::INFINITY
47
+ "equal or above #{min_size / 10**9}GB"
48
+ else
49
+ "between #{min_size / 10**9}GB and #{max_size / 10**9}GB"
50
+ end
51
+ raise_invalid_request_error(message)
52
+ end
53
+ end
54
+ # rubocop:enable Metrics/BlockNesting
55
+
36
56
  task['description'] = 'server_batch_poweron'
37
57
 
38
58
  server['ipv6'] = create_ipv6 if server['enable_ipv6']
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def list_product_servers
6
+ get('/products/servers')
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def list_product_servers
12
+ response(status: 200, body: { 'servers' => PRODUCTS['servers'] })
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -19,6 +19,12 @@ module Fog
19
19
  lookup(:bootscripts, body['bootscript'])
20
20
  end
21
21
 
22
+ _, product_server = lookup_product_server(server['commercial_type'])
23
+
24
+ if body['enable_ipv6'] && !product_server['network']['ipv6_support']
25
+ raise_invalid_request_error("Cannot enable ipv6 on #{commercial_type}")
26
+ end
27
+
22
28
  volumes = {}
23
29
  body['volumes'].each do |index, volume|
24
30
  volume = lookup(:volumes, volume['id'])
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Scaleway
3
- VERSION = '0.2.1'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-scaleway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi Matsumoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-06 00:00:00.000000000 Z
11
+ date: 2017-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -186,6 +186,8 @@ files:
186
186
  - lib/fog/scaleway/models/compute/images.rb
187
187
  - lib/fog/scaleway/models/compute/ip.rb
188
188
  - lib/fog/scaleway/models/compute/ips.rb
189
+ - lib/fog/scaleway/models/compute/product_server.rb
190
+ - lib/fog/scaleway/models/compute/product_servers.rb
189
191
  - lib/fog/scaleway/models/compute/security_group.rb
190
192
  - lib/fog/scaleway/models/compute/security_group_rule.rb
191
193
  - lib/fog/scaleway/models/compute/security_group_rules.rb
@@ -243,6 +245,7 @@ files:
243
245
  - lib/fog/scaleway/requests/compute/list_containers.rb
244
246
  - lib/fog/scaleway/requests/compute/list_images.rb
245
247
  - lib/fog/scaleway/requests/compute/list_ips.rb
248
+ - lib/fog/scaleway/requests/compute/list_product_servers.rb
246
249
  - lib/fog/scaleway/requests/compute/list_security_group_rules.rb
247
250
  - lib/fog/scaleway/requests/compute/list_security_groups.rb
248
251
  - lib/fog/scaleway/requests/compute/list_server_actions.rb