Migrating from v1 to v2
The goal of this document is to help you migrate from CLI v1 to CLI v2.
Summary
Justification for a v2
Multiple products design
CLI v1 was created while targeting a single Scaleway Elements product: instance. Scaleway got many more products in its Elements ecosystem that need to be available from the CLI. Having ad-hoc commands for all our products was not going to be a scalable solution. We needed to have a more systematic approach across all products.
In CLI v2, we have a common syntax across all our products: namespace, resource and verb. As an example:
Code
- instance: Refers to the product namespace
- server: Refers to a resource maintained in the product namespace
- list: Refers to a verb applied to the currently selected API
In plain English, it would be: "list all servers available on the instance API".
Consistent workflow across products
CLI v1 was designed to offer a syntax close to the Docker syntax.
For instance, to run a command such as echo foobar on a remote server, we can write scw run ubuntu_focal echo foobar which mimics docker run ubuntu echo foobar.
While this can be useful for some tasks, there are plenty of actions that do not fit in with this paradigm.
E.g., attaching to a running server sub-resources such as volumes or security groups are not performed easily using this paradigm because Docker doesn't provide the same features.
In CLI v2 we offer support for a wide range of actions on all resources present and coming in the Scaleway Elements ecosystem.
Actions are organized around a set of verbs such as list, get, create, update that can be used with a wide variety of products and do not suppose any preconceived workflow.
Automated code generation
CLI v1 did not take advantage of code generation features to easily create supports like in SDKs and other developer tools.
We invested in our code generation features to be able to synchronize support and fixes across all our tools:
- scaleway-cliOpen in new context
- scaleway-sdk-goOpen in new context
- scaleway provider for TerraformOpen in new context
Cleanup of old and unmaintained dependencies
CLI v1 required a lot of dependencies that are not actively maintained anymore.
With the CLI v2, we want to minimize them as much as possible and focus only on well-supported external libraries when required.
New tests infrastructure
CLI v1 did not have high test coverage and no test generation that could be inferred from an underlying SDK.
CLI v2 builds on top of the tests infrastructure of the code generation we have to increase test coverage. We also support different types of test: unit test, acceptance test, and end-to-end test.
Commands Migration
scw help
scw help displays the help of the CLI.
Code
In CLI v1, the --help is required to print the help.
In CLI v2, the help can be printed using --help as before but can also be printed by not specifying any arguments:
Code
scw attach
scw attach opens a serial port connection to your Scaleway instance.
Code
This command will create a connection through a websocket to your foobar Scaleway instance serial port and make it available in your terminal.
In CLI v2, we do not offer at the moment any support for connecting to a serial port. We strongly encourage you to connect to your instance using SSH. In case your SSH server configuration is broken and you cannot connect to your instance, we encourage you to use the rescue modeOpen in new context and fix your SSH server configuration. You can still use the serial port in your console.
scw commit
scw commit creates a new snapshot from a server's volume.
Code
This command will create a snapshot of the local volume of the instance named foobar.
In CLI v2, a volume-id is required to create a snapshot.
Code
scw instance snapshot create volume-id= creates a snapshot for the targeted volume id.
scw instance server list name=foobar -o json | jq -r '.[0].volumes["0"].id' will filter all your server, output it as a JSON and pipe it to the jq program.
jq will then extract from the server information your volume id.
If you want to change the volume index and target a different volume, change the volumes["0"] to volumes["X"] where X is the volume index you want.
scw cp
scw cp provides a wrapper around the scp command.
Code
Let's suppose you want to receive a file my_file with the absolute path /my_file from your home directory you would do:
Code
scw create
scw create creates a Scaleway Elements Instance.
Code
In the CLI v2, you can use scw instance server create to create a server.
For instance:
Code
scw events
scw events provides an audit log of all the actions performed by the user on Scaleway Elements Instance.
Code
You can still access those data using the API:
Code
scw exec
scw exec provides SSH access on a Scaleway Elements Instance.
Code
In CLI v2, You can obtain an access to a server named foobar through a command such as:
Code
scw history
scw history provides the history of an image.
Code
In CLI v2, you can access the same information using the scw instance image get command:
Code
scw images
scw images will output the most common images available on Scaleway Elements Instances.
Code
This command will print all the images available across regions. You can filter the architecture and the region parameter to only get the information about the image you are interested in.
In CLI v2, you would use the scw marketplace image list.
Code
scw info
scw info displays system-wide information about your account and quotas.
Constants
The constant URLs are not changing with the new CLI. You can still access them using their address.
| Service | URL |
|---|---|
| account | https://api.scaleway.com/account/v1Open in new context |
| metadata | http://169.254.42.42Open in new context |
| marketplace | https://api.scaleway.com/marketplace/v1Open in new context |
Quotas
CLI v2 does not support quotas at the moment. Your quotas can still be accessed through the consoleOpen in new context and the API:
Code
scw inspect
scw inspect returns information about a server as a JSON format.
Code
In CLI v2, you can access your server information details using its Instance ID:
Code
scw kill
scw kill will connect to your instance using SSH and run a halt command to shut down your machine.
Code
Let's suppose you want to connect to an instance named foobar, you would use a command similar such as:
Code
- The
ssh -tcommand will create a terminal output inside your own terminal. $(scw instance server list name=foobar -o json | jq -r ".[0].public_ip.address")will find the first server named foobar in your account and extract its IP address.
scw login
scw login asks interactively for user email and password, authenticate on the Scaleway consoleOpen in new context and save a configuration file.
In CLI v2, scw init will perform the same authentication, configuration file creation task for you.
Check out scw init --help to know more about this command.
scw logout
scw logout deletes the scaleway-cli v1 configuration file (usually stored at $(HOME)/.scwrc).
If you want to delete your configuration file you can do so by manually removing this file.
On v2, the command scw config reset will overwrite your configuration file (stored in $(HOME)/.config/scw/config.yaml) with a blank one.
All your credentials will be erased.
scw logs
scw logs will connect to your instance using SSH and run a dmesg command and give you the output into your terminal.
Let's suppose you want to connect to an instance named foobar, you would use a command similar such as:
Code
- The
ssh -tcommand will create a terminal output inside your own terminal. $(scw instance server list name=foobar -o json | jq -r ".[0].public_ip.address")will find the first server named foobar in your account and extract its IP address.
scw port
scw port will connect to your instance using SSH and run a netstat -lutn 2>/dev/null | grep LISTEN command and give you the output into your terminal.
Let's suppose you want to connect to an instance named foobar, you would use a command similar such as:
Code
- The
ssh -tcommand will create a terminal output inside your own terminal. $(scw instance server list name=foobar -o json | jq -r ".[0].public_ip.address")will find the first server named foobar in your account and extract its IP address.
scw products
scw products shows all the products available on the Scaleway Elements console.
This command only supported scw products servers which gave for each instance type its main characteristics: architecture (x86_64, arm64, arm), CPU cores, RAM and whether an instance is a bare-metal one.
Code
In CLI v2, you would use the following command:
Code
scw ps
scw ps will list all the Scaleway Elements Instances available in your account.
You can have the same listing in the CLI v2 using the following command:
Code
scw rename
scw rename will update the name of an instance.
Will update to "bar" the name of a server identified with its previous name
Code
In the CLI v2, you can rename a server using the following command: Will update to "bar" the name of a server identified with a given Instance ID
Code
scw restart
scw restart will restart an instance identified by its name.
For instance:
Code
In v2, you would do this operation using its instance ID. For instance:
Code
scw rm
scw rm deletes a running Scaleway Elements Instance.
Code
In CLI v2, you would need to specify explicitly that you want to delete a server.
Code
scw rmi
scw rmi deletes an image/snapshot/volume that matches a given name.
You would use it like:
Code
This command will try to delete an image named foobar and if no image exists, il will try to delete a snapshot named foobar and then try to delete a volume named foobar.
We chose a more explicit approach in CLI v2. You need to specify explicitly the kind of resource you want to delete.
Code
scw run
scw run is a command that will perform several tasks:
- Instantiate a Scaleway Elements Instance
- Open an SSH connection to the instance
- Run a given command
Using CLIv2 you would:
-
Create an instance:
CodeYou can add
--waitto make this command returns only when your server is ready. This command will output an IP address in the fieldpublic-ip.address.Code -
Run your command (let's say
uname -a) on your instance using thepublic-ip.addressaddress.Code
scw search
scw search searches through the marketplace to find an image that matches a given name.
Let's suppose that you are looking for ubuntu image, in v1 you would do this:
Code
Now in v2, all commands related to the image marketplace are namespaced. You would use a list command such as:
Code
scw start
scw start will start an instance identified by its name.
For instance:
Code
In v2, you would do this operation using its instance ID. For instance:
Code
scw stop
scw stop will stop an instance identified by its name.
For instance:
Code
In v2, you would do this operation using its instance ID. For instance:
Code
scw tag
scw tag will make an image for x86_64 instances from a snapshot.
Code
Code
scw top
scw top will connect to your instance using SSH and run a top command and give you the output into your terminal.
Let's suppose you want to connect to an instance named foobar, you would use a command similar such as:
Code
- The
ssh -tcommand will create a terminal output inside your own terminal. $(scw instance server list name=foobar -o json | jq -r ".[0].public_ip.address")will find the first server named foobar in your account and extract its IP address.
scw version
This command exists in both versions.
In version 1.X:
Code
In version 2.X:
Code
scw wait
scw wait blocks until a server stops.
If you want your shell to block until a server named foobar is stopped you would use:
Code
In v2, you would precise the --wait flag to the stop operation such as:
Code