Manage Scaleway Instances via Their API Like a Boss With Their Command Line Tool Scw
Let’s set things straight: I am a command line fan boy, If I can do the things I have to do with a command line interface, i’m happy! And that means automation ftw! :D
Scaleway Command Line Interface:
I have been using Scaleway for about 2 years now, and absolutely loving their services! So I recently found their command line interface utility: scw, which is written in golang and has a very similar feel to docker.
Install the SCW CLI Tool:
A golang environment is needed and I will be using docker to drop myself into a golang environment and then install the scw utility:
1234
$ docker run -it golang:alpine sh
$ apk update
$ apk add openssl git openssh curl
$ go get -u github.com/scaleway/scaleway-cli/cmd/scw
Verify that it was installed:
12
$ scw --version
scw version v1.16+dev, build
Awesome sauce!
Authentication:
When we authenticate to Scaleway, it will prompt you to upload your public ssh key, as I am doing this in a container I have no ssh keys, so therefore will generate one before I authenticate.
Generate the SSH Key:
1234567
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
Now loging to Scaleway using the cli tools:
123456789101112
$ scw login
Login (cloud.scaleway.com): <youremail@domain.com>
Password:
Do you want to upload an SSH key ?
[0] I don't want to upload a key !
[1] id_rsa.pub
Which [id]: 1
You are now authenticated on Scaleway.com as Ruan.
You can list your existing servers using `scw ps` or create a new one using `scw run ubuntu-xenial`.
You can get a list of all available commands using `scw -h` and get more usage examples on github.com/scaleway/scaleway-cli.
Happy cloud riding.
Get a list of available Images, in my case I am just looking for Ubuntu:
123
$ scw images | grep -i ubuntu
Ubuntu_Bionic latest a21bb700 11 days [ams1 par1][x86_64]Ubuntu_Mini_Xenial_25G latest bc75c00b 13 days [ams1 par1][x86_64]
List Running Instances:
12345
$ scw ps
SERVER ID IMAGE ZONE CREATED STATUS PORTS NAME COMMERCIAL TYPE
abc123de Ubuntu_Xenial_16_04_lates ams1 5 weeks running xx.xx.xx.xx scw-elasticsearch-01 ARM64-4GB
abc456de ruan-docker-swarm-17_03 par1 10 months running xx.xx.xxx.xxx scw-swarm-manager-01 VC1M
...
List All Instances (Running, Stopped, Started, etc):
1234
$ scw ps -a
SERVER ID IMAGE ZONE CREATED STATUS PORTS NAME COMMERCIAL TYPE
abc123df Ubuntu_Xenial_16_04_lates ams1 5 weeks stopped xx.xx.xx.xx scw-elasticsearch-02 ARM64-4GB
...
List Instances with a filter based on its name:
123
$ scw ps -f name=scw-swarm-worker-02
SERVER ID IMAGE ZONE CREATED STATUS PORTS NAME COMMERCIAL TYPE
1234abcd Ubuntu_Xenial par1 8 minutes running xx.xx.xxx.xxx scw-swarm-worker-2 START1-XS
List the Latest Instance that was created:
123
$ scw ps -l
SERVER ID IMAGE ZONE CREATED STATUS PORTS NAME COMMERCIAL TYPE
1234abce Ubuntu_Xenial par1 6 minutes running xx.xx.xxx.xxx scw-swarm-worker-3 START1-XS
Create Instances:
In my scenario, I would like to create a instance named docker-swarm-worker-4 with the instance type START1-XS in the Paris datacenter, and I will be using my key that I have uploaded, also the image id that I passed, was retrieved when listing for images:
Now that the instance is created, we can start it by calling either the name or the id:
1
$ scw start docker-swarm-worker-4
To verify the status of the instance, we can do:
123
$ scw ps -l
SERVER ID IMAGE ZONE CREATED STATUS PORTS NAME COMMERCIAL TYPE
102abc34 Ubuntu_Xenial 28 seconds starting docker-swarm-worker-4 START1-XS
At this moment it is still starting, after waiting a minute or so, run it again:
123
$ scw ps -l
SERVER ID IMAGE ZONE CREATED STATUS PORTS NAME COMMERCIAL TYPE
102abc34 Ubuntu_Xenial par1 About a minute running xx.xx.xx.xx docker-swarm-worker-4 START1-XS
As we can see its in a running state, so we are good to access our instance. You have 2 options to access your server, via exec and ssh.
Have a look at Scaleway-CLI Documentation and their Website for more info, and have a look at their new START1-XS instance types, that is only 1.99 Euro’s, that is insane!
Personally love what they are doing, feel free to head over to their pricing page to see some sweet deals!