Openstack – Create and Manage Instances via CLI

SUMMARY

Instances are virtual machines that run inside the cloud. You can launch an instance from the following sources:

  • Images uploaded to the OpenStack Glance Image service (ephemeral instance).
  • Image that you have copied to a persistent volume (persistent instance).

 

GATHER DETAILS FOR INSTANCE LAUNCH

Before you can launch an instance, gather the following parameters:

  • The instance source can be an image, snapshot, or block storage volume that contains an image or snapshot.
  • A name for your instance.
  • The flavor for your instance, which defines the compute, memory, and storage capacity of nova computing instances. A flavor is an available hardware configuration for a server. It defines the size of a virtual server that can be launched.
  • 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, which include one or both of the following credentials:
  • A key pair for your instance, which 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.
  • A security group that defines which incoming network traffic is forwarded to instances. Security groups hold a set of firewall policies, known as security group rules.
  • If needed, you can assign a floating (public) IP address to a running instance.
  • You can also attach a block storage device, or volume, for persistent storage.

You can gather these parameters the following way:

 

Before you begin, source the openrc file. The proceed as follows:

List the available flavors:


Make note of the flavor ID and copy the variable to paste into the nova boot command.

List the available images:


Make note of the image ID and copy the variable to paste into the nova boot command.

List the available security groups:


Make note of the security group ID and copy the variable to paste into the nova boot command.

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


Make note of the keypair name and copy the variable to paste into the nova boot command.

List the available networks, and note the network name that you will use for the instance:


Make note of the network ID and copy the variable to paste into the nova boot command.

LAUNCH INSTANCE

After you gather required parameters, run the following command to launch an instance. Specify the server name, flavor ID, and image ID:

For example, using the parameters above we executed the command as follows:

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.

Once the nova boot command has been executed you can view your instances using the following command:

And to see the details of the instance:

Lastly, if you wish to delete the instance you can execute the following command:

Leave a comment