scaleway 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/README.md +141 -106
- data/lib/scaleway.rb +108 -47
- data/lib/scaleway/version.rb +1 -1
- data/spec/scaleway_spec.rb +13 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24bc58f3cf0038fb5cf63a6d9de5dbe3b1eee4a3
|
4
|
+
data.tar.gz: 61c3fcbf49df0ae41a4113600113b0b30cfc81d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fd8343dace6d35e24bd6afdd7c8a9fb6cffe5896deeca8ece2263332b4e695df4fbb82b2d05dc8ddfd93defdefa8cb449feade37a6ca7986bd7a5a91a63e170
|
7
|
+
data.tar.gz: 920b2215110df212c56b47f01b282ef5099ce1499fed489efa23dbbac937dff2a9559080a58d136161a7f4dcc8902c69eb0dc5dd914363e27392cd13739c68d5
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -9,171 +9,206 @@ Easy to use Scaleway api client.
|
|
9
9
|
|
10
10
|
Manual instalation:
|
11
11
|
|
12
|
-
|
12
|
+
```bash
|
13
|
+
gem install scaleway
|
14
|
+
```
|
13
15
|
|
14
16
|
add this to your gemfile:
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
```bash
|
19
|
+
gem 'scaleway'
|
20
|
+
```
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
24
|
### Configure the client
|
22
25
|
|
23
|
-
|
26
|
+
```ruby
|
27
|
+
require 'scaleway'
|
28
|
+
|
29
|
+
Scaleway.organization = <organization_key>
|
30
|
+
Scaleway.token = <token>
|
24
31
|
|
25
|
-
|
26
|
-
|
32
|
+
# You can specify the zone, the default zone is 'par1'
|
33
|
+
Scaleway.zone = 'ams1'
|
34
|
+
```
|
27
35
|
|
28
36
|
### Servers
|
29
37
|
|
30
|
-
|
31
|
-
|
38
|
+
```ruby
|
39
|
+
# list all servers
|
40
|
+
Scaleway::Server.all
|
32
41
|
|
33
|
-
|
34
|
-
|
42
|
+
# list with filter
|
43
|
+
Scaleway::Server.all state: :running
|
35
44
|
|
36
|
-
|
37
|
-
|
45
|
+
# create a new server with default values
|
46
|
+
Scaleway::Server.create
|
38
47
|
|
39
|
-
|
40
|
-
|
48
|
+
# create a new server with name and tags
|
49
|
+
Scaleway::Server.create :name => 'my_new_server', tags: ['prod']
|
41
50
|
|
42
|
-
|
43
|
-
|
51
|
+
# get a server by id
|
52
|
+
server = Scaleway::Server.find <server_id>
|
44
53
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
54
|
+
# edit a server
|
55
|
+
server = Scaleway::Server.find <server_id>
|
56
|
+
server.name = 'new_name'
|
57
|
+
Scaleway::Server.edit server.id, server
|
49
58
|
|
50
|
-
|
51
|
-
|
59
|
+
# actions on a server
|
60
|
+
Scaleway::Server.power_on server.id
|
52
61
|
|
53
|
-
|
62
|
+
Scaleway::Server.power_off server.id
|
54
63
|
|
55
|
-
|
64
|
+
Scaleway::Server.terminate server.id
|
56
65
|
|
57
|
-
|
58
|
-
|
66
|
+
# destroy a server
|
67
|
+
Scaleway::Server.destroy server.id
|
68
|
+
```
|
59
69
|
|
60
|
-
###
|
70
|
+
### Marketplace
|
61
71
|
|
62
|
-
|
63
|
-
|
72
|
+
```ruby
|
73
|
+
# list all marketplace images
|
74
|
+
Scaleway::Marketplace.all
|
64
75
|
|
65
|
-
|
66
|
-
|
76
|
+
# get local image by id
|
77
|
+
image = Scaleway::Marketplace.find_local_image <marketplace_image_id>
|
67
78
|
|
68
|
-
|
69
|
-
|
79
|
+
# get local image by marketplace image id for arch arm
|
80
|
+
image = Scaleway::Marketplace.find_local_image <marketplace_image_id>, arch: 'arm'
|
70
81
|
|
71
|
-
|
72
|
-
|
82
|
+
# get local image by name
|
83
|
+
image = Scaleway::Marketplace.find_local_image_by_name("Docker")
|
84
|
+
```
|
85
|
+
|
86
|
+
### Images
|
73
87
|
|
74
|
-
|
75
|
-
|
88
|
+
```ruby
|
89
|
+
# list all images
|
90
|
+
Scaleway::Image.all
|
76
91
|
|
77
|
-
|
78
|
-
|
92
|
+
# get image by id
|
93
|
+
image = Scaleway::Image.find <image_id>
|
79
94
|
|
80
|
-
|
81
|
-
|
95
|
+
# get image by name
|
96
|
+
image = Scaleway::Image.find_by_name('Ubuntu')
|
97
|
+
|
98
|
+
# create an image
|
99
|
+
image = Scaleway::Image.create root_volume: snapshot
|
100
|
+
|
101
|
+
# edit an image
|
102
|
+
image = Scaleway::Image.edit id, image
|
103
|
+
|
104
|
+
# destroy an image
|
105
|
+
image = Scaleway::Image.destroy id
|
106
|
+
```
|
82
107
|
|
83
108
|
### Volumes
|
84
109
|
|
85
|
-
|
86
|
-
|
110
|
+
```ruby
|
111
|
+
# list all volumes
|
112
|
+
Scaleway::Volume.all
|
87
113
|
|
88
|
-
|
89
|
-
|
114
|
+
# get volume by id
|
115
|
+
volume = Scaleway::Volume.find <volume_id>
|
90
116
|
|
91
|
-
|
92
|
-
|
93
|
-
|
117
|
+
# create an volume
|
118
|
+
volume = Scaleway::Volume.create
|
119
|
+
volume = Scaleway::Volume.create size: 100 * 10 ** 9, volume_type: 'l_ssd'
|
94
120
|
|
95
|
-
|
96
|
-
|
121
|
+
# edit an volume
|
122
|
+
volume = Scaleway::Volume.edit id, volume
|
97
123
|
|
98
|
-
|
99
|
-
|
124
|
+
# destroy an volume
|
125
|
+
volume = Scaleway::Volume.destroy id
|
126
|
+
```
|
100
127
|
|
101
128
|
### Snapshots
|
102
129
|
|
103
|
-
|
104
|
-
|
130
|
+
```ruby
|
131
|
+
# list all snapshots
|
132
|
+
Scaleway::Volume.all
|
105
133
|
|
106
|
-
|
107
|
-
|
134
|
+
# get snapshot by id
|
135
|
+
snapshot = Scaleway::Snapshot.find <snapshot_id>
|
108
136
|
|
109
|
-
|
110
|
-
|
137
|
+
# create an snapshot
|
138
|
+
snapshot = Scaleway::Snapshot.create volume_id: id
|
111
139
|
|
112
|
-
|
113
|
-
|
140
|
+
# edit an snapshot
|
141
|
+
snapshot = Scaleway::Snapshot.edit id, snapshot
|
114
142
|
|
115
|
-
|
116
|
-
|
143
|
+
# destroy an snapshot
|
144
|
+
snapshot = Scaleway::Snapshot.destroy id
|
145
|
+
```
|
117
146
|
|
118
147
|
### Ip addresses
|
119
148
|
|
120
|
-
|
121
|
-
|
149
|
+
```ruby
|
150
|
+
# list all ip addresses
|
151
|
+
Scaleway::Ip.all
|
122
152
|
|
123
|
-
|
124
|
-
|
125
|
-
|
153
|
+
# get Ip
|
154
|
+
ip = Scaleway::Ip.find <ip_id>
|
155
|
+
ip = Scaleway::Ip.find 127.0.0.1
|
126
156
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
157
|
+
# reserve an ip
|
158
|
+
ip = Scaleway::Ip.reserve
|
159
|
+
# or
|
160
|
+
ip = Scaleway::Ip.create
|
131
161
|
|
132
|
-
|
133
|
-
|
162
|
+
# edit an ip
|
163
|
+
ip = Scaleway::Ip.edit id, ip
|
134
164
|
|
135
|
-
|
136
|
-
|
165
|
+
# release an ip
|
166
|
+
ip = Scaleway::Ip.destroy id
|
167
|
+
```
|
137
168
|
|
138
169
|
### Handle exceptions
|
139
170
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
171
|
+
```ruby
|
172
|
+
# Not found
|
173
|
+
begin
|
174
|
+
puts Scaleway::Server.find <invalid_id>
|
175
|
+
rescue Scaleway::NotFound => e
|
176
|
+
# handle error here
|
177
|
+
end
|
178
|
+
|
179
|
+
# Other
|
180
|
+
begin
|
181
|
+
puts Scaleway::Server.create extra_field: ['nope']
|
182
|
+
rescue Scaleway::APIError => e
|
183
|
+
# handle error here
|
184
|
+
end
|
185
|
+
```
|
153
186
|
|
154
187
|
## Example
|
155
188
|
|
156
|
-
|
189
|
+
```ruby
|
190
|
+
require 'scaleway'
|
157
191
|
|
158
|
-
|
159
|
-
|
192
|
+
Scaleway.organization = <organization_key>
|
193
|
+
Scaleway.token = <token>
|
160
194
|
|
161
|
-
|
162
|
-
|
195
|
+
# get the docker image from the marketplace
|
196
|
+
image = Scaleway::Marketplace.find_local_image_by_name('Docker')
|
163
197
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
198
|
+
# create 5 new servers
|
199
|
+
5.times do |x|
|
200
|
+
Scaleway::Server.create name: "docker#{x}", image: image.id, tags: ['docker']
|
201
|
+
end
|
168
202
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
203
|
+
# power on
|
204
|
+
Scaleway::Server.all.each do |server|
|
205
|
+
Scaleway::Server.power_on(server.id)
|
206
|
+
end
|
173
207
|
|
174
|
-
|
208
|
+
# do something ...
|
175
209
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
210
|
+
# terminate
|
211
|
+
Scaleway::Server.all.each do |server|
|
212
|
+
Scaleway::Server.terminate(server.id)
|
213
|
+
end
|
214
|
+
```
|
data/lib/scaleway.rb
CHANGED
@@ -8,13 +8,26 @@ module Scaleway
|
|
8
8
|
extend self
|
9
9
|
|
10
10
|
def compute_endpoint
|
11
|
-
"https://
|
11
|
+
"https://cp-#{Scaleway.zone}.scaleway.com"
|
12
12
|
end
|
13
13
|
|
14
14
|
def account_endpoint
|
15
15
|
"https://account.scaleway.com"
|
16
16
|
end
|
17
17
|
|
18
|
+
def marketplace_endpoint
|
19
|
+
"https://api-marketplace.scaleway.com"
|
20
|
+
end
|
21
|
+
|
22
|
+
def zone=(zone)
|
23
|
+
@zone = zone
|
24
|
+
@zone
|
25
|
+
end
|
26
|
+
|
27
|
+
def zone
|
28
|
+
return @zone || 'par1'
|
29
|
+
end
|
30
|
+
|
18
31
|
def token=(token)
|
19
32
|
@token = token
|
20
33
|
setup!
|
@@ -38,36 +51,67 @@ module Scaleway
|
|
38
51
|
end
|
39
52
|
|
40
53
|
DEFINITIONS = {
|
41
|
-
"
|
54
|
+
"Marketplace" => {
|
42
55
|
:all => {
|
43
56
|
:method => :get,
|
44
|
-
:endpoint => "#{Scaleway.
|
57
|
+
:endpoint => "#{Scaleway.marketplace_endpoint}/images",
|
58
|
+
},
|
59
|
+
:find_local_image_by_name => {
|
60
|
+
:method => :get,
|
61
|
+
:endpoint => "#{Scaleway.marketplace_endpoint}/images",
|
45
62
|
:default_params => {
|
46
|
-
|
47
|
-
}
|
63
|
+
arch: 'x86_64',
|
64
|
+
},
|
65
|
+
:filters => [
|
66
|
+
Proc.new { |params, body, item|
|
67
|
+
item.name.include? params.first }
|
68
|
+
],
|
69
|
+
:transform => Proc.new { |params, body, item|
|
70
|
+
item[0].versions[0].local_images.keep_if do |local_image|
|
71
|
+
if local_image.zone == Scaleway.zone and local_image.arch == body[:arch]
|
72
|
+
true
|
73
|
+
end
|
74
|
+
end.first
|
75
|
+
},
|
48
76
|
},
|
49
|
-
:
|
77
|
+
:find_local_image => {
|
50
78
|
:method => :get,
|
51
|
-
:endpoint => "#{Scaleway.
|
79
|
+
:endpoint => "#{Scaleway.marketplace_endpoint}/images/%s/versions/current",
|
80
|
+
:default_params => {
|
81
|
+
arch: 'x86_64',
|
82
|
+
},
|
83
|
+
:transform => Proc.new { |params, body, item|
|
84
|
+
item.local_images.keep_if do |local_image|
|
85
|
+
if local_image.zone == Scaleway.zone and local_image.arch == body[:arch]
|
86
|
+
true
|
87
|
+
end
|
88
|
+
end.first
|
89
|
+
},
|
90
|
+
},
|
91
|
+
},
|
92
|
+
"Image" => {
|
93
|
+
:all => {
|
94
|
+
:method => :get,
|
95
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/images" },
|
52
96
|
:default_params => {
|
53
97
|
:public => true
|
54
98
|
}
|
55
99
|
},
|
56
100
|
:find => {
|
57
101
|
:method => :get,
|
58
|
-
:endpoint => "#{Scaleway.compute_endpoint}/images/%s",
|
102
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/images/%s" },
|
59
103
|
},
|
60
104
|
:find_by_name => {
|
61
105
|
:method => :get,
|
62
|
-
:endpoint => "#{Scaleway.compute_endpoint}/images",
|
106
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/images" },
|
63
107
|
:filters => [
|
64
|
-
Proc.new { |
|
108
|
+
Proc.new { |params, body, item| item.name.include? params.first }
|
65
109
|
],
|
66
|
-
:transform => Proc.new { |
|
110
|
+
:transform => Proc.new { |params, body, item| item.first },
|
67
111
|
},
|
68
112
|
:create => {
|
69
113
|
:method => :post,
|
70
|
-
:endpoint => "#{Scaleway.compute_endpoint}/images",
|
114
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/images" },
|
71
115
|
:default_params => {
|
72
116
|
:name => 'default',
|
73
117
|
:root_volume => 'required',
|
@@ -76,33 +120,33 @@ module Scaleway
|
|
76
120
|
},
|
77
121
|
:edit => {
|
78
122
|
:method => :put,
|
79
|
-
:endpoint => "#{Scaleway.compute_endpoint}/images/%s",
|
123
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/images/%s" },
|
80
124
|
},
|
81
125
|
:destroy => {
|
82
126
|
:method => :delete,
|
83
|
-
:endpoint => "#{Scaleway.compute_endpoint}/images/%s",
|
127
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/images/%s" },
|
84
128
|
},
|
85
129
|
},
|
86
130
|
"Volume" => {
|
87
131
|
:all => {
|
88
132
|
:method => :get,
|
89
|
-
:endpoint => "#{Scaleway.compute_endpoint}/volumes",
|
133
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/volumes" },
|
90
134
|
},
|
91
135
|
:find => {
|
92
136
|
:method => :get,
|
93
|
-
:endpoint => "#{Scaleway.compute_endpoint}/volumes/%s",
|
137
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/volumes/%s" },
|
94
138
|
},
|
95
139
|
:edit => {
|
96
140
|
:method => :put,
|
97
|
-
:endpoint => "#{Scaleway.compute_endpoint}/volumes/%s",
|
141
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/volumes/%s" },
|
98
142
|
},
|
99
143
|
:destroy => {
|
100
144
|
:method => :delete,
|
101
|
-
:endpoint => "#{Scaleway.compute_endpoint}/volumes/%s",
|
145
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/volumes/%s" },
|
102
146
|
},
|
103
147
|
:create => {
|
104
148
|
:method => :post,
|
105
|
-
:endpoint => "#{Scaleway.compute_endpoint}/volumes",
|
149
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/volumes" },
|
106
150
|
:default_params => {
|
107
151
|
:name => 'default',
|
108
152
|
:size => 20 * 10**9,
|
@@ -114,30 +158,30 @@ module Scaleway
|
|
114
158
|
"Ip" => {
|
115
159
|
:all => {
|
116
160
|
:method => :get,
|
117
|
-
:endpoint => "#{Scaleway.compute_endpoint}/ips",
|
161
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/ips" },
|
118
162
|
},
|
119
163
|
:find => {
|
120
164
|
:method => :get,
|
121
|
-
:endpoint => "#{Scaleway.compute_endpoint}/ips/%s",
|
165
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/ips/%s" },
|
122
166
|
},
|
123
167
|
:edit => {
|
124
168
|
:method => :put,
|
125
|
-
:endpoint => "#{Scaleway.compute_endpoint}/ips/%s",
|
169
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/ips/%s" },
|
126
170
|
},
|
127
171
|
:destroy => {
|
128
172
|
:method => :delete,
|
129
|
-
:endpoint => "#{Scaleway.compute_endpoint}/ips/%s",
|
173
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/ips/%s" },
|
130
174
|
},
|
131
175
|
:reserve => {
|
132
176
|
:method => :post,
|
133
|
-
:endpoint => "#{Scaleway.compute_endpoint}/ips",
|
177
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/ips" },
|
134
178
|
:default_params => {
|
135
179
|
:organization => Proc.new { Scaleway.organization },
|
136
180
|
}
|
137
181
|
},
|
138
182
|
:create => {
|
139
183
|
:method => :post,
|
140
|
-
:endpoint => "#{Scaleway.compute_endpoint}/ips",
|
184
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/ips" },
|
141
185
|
:default_params => {
|
142
186
|
:organization => Proc.new { Scaleway.organization },
|
143
187
|
}
|
@@ -146,23 +190,23 @@ module Scaleway
|
|
146
190
|
"Snapshot" => {
|
147
191
|
:all => {
|
148
192
|
:method => :get,
|
149
|
-
:endpoint => "#{Scaleway.compute_endpoint}/snapshots",
|
193
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/snapshots" },
|
150
194
|
},
|
151
195
|
:find => {
|
152
196
|
:method => :get,
|
153
|
-
:endpoint => "#{Scaleway.compute_endpoint}/snapshots/%s",
|
197
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/snapshots/%s" },
|
154
198
|
},
|
155
199
|
:edit => {
|
156
200
|
:method => :put,
|
157
|
-
:endpoint => "#{Scaleway.compute_endpoint}/snapshots/%s",
|
201
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/snapshots/%s" },
|
158
202
|
},
|
159
203
|
:destroy => {
|
160
204
|
:method => :delete,
|
161
|
-
:endpoint => "#{Scaleway.compute_endpoint}/snapshots/%s",
|
205
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/snapshots/%s" },
|
162
206
|
},
|
163
207
|
:create => {
|
164
208
|
:method => :post,
|
165
|
-
:endpoint => "#{Scaleway.compute_endpoint}/snapshots",
|
209
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/snapshots" },
|
166
210
|
:default_params => {
|
167
211
|
:name => 'default',
|
168
212
|
:volume_id => 'required',
|
@@ -173,54 +217,63 @@ module Scaleway
|
|
173
217
|
"Server" => {
|
174
218
|
:all => {
|
175
219
|
:method => :get,
|
176
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers",
|
220
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers" },
|
177
221
|
},
|
178
222
|
:power_on => {
|
179
223
|
:method => :post,
|
180
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s/action",
|
224
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers/%s/action" },
|
181
225
|
:default_params => {
|
182
226
|
:action => :poweron
|
183
227
|
}
|
184
228
|
},
|
185
229
|
:reboot => {
|
186
230
|
:method => :post,
|
187
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s/action",
|
231
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers/%s/action" },
|
188
232
|
:default_params => {
|
189
233
|
:action => :reboot
|
190
234
|
}
|
191
235
|
},
|
192
236
|
:power_off => {
|
193
237
|
:method => :post,
|
194
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s/action",
|
238
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers/%s/action" },
|
195
239
|
:default_params => {
|
196
240
|
:action => :poweroff
|
197
241
|
}
|
198
242
|
},
|
199
243
|
:terminate => {
|
200
244
|
:method => :post,
|
201
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s/action",
|
245
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers/%s/action" },
|
202
246
|
:default_params => {
|
203
247
|
:action => :terminate
|
204
248
|
}
|
205
249
|
},
|
206
250
|
:find => {
|
207
251
|
:method => :get,
|
208
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s",
|
252
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers/%s" },
|
209
253
|
},
|
210
254
|
:edit => {
|
211
255
|
:method => :put,
|
212
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s",
|
256
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers/%s" },
|
213
257
|
},
|
214
258
|
:destroy => {
|
215
259
|
:method => :delete,
|
216
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s",
|
260
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers/%s" },
|
217
261
|
},
|
218
262
|
:create => {
|
219
263
|
:method => :post,
|
220
|
-
:endpoint => "#{Scaleway.compute_endpoint}/servers",
|
264
|
+
:endpoint => Proc.new { "#{Scaleway.compute_endpoint}/servers" },
|
221
265
|
:default_params => {
|
222
266
|
:name => 'default',
|
223
|
-
:
|
267
|
+
:commercial_type => 'VC1S',
|
268
|
+
:image => Proc.new { |params, body|
|
269
|
+
if body[:commercial_type] == 'C1'
|
270
|
+
arch = 'arm'
|
271
|
+
else
|
272
|
+
arch = 'x86_64'
|
273
|
+
end
|
274
|
+
Scaleway::Marketplace.find_local_image_by_name(
|
275
|
+
'Ubuntu Xenial', arch: arch).id
|
276
|
+
},
|
224
277
|
:volumes => {},
|
225
278
|
:organization => Proc.new { Scaleway.organization },
|
226
279
|
}
|
@@ -257,6 +310,10 @@ module Scaleway
|
|
257
310
|
body.merge! query[:default_params] || {}
|
258
311
|
endpoint = query[:endpoint]
|
259
312
|
|
313
|
+
if endpoint.respond_to? :call
|
314
|
+
endpoint = endpoint.call()
|
315
|
+
end
|
316
|
+
|
260
317
|
params.each do |param|
|
261
318
|
if param.is_a? Hash or param.is_a? RecursiveOpenStruct
|
262
319
|
body.merge! param
|
@@ -266,11 +323,15 @@ module Scaleway
|
|
266
323
|
end
|
267
324
|
|
268
325
|
body = Hash[body.map { |k, v|
|
269
|
-
if v.respond_to? :call then [k, v.call()] else [k, v] end
|
326
|
+
if v.respond_to? :call then [k, v.call(params, body)] else [k, v] end
|
270
327
|
}]
|
271
328
|
|
329
|
+
if Scaleway.request.nil?
|
330
|
+
raise ::RuntimeError.new("Authentication is missing")
|
331
|
+
end
|
332
|
+
|
272
333
|
resp = Scaleway.request.send(query[:method], endpoint, body)
|
273
|
-
|
334
|
+
response_body = resp.body
|
274
335
|
if resp.status == 204
|
275
336
|
return
|
276
337
|
end
|
@@ -281,23 +342,23 @@ module Scaleway
|
|
281
342
|
raise Scaleway::APIError, resp
|
282
343
|
end
|
283
344
|
|
284
|
-
hash = RecursiveOpenStruct.new(
|
345
|
+
hash = RecursiveOpenStruct.new(response_body, :recurse_over_arrays => true)
|
285
346
|
|
286
|
-
if
|
287
|
-
hash = hash.send(
|
347
|
+
if response_body.length == 1
|
348
|
+
hash = hash.send(response_body.keys.first)
|
288
349
|
end
|
289
350
|
|
290
351
|
if query[:filters]
|
291
352
|
filters = query[:filters]
|
292
353
|
hash = hash.find_all do |item|
|
293
354
|
filters.all? do |filter|
|
294
|
-
filter.call(
|
355
|
+
filter.call(params, body, item)
|
295
356
|
end
|
296
357
|
end
|
297
358
|
end
|
298
359
|
|
299
360
|
if query[:transform]
|
300
|
-
hash = query[:transform].call(
|
361
|
+
hash = query[:transform].call(params, body, hash)
|
301
362
|
end
|
302
363
|
|
303
364
|
hash
|
data/lib/scaleway/version.rb
CHANGED
data/spec/scaleway_spec.rb
CHANGED
@@ -8,23 +8,34 @@ describe Scaleway do
|
|
8
8
|
before do
|
9
9
|
Scaleway.organization = organization
|
10
10
|
Scaleway.token = token
|
11
|
+
Scaleway.zone = zone
|
11
12
|
end
|
12
13
|
|
13
14
|
describe "defaults" do
|
14
15
|
let(:organization) { nil }
|
15
16
|
let(:token) { nil }
|
17
|
+
let(:zone) { nil }
|
16
18
|
|
17
|
-
its(:compute_endpoint) { should eq "https://
|
19
|
+
its(:compute_endpoint) { should eq "https://cp-par1.scaleway.com" }
|
18
20
|
its(:account_endpoint) { should eq "https://account.scaleway.com" }
|
19
21
|
its(:token) { should eq "token_required" }
|
20
22
|
its(:organization) { should eq "organization_required" }
|
21
23
|
|
22
|
-
it { expect(Scaleway::VERSION).to eq "0.
|
24
|
+
it { expect(Scaleway::VERSION).to eq "1.0.0" }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "test ams1" do
|
28
|
+
let(:organization) { nil }
|
29
|
+
let(:token) { nil }
|
30
|
+
let(:zone) { "ams1" }
|
31
|
+
|
32
|
+
its(:compute_endpoint) { should eq "https://cp-ams1.scaleway.com" }
|
23
33
|
end
|
24
34
|
|
25
35
|
describe "test token and organization" do
|
26
36
|
let(:organization) { "organization_id" }
|
27
37
|
let(:token) { "token_id" }
|
38
|
+
let(:zone) { nil }
|
28
39
|
|
29
40
|
its(:organization) { should eq "organization_id" }
|
30
41
|
its(:token) { should eq "token_id" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaleway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bchatelard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|