How do you know what images are available for building new servers?
You can list available server images by sending your request to the /images URL using the GET method. The following example shows how it is done using the curl command:
$ curl -v -H "X-Auth-Token:999888777666" http://localhost:8774/v1.1/openstack/images
As you can see, you must include the X-Auth-Token header with a valid token otherwise the OpenStack Compute API will return the 401 Unauthorized error.
When all goes well, you will get a lump of JSON that looks a bit like this:
{"images": [{"id": 3, "links": [{"href": "http://localhost:8774/v1.1/openstack/images/3", "rel": "self"}, {"href": "http://localhost:8774/openstack/images/3", "rel": "bookmark"}], "name": "ubuntu-11.04-server"}, {"id": 2, "links": [{"href": "http://localhost:8774/v1.1/openstack/images/2", "rel": "self"}, {"href": "http://localhost:8774/openstack/images/2", "rel": "bookmark"}], "name": "ubuntu-11.04-initrd"}, {"id": 1, "links": [{"href": "http://localhost:8774/v1.1/openstack/images/1", "rel": "self"}, {"href": "http://localhost:8774/openstack/images/1", "rel": "bookmark"}], "name": "ubuntu-11.04-kernel"}]}
Here is a version that is easier to read:
{
"images": [
{
"id": 3,
"links": [
{
"href": "http://localhost:8774/v1.1/openstack/images/3",
"rel": "self"
},
{
"href": "http://localhost:8774/openstack/images/3",
"rel": "bookmark"
}
],
"name": "ubuntu-11.04-server"
},
{
"id": 2,
"links": [
{
"href": "http://localhost:8774/v1.1/openstack/images/2",
"rel": "self"
},
{
"href": "http://localhost:8774/openstack/images/2",
"rel": "bookmark"
}
],
"name": "ubuntu-11.04-initrd"
},
{
"id": 1,
"links": [
{
"href": "http://localhost:8774/v1.1/openstack/images/1",
"rel": "self"
},
{
"href": "http://localhost:8774/openstack/images/1",
"rel": "bookmark"
}
],
"name": "ubuntu-11.04-kernel"
}
]
}
Each item on the images list represents a single server image. It is a dictionary with three keys:
id — the numeric ID of the server image.
links — the list of the URLs of the locations where you can find the image.
name — a descriptive name of the image.
Here's how one server image is represented in that response:
{
"id": 1,
"links": [
{
"href": "http://localhost:8774/v1.1/openstack/images/1",
"rel": "self"
},
{
"href": "http://localhost:8774/openstack/images/1",
"rel": "bookmark"
}
],
"name": "ubuntu-11.04-kernel"
}
Please note that this is not a complete set of information about server images that you can extract using the OpenStack Compute API, but it is enough to create a server unless you are trying to use a freshly created image, which hasn't been activated yet. For more information about handling such cases and how to work with server images in general, read the Images chapter later in this book.
One question that programmers sometimes ask is which kind of server image identification is more reliable to rely upon, the server image id or its name? Personally, I rely on the names of server images, assuming that should some administrative mishap happen and the server image store got reorganized, names are less likely to be altered than the numeric IDs.
Another argument for using names to identify server images is handling errors and ensuring operational continuity. If you want to make sure that the region or the provider you want to boot your server with has the right server image, you will want to use a unique name instead of a numeric ID, which can differ between OpenStack regions and providers. As always, check and double-check these things in your code. The best strategy is to use automation to create and save same server images in each region and with each OpenStack provider you plan to use. This is necessary, because you cannot transfer server images between OpenStack regions or providers. The automation tool of choice for Python programmers is Fabric, which you can download from the following site:
