Slices CLI (Command Line Interface)¶
Introduction¶
For some of the services, the Slices CLI can be used. For other services, a specific service dashboard is used. See the specific service documentation. If the Slices CLI can be used, this is the documentation how to install it. In some services, you can use dashboards where the Slices CLI is pre-installed.
Get a Slices account¶
If you do not have a Slices account yet, please register for one.
Install Slices CLI¶
Install the Slices CLI with pip install slices-cli --extra-index-url=https://doc.slices-ri.eu/pypi/
.
We create a separate Python virtual environment to install this in, as this prevents conflicts
with other Python-based software.
# It might be possible that the python virtual environment tools are not yet available, install them if needed
sudo apt update
sudo apt install python3-venv
# Create a Python virtual environment in the folder 'slices-venv'
~$ python3 -m venv slices-venv
# Activate the environment that you just created
~$ source slices-venv/bin/activate
(slices-venv)~$ pip install slices-cli --extra-index-url=https://doc.slices-ri.eu/pypi/
Looking in indexes: https://pypi.org/simple, https://doc.slices-ri.eu/pypi/
Collecting slices-cli
...
Successfully installed ... (a lot of packages including slices-cli-x.x.x slices-expauth-client-x.x.x ...
You now have the slices command available in your console. --help
can be used to ask more information for each (sub)command:
(slices-venv)~$ slices --version
Slices CLI v0.1.71
(slices-venv)~$ slices --help
Usage: slices [OPTIONS] COMMAND [ARGS]...
Slices CLI
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --version -v Show CLI version. │
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to copy it or customize the installation. │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands with subcommands ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ auth User authentication │
│ bi Basic Infrastructure │
│ experiment Experiments │
│ project Projects │
│ pubkey SSH key management │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Upgrade Slices CLI¶
Regularly, new versions of the CLI are launched. You can install them with
(slices-venv)~$ pip install --upgrade slices-cli --extra-index-url=https://doc.slices-ri.eu/pypi/
Especially if you would run into a problem try first to upgrade the CLI and then retry.
Authentication¶
We need to authenticate ourselves before we can request our first resource.
Use slices auth login
to start the authentication flow.
You will be asked to open a browser, go to the Slices RI portal to authenticate and authorize the CLI.
(slices-venv) ~$ slices auth login
Please go to https://portal.slices-ri.eu/oauth/authorize_device?user_code=FFWK-BJTB and login to continue.
⠋ Waiting for authorization
After completing the authentication flow in your browser, you will be logged in succesfully:
(slices-venv) ~$ slices auth login
Please go to https://portal.slices-ri.eu/oauth/authorize_device?user_code=FFWK-BJTB and login to continue.
Successfully logged in as 'demo_user'
💾 Saved to /home/demo_user/.slices/auth.json
Now select the project that you want to use with slices project use <project name>
As mentioned in the output, your authentication token is saved in the file auth.json
located in the .slices
folder in your home directory.
Never share this file with anybody else, as they will be able to impersonate you with it.
You can verify that you are correctly logged in via slices auth status
:
(slices-venv) ~$ slices auth show
Logged in as 'demo_user'
Selecting a project¶
In Slices, your resources live in an experiment and an experiment lives in a project. You can request or join a project at https://portal.slices-ri.eu.
Before continuing, we need to select a project in the Slices CLI first.
You can list your available projects with slices project list
(you should see at least one project):
(slices-venv) ~$ slices project list
Projects for demo_user
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Name ┃ Role ┃ Created At ┃ Expires At ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━┩
│ demo_project │ member │ 2024-01-06 13:00 CEST │ 2030-12-15 01:00 CEST │
│ my_project │ lead │ 2024-08-17 11:41 CEST │ 2024-12-15 01:00 CEST │
└─────────────────────────┴────────┴───────────────────────┴───────────────────────┘
To select a project use slices project use <project_name>
:
(slices-venv) ~$ slices project use demo_project
The current project was set to 'demo_project', in which you are a member and which expires on 2030-12-15 01:00 CEST.
Your Slices CLI is now configured to use this project.
All future commands will take place within this project.
You can change to another project any time by selecting it with slices project use
. You can ask the current project with slices project show
.
Registering your public SSH key¶
For some resources (e.g. in the Basic infrastructure service) key-based SSH authentication is needed. It’s a good idea to register (and create if necessary, see the below tip) a public SSH key now.
We do this with slices pubkey register <public key>
:
(slices-venv) ~/.ssh$ slices pubkey register ~/.ssh/id_ed25519.pub
Registered public key. ✅
alternative: slices pubkey register ~/.ssh/id_rsa.pub
Tip: Generating your first SSH keypair
If you haven’t generated an SSH keypair yet, you can do this with ssh-keygen
.
(slices-venv) ~$ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/demo_user/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/demo_user/.ssh/id_ed25519
Your public key has been saved in /home/demo_user/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:1QRodFGJqHhnFAlYDvKdGXKP3FzsFwaw+b8OZq1a4I4 demo_user@demo
The key randomart image is:
+--[ED25519 256]--+
| . oo=o+B**o. |
| o.B O*=oo+ |
| ..B+*..... |
| . o oo. . |
| . oS .. |
| . . o |
| . = o |
| o + o . |
| E o...o |
+----[SHA256]-----+
This will create two files in the folder .ssh
in your home directory.
The file id_ed25519
contains your private key, while id_ed25519.pub
is your public key.
Depending on your system this can be also id_rsa
and id_rsa.pub
.