Cloud
banshee/cloud-collection/cloud/scaleway/https/
instances
The state of each instance of a Scaleway zone, by the Instance API.
by banshee1 installation1 version
Published on October 27, 2026. First version.
// The instances of a Scaleway zone, by the Instance API with an API key: the state of each instance.
// Reads GET https://api.scaleway.com/instance/v1/zones/<zone>/servers, page after page.
need('protocol:http');
$key = need('protocol:http:token');
$zone = variable('scaleway:zone', 'text', array(
'label' => 'Zone',
'help' => 'The availability zone of the instances: fr-par-1, fr-par-2, nl-ams-1, pl-waw-1…',
'default' => 'fr-par-1',
));
per('instance', 'Instances');
output('state', 'text', array('label' => 'State', 'per' => 'instance'));
watch.expect('not-running', 'Instance not running', 'state', array('critical' => array('running'), 'for' => '2 runs'));
watch.missing('missing', 'Instance missing', 'state', array('enabled' => false));
// One GET on the API of Scaleway, the secret key of the API key in the header X-Auth-Token; the answer is not
// secret, its body having carried none.
function api_get($url, $key) {
$answer = http.get($url, headers=array('X-Auth-Token' => $key));
if ($answer['status'] == 401) {
fail('misconfigured', 'Scaleway refuses the API key, code 401');
}
if ($answer['status'] == 403) {
fail('misconfigured', 'The API key may not list the instances, code 403');
}
if ($answer['status'] == 400 || $answer['status'] == 404) {
fail('misconfigured', 'Scaleway refuses to list the instances, code ' . $answer['status'], 'Check the zone.');
}
if ($answer['status'] != 200) {
fail('unreachable', 'Scaleway answers the list of the instances with code ' . $answer['status']);
}
return json.read($answer['body']);
}
// The zone goes into the path of the address: it must be a name.
if (list.count(text.match($zone, '^[a-z0-9-]+$')) == 0) {
fail('misconfigured', 'The zone holds other characters than lower-case letters, digits and hyphens');
}
// {"servers": [{"id": "…", "name": "web-1", "state": "running", "state_detail": "booted", "commercial_type":
// "PRO2-S", …}]}, a page of 100 at a time: a page shorter than that is the last. state is running, stopped,
// stopped in place, starting, stopping or locked.
$servers = array();
$page = 1;
while (true) {
$answer = api_get('https://api.scaleway.com/instance/v1/zones/' . $zone . '/servers?'
. url.query(array('page' => $page, 'per_page' => 100)), $key);
$found = list.get($answer, 'servers', array());
foreach ($found as $server) {
$servers = list.add($servers, $server);
}
if (list.count($found) < 100) {
break;
}
$page = $page + 1;
}
// An instance is named by its name; two instances of one name each keep their own, the second carrying its id.
$seen = array();
foreach ($servers as $server) {
$name = $server['name'];
if (list.has($seen, $name)) {
$name = $name . ' #' . $server['id'];
}
$seen[$name] = true;
value('state', $server['state'], $name);
}