OpenStack also provides a command line tool (OpenStack Client) to access, provision, and manage cloud resources. This section provides tutorials on how to use the OpenStack Client tool for some common scenarios. Please refer to the instructions on installing the client. Also, ensure that the client is authenticated with an openrc file containing required credentials.
Create and Upload SSH Key
SSH keys are used to SSH into instances launched with OpenStack. OpenStack has a built-in method for inserting an SSH keypair’s public half into the authorized keys file for a newly booted instance. Compute can create the private part of the key for you, or you can upload the public part of an existing key pair.
To Upload Public Half of Existing Pair
$ nova keypair-add --public-key ~/.ssh/id_rsa.pub
Launch Instance Using Created Key
In order to launch an instance, a minimal set of info is required: image, flavor, and name. Most OpenStack environments also require a provided network device.
$ nova boot --image <image_name> --flavor <flavor_name>
--nic net-id=<network_id> --key-name <keypairname> <server_name>
You can use the following commands to find required info,such as image, flavor, and network.
Discover Available Images
$ glance image-list
Discover Available Flavors
$ nova flavor-list
Discover Available Networks
$ neutron network-list
$ nova list
List Instances by Status
$ nova list --status build
$ nova list --status active
$ nova list --status error
Set Instance Metadata
Instance metadata can be useful for sorting or cataloging instances. Metadata is a freeform key=value store per- instance.
$ nova meta <server> set key=value [key=value]
Rebuild a Server
Rebuilding a server takes less arguments than an initial build. It can be an easy way to reset state and start over.
$ nova rebuild <server> <image>
Display Logs From a Server
OpenStack has the ability to show logs.
$ nova console-log <server>
Allocate Floating IP and Attach to a VMA
Floating IPs create a public reachable IP and direct traffic from it to a configured instance. The IP won’t actually exist on the instance; instead, it provides a NAT-like relationship. First, one must be allocated from a provided pool, and then it can be attached to an instance.
Dicover Available Floating IP Pools
$ neutron floatingip-list
Allocate Floating IP
$ nova floating-ip-create <floating ip pool>
Associate Floating IP to Server Instance
$ nova add-floating-ip <server> <floating-p>
Update Security Group
A security group is like a firewall for a group of systems. You can provide access rules that reference other groups or CIDR blocks. These groups can be attached to an instance to provide access to that instance.
Create a Security Group for SSH
$ nova secgroup-create <name> <description>
Creawte an Inbound SSH Rule
$ nova secgroup-add-rule --proto tcp --dst-port 22 <group_name>
Add Security Group to Server Instance
$ nova add-secgroup <server> <group_name>
Create Image of Running Server
Server images allow creating pre-configured images for reuse at a later time. They can be used to launch new server instances, and will show up when listing images.
$ nova image-create <server> <image>
Creates a new image from an existing image or URL. Optional parameters include image ID, disk format, project, volume to create from, etc.
$ glance image-create –name <image>
$ glance image-list
$ glance image-delete <image>
Create a Block Storage Volume
A block storage volume is a block device that is not directly connected to a running instance. It can be attached to one instance at a time, but will survive if the instance itself fails or is shut down. OpenStack volumes are often an interface to an existing SAN, allowing the use of an easy-to-use API to interact with them.
$ cinder create – -dislplay-name <name> <size_in_GB>
Attach a Block Storage Volume to a Server Instance
When attaching a volume to a server, it is possible to rely on the system to automatically assign a device ID within the instance to the new volume. You can choose to specify if desired. Once the volume is attached, if it is a new volume, it is necessary to format the volume for use. Subsequent usage of the volume will not require formatting.
$ nova volume-attach <server> <volume> <device>
Create an Object Storage Container
OpenStack object storage is not a traditional file system, but rather a distributed storage system for static data such as virtual machine images, photo storage, email storage, backups, and archives. Having no central “brain” or master point of control provides greater scalability, redundancy, and durability. Data is represented by objects, and objects are stored in containers.
$ swift post <container_name>
$ swift post <container_name> <file_path>
Download an Object From a Container
$ swift download <container_name> <object_name>
Identity and Access Control
Cloud Admin can create new users with just a user name. Optional parameters include project ID, email, and password.
$ keystone user-create <name>
One can list all the users, optionally filtered by specific project (filtered by project name or ID).
$ keystone user-list [--tenant <tenant>]
$ keystone user-delete <name>
$ keystone role-create <name>
$ keystone role-delete <role>
$ keystone role-list
Add Role to Tenant::User
$ keystone user-role-add --user <user> --role <role>
$ keystone tenant-create <name>
$ keystone tenant-list
Set Tenant Properties
$ keystone tenant-update –property <update> <tenant>
$ keystone tenant-delete <tenant>
Quotas can be set at a project or class basis to limit consumption of resources, such as size of memory (RAM), IP addresses, number of cores, size of storage volumes, etc.
$ nova quota-update – - properties <update> <tenant>
OpenStack can enforce quotas on resource consumption. This command expects a project name; projects are the new name for tenants.
$ nova quota-show <tenant>
Show a List of Availability Zones
OpenStack supports availability zones that may be provided to allow either logical separation or clustering of services. Typically, these are for power-accessibility or geographical reasons. A zone can be selected when launching new instances.
$ nova availability-zone-list