Difference between revisions of "Images"
(→Available Images: Filled in content) |
(Add information about deleting images) |
||
(6 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | + | [https://docs.openstack.org/image-guide/ OpenStack Images] can take several forms, but generally an image consists of a static copy of a [https://en.wikipedia.org/wiki/Virtual_machine virtual machine] with an [https://en.wikipedia.org/wiki/Operating_system operating system] with some amount of storage. Each project starts out with a few base [[Red_Cloud_Linux_Instances#Creating_a_New_Linux_Instance|Linux]] and [[Red_Cloud_Windows_Instances#Creating_A_New_Windows_Instance|Windows]] images from which [[OpenStack#Instances|instances]] can be created. Images can also be created or uploaded to [[OpenStack]], and then used to [[OpenStack#Launch_an_Instance|launch instances]]. | |
− | |||
− | [https://docs.openstack.org/image-guide/ OpenStack Images] can take several forms, but generally an image consists of a static copy of a [https://en.wikipedia.org/wiki/Virtual_machine virtual machine] with an operating system with some amount of storage. Each project starts out with a few base [[Red_Cloud_Linux_Instances#Creating_a_New_Linux_Instance|Linux]] and [[Red_Cloud_Windows_Instances#Creating_A_New_Windows_Instance|Windows]] images from which [[OpenStack#Instances|instances]] can be created. Images can also be created or uploaded to [[OpenStack]], and then used to [[OpenStack#Launch_an_Instance|launch instances]]. | ||
__TOC__ | __TOC__ | ||
Line 16: | Line 14: | ||
== Creating an Image == | == Creating an Image == | ||
+ | This section details how to create images from existing resources such as [[#From an Instance|instances]] and [[#From a Volume|volumes]]. If you are looking to create an image from some other source, see the [[#Upload an Image|Upload an Image]] section. | ||
− | + | === From an Instance === | |
+ | |||
+ | Snapshots in OpenStack can be used like images, so the simplest way to create an image from an instance is to create a snapshot: | ||
+ | |||
+ | # Shut Off the instance by selecting "<tt>Shut Off Instance</tt>" for the instance from the [https://redcloud.cac.cornell.edu/dashboard/project/instances/ <tt>Instances</tt> tab] | ||
+ | # Create a snapshot of the instance by selecting "<tt>Create Snapshot</tt>" for the instance | ||
+ | # You will have to give the snapshot a name (this will be the name of your image) | ||
+ | # Wait for the snapshot to finish being created, and it will show up on the [https://redcloud.cac.cornell.edu/dashboard/project/images <tt>Images</tt> tab] | ||
− | + | You can now [[OpenStack#Launch_an_Instance|launch new instances]] or create a [[Volumes|volume]] from the snapshot. | |
+ | Note: You should not take a snapshot of a file system that's mounted. You will lose all the info that's still in Linux's write cache. So if you want to take a snapshot of the root file system, the OS cannot be running. | ||
=== From a Volume === | === From a Volume === | ||
+ | Create an image from the volume: | ||
− | + | # Select "<tt>Upload Volume to Image</tt>" for the volume from the [https://redcloud.cac.cornell.edu/dashboard/project/volumes/ <tt>Volumes</tt> tab] | |
+ | # Give the image a name and select "<tt>Upload</tt>" | ||
+ | # Wait for the image to finish being created, and it will show up on the [https://redcloud.cac.cornell.edu/dashboard/project/images <tt>Images</tt> tab] | ||
+ | You can now [[OpenStack#Launch_an_Instance|launch new instances]] from the image. | ||
+ | |||
+ | If you have a volume snapshot that you would like to create an image from, create a volume from the snapshot, then follow the above steps. | ||
== Upload an Image == | == Upload an Image == | ||
Line 38: | Line 51: | ||
# '''Optional:''' Select "<tt>Yes</tt>" under Protected to ensure that the image cannot be changed or deleted accidentally (this setting can be changed later) | # '''Optional:''' Select "<tt>Yes</tt>" under Protected to ensure that the image cannot be changed or deleted accidentally (this setting can be changed later) | ||
# Select "<tt>Create Image</tt>" | # Select "<tt>Create Image</tt>" | ||
+ | |||
+ | == Delete an Image == | ||
+ | |||
+ | Users can delete images that were created in the current project using the Horizon web interface. | ||
+ | However, an image cannot be deleted if any volumes created from it still exist. | ||
+ | When an instance is created from an image, a volume is created from the image for that instance. | ||
+ | When an instance is deleted, its volume may remain and block the deletion of the image from which it was created. | ||
+ | The default Horizon behavior is to not delete such underlying volumes along with their owning instance, but this can be overridden during instance creation. | ||
+ | |||
+ | If your attempt to delete an image fails, check for existing instances that were created from it. | ||
+ | If you find such instances and want to delete them, first look at each instance's details and record the ID of its volume. | ||
+ | After deleting an instance, check the project's list of volumes to see if the instance's volume still exists and delete it if necessary. | ||
+ | A volume that was orphaned when its parent instance was deleted can still be identified by checking its detail page, where its source image (if any) will be listed. | ||
== Share an Image == | == Share an Image == | ||
− | + | {{:Share An Image In Openstack}} |
Latest revision as of 17:07, 7 May 2019
OpenStack Images can take several forms, but generally an image consists of a static copy of a virtual machine with an operating system with some amount of storage. Each project starts out with a few base Linux and Windows images from which instances can be created. Images can also be created or uploaded to OpenStack, and then used to launch instances.
Available Images
In OpenStack, there are several stock images from which you can easily launch new instances. Typically you will want to create an instance from one of these stock images. You can view the available images (once logged in) by going to the "Images" tab in the Web Interface.
You would only need to create/upload your own image if you are unhappy with the stock images available, or if you would like to make an image from one of your current instances (to easily launch new instances with the same software and data). Currently, we have images for:
Creating an Image
This section details how to create images from existing resources such as instances and volumes. If you are looking to create an image from some other source, see the Upload an Image section.
From an Instance
Snapshots in OpenStack can be used like images, so the simplest way to create an image from an instance is to create a snapshot:
- Shut Off the instance by selecting "Shut Off Instance" for the instance from the Instances tab
- Create a snapshot of the instance by selecting "Create Snapshot" for the instance
- You will have to give the snapshot a name (this will be the name of your image)
- Wait for the snapshot to finish being created, and it will show up on the Images tab
You can now launch new instances or create a volume from the snapshot.
Note: You should not take a snapshot of a file system that's mounted. You will lose all the info that's still in Linux's write cache. So if you want to take a snapshot of the root file system, the OS cannot be running.
From a Volume
Create an image from the volume:
- Select "Upload Volume to Image" for the volume from the Volumes tab
- Give the image a name and select "Upload"
- Wait for the image to finish being created, and it will show up on the Images tab
You can now launch new instances from the image.
If you have a volume snapshot that you would like to create an image from, create a volume from the snapshot, then follow the above steps.
Upload an Image
Images can be uploaded if you already have an image file that you would like to use. For example, if you are unsatisfied with the stock image options available on Red Cloud, you can Get Images from elsewhere. Images can be uploaded via the Web Interface:
- Go to the Images tab
- Select the "Create Image" option
- Give the image a name
- Select the file of the source image to upload
- Select "Raw" for the Format
- Optional: Select "Yes" under Protected to ensure that the image cannot be changed or deleted accidentally (this setting can be changed later)
- Select "Create Image"
Delete an Image
Users can delete images that were created in the current project using the Horizon web interface. However, an image cannot be deleted if any volumes created from it still exist. When an instance is created from an image, a volume is created from the image for that instance. When an instance is deleted, its volume may remain and block the deletion of the image from which it was created. The default Horizon behavior is to not delete such underlying volumes along with their owning instance, but this can be overridden during instance creation.
If your attempt to delete an image fails, check for existing instances that were created from it. If you find such instances and want to delete them, first look at each instance's details and record the ID of its volume. After deleting an instance, check the project's list of volumes to see if the instance's volume still exists and delete it if necessary. A volume that was orphaned when its parent instance was deleted can still be identified by checking its detail page, where its source image (if any) will be listed.
You can share an image from your project with a collaborator in a different project in OpenStack cloud so you can both launch instances using the same image. As the owner of the image, you can revoke the sharing privilege at any time. You can also use these methods to share an image with yourself in other projects, just think of yourself as the collaborator.
Prerequisites:
- Both you and your collaborator need to use the OpenStack CLI.
- You will need to set up the CLI to work with the project where the image to be shared is located.
- If you are sharing an image with yourself, you will need to download the RC File for both projects (the one you are sharing from and to).
- You will need to know the project name or ID of your collaborator.
1. Find the project ID of your collaborator first:
- The project ID is the string of the format
xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
composed of lowercase letters and numbers. The project name in the typical format will not work in the below commands. You will need to have sourced the RC File of the project where the image is located before running the OpenStack CLI command to get the project ID:
openstack project list
- and the first field of the output is the ID of your collaborator's project ID. If you know the name of your collaborator's project, you can find the ID by adding
| grep <collaborator's project name>
to the above command.
2. Find the ID of the image you want to share:
openstack image show <image name>
- Similar to project ID, this will be a long string of letters and numbers next to the name of your image. You will use the image ID, rather than the name, in the commands below.
3. Share the image with your collaborator's project:
openstack image set --shared <image ID> openstack image add project <image ID> <collaborator's project ID>
4. Verify the image is now shared:
openstack image member list <image ID>
- The status field should say
pending
until your collaborator accepts the image.
5. Give the ID of the shared image to your collaborator so they can follow the steps in the Accept a Shared Image section to add the image to their project. If you are sharing the image with yourself, you will need to source the RC File of the second project and then perform the acceptance yourself.
- Currently this action can only be performed by cloud administrators.
- This generally shouldn't be done unless creating something that is a public resource that is intended to be used with any project.
- Additionally, don't use such an image from a third party unless you trust the source.
openstack image set --public <image ID>
1. Get the ID of the shared image from the owner. Make sure the owner has performed the steps in the Share an Image section above, and source the RC File of your project. 2. Accept the shared image:
openstack image set --accept <image ID>
3. Verify the image is now available to your project:
openstack image list
- If the image is listed in the output, it should also appear in OpenStack web console (Horizon).
- An image's owner can see which projects have access to the image:
openstack image member list <image ID>
- The owner can unshare an image like this:
openstack image remove project <image ID> <project ID>