scaleway 0.2.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 +7 -0
- data/.gitignore +34 -0
- data/.travis.yml +1 -0
- data/CHANGES.md +14 -0
- data/Gemfile +3 -0
- data/README.md +176 -0
- data/Rakefile +1 -0
- data/lib/scaleway/version.rb +3 -0
- data/lib/scaleway.rb +350 -0
- data/scaleway.gemspec +29 -0
- data/spec/scaleway_spec.rb +32 -0
- data/spec/servers_spec.rb +60 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4221212c581c02e76a53304098a948188155ac74
|
4
|
+
data.tar.gz: 824b40eb6c814166c8a48d77d1c40f40da11fdb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce6a9abd5b98e486ea83492236c355c9d8ab2aa63ef34cdc083c1f9dd9ab68592f930728acc22fcf742d31f81e125097ce4a5e4386eeaba5924b3646fe23cb5f
|
7
|
+
data.tar.gz: 9d2c47c4986825c28c16b4e5450ba768422461966b34bccd9769c4f54a707d5d064fd6439af55c45b7b2998d8aed748aeb3692f63ee178a7a6806df76718e399
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
script: "bundle exec rspec"
|
data/CHANGES.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
# Scaleway Rubygem
|
2
|
+
|
3
|
+
Easy to use Scaleway api client.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Manual instalation:
|
8
|
+
|
9
|
+
gem install scaleway
|
10
|
+
|
11
|
+
add this to your gemfile:
|
12
|
+
|
13
|
+
gem 'scaleway'
|
14
|
+
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
### Configure the client
|
19
|
+
|
20
|
+
require 'scaleway'
|
21
|
+
|
22
|
+
Scaleway.organization = <organization_key>
|
23
|
+
Scaleway.token = <token>
|
24
|
+
|
25
|
+
### Servers
|
26
|
+
|
27
|
+
# list all servers
|
28
|
+
Scaleway::Server.all
|
29
|
+
|
30
|
+
# list with filter
|
31
|
+
Scaleway::Server.all state: :running
|
32
|
+
|
33
|
+
# create a new server with default values
|
34
|
+
Scaleway::Server.create
|
35
|
+
|
36
|
+
# create a new server with name and tags
|
37
|
+
Scaleway::Server.create :name => 'my_new_server', tags: ['prod']
|
38
|
+
|
39
|
+
# get a server by id
|
40
|
+
server = Scaleway::Server.find <server_id>
|
41
|
+
|
42
|
+
# edit a server
|
43
|
+
server = Scaleway::Server.find <server_id>
|
44
|
+
server.name = 'new_name'
|
45
|
+
Scaleway::Server.edit server.id, server
|
46
|
+
|
47
|
+
# actions on a server
|
48
|
+
Scaleway::Server.power_on server.id
|
49
|
+
|
50
|
+
Scaleway::Server.power_off server.id
|
51
|
+
|
52
|
+
Scaleway::Server.terminate server.id
|
53
|
+
|
54
|
+
# destroy a server
|
55
|
+
Scaleway::Server.destroy server.id
|
56
|
+
|
57
|
+
### Images
|
58
|
+
|
59
|
+
# list all images
|
60
|
+
Scaleway::Image.all
|
61
|
+
|
62
|
+
# list marketplace images
|
63
|
+
Scaleway::Image.marketplace
|
64
|
+
|
65
|
+
# get image by id
|
66
|
+
image = Scaleway::Image.find <image_id>
|
67
|
+
|
68
|
+
# get image by name
|
69
|
+
image = Scaleway::Image.find_by_name('Ubuntu')
|
70
|
+
|
71
|
+
# create an image
|
72
|
+
image = Scaleway::Image.create root_volume: snapshot
|
73
|
+
|
74
|
+
# edit an image
|
75
|
+
image = Scaleway::Image.edit id, image
|
76
|
+
|
77
|
+
# destroy an image
|
78
|
+
image = Scaleway::Image.destroy id
|
79
|
+
|
80
|
+
### Volumes
|
81
|
+
|
82
|
+
# list all volumes
|
83
|
+
Scaleway::Volume.all
|
84
|
+
|
85
|
+
# get volume by id
|
86
|
+
volume = Scaleway::Volume.find <volume_id>
|
87
|
+
|
88
|
+
# create an volume
|
89
|
+
volume = Scaleway::Volume.create
|
90
|
+
volume = Scaleway::Volume.create size: 100 * 10 ** 9, volume_type: 'l_ssd'
|
91
|
+
|
92
|
+
# edit an volume
|
93
|
+
volume = Scaleway::Volume.edit id, volume
|
94
|
+
|
95
|
+
# destroy an volume
|
96
|
+
volume = Scaleway::Volume.destroy id
|
97
|
+
|
98
|
+
### Snapshots
|
99
|
+
|
100
|
+
# list all snapshots
|
101
|
+
Scaleway::Volume.all
|
102
|
+
|
103
|
+
# get snapshot by id
|
104
|
+
snapshot = Scaleway::Snapshot.find <snapshot_id>
|
105
|
+
|
106
|
+
# create an snapshot
|
107
|
+
snapshot = Scaleway::Snapshot.create volume_id: id
|
108
|
+
|
109
|
+
# edit an snapshot
|
110
|
+
snapshot = Scaleway::Snapshot.edit id, snapshot
|
111
|
+
|
112
|
+
# destroy an snapshot
|
113
|
+
snapshot = Scaleway::Snapshot.destroy id
|
114
|
+
|
115
|
+
### Ip addresses
|
116
|
+
|
117
|
+
# list all ip addresses
|
118
|
+
Scaleway::Ip.all
|
119
|
+
|
120
|
+
# get Ip
|
121
|
+
ip = Scaleway::Ip.find <ip_id>
|
122
|
+
ip = Scaleway::Ip.find 127.0.0.1
|
123
|
+
|
124
|
+
# reserve an ip
|
125
|
+
ip = Scaleway::Ip.reserve
|
126
|
+
# or
|
127
|
+
ip = Scaleway::Ip.create
|
128
|
+
|
129
|
+
# edit an ip
|
130
|
+
ip = Scaleway::Ip.edit id, ip
|
131
|
+
|
132
|
+
# release an ip
|
133
|
+
ip = Scaleway::Ip.destroy id
|
134
|
+
|
135
|
+
### Handle exceptions
|
136
|
+
|
137
|
+
# Not found
|
138
|
+
begin
|
139
|
+
puts Scaleway::Server.find <invalid_id>
|
140
|
+
rescue Scaleway::NotFound => e
|
141
|
+
# handle error here
|
142
|
+
end
|
143
|
+
|
144
|
+
# Other
|
145
|
+
begin
|
146
|
+
puts Scaleway::Server.create extra_field: ['nope']
|
147
|
+
rescue Scaleway::APIError => e
|
148
|
+
# handle error here
|
149
|
+
end
|
150
|
+
|
151
|
+
## Example
|
152
|
+
|
153
|
+
require 'scaleway'
|
154
|
+
|
155
|
+
Scaleway.organization = <organization_key>
|
156
|
+
Scaleway.token = <token>
|
157
|
+
|
158
|
+
# get the docker image
|
159
|
+
image = Scaleway::Image.find_by_name('Docker')
|
160
|
+
|
161
|
+
# create 5 new servers
|
162
|
+
5.times do |x|
|
163
|
+
Scaleway::Server.create name: "docker#{x}", image: image.id, tags: ['docker']
|
164
|
+
end
|
165
|
+
|
166
|
+
# power on
|
167
|
+
Scaleway::Server.all.each do |server|
|
168
|
+
Scaleway::Server.power_on(server.id)
|
169
|
+
end
|
170
|
+
|
171
|
+
# do something ...
|
172
|
+
|
173
|
+
# terminate
|
174
|
+
Scaleway::Server.all.each do |server|
|
175
|
+
Scaleway::Server.terminate(server.id)
|
176
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/scaleway.rb
ADDED
@@ -0,0 +1,350 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'recursive-open-struct'
|
4
|
+
require 'scaleway/version'
|
5
|
+
|
6
|
+
module Scaleway
|
7
|
+
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def compute_endpoint
|
11
|
+
"https://api.scaleway.com"
|
12
|
+
end
|
13
|
+
|
14
|
+
def account_endpoint
|
15
|
+
"https://account.scaleway.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
def token=(token)
|
19
|
+
@token = token
|
20
|
+
setup!
|
21
|
+
@token
|
22
|
+
end
|
23
|
+
|
24
|
+
def token
|
25
|
+
return @token if @token
|
26
|
+
"token_required"
|
27
|
+
end
|
28
|
+
|
29
|
+
def organization=(organization)
|
30
|
+
@organization = organization
|
31
|
+
setup!
|
32
|
+
@organization
|
33
|
+
end
|
34
|
+
|
35
|
+
def organization
|
36
|
+
return @organization if @organization
|
37
|
+
"organization_required"
|
38
|
+
end
|
39
|
+
|
40
|
+
DEFINITIONS = {
|
41
|
+
"Image" => {
|
42
|
+
:all => {
|
43
|
+
:method => :get,
|
44
|
+
:endpoint => "#{Scaleway.compute_endpoint}/images",
|
45
|
+
:default_params => {
|
46
|
+
:organization => Proc.new { Scaleway.organization }
|
47
|
+
}
|
48
|
+
},
|
49
|
+
:marketplace => {
|
50
|
+
:method => :get,
|
51
|
+
:endpoint => "#{Scaleway.compute_endpoint}/images",
|
52
|
+
:default_params => {
|
53
|
+
:public => true
|
54
|
+
}
|
55
|
+
},
|
56
|
+
:find => {
|
57
|
+
:method => :get,
|
58
|
+
:endpoint => "#{Scaleway.compute_endpoint}/images/%s",
|
59
|
+
},
|
60
|
+
:find_by_name => {
|
61
|
+
:method => :get,
|
62
|
+
:endpoint => "#{Scaleway.compute_endpoint}/images",
|
63
|
+
:filters => [
|
64
|
+
Proc.new { |item, params| item.name.include? params.first }
|
65
|
+
],
|
66
|
+
:transform => Proc.new { |item, params| item.first },
|
67
|
+
},
|
68
|
+
:create => {
|
69
|
+
:method => :post,
|
70
|
+
:endpoint => "#{Scaleway.compute_endpoint}/images",
|
71
|
+
:default_params => {
|
72
|
+
:name => 'default',
|
73
|
+
:root_volume => 'required',
|
74
|
+
:organization => Proc.new { Scaleway.organization },
|
75
|
+
}
|
76
|
+
},
|
77
|
+
:edit => {
|
78
|
+
:method => :put,
|
79
|
+
:endpoint => "#{Scaleway.compute_endpoint}/images/%s",
|
80
|
+
},
|
81
|
+
:destroy => {
|
82
|
+
:method => :delete,
|
83
|
+
:endpoint => "#{Scaleway.compute_endpoint}/images/%s",
|
84
|
+
},
|
85
|
+
},
|
86
|
+
"Volume" => {
|
87
|
+
:all => {
|
88
|
+
:method => :get,
|
89
|
+
:endpoint => "#{Scaleway.compute_endpoint}/volumes",
|
90
|
+
},
|
91
|
+
:find => {
|
92
|
+
:method => :get,
|
93
|
+
:endpoint => "#{Scaleway.compute_endpoint}/volumes/%s",
|
94
|
+
},
|
95
|
+
:edit => {
|
96
|
+
:method => :put,
|
97
|
+
:endpoint => "#{Scaleway.compute_endpoint}/volumes/%s",
|
98
|
+
},
|
99
|
+
:destroy => {
|
100
|
+
:method => :delete,
|
101
|
+
:endpoint => "#{Scaleway.compute_endpoint}/volumes/%s",
|
102
|
+
},
|
103
|
+
:create => {
|
104
|
+
:method => :post,
|
105
|
+
:endpoint => "#{Scaleway.compute_endpoint}/volumes",
|
106
|
+
:default_params => {
|
107
|
+
:name => 'default',
|
108
|
+
:size => 20 * 10**9,
|
109
|
+
:volume_type => 'l_hdd',
|
110
|
+
:organization => Proc.new { Scaleway.organization },
|
111
|
+
}
|
112
|
+
},
|
113
|
+
},
|
114
|
+
"Ip" => {
|
115
|
+
:all => {
|
116
|
+
:method => :get,
|
117
|
+
:endpoint => "#{Scaleway.compute_endpoint}/ips",
|
118
|
+
},
|
119
|
+
:find => {
|
120
|
+
:method => :get,
|
121
|
+
:endpoint => "#{Scaleway.compute_endpoint}/ips/%s",
|
122
|
+
},
|
123
|
+
:edit => {
|
124
|
+
:method => :put,
|
125
|
+
:endpoint => "#{Scaleway.compute_endpoint}/ips/%s",
|
126
|
+
},
|
127
|
+
:destroy => {
|
128
|
+
:method => :delete,
|
129
|
+
:endpoint => "#{Scaleway.compute_endpoint}/ips/%s",
|
130
|
+
},
|
131
|
+
:reserve => {
|
132
|
+
:method => :post,
|
133
|
+
:endpoint => "#{Scaleway.compute_endpoint}/ips",
|
134
|
+
:default_params => {
|
135
|
+
:organization => Proc.new { Scaleway.organization },
|
136
|
+
}
|
137
|
+
},
|
138
|
+
:create => {
|
139
|
+
:method => :post,
|
140
|
+
:endpoint => "#{Scaleway.compute_endpoint}/ips",
|
141
|
+
:default_params => {
|
142
|
+
:organization => Proc.new { Scaleway.organization },
|
143
|
+
}
|
144
|
+
},
|
145
|
+
},
|
146
|
+
"Snapshot" => {
|
147
|
+
:all => {
|
148
|
+
:method => :get,
|
149
|
+
:endpoint => "#{Scaleway.compute_endpoint}/snapshots",
|
150
|
+
},
|
151
|
+
:find => {
|
152
|
+
:method => :get,
|
153
|
+
:endpoint => "#{Scaleway.compute_endpoint}/snapshots/%s",
|
154
|
+
},
|
155
|
+
:edit => {
|
156
|
+
:method => :put,
|
157
|
+
:endpoint => "#{Scaleway.compute_endpoint}/snapshots/%s",
|
158
|
+
},
|
159
|
+
:destroy => {
|
160
|
+
:method => :delete,
|
161
|
+
:endpoint => "#{Scaleway.compute_endpoint}/snapshots/%s",
|
162
|
+
},
|
163
|
+
:create => {
|
164
|
+
:method => :post,
|
165
|
+
:endpoint => "#{Scaleway.compute_endpoint}/snapshots",
|
166
|
+
:default_params => {
|
167
|
+
:name => 'default',
|
168
|
+
:volume_id => 'required',
|
169
|
+
:organization => Proc.new { Scaleway.organization },
|
170
|
+
}
|
171
|
+
},
|
172
|
+
},
|
173
|
+
"Server" => {
|
174
|
+
:all => {
|
175
|
+
:method => :get,
|
176
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers",
|
177
|
+
},
|
178
|
+
:power_on => {
|
179
|
+
:method => :post,
|
180
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s/action",
|
181
|
+
:default_params => {
|
182
|
+
:action => :poweron
|
183
|
+
}
|
184
|
+
},
|
185
|
+
:reboot => {
|
186
|
+
:method => :post,
|
187
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s/action",
|
188
|
+
:default_params => {
|
189
|
+
:action => :reboot
|
190
|
+
}
|
191
|
+
},
|
192
|
+
:power_off => {
|
193
|
+
:method => :post,
|
194
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s/action",
|
195
|
+
:default_params => {
|
196
|
+
:action => :poweroff
|
197
|
+
}
|
198
|
+
},
|
199
|
+
:terminate => {
|
200
|
+
:method => :post,
|
201
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s/action",
|
202
|
+
:default_params => {
|
203
|
+
:action => :terminate
|
204
|
+
}
|
205
|
+
},
|
206
|
+
:find => {
|
207
|
+
:method => :get,
|
208
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s",
|
209
|
+
},
|
210
|
+
:edit => {
|
211
|
+
:method => :put,
|
212
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s",
|
213
|
+
},
|
214
|
+
:destroy => {
|
215
|
+
:method => :delete,
|
216
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers/%s",
|
217
|
+
},
|
218
|
+
:create => {
|
219
|
+
:method => :post,
|
220
|
+
:endpoint => "#{Scaleway.compute_endpoint}/servers",
|
221
|
+
:default_params => {
|
222
|
+
:name => 'default',
|
223
|
+
:image => Proc.new { Scaleway::Image.find_by_name('Ubuntu').id },
|
224
|
+
:volumes => {},
|
225
|
+
:organization => Proc.new { Scaleway.organization },
|
226
|
+
}
|
227
|
+
}
|
228
|
+
},
|
229
|
+
}
|
230
|
+
|
231
|
+
DEFINITIONS.each do |resource|
|
232
|
+
resource_name = resource[0]
|
233
|
+
|
234
|
+
resource_class = Class.new(Object) do
|
235
|
+
singleton = class << self; self end
|
236
|
+
|
237
|
+
DEFINITIONS[resource_name].each do |method_name, query|
|
238
|
+
singleton.send :define_method, method_name do |*args|
|
239
|
+
Scaleway.request_and_respond(query, *args)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
Scaleway.const_set(resource_name, resource_class)
|
245
|
+
end
|
246
|
+
|
247
|
+
def request=(request)
|
248
|
+
@request = request
|
249
|
+
end
|
250
|
+
|
251
|
+
def request
|
252
|
+
@request
|
253
|
+
end
|
254
|
+
|
255
|
+
def request_and_respond(query, *params)
|
256
|
+
body = {}
|
257
|
+
body.merge! query[:default_params] || {}
|
258
|
+
endpoint = query[:endpoint]
|
259
|
+
|
260
|
+
params.each do |param|
|
261
|
+
if param.is_a? Hash or param.is_a? RecursiveOpenStruct
|
262
|
+
body.merge! param
|
263
|
+
elsif not param.nil?
|
264
|
+
endpoint = endpoint % param
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
body = Hash[body.map { |k, v|
|
269
|
+
if v.respond_to? :call then [k, v.call()] else [k, v] end
|
270
|
+
}]
|
271
|
+
|
272
|
+
resp = Scaleway.request.send(query[:method], endpoint, body)
|
273
|
+
body = resp.body
|
274
|
+
if resp.status == 204
|
275
|
+
return
|
276
|
+
end
|
277
|
+
|
278
|
+
if resp.status == 404
|
279
|
+
raise Scaleway::NotFound, resp
|
280
|
+
elsif resp.status >= 300
|
281
|
+
raise Scaleway::APIError, resp
|
282
|
+
end
|
283
|
+
|
284
|
+
hash = RecursiveOpenStruct.new(body, :recurse_over_arrays => true)
|
285
|
+
|
286
|
+
if body.length == 1
|
287
|
+
hash = hash.send(body.keys.first)
|
288
|
+
end
|
289
|
+
|
290
|
+
if query[:filters]
|
291
|
+
filters = query[:filters]
|
292
|
+
hash = hash.find_all do |item|
|
293
|
+
filters.all? do |filter|
|
294
|
+
filter.call(item, params)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
if query[:transform]
|
300
|
+
hash = query[:transform].call(hash, params)
|
301
|
+
end
|
302
|
+
|
303
|
+
hash
|
304
|
+
end
|
305
|
+
|
306
|
+
class APIError < Exception
|
307
|
+
def initialize(response)
|
308
|
+
self.status = response.status
|
309
|
+
self.body = RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
|
310
|
+
self.type = self.body.type
|
311
|
+
self.error_message = self.body.message
|
312
|
+
end
|
313
|
+
|
314
|
+
def to_s
|
315
|
+
"<status:#{status}, type:#{type}, message:\'#{error_message}\'>"
|
316
|
+
end
|
317
|
+
|
318
|
+
def message
|
319
|
+
"#{self}"
|
320
|
+
end
|
321
|
+
|
322
|
+
attr_accessor :status
|
323
|
+
attr_accessor :type
|
324
|
+
attr_accessor :error_message
|
325
|
+
attr_accessor :body
|
326
|
+
end
|
327
|
+
|
328
|
+
class NotFound < Scaleway::APIError
|
329
|
+
end
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
private
|
334
|
+
|
335
|
+
def setup!
|
336
|
+
options = {
|
337
|
+
:headers => {
|
338
|
+
'x-auth-token' => Scaleway.token,
|
339
|
+
'content-type' => 'application/json',
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
Scaleway.request = ::Faraday::Connection.new(options) do |builder|
|
344
|
+
builder.use ::FaradayMiddleware::EncodeJson
|
345
|
+
builder.use ::FaradayMiddleware::ParseJson
|
346
|
+
builder.use ::FaradayMiddleware::FollowRedirects
|
347
|
+
builder.adapter ::Faraday.default_adapter
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
data/scaleway.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'scaleway/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "scaleway"
|
8
|
+
gem.version = Scaleway::VERSION
|
9
|
+
gem.authors = ["bchatelard"]
|
10
|
+
gem.email = ["chatel.bast@gmail.com"]
|
11
|
+
gem.description = %q{Ruby bindings for the Scaleway API.}
|
12
|
+
gem.summary = %q{Ruby bindings for the Scaleway API.}
|
13
|
+
|
14
|
+
# should change
|
15
|
+
gem.homepage = "http://github.com/bchatelard/scaleway-ruby"
|
16
|
+
|
17
|
+
gem.add_dependency "faraday", "~> 0.9"
|
18
|
+
gem.add_dependency "faraday_middleware", "~> 0.9"
|
19
|
+
gem.add_dependency "recursive-open-struct", "~> 0.5"
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake", "~> 10.1"
|
22
|
+
gem.add_development_dependency "rspec", "~> 3.1"
|
23
|
+
gem.add_development_dependency "its", "~> 0.2"
|
24
|
+
|
25
|
+
gem.files = `git ls-files`.split($/)
|
26
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
27
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
28
|
+
gem.require_paths = ["lib"]
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'its'
|
3
|
+
require 'scaleway'
|
4
|
+
|
5
|
+
describe Scaleway do
|
6
|
+
subject(:Scaleway) { described_class }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Scaleway.organization = organization
|
10
|
+
Scaleway.token = token
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "defaults" do
|
14
|
+
let(:organization) { nil }
|
15
|
+
let(:token) { nil }
|
16
|
+
|
17
|
+
its(:compute_endpoint) { should eq "https://api.scaleway.com" }
|
18
|
+
its(:account_endpoint) { should eq "https://account.scaleway.com" }
|
19
|
+
its(:token) { should eq "token_required" }
|
20
|
+
its(:organization) { should eq "organization_required" }
|
21
|
+
|
22
|
+
it { expect(Scaleway::VERSION).to eq "0.1.2" }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "test token and organization" do
|
26
|
+
let(:organization) { "organization_id" }
|
27
|
+
let(:token) { "token_id" }
|
28
|
+
|
29
|
+
its(:organization) { should eq "organization_id" }
|
30
|
+
its(:token) { should eq "token_id" }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'its'
|
3
|
+
require 'scaleway'
|
4
|
+
|
5
|
+
describe Scaleway::Server do
|
6
|
+
subject(:server) { described_class }
|
7
|
+
|
8
|
+
before do
|
9
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
10
|
+
stub.get('/servers') { |env| [200, {}, {:servers => [test_server]}] }
|
11
|
+
stub.get('/servers/1234') { |env| [200, {}, {:server => test_server}] }
|
12
|
+
stub.get('/servers/not_found') { |env| [404, {}, {:type => 'not_found', :message => 'not found'}] }
|
13
|
+
end
|
14
|
+
Scaleway.request = Faraday.new do |builder|
|
15
|
+
builder.adapter :test, stubs
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "all" do
|
20
|
+
let(:test_server) { RecursiveOpenStruct.new({:name => 'hello', :id => '1234'}, :recurse_over_arrays => true) }
|
21
|
+
|
22
|
+
its(:all) { should eq [test_server] }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "item" do
|
26
|
+
let(:test_server) { RecursiveOpenStruct.new({:name => 'hello', :id => '1234'}, :recurse_over_arrays => true) }
|
27
|
+
|
28
|
+
its(:find, '1234') { should eq test_server }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "not found" do
|
32
|
+
let(:test_server) { RecursiveOpenStruct.new({:name => 'hello', :id => '1234'}, :recurse_over_arrays => true) }
|
33
|
+
|
34
|
+
it { expect{Scaleway::Server.find('not_found')}.to raise_error(Scaleway::NotFound) }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
describe Scaleway::Server do
|
41
|
+
subject(:server) { described_class }
|
42
|
+
|
43
|
+
before do
|
44
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
45
|
+
stub.get('/servers?state=running') { |env| [200, {}, {:servers => []}] }
|
46
|
+
stub.get('/servers?invalid_filter=42') { |env| [400, {}, {:type => 'invalid_filter', :message => 'invalid filter'}] }
|
47
|
+
end
|
48
|
+
Scaleway.request = Faraday.new do |builder|
|
49
|
+
builder.adapter :test, stubs
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "filter" do
|
54
|
+
its(:all, state: 'running') { should eq [] }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "invalid filter" do
|
58
|
+
it { expect{Scaleway::Server.all(invalid_filter: 42)}.to raise_error(Scaleway::APIError) }
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scaleway
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bchatelard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: recursive-open-struct
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: its
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.2'
|
97
|
+
description: Ruby bindings for the Scaleway API.
|
98
|
+
email:
|
99
|
+
- chatel.bast@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- CHANGES.md
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/scaleway.rb
|
111
|
+
- lib/scaleway/version.rb
|
112
|
+
- scaleway.gemspec
|
113
|
+
- spec/scaleway_spec.rb
|
114
|
+
- spec/servers_spec.rb
|
115
|
+
homepage: http://github.com/bchatelard/scaleway-ruby
|
116
|
+
licenses: []
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.2.2
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Ruby bindings for the Scaleway API.
|
138
|
+
test_files:
|
139
|
+
- spec/scaleway_spec.rb
|
140
|
+
- spec/servers_spec.rb
|
141
|
+
has_rdoc:
|