How to launch an instance using the OpenStack CLI

Overview

Virtual machines that run inside the cloud are called instances. Before you can launch an instance, gather the following parameters:

  • Instance source — Can be an image, snapshot, or block storage volume that contains an image or snapshot.
  • Instance name — The name for your instance.
  • Flavor — The flavor for your instance defines the vCPU and RAM memory limits for an instance.
  • User data (not required) — Any user data files. A user data file is a special key in the metadata service that holds a file that cloud-aware applications in the guest instance can access. For example, one application that uses user data is the cloud-init system, which is an open-source package from Ubuntu that is available on various Linux distributions and that handles early initialization of a cloud instance.
  • Access and security credentials — This includes one or both of the following credentials:
    • key pair — These are SSH credentials that are injected into images when they are launched. For the key pair to be successfully injected, the image must contain the cloud-init package. Create at least one key pair for each project. If you already have generated a key pair with an external tool, you can import it into DreamCompute. You can use the key pair for multiple instances that belong to that project.
    • Security group — Defines which incoming and outgoing network traffic is forwarded to and from the instances. Security groups hold a set of firewall policies, known as security group rules.
  • IP addresses — If needed, you can assign a floating (public) IP address to a running instance.
  • Volume — You can also attach a block storage device, or volume, for persistent storage.

You can launch an instance directly from one of the available OpenStack images, or from an image that you have copied to a persistent volume. The OpenStack Image service provides a pool of images that are accessible to members of different projects.

Gather parameters to launch an instance

The following examples use the OpenStack command line client:

List the available flavors

Note the ID of the flavor you want to use for your instance:

[user@localhost]$ openstack flavor list
+-----+----------------+-------+------+-----------+-------+-----------+
| ID  | Name           |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+-----+----------------+-------+------+-----------+-------+-----------+
| 100 | gp1.subsonic   |  1024 |   80 |         0 |     1 | True      |
| 200 | gp1.supersonic |  2048 |   80 |         0 |     1 | True      |
| 300 | gp1.lightspeed |  4096 |   80 |         0 |     2 | True      |
| 400 | gp1.warpspeed  |  8192 |   80 |         0 |     4 | True      |
| 50  | gp1.semisonic  |   512 |   80 |         0 |     1 | True      |
| 500 | gp1.hyperspeed | 16384 |   80 |         0 |     8 | True      |
+-----+----------------+-------+------+-----------+-------+-----------+

List the available images

Note the ID of the image from which you want to boot your instance:

[user@localhost]$ openstack image list
+--------------------------------------+---------------+-------------+
| ID                                   | Name          | Status      |
+--------------------------------------+---------------+-------------+
| 76a93b4b-566c-41eb-ab9d-26ce5be04010 | CentOS-7      | active      |
| 0c35ed32-a053-4481-8bac-efd3a5f9513e | CoreOS-Stable | active      |
| 0415d69c-28b3-4bfd-ab64-711c699c60b9 | Debian-8      | active      |
| cbd81524-f477-4d7c-963c-84699acf711b | Debian-9      | active      |
| b0a29bbc-dd13-4305-8380-043b86356edf | Fedora-25     | active      |
| 03b1467b-4c5d-4f85-aa62-035841a88aca | Fedora-29     | active      |
| 03a87e23-77e5-403b-a437-10e0b28b2583 | Ubuntu-14.04  | active      |
| 04f22a69-bdfe-4c2d-b996-aab8d69e4a0e | Ubuntu-16.04  | active      |
| fc6510a1-c057-4a74-bac9-3d8b74270038 | Ubuntu-17.10  | active      |
| b86ca11c-e7c1-4ae1-8580-62c464b19dfd | Ubuntu-18.04  | active      |
+--------------------------------------+---------------+-------------+

You can also filter the image list by using grep to find a specific image, as follows:

[user@localhost]$ openstack image list | grep -i Ubuntu-14
| 03a87e23-77e5-403b-a437-10e0b28b2583 | Ubuntu-14.04 | active      |

List the available security groups.

Note the ID of the security group that you want to use for your instance:

[user@localhost]$ openstack security group list
+-----------------------+---------+------------------------+-------------------------+
| ID                    | Name    | Description            | Project                 |
+-----------------------+---------+------------------------+-------------------------+
| 29abef85-b89f-43a0... | default | Default security group | e52ede2a420548cf25...   |
+-----------------------+---------+------------------------+-------------------------+

If you have not created any security groups, you can assign the instance to only the default security group. You can view rules for a specified security group by running the following:

