Protecting images

Like other OpenStack objects, images and snapshots are susceptible to accidental deletion by users. By default, images are unprotected, meaning they can be deleted at any time by a user within a project. The following sections explain how an image can be protected to ensure its survival.

Protecting an image

Images can be protected using the openstack image set command with the --protected argument.

Getting ready

When protecting an image, ensure that you are authenticated as an administrator or are the owner of the image. You will need the following details, at a minimum:

  • Image name or ID

For our examples, the following will be used:

  • Image name: COOKBOOK_UBUNTU_IMAGE

How to do it…

With the OpenStack client installed on our system, we are now able to protect an image with the following command:

openstack image set COOKBOOK_UBUNTU_IMAGE --protected

No output is returned if the operation is successful. Use the openstack image show command to reveal the status of the image:

How to do it…

How it works...

When an image is protected in OpenStack, users are unable to delete the image. Attempting to delete a protected image results in an error similar to the following:

Failed to delete image with name or ID 'COOKBOOK_UBUNTU_IMAGE': 403 Forbidden: Image d120a923-5246-4dca-8f52-51a951bffce5 is protected and cannot be deleted. (HTTP 403)
Failed to delete 1 of 1 images.

Protecting an image is a useful step in ensuring that snapshots and other special images remain unharmed in a cloud shared by many users and projects.

Unprotecting an image

Images can be unprotected using the openstack image set command with the --unprotected argument.

Getting ready

When unprotecting an image, ensure that you are authenticated as an administrator or are the owner of the image. You will need the following details, at a minimum:

  • Image name or ID

For our examples, the following will be used:

  • Image name: COOKBOOK_UBUNTU_IMAGE

How to do it…

With the OpenStack client installed on our system, we are now able to unprotect an image with the following command:

openstack image set COOKBOOK_UBUNTU_IMAGE --unprotected

No output is returned if the operation is successful. Use the openstack image show command to reveal the status of the image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.120.178