Skip to content

⚡ Create a virtual machine in cPouta from the CLI

Summary
This tutorial guide you through creating a virtual machine using the cPouta CLI interface.
Internet
https://docs.openstack.org/python-openstackclient/latest/cli/index.html
flowchart LR
    A(Launch terminal) --> B(Source project's openrc file)
    B --> C(Check wanted flavour and image)
    C --> D(Check available quota)
    D --> E(Launch virtual machine)

Prerequisites

  1. cPouta service is enabled in the MyCSC project
  2. CLI tools installed and possible Python virtual environment, where CLI tools are installed, activated.
  3. API access to cPouta enabled. Enable API access to cPouta from the CLI and create application credentials
  4. SSH key pair is created. Create an SSH key pair.

🟨 Procedure

Open the terminal. Make sure your project RC file is sourced.

Launching a virtual machine is one command.

openstack server create --flavor <flavor> --image <image-id> --key-name <key-name> <name-for-machine>

However, in order to use the command, the following issues must be resolved:

  1. The flavour,
  2. The image ID and
  3. The key pair name.

Let us solve them first.

Available flavours can be listed with the command:

openstack flavor list

The command produces the following kind of print:

+--------------------------------------+------------------+--------+------+-----------+-------+-----------+
| ID                                   | Name             |    RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+------------------+--------+------+-----------+-------+-----------+
| 0143b0d1-4788-4d1f-aa04-4473e4a7c2a6 | standard.tiny    |   1000 |   80 |         0 |     1 | True      |
| 053c4852-dd1e-42dc-947a-fe4263548fa9 | hpc-gen2.48core  | 240000 |   80 |         0 |    48 | True      |
| 110eb004-f7cc-474b-8158-14bb244cb05e | hpc-gen2.24core  | 120000 |   80 |         0 |    24 | True      |
...

Note

Note the Name, RAM and VCPUs columns. These are used when calculating the availability of resources (quota).

Next, we'll list the images available:

openstack image list

The following or similar output is printed:

+--------------------------------------+-----------------+--------+
| ID                                   | Name            | Status |
+--------------------------------------+-----------------+--------+
| 89e14cf5-9b82-4be7-856d-2607716f0fc7 | AlmaLinux-8     | active |
| bffec53b-a626-47ad-9049-f0ec800060bc | AlmaLinux-9     | active |
...
Finally, we need an SSH key pair. You can list the available ones in cPouta OpenStack environment with command:

openstack keypair list

and it will print something like:

+------------+-------------------------------------------------+------+
| Name       | Fingerprint                                     | Type |
+------------+-------------------------------------------------+------+
| gold-key   | 53:a6:81:1c:9d:20:1d:85:4e:3b:76:e8:42:71:af:6c | ssh  |
...

Tip

If you don't have an SSH key pair - here's a related tutorial: Create an SSH key pair.

You now have all the information you need to create a virtual machine:

openstack server create --flavor standard.tiny --image AlmaLinux-9 --key-name gold-key astro-linux

The command will print you the following output:

+--------------------------------------+------------------------------------------------------+
| Field                                | Value                                                |
+--------------------------------------+------------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                               |
| OS-EXT-AZ:availability_zone          |                                                      |
| OS-EXT-STS:power_state               | NOSTATE                                              |
| OS-EXT-STS:task_state                | scheduling                                           |
| OS-EXT-STS:vm_state                  | building                                             |
| OS-SRV-USG:launched_at               | None                                                 |
| OS-SRV-USG:terminated_at             | None                                                 |
| accessIPv4                           |                                                      |
| accessIPv6                           |                                                      |
| addresses                            |                                                      |
| adminPass                            | sUxfJvCVgpM4                                         |
| config_drive                         |                                                      |
| created                              | 20xx-06-12T08:38:47Z                                 |
| flavor                               | standard.tiny (0143b0d1-4788-4d1f-aa04-4473e4a7c2a6) |
| hostId                               |                                                      |
| id                                   | 93c085d6-8455-4b6c-863e-c438185bc570                 |
| image                                | AlmaLinux-9 (bffec53b-a626-47ad-9049-f0ec800060bc)   |
| key_name                             | gold-key                                             |
| name                                 | astro-linux                                          |
| os-extended-volumes:volumes_attached | []                                                   |
| progress                             | 0                                                    |
| project_id                           | 42f7a84e026647e352bacf7b20a421ad                     |
| properties                           |                                                      |
| security_groups                      | name='default'                                       |
| status                               | BUILD                                                |
| updated                              | 20xx-06-12T08:38:47Z                                 |
| user_id                              | cbrown                                               |
+--------------------------------------+------------------------------------------------------+

That's it!

Now you have a virtual machine up and running.

In the example we have used the standard.tiny flavour, which is the smallest flavour available. Larger flavours are available depending on your quota.

The quota can be checked using the following command:

openstack limits show --absolute

The output shows the maximum available value and the total used value of a resource. For example, for RAM these values would be totalRAMUsed and maxTotalRAMSize.

+--------------------------+-------+
| Name                     | Value |
+--------------------------+-------+
| maxTotalKeypairs         |   100 |
| maxSecurityGroupRules    |   400 |
| maxServerGroups          |    10 |
| totalCoresUsed           |     2 |
| totalRAMUsed             |  2000 |
| totalInstancesUsed       |     2 |
| maxTotalCores            |     8 |
| maxServerGroupMembers    |    24 |
| maxTotalFloatingIps      |     2 |
| totalSecurityGroupsUsed  |     1 |
| maxTotalInstances        |     8 |
| maxTotalRAMSize          | 33000 |
...

🌵 Here's a script that would calculate and print the quota used in the project: Used cPouta quota script

You can list the running instances:

openstack server list

that will give you an output similar to:

+--------------------------------------+-------------+--------+------------------------------------------------+--------------+---------------+
| ID                                   | Name        | Status | Networks                                       | Image        | Flavor        |
+--------------------------------------+-------------+--------+------------------------------------------------+--------------+---------------+
| b17819c4-935b-4b6b-acd1-fb6232c06e44 | astro-linux | ACTIVE | project_2000099=192.168.1.8                    | AlmaLinux-9  | standard.tiny |
| 93c085d6-8455-4b6c-863e-c438185bc570 | space-linux | ACTIVE | project_2000099=138.124.255.220, 192.168.1.238 | Ubuntu-22.04 | standard.tiny |
+--------------------------------------+-------------+--------+------------------------------------------------+--------------+---------------+

In the print example, there are two virtual machines, one connected to the public Internet and the other not.

Warning

By default, your virtual machine is isolated and inaccessible. This also applies to CSC employees - we cannot access your virtual machine. You will need to continue with Connect your virtual machine to the Internet from the CLI tutorial to gain an access for yourself.

Further Learning

Here are some suggestions for what to read next: