Skip to content

Command Line Interface

Help

See all options:

 $ cloudscale-cli
Usage: cloudscale-cli [OPTIONS] COMMAND [ARGS]...

Options:
  --version                  Show the version and exit.
  -a, --api-token TEXT       API token.
  -p, --profile TEXT         Profile used in config file.
  --debug                    Enables debug log output.
  -o, --output [table|json]  Output format.  [default: table]
  -h, --help                 Show this message and exit.

Commands:
  flavor
  floating-ip
  image
  network
  objects-user
  region
  server
  server-group
  subnet
  volume

Autocompletion

zsh:

eval "$(_CLOUDSCALE_CLI_COMPLETE=source_zsh cloudscale-cli)"

bash:

eval "$(_CLOUDSCALE_CLI_COMPLETE=source cloudscale-cli)"

Authentication

Evironment variable

Using the ENV CLOUDSCALE_API_TOKEN variable:

export CLOUDSCALE_API_TOKEN=<your token>
cloudscale-cli flavor list

Command line argument

Passing the --api-token parameter:

cloudscale-cli --api-token <your_token> server create ...

Config file

Creating an ini file .cloudscale.ini (leading dot) in your $HOME or a cloudscale.ini (without leading dot) in the CWD with the following schema:

[default]
api_token = <token>

The default profile taken if available is default. The profile can be chosen by passing --profile or CLOUDSCALE_PROFILE ENV variable.

export CLOUDSCALE_PROFILE=staging
[production]
api_token = <token>

[staging]
api_token = <token>

Passing the command line option will overwrite the ENV var as one would expect:

cloudscale-cli --profile production server list

Usage Examples

Create Servers

Create one server:

cloudscale-cli server create \
--name my-server \
--flavor flex-2 \
--image centos-7 \
--ssh-key "$(cat ~/.ssh/id_rsa.pub)"

Create up to 10 servers in a row with --count:

Tip

When using --count, the option --name allows to use string format syntax with 2 special variables:

  • counter: A number representing the current interation while creating multiple servers.
  • uid: A random 8 char/number long string.

This allows to create dynamic names, e.g.:

  • Single number suffix: --name 'myserver-{counter}'
  • Number with leading zero suffix: --name 'server-{counter:02d}'
  • Random string suffix: --name 'server-{uid}'
  • Combinations: --name 'server-{uid}-{counter:02d}.example.com'
cloudscale-cli server create \
--name 'my-server-{uid}' \
--flavor flex-2 \
--image centos-7 \
--ssh-key "$(cat ~/.ssh/id_rsa.pub)" \
--count 10

List Servers

Get a list as table view:

cloudscale-cli server list

Get a list as JSON response:

cloudscale-cli -o json server list

List Servers and Filter by Tag

List servers having the tag project with value gemini:

cloudscale-cli server list --filter-tag project=gemini

List servers having a tag project:

cloudscale-cli server list --filter-tag project

List Servers and Filter by JSON Query

Get a list of stopped servers:

cloudscale-cli server list --filter-json '[?status == `stopped`]'

Get a list of stopped servers having tag project=demo and start them after accepting:

cloudscale-cli server list \
--filter-tag project=demo \
--filter-json '[?status == `stopped`]' \
--action start
...
Do you want to start? [y/N]:

Start a list of stopped servers after accepting having tag project=demo:

cloudscale-cli server list \
--filter-tag project=demo \
--filter-json '[?status == `stopped`]' \
--action start
...
Do you want to start? [y/N]:

Delete a list of stopped servers after accepting having tag project=demo:

cloudscale-cli server list \
--filter-tag project=demo \
--filter-json '[?status == `stopped`]' \
--delete
...
Do you want to delete? [y/N]:

Get a simplified custom JSON list of stopped servers in profile production:

cloudscale-cli \
--output json \
--profile production \
server list \
--filter-json '[?status == `stopped`].{"server_name": name, "zone": zone.slug, "image": image.slug, "flavor": flavor.slug}'
[
    {
        "flavor": "flex-8",
        "image": "rhel-7",
        "server_name": "server1",
        "zone": "rma1"
    },
    {
        "flavor": "flex-8",
        "image": "centos-7",
        "server_name": "server2",
        "zone": "rma1"
    }
]

Working with Tags

Add/Update servers tags (but keep all existing with different keys):

cloudscale-cli server update <uuid> --tag project=apollo --tag stage=prod

Delete a server tag (but keep all others existing):

cloudscale-cli server update <uuid> --clear-tag status

Add/Update server tags and remove a specific tag key:

cloudscale-cli server update <uuid> \
--tag project=apollo --tag stage=prod --clear-tag status

Add/Update server tags, remove other tags:

cloudscale-cli server update <uuid> \
--tag project=apollo --tag stage=prod --clear-all-tags

Server Actions

Stop a server:

cloudscale-cli server stop <uuid>

Start a server:

cloudscale-cli server start <uuid>

Delete a server after accepting:

cloudscale-cli server delete <uuid>

Just delete without questions asked:

cloudscale-cli server delete -f <uuid>

Verbosity and Debugging

Increase the verbosity by changing the log level from its default value ERROR to the value INFO:

cloudscale-cli --debug server list

or alternatively

export CLOUDSCALE_DEBUG=1
cloudscale-cli server list

To set the default log level e.g. to DEBUG use the CLOUDSCALE_LOG_LEVEL environment variable:

export CLOUDSCALE_LOG_LEVEL=debug
cloudscale-cli server list