# Command-line access

Everything you can do in the [Horizon dashboard](https://datalab.tuwien.ac.at/infrastructure/openstack/login/), you can also do from the command line using the
`openstack` client. This is useful for automation and for tasks that are tedious to click through in the GUI.

## Install the client

``` bash
pip install python-openstackclient
```

## Get your credentials

1. In Horizon, go to **Project → API Access** (sometimes **Compute → Access & Security → API Access**) and click
   **Download OpenStack RC File**.
2. Open the downloaded file and set `OS_CLOUD` or (on older setups) source it directly:

   ``` bash
   source openrc.sh
   ```

   When asked, enter your TU Wien password. The environment variables are only active in the current shell.

!!! note
    The RC file contains your credentials in plain text. Do not commit it to a repository or share it.

## Useful commands

``` bash
openstack flavor list                        # available flavors
openstack image list                         # available images
openstack server list                        # your instances
openstack server create --flavor a1.standard.4 --image ubuntu-noble-24.04 --key-name mykey myvm
openstack server ssh --login ubuntu myvm    # ssh into an instance by name
openstack floating ip create public          # allocate a floating IP
openstack server add floating ip myvm <ip>  # attach it to an instance
openstack server delete myvm
```

Replace `<ip>` and `mykey`/`myvm` with your own values. For the full command reference, see the
[official OpenStack CLI documentation](https://datalab.tuwien.ac.at/infrastructure/openstack/links/).

## Scripting

Because the client is just a set of commands, you can script it with your shell of choice. The
[Ansible `openstack.cloud` collection](https://docs.ansible.com/ansible/latest/collections/openstack/cloud/index.html)
is also available if you prefer declarative infrastructure.