[user@localhost]$ openstack security group show default

List available key pairs

List the available key pairs, and note the key pair name that you use for SSH access.

[user@localhost]$ openstack keypair list

Launch an instance from an image

After you've gathered the required parameters, you can now create an instance. At this point, you should have the following credentials:

  • flavor — 300
  • image — afa49adf-2831-4a00-9c57-afe1624d5557
  • keypair — myKey
  • security group — 29acef25-b59f-43a0-babf-6a5bb5cc7bed
  • servername — You can name it anything you like, but in this example myNewInstance will be used.

    If you boot an instance with an INSTANCE_NAME greater than 63 characters, Compute truncates it automatically when turning it into a hostname to ensure the correct functionality of dnsmasq.

Run the following to create your instance.

This example splits up the command into separate lines.

[user@localhost]$ openstack server create --flavor 300 \
                        --image afa49adf-2831-4a00-9c57-afe1624d5557 \
                        --key-name myKey \
                        --security-group 29abef85-b89f-43a0-babf-6a5bb5cc7bed \
                        myNewInstance

The backslash character \ is used when entering a long command. When you enter the \, the terminal command continues to the next line until you finish entering it.

You could also remove the \ character and put every parameter into a single line. For example:

[user@localhost]$ openstack server create --flavor 300 --image afa49adf-2831-4a00-9c57-afe1624d5557 --key-name myKey --security-group 29abef85-b89f-43a0-babf-6a5bb5cc7bed myNewServer

If the instance was correctly created, you'll see an output like this:

+-----------------------------+-------------------------------------------------+
| Field                       | Value                                           |
+-----------------------------+-------------------------------------------------+
| OS-DCF:diskConfig           | MANUAL                                          |
| OS-EXT-AZ:availability_zone | iad-2                                           |
| 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                   | RPwLFr5ze5fB                                    |
| config_drive                |                                                 |
| created                     | 2017-10-10T01:25:10Z                            |
| flavor                      | gp1.lightspeed (300)                            |
| hostId                      |                                                 |
| id                          | 76b3adb3-1f5a-4276-8b82-abdf21352946            |
| image                       | CentOS-6 (afa49adf-2831-4a00-9c57-afe1624d5557) |
| key_name                    | myKey                                           |
| name                        | myNewInstance                                   |
| progress                    | 0                                               |
| project_id                  | e52ece2a560548cf950ba86297300079                |
| properties                  |                                                 |
| security_groups             | name='29abcf85-b79f-43b0-babf-6a5bb5cc7bed'     |
| status                      | BUILD                                           |
| updated                     | 2024-03-29T01:25:10Z                            |
| user_id                     | 29825415c4be4d49c27e787a63eb8320                |
| volumes_attached            |                                                 |
+-----------------------------+-------------------------------------------------+

A status of BUILD indicates that the instance has started, but is not yet online. A status of ACTIVE indicates that the instance is active. Copy the administrative password value from the adminPass field. You can use this password later to log in to your instance.

You'll also be able to see the new instance in your DreamCompute panel.

For more options, use the following command or view OpenStack's documentation below.

[user@localhost]$ openstack help server create

You can also place arbitrary local files into the instance file system at creation time by using the --file <dest-filename=source-filename> parameter. You can store up to five files.

For example, if you have a special authorized keys file named special_authorized_keysfile that you want to put on the instance rather than using the regular SSH key injection, you can add the –file option as shown in the following example.

--file /root/.ssh/authorized_keys=special_authorized_keysfile

Check if the instance is online

Use the list command to view a list of all instances:

[user@localhost]$ openstack server list
+--------------------------------------+--------------+--------+----------------------------------------------------+
| ID                                   | Name         | Status | Networks               | Image    | Flavor         |
+--------------------------------------+--------------+--------+------------------------+----------+----------------+
| 76b3adb3-1f5a-4276-8b82-abdf21352946 | myNewInstance| ACTIVE | public=xxx.xxx.xxx.xxx | CentOS-6 | gp1.lightspeed |
| 246e50b8-29fa-4310-b972-a71cd0df43bf | Ubuntu14     | ACTIVE | public=xxx.xxx.xxx.xxx |          | gp1.subsonic   |
+--------------------------------------+--------------+--------+------------------------+----------+----------------+

The list shows the ID, Name, Status, IP addresses, Image, and Flavor for all instances in the project.

If you do not provide a key pair, you will be unable to access the instance.

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?