How to launch an instance using the OpenStack CLI

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 compute, memory, and storage capacity of computing instances. A flavor is an available hardware configuration for a server. It defines the size of a virtual server that can be launched.
  • User data — 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 OpenStack. You can use the key pair for multiple instances that belong to that project.
    • Security group — Defines which incoming network traffic is forwarded to 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.

After you gather the parameters you need to launch an instance, you can launch it from an image or a volume.

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      |
+--------------------------------------+--------------+-------------+
| afa49adf-2831-4a00-9c57-afe1624d5557 | CentOS-6     | active      |
| d83cc53a-720a-4972-8d9a-f92299571920 | CentOS-7     | deactivated |
| f84868a5-5261-404a-9c54-ec317ea16b94 | CentOS-7     | active      |
| a93aa9fa-b6b5-4fe3-8e53-1373612628f5 | CoreOS       | active      |
| b67b74bc-c3a8-4087-9c28-de02161fdedd | CoreOS       | deactivated |
| 5cb9c233-5867-4e47-80a1-9d774f800444 | Debian-7     | active      |
| 8eac618e-ee9b-459d-92d4-b6a49e94b207 | Debian-8     | active      |
| b105ad3b-7df8-4318-9c3d-4e4fa4cc4563 | Debian-8     | deactivated |
| 713f2fbc-05c5-491b-9e02-e000861e7b30 | Fedora-24    | active      |
| b4516e23-2358-4400-9396-32e223eceb01 | Fedora-25    | active      |
| 842c207f-6964-4ed7-a41a-06ec66a7c954 | Ubuntu-14.04 | active      |
| 23f77038-51dc-40f3-8714-50612b0efb24 | Ubuntu-16.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
| 842c207f-6964-4ed7-a41a-06ec66a7c954 | 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-babf-6a5bb5cc7bed | default | Default security group | e52ede2a420548cf250bac6497300079 |
+--------------------------------------+---------+------------------------+----------------------------------+

If you are an admin user, specify the -–all-projects parameter to list groups for all tenants.

[user@localhost]$ openstack security group list --all-projects

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:

[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

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

Run the following to create your server.

This example splits up the command into separate lines.

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

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 windows --security-group 29abef85-b89f-43a0-babf-6a5bb5cc7bed myNewServer

If the server 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                        | myNewServer                                     |
| progress                    | 0                                               |
| project_id                  | e52ece2a560548cf950ba86297300079                |
| properties                  |                                                 |
| security_groups             | name='29abcf85-b79f-43b0-babf-6a5bb5cc7bed'     |
| status                      | BUILD                                           |
| updated                     | 2017-10-10T01: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. Use the password to log in to your server.

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

For more options, view the following article:

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 servers:

[user@localhost]$ openstack server list
+--------------------------------------+--------------+--------+----------------------------------------------------+
| ID                                   | Name         | Status | Networks               | Image    | Flavor         |
+--------------------------------------+--------------+--------+------------------------+----------+----------------+
| 76b3adb3-1f5a-4276-8b82-abdf21352946 | myNewServer  | 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 did not provide a key pair, security groups, or rules, you can access the instance only from inside the cloud through VNC. Even pinging the instance is not possible.

Did this article answer your questions?

Article last updated .