fog-scaleway 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +58 -0
  8. data/Rakefile +21 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/fog-scaleway.gemspec +31 -0
  12. data/lib/fog/scaleway.rb +15 -0
  13. data/lib/fog/scaleway/account.rb +306 -0
  14. data/lib/fog/scaleway/client.rb +54 -0
  15. data/lib/fog/scaleway/compute.rb +350 -0
  16. data/lib/fog/scaleway/errors.rb +37 -0
  17. data/lib/fog/scaleway/models/account/organization.rb +42 -0
  18. data/lib/fog/scaleway/models/account/organizations.rb +22 -0
  19. data/lib/fog/scaleway/models/account/token.rb +60 -0
  20. data/lib/fog/scaleway/models/account/tokens.rb +22 -0
  21. data/lib/fog/scaleway/models/account/user.rb +69 -0
  22. data/lib/fog/scaleway/models/account/users.rb +23 -0
  23. data/lib/fog/scaleway/models/compute/bootscript.rb +19 -0
  24. data/lib/fog/scaleway/models/compute/bootscripts.rb +22 -0
  25. data/lib/fog/scaleway/models/compute/image.rb +83 -0
  26. data/lib/fog/scaleway/models/compute/images.rb +22 -0
  27. data/lib/fog/scaleway/models/compute/ip.rb +70 -0
  28. data/lib/fog/scaleway/models/compute/ips.rb +22 -0
  29. data/lib/fog/scaleway/models/compute/security_group.rb +77 -0
  30. data/lib/fog/scaleway/models/compute/security_group_rule.rb +59 -0
  31. data/lib/fog/scaleway/models/compute/security_group_rules.rb +34 -0
  32. data/lib/fog/scaleway/models/compute/security_groups.rb +22 -0
  33. data/lib/fog/scaleway/models/compute/server.rb +243 -0
  34. data/lib/fog/scaleway/models/compute/servers.rb +47 -0
  35. data/lib/fog/scaleway/models/compute/snapshot.rb +90 -0
  36. data/lib/fog/scaleway/models/compute/snapshots.rb +22 -0
  37. data/lib/fog/scaleway/models/compute/task.rb +31 -0
  38. data/lib/fog/scaleway/models/compute/tasks.rb +22 -0
  39. data/lib/fog/scaleway/models/compute/volume.rb +96 -0
  40. data/lib/fog/scaleway/models/compute/volumes.rb +22 -0
  41. data/lib/fog/scaleway/request_helper.rb +32 -0
  42. data/lib/fog/scaleway/requests/account/create_token.rb +62 -0
  43. data/lib/fog/scaleway/requests/account/delete_token.rb +21 -0
  44. data/lib/fog/scaleway/requests/account/get_organization.rb +19 -0
  45. data/lib/fog/scaleway/requests/account/get_organization_quotas.rb +21 -0
  46. data/lib/fog/scaleway/requests/account/get_token.rb +19 -0
  47. data/lib/fog/scaleway/requests/account/get_token_permissions.rb +21 -0
  48. data/lib/fog/scaleway/requests/account/get_user.rb +19 -0
  49. data/lib/fog/scaleway/requests/account/list_organizations.rb +19 -0
  50. data/lib/fog/scaleway/requests/account/list_tokens.rb +19 -0
  51. data/lib/fog/scaleway/requests/account/update_token.rb +27 -0
  52. data/lib/fog/scaleway/requests/account/update_user.rb +39 -0
  53. data/lib/fog/scaleway/requests/compute/create_image.rb +61 -0
  54. data/lib/fog/scaleway/requests/compute/create_ip.rb +68 -0
  55. data/lib/fog/scaleway/requests/compute/create_security_group.rb +49 -0
  56. data/lib/fog/scaleway/requests/compute/create_security_group_rule.rb +49 -0
  57. data/lib/fog/scaleway/requests/compute/create_server.rb +129 -0
  58. data/lib/fog/scaleway/requests/compute/create_snapshot.rb +54 -0
  59. data/lib/fog/scaleway/requests/compute/create_volume.rb +88 -0
  60. data/lib/fog/scaleway/requests/compute/delete_image.rb +27 -0
  61. data/lib/fog/scaleway/requests/compute/delete_ip.rb +29 -0
  62. data/lib/fog/scaleway/requests/compute/delete_security_group.rb +31 -0
  63. data/lib/fog/scaleway/requests/compute/delete_security_group_rule.rb +23 -0
  64. data/lib/fog/scaleway/requests/compute/delete_server.rb +40 -0
  65. data/lib/fog/scaleway/requests/compute/delete_snapshot.rb +29 -0
  66. data/lib/fog/scaleway/requests/compute/delete_task.rb +21 -0
  67. data/lib/fog/scaleway/requests/compute/delete_user_data.rb +21 -0
  68. data/lib/fog/scaleway/requests/compute/delete_volume.rb +31 -0
  69. data/lib/fog/scaleway/requests/compute/execute_server_action.rb +101 -0
  70. data/lib/fog/scaleway/requests/compute/get_bootscript.rb +19 -0
  71. data/lib/fog/scaleway/requests/compute/get_container.rb +19 -0
  72. data/lib/fog/scaleway/requests/compute/get_dashboard.rb +37 -0
  73. data/lib/fog/scaleway/requests/compute/get_image.rb +19 -0
  74. data/lib/fog/scaleway/requests/compute/get_ip.rb +19 -0
  75. data/lib/fog/scaleway/requests/compute/get_security_group.rb +19 -0
  76. data/lib/fog/scaleway/requests/compute/get_security_group_rule.rb +23 -0
  77. data/lib/fog/scaleway/requests/compute/get_server.rb +48 -0
  78. data/lib/fog/scaleway/requests/compute/get_snapshot.rb +19 -0
  79. data/lib/fog/scaleway/requests/compute/get_task.rb +25 -0
  80. data/lib/fog/scaleway/requests/compute/get_user_data.rb +25 -0
  81. data/lib/fog/scaleway/requests/compute/get_volume.rb +19 -0
  82. data/lib/fog/scaleway/requests/compute/list_bootscripts.rb +23 -0
  83. data/lib/fog/scaleway/requests/compute/list_containers.rb +19 -0
  84. data/lib/fog/scaleway/requests/compute/list_images.rb +27 -0
  85. data/lib/fog/scaleway/requests/compute/list_ips.rb +19 -0
  86. data/lib/fog/scaleway/requests/compute/list_security_group_rules.rb +21 -0
  87. data/lib/fog/scaleway/requests/compute/list_security_groups.rb +19 -0
  88. data/lib/fog/scaleway/requests/compute/list_server_actions.rb +21 -0
  89. data/lib/fog/scaleway/requests/compute/list_servers.rb +19 -0
  90. data/lib/fog/scaleway/requests/compute/list_snapshots.rb +19 -0
  91. data/lib/fog/scaleway/requests/compute/list_tasks.rb +19 -0
  92. data/lib/fog/scaleway/requests/compute/list_user_data.rb +21 -0
  93. data/lib/fog/scaleway/requests/compute/list_volumes.rb +19 -0
  94. data/lib/fog/scaleway/requests/compute/update_image.rb +31 -0
  95. data/lib/fog/scaleway/requests/compute/update_ip.rb +47 -0
  96. data/lib/fog/scaleway/requests/compute/update_security_group.rb +29 -0
  97. data/lib/fog/scaleway/requests/compute/update_security_group_rule.rb +31 -0
  98. data/lib/fog/scaleway/requests/compute/update_server.rb +71 -0
  99. data/lib/fog/scaleway/requests/compute/update_snapshot.rb +24 -0
  100. data/lib/fog/scaleway/requests/compute/update_user_data.rb +25 -0
  101. data/lib/fog/scaleway/requests/compute/update_volume.rb +24 -0
  102. data/lib/fog/scaleway/version.rb +5 -0
  103. metadata +285 -0
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_bootscript(bootscript_id)
6
+ get("/bootscripts/#{bootscript_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_bootscript(bootscript_id)
12
+ bootscript = lookup(:bootscripts, bootscript_id)
13
+
14
+ response(status: 200, body: { 'bootscript' => bootscript })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_container(container_id)
6
+ get("/containers/#{container_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_container(container_id)
12
+ container = lookup(:containers, container_id)
13
+
14
+ response(status: 200, body: { 'container' => container })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_dashboard
6
+ get('/dashboard')
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_dashboard
12
+ running_servers = data[:servers].select do |_id, s|
13
+ s['state'] == 'running'
14
+ end
15
+
16
+ servers_by_types = data[:servers].group_by { |s| s['commercial_type'] }
17
+ servers_count_by_types = Hash[servers_by_types.map { |t, s| [t, s.size] }]
18
+
19
+ ips_unused = data[:ips].reject { |ip| ip['server'] }.size
20
+
21
+ dashboard = {
22
+ 'snapshots_count' => data[:snapshots].size,
23
+ 'servers_count' => data[:servers].size,
24
+ 'volumes_count' => data[:volumes].size,
25
+ 'images_count' => data[:images].size,
26
+ 'ips_count' => data[:ips].size,
27
+ 'running_servers_count' => running_servers.size,
28
+ 'servers_by_types' => servers_count_by_types,
29
+ 'ips_unused' => ips_unused
30
+ }
31
+
32
+ response(status: 200, body: { 'dashboard' => dashboard })
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_image(image_id)
6
+ get("/images/#{image_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_image(image_id)
12
+ image = lookup(:images, image_id)
13
+
14
+ response(status: 200, body: { 'image' => image })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_ip(ip_id)
6
+ get("/ips/#{ip_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_ip(ip_id)
12
+ ip = lookup(:ips, ip_id)
13
+
14
+ response(status: 200, body: { 'ip' => ip })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_security_group(security_group_id)
6
+ get("/security_groups/#{security_group_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_security_group(security_group_id)
12
+ security_group = lookup(:security_groups, security_group_id)
13
+
14
+ response(status: 200, body: { 'security_group' => security_group })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_security_group_rule(security_group_id, rule_id)
6
+ get("/security_groups/#{security_group_id}/rules/#{rule_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_security_group_rule(security_group_id, rule_id)
12
+ security_group = lookup(:security_groups, security_group_id)
13
+
14
+ rule = data[:security_group_rules][security_group_id][rule_id]
15
+
16
+ raise_unknown_resource(rule_id) unless rule
17
+
18
+ response(status: 200, body: { 'rule' => rule })
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_server(server_id)
6
+ get("/servers/#{server_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_server(server_id)
12
+ server = lookup(:servers, server_id)
13
+
14
+ elapsed_time = Time.now - Time.parse(server['modification_date'])
15
+
16
+ if server['state'] == 'starting' && elapsed_time >= Fog::Mock.delay
17
+ server['state'] = 'running'
18
+ server['state_detail'] = 'booted'
19
+ server['modification_date'] = now
20
+ elsif server['state'] == 'stopping' && elapsed_time >= Fog::Mock.delay
21
+ case server['state_detail']
22
+ when 'stopping'
23
+ server['ipv6'] = nil
24
+ server['location'] = nil
25
+ server['private_ip'] = nil
26
+
27
+ if server['public_ip'] && server['public_ip']['dynamic']
28
+ server['public_ip'] = nil
29
+ end
30
+
31
+ server['state'] = 'stopped'
32
+ server['state_detail'] = ''
33
+ server['modification_date'] = now
34
+ when 'rebooting'
35
+ server['state'] = 'running'
36
+ server['state_detail'] = 'booted'
37
+ server['modification_date'] = now
38
+ when 'terminating'
39
+ terminate_server(server)
40
+ end
41
+ end
42
+
43
+ response(status: 200, body: { 'server' => server })
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_snapshot(snapshot_id)
6
+ get("/snapshots/#{snapshot_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_snapshot(snapshot_id)
12
+ snapshot = lookup(:snapshots, snapshot_id)
13
+
14
+ response(status: 200, body: { 'snapshot' => snapshot })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_task(task_id)
6
+ get("/tasks/#{task_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_task(task_id)
12
+ task = lookup(:tasks, task_id)
13
+
14
+ if Time.now - Time.parse(task['started_at']) >= Fog::Mock.delay
15
+ task['status'] = 'success'
16
+ task['terminated_at'] = now
17
+ task['progress'] = 100
18
+ end
19
+
20
+ response(status: 200, body: { 'task' => task })
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_user_data(server_id, key)
6
+ get("/servers/#{server_id}/user_data/#{key}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_user_data(server_id, key)
12
+ server = lookup(:servers, server_id)
13
+
14
+ user_data = data[:user_data][server['id']][key]
15
+
16
+ raise Excon::Error::NotFound unless user_data
17
+
18
+ response(status: 200,
19
+ headers: { 'Content-Type' => 'text/plain' },
20
+ body: user_data)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def get_volume(volume_id)
6
+ get("/volumes/#{volume_id}")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def get_volume(volume_id)
12
+ volume = lookup(:volumes, volume_id)
13
+
14
+ response(status: 200, body: { 'volume' => volume })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def list_bootscripts(filters = {})
6
+ get('/bootscripts', filters)
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def list_bootscripts(filters = {})
12
+ bootscripts = data[:bootscripts].values
13
+
14
+ if (arch = filters[:arch])
15
+ bootscripts.select! { |b| b['architecture'] == arch }
16
+ end
17
+
18
+ response(status: 200, body: { 'bootscripts' => bootscripts })
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def list_containers
6
+ get('/containers')
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def list_containers
12
+ containers = data[:containers].values
13
+
14
+ response(status: 200, body: { 'containers' => containers })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def list_images(filters = {})
6
+ get('/images', filters)
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def list_images(filters = {})
12
+ images = data[:images].values
13
+
14
+ if (organization = filters[:organization])
15
+ images.select! { |i| i['organization'] == organization }
16
+ end
17
+
18
+ if (arch = filters[:arch])
19
+ images.select! { |b| b['arch'] == arch }
20
+ end
21
+
22
+ response(status: 200, body: { 'images' => images })
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def list_ips
6
+ get('/ips')
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def list_ips
12
+ ips = data[:ips].values
13
+
14
+ response(status: 200, body: { 'ips' => ips })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def list_security_group_rules(security_group_id)
6
+ get("/security_groups/#{security_group_id}/rules")
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def list_security_group_rules(security_group_id)
12
+ security_group = lookup(:security_groups, security_group_id)
13
+
14
+ rules = data[:security_group_rules][security_group_id].values
15
+
16
+ response(status: 200, body: { 'rules' => rules })
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Scaleway
3
+ class Compute
4
+ class Real
5
+ def list_security_groups
6
+ get('/security_groups')
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def list_security_groups
12
+ security_groups = data[:security_groups].values
13
+
14
+ response(status: 200, body: { 'security_groups' => security_groups })
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end