Shelving Instances (by hand)

When an instance of a VM is stopped the resources it requires are not released to the project quotas. This is a design feature that ensures a stopped instance can always be restarted, since the resources it needs are still available. In some cases it is useful to stop an instance and release the resources, thus allowing projects to deploy other instances. In openstack this is referred to as “shelving”. The current deployment of openstack at MPCDF does not fully support shelving and although it can be used to stop an instance the quotas are not updated. This recipe details how an instance can be shelved by hand as a work-around.

This process consists of 3 parts.

  1. Creating a snapshot of a VM

  2. Deleting the VM

  3. Re-creating the VM once it is again required

Creating a Snapshot

Stop the VM (ensuring no disk I/O is active) and then create a snapshot with a meaningful name.

$ openstack server stop <INSTANCE-NAME>

$ openstack server image create --name <INSTANCE-NAME>-snapshot <INSTANCE-NAME>

$ openstack image list

Wait until the image is in the “active” state before continuing to delete the VM instance.

Deleting the VM

Before deleting the VM check the current configuration; instance flavor, floating IP, security groups, networks etc. This information will be needed if the VM is to be re-created with the same configuration as the existing instance.

Then delete the VM.

$ openstack server delete <INSTANCE-NAME> 

Now the resources will have been returned to the project quotas.

Re-creating the VM

The VM instance an be re-created by creating an instance using the snapshot as the image source.

$ openstack server create --flavor <flavor> --image <INSTANCE-NAME>-snapshot --network <network> <INSTANCE-NAME>

Take care to assign all the needed infrastructure to the newly created VM instance; networks, security groups, floating IPs etc.

Ensure that the flavor of the new instance is equal to, or larger, than the original instance w.r.t the boot disk size.