Easy to use Scaleway api client. (former Online Labs)
Switch branches/tags
Nothing to show
Clone or download
Latest commit a266832 Feb 28, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Post release version bump Oct 31, 2016
spec Post release version bump Oct 31, 2016
.gitignore Initial commit Nov 9, 2014
.travis.yml Initial setup Nov 14, 2014
CHANGES.md Post release version bump Oct 31, 2016
Gemfile Initial setup Nov 14, 2014
Gemfile.lock Fix Gemfile Feb 24, 2017
README.md Update how we query the image Oct 31, 2016
Rakefile Initial setup Nov 14, 2014
scaleway.gemspec Fix Gemfile Feb 24, 2017

README.md

Scaleway Rubygem

Build Status Gem Version

Easy to use Scaleway api client.

Installation

Manual instalation:

gem install scaleway

add this to your gemfile:

gem 'scaleway'

Usage

Configure the client

require 'scaleway'

Scaleway.organization = <organization_key>
Scaleway.token = <token>

# You can specify the zone, the default zone is 'par1'
Scaleway.zone = 'ams1'

Servers

# list all servers
Scaleway::Server.all

# list with filter
Scaleway::Server.all state: :running

# create a new server with default values
Scaleway::Server.create

# create a new server with name and tags
Scaleway::Server.create :name => 'my_new_server', tags: ['prod']

# get a server by id
server = Scaleway::Server.find <server_id>

# edit a server
server = Scaleway::Server.find <server_id>
server.name = 'new_name'
Scaleway::Server.edit server.id, server

# actions on a server
Scaleway::Server.power_on server.id

Scaleway::Server.power_off server.id

Scaleway::Server.terminate server.id

# destroy a server
Scaleway::Server.destroy server.id

Marketplace

# list all marketplace images
Scaleway::Marketplace.all

# get local image by id
image = Scaleway::Marketplace.find_local_image <marketplace_image_id>

# get local image by marketplace image id for arch arm
image = Scaleway::Marketplace.find_local_image <marketplace_image_id>, arch: 'arm'

# get local image by name
image = Scaleway::Marketplace.find_local_image_by_name("Docker")

Images

# list all images
Scaleway::Image.all

# get image by id
image = Scaleway::Image.find <image_id>

# get image by name
image = Scaleway::Image.find_by_name('Ubuntu')

# create an image
image = Scaleway::Image.create root_volume: snapshot

# edit an image
image = Scaleway::Image.edit id, image

# destroy an image
image = Scaleway::Image.destroy id

Volumes

# list all volumes
Scaleway::Volume.all

# get volume by id
volume = Scaleway::Volume.find <volume_id>

# create an volume
volume = Scaleway::Volume.create
volume = Scaleway::Volume.create size: 100 * 10 ** 9, volume_type: 'l_ssd'

# edit an volume
volume = Scaleway::Volume.edit id, volume

# destroy an volume
volume = Scaleway::Volume.destroy id

Snapshots

# list all snapshots
Scaleway::Volume.all

# get snapshot by id
snapshot = Scaleway::Snapshot.find <snapshot_id>

# create an snapshot
snapshot = Scaleway::Snapshot.create volume_id: id

# edit an snapshot
snapshot = Scaleway::Snapshot.edit id, snapshot

# destroy an snapshot
snapshot = Scaleway::Snapshot.destroy id

Ip addresses

# list all ip addresses
Scaleway::Ip.all

# get Ip
ip = Scaleway::Ip.find <ip_id>
ip = Scaleway::Ip.find 127.0.0.1

# reserve an ip
ip = Scaleway::Ip.reserve
# or
ip = Scaleway::Ip.create

# edit an ip
ip = Scaleway::Ip.edit id, ip

# release an ip
ip = Scaleway::Ip.destroy id

Handle exceptions

# Not found
begin
	puts Scaleway::Server.find <invalid_id>
rescue Scaleway::NotFound => e
	# handle error here
end

# Other
begin
	puts Scaleway::Server.create extra_field: ['nope']
rescue Scaleway::APIError => e
	# handle error here
end

Example

require 'scaleway'

Scaleway.organization = <organization_key>
Scaleway.token = <token>

# get the docker image from the marketplace
image = Scaleway::Marketplace.find_local_image_by_name('Docker')

# create 5 new servers
5.times do |x|
	Scaleway::Server.create name: "docker#{x}", image: image.id, tags: ['docker']
end

# power on
Scaleway::Server.all.each do |server|
	Scaleway::Server.power_on(server.id)
end

# do something ...

# terminate
Scaleway::Server.all.each do |server|
	Scaleway::Server.terminate(server.id)
end