Manage an instance

Perform lifecycle operations on an instance, such as resizing, snapshotting, rescuing, or shelving the instance.

Note

To run openstack client commands on the cloud, you must specify the name of the cloud detailed in your clouds.yaml file. You can specify the name of the cloud by using one of the following methods:

  • Use the --os-cloud option with each command, for example:
    $ openstack flavor list --os-cloud <cloud_name>

    Use this option if you access more than one cloud.

  • Create an environment variable for the cloud name in your bashrc file:
    `export OS_CLOUD=<cloud_name>`

Resize an instance

Resize an instance to increase or decrease its memory or CPU count by selecting a new flavor. Resizing rebuilds and restarts the instance, so migrate workloads beforehand to minimize downtime.

Before you begin

  • The administrator has created a project for you and they have provided you with a clouds.yaml file for you to access the cloud.
  • You have installed the python-openstackclient package.

Procedure

  1. Retrieve the name or ID of the instance that you want to resize:
    $ openstack server list
  2. Retrieve the name or ID of the new flavor that you want to use to resize the instance:
    $ openstack flavor list
    Note

    When you resize an instance, you must use a new flavor.

  3. Resize the instance:
    $ openstack server resize --flavor <flavor> \
      --wait <instance>
    • Replace <flavor> with the name or ID of the flavor that you retrieved in step 2.
    • Replace <instance> with the name or ID of the instance that you are resizing. Note

      Resizing can take time. The operating system on the instance performs a controlled shutdown before the instance is powered off and the instance is resized. During this time, the instance status is RESIZE:

      $ openstack server list
      +----------------------+----------------+--------+----------------------------+
      | ID                   | Name           | Status | Networks                                |
      +----------------------+----------------+--------+----------------------------+
      | 67bc9a9a-5928-47c... | myCirrosServer | RESIZE | admin_internal_net=192.168.111.139    |
      +----------------------+----------------+--------+----------------------------+
  4. When the resize completes, the instance status changes to VERIFY_RESIZE. You must now either confirm or revert the resize:
    • To confirm the resize, enter the following command:
      $ openstack server resize confirm <instance>
    • To revert the resize, enter the following command:
      $ openstack server resize revert <instance>

      The instance is reverted to the original flavor and the status is changed to ACTIVE.

      Note
      The cloud might be configured to automatically confirm instance resizes if you do not confirm or revert within a configured time frame.

Create an instance snapshot

A snapshot captures the state of the running disk of an instance as an image. Use snapshots as templates to create new instances from an existing one, or to restore an instance to a previous state.

Before you begin

  • The administrator has created a project for you and they have provided you with a clouds.yaml file for you to access the cloud.
  • You have installed the python-openstackclient package.

About this task

If you delete an instance on which a snapshot is based, you can use the snapshot image to create a new instance to the same state as the snapshot.

Procedure

  1. Retrieve the name or ID of the instance that you want to take a snapshot of:
    $ openstack server list
  2. Create the snapshot:
    $ openstack server image create --name <image_name> <instance>
    • Replace <image_name> with a name for the new snapshot image.
    • Replace <instance> with the name or ID of the instance that you want to create the snapshot from.
  3. Optional: To ensure that the disk state is consistent when you use the instance snapshot as a template to create new instances, enable the QEMU guest agent and specify that the filesystem must be quiesced during snapshot processing by adding the following metadata to the snapshot image:
    $ openstack image set --property hw_qemu_guest_agent=yes \
     --property os_require_quiesce=yes <image_name>

    The QEMU guest agent is a background process that helps management applications run instance operating system level commands. Enabling this agent adds another device to the instance, which consumes a PCI slot, and limits the number of other devices you can allocate to the instance. It also causes Windows instances to display a warning message about an unknown hardware device.

Rescue an instance

In an emergency such as a system failure or access failure, you can put an instance in rescue mode. This shuts down the instance, reboots it with a new instance disk, and mounts the original instance disk and config drive as a volume on the rebooted instance.

Before you begin

  • The administrator has created a project for you and they have provided you with a clouds.yaml file for you to access the cloud.
  • You have installed the python-openstackclient package.

About this task

You can connect to the rebooted instance to view the original instance disk to repair the system and recover your data.

Procedure

  1. To rescue a volume-boot instance or a non-volume-boot instance, set the hw_rescue_device and hw_rescue_bus parameters:
    # openstack image set rescue_image --property hw_rescue_device=<device_value>
    # openstack image set rescue_image --property hw_rescue_bus=<bus_value>
    • Replace <device_value> with one of the following values: disk, floppy, cdrom
    • Replace <bus_value> with one of the following values: virtio, ide, usb, scsi Note
      The parameter settings hw_rescue_device=disk and hw_rescue_bus=virtio are commonly used.
  2. Perform the instance rescue:
    $ openstack server rescue --os-compute-api-version 2.87 [--image <image>] <instance>
    • Optional: By default, the instance is booted from a rescue image provided by the cloud admin, or a fresh copy of the original instance image. Use the --image option to specify an alternative image to use when rebooting the instance in rescue mode.
    • Replace <instance> with the name or ID of the instance that you want to rescue.
  3. Connect to the rescued instance to fix the issue.
  4. Restart the instance from the normal boot disk:
    $ openstack server unrescue <instance>

Shelve an instance

Shelving is useful if you have an instance that you are not using, but that you do not want to delete. When you shelve an instance, you retain the instance data and resource allocations, but clear the instance memory.

Before you begin

  • The administrator has created a project for you and they have provided you with a clouds.yaml file for you to access the cloud.
  • You have installed the python-openstackclient package.

About this task

Depending on the cloud configuration, shelved instances are moved to the SHELVED_OFFLOADED state either immediately or after a timed delay. When SHELVED_OFFLOADED, the instance data and resource allocations are deleted.

When you shelve an instance, the Compute service generates a snapshot image that captures the state of the instance, and allocates a name to the image in the following format: <instance>-shelved. This snapshot image is deleted when the instance is unshelved or deleted.

If you no longer need a shelved instance, you can delete it. You can shelve more than one instance at a time.

Procedure

  1. Retrieve the name or ID of the instance or instances that you want to shelve:
    $ openstack server list
  2. Shelve the instance or instances:
    $ openstack server shelve <instance> [<instance> ...]

    Replace <instance> with the name or ID of the instance that you want to shelve. You can specify more than one instance to shelve, as required.

  3. Verify that the instance has been shelved:
    $ openstack server list

    Shelved instances have status SHELVED_OFFLOADED.