WebService::Scaleway - Perl interface to Scaleway cloud server provider API
use WebService::Scaleway; my $token = ...; # API token here my $sw = WebService::Scaleway->new($token); my $org = $sw->organizations; # Create an IP, a volume, and use them for a new Debian Jessie server my $ip = $sw->create_ip($org); my $vol = $sw->create_volume('testvol', $org, 'l_ssd', 50_000_000_000); my ($debian) = grep { $_->name =~ /debian jessie/i } $sw->images; my $srv = $sw->create_server('testsrv', $org, $debian, {1 => $vol->id}); # Now we have a server, an IP, and two volumes (the root volume with # Debian Jessie, and the extra volume we just created). # Change the server name $srv->{name} = 'Debian'; $sw->update_server($srv); # Boot the server $sw->perform_server_action($srv, 'poweron'); say "The server is now booting. To access it, do ssh root@", $ip->address;
Scaleway is an IaaS provider that offers bare metal ARM cloud servers. WebService::Scaleway is a Perl interface to the Scaleway API.
WebService::Scaleway objects are defined by their authentication token. There are two consructors:
Construct a WebService::Scaleway object from a given authentication token.
Construct a WebService::Scaleway object from an authentication token obtained by logging in with the given credentials.
These methods return a list of all resources of a given type associated to your account. Each resource is a blessed hashref with AUTOLOADed accessors (for example $resource->{name} can be written as $resource->name) and that stringifies to the ID of the resource: $resource->id.
AUTOLOAD
$resource->{name}
$resource->name
$resource->id
There is no difference between resources() and list_resources().
Official documentation: https://developer.scaleway.com/#tokens-tokens-get.
Official documentation: https://developer.scaleway.com/#organizations-organizations.
Official documentation: https://developer.scaleway.com/#servers-servers-get.
Official documentation: https://developer.scaleway.com/#volumes-volumes-get.
Official documentation: https://developer.scaleway.com/#snapshots-snapshots-get.
Official documentation: https://developer.scaleway.com/#images-images-get.
Official documentation: https://developer.scaleway.com/#ips-ips-get.
Official documentation: https://developer.scaleway.com/#security-groups-security-groups-get.
Official documentation: https://developer.scaleway.com/#security-groups-manage-rules-get.
These methods take the ID of a resource and return the resource as a blessed hashref as described in the previous section.
You can pass a blessed hashref instead of a resource ID, and you'll get a fresh version of the object passed. Useful if something updated the object in the meantime.
There is no difference between resource($id) and get_resource($id).
Official documentation: https://developer.scaleway.com/#tokens-token-get.
Official documentation: https://developer.scaleway.com/#users-user.
Official documentation: https://developer.scaleway.com/#servers-server-get.
Official documentation: https://developer.scaleway.com/#volumes-volume-get.
Official documentation: https://developer.scaleway.com/#snapshots-snapshot-get.
Official documentation: https://developer.scaleway.com/#images-operation-on-a-single-image-get.
Official documentation: https://developer.scaleway.com/#ips-ip-get.
Official documentation: https://developer.scaleway.com/#security-groups-operation-on-a-security-groups-get.
Official documentation: https://developer.scaleway.com/#security-groups-operation-on-a-security-rule-get.
These methods take the ID of a resource and delete it. They do not return anything. You can pass a blessed hashref instead of a resource ID.
Official documentation: https://developer.scaleway.com/#tokens-token-delete.
Official documentation: https://developer.scaleway.com/#servers-server-delete.
Official documentation: https://developer.scaleway.com/#volumes-volume-delete.
Official documentation: https://developer.scaleway.com/#snapshots-snapshot-delete.
Official documentation: https://developer.scaleway.com/#images-operation-on-a-single-image-delete.
Official documentation: https://developer.scaleway.com/#ips-ip-delete.
Official documentation: https://developer.scaleway.com/#security-groups-operation-on-a-security-groups-delete.
Official documentation: https://developer.scaleway.com/#security-groups-operation-on-a-security-rule-delete.
These methods take a hashref representing a resource that already exists and update it. The value of $resource->{id} is used for identifying this resource on the remote end. Both blessed and unblessed hashrefs are accepted. The updated resource is returned as a blessed hashref as described in "Listing resources".
$resource->{id}
Official documentation: https://developer.scaleway.com/#servers-server-put.
Official documentation: https://developer.scaleway.com/#snapshots-snapshot-put.
Official documentation: https://developer.scaleway.com/#images-operation-on-a-single-image-put.
Official documentation: https://developer.scaleway.com/#ips-ip-put.
Official documentation: https://developer.scaleway.com/#security-groups-operation-on-a-security-groups-put.
Official documentation: https://developer.scaleway.com/#security-groups-operation-on-a-security-rule-put.
These methods take either a hash that is passed directly to the API or a method-specific list of positional parameters. They create a new resource and return it as a blessed hashref as described in "Listing resources".
When using positional parameters, you can pass a resource in blessed hashref format where a resource ID is expected, unless the method's documentation says otherwise.
Most of these methods require an organization ID. You can obtain it with the organizations method described above.
Authenticates a user against their username and password and returns an authentication token. If $expires (default: false) is true, the token will expire.
This method is called internally by the two-argument constructor.
Creates and returns a new server.
$name is the server name. $organization is the organization ID. $image is the image ID. $volumes is a "sparse array" (hashref from indexes to volume IDs, indexed from 1) of extra volumes (that is, volumes other than the root volume). $tags is an optional arrayref of tags.
For the $volumes parameter you can pass hashrefs that describe volumes instead of volume IDs. This will create new volumes. The hashrefs are (presumably) passed to create_volume. An example inspired by the official documentation:
$volumes = { 1 => { name => "vol_demo", organization => "ecc1c86a-eabb-43a7-9c0a-77e371753c0a", size => 10_000_000_000, volume_type => "l_sdd", }};
Note that there may not be any blessed hashrefs inside $volumes.
Creates and returns a new volume. $volume_type currently must be l_ssd. $size is the size in bytes.
l_ssd
Creates and returns a snapshot of the volume $volume_id.
Creates and returns an image from the volume $root_volume. $arch is the architecture of the image (currently must be "arm").
"arm"
These are methods that don't fit any previous category. Any use of "blessed hashref" refers to the concept described in "Listing resources". Wherever a resource ID is expected, you can instead pass a resource as a blessed hashref and the method will call ->id on it for you.
->id
Returns a list of strings representing possible actions you can perform on the given server. Example actions are powering on/off a server or rebooting it.
Official documentation: https://developer.scaleway.com/#servers-actions-get
Performs an action on a server. $action is one of the strings returned by server_actions. The function returns a blessed hashref with information about the task.
This is not very useful, as this module does not currently offer any function for tracking tasks.
Official documentation: https://developer.scaleway.com/#servers-actions-post
This method takes the ID of an expirable token, extends its expiration date by 30 minutes, and returns the new token as a blessed hashref.
Official documentation: https://developer.scaleway.com/#tokens-token-patch
This method can only be called from a Scaleway server. It returns information about the server as a blessed hashref.
Official documentation: https://developer.scaleway.com/#metadata-c1-server-metadata
https://developer.scaleway.com/
Marius Gavrilescu, <marius@ieval.ro>
Copyright (C) 2015 by Marius Gavrilescu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.20.2 or, at your option, any later version of Perl 5 you may have available.
To install WebService::Scaleway, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebService::Scaleway
CPAN shell
perl -MCPAN -e shell install WebService::Scaleway
For more information on module installation, please visit the detailed CPAN module installation guide.