How does all this look in practice? We will start with a simple
key-value pairs, and see how an instance retrieves metadata.
We will then become a bit more sophisticated and try out user-data,
and finally we will have a look at the config drive.
We have already launched a few servers, the next launch will have a
new option, property. This option allows me to add key-value pairs to the instance.
Let me reiterate that Nova does not understand the meaning of those
key-value pairs, it's the instance and the instance only that interprets them.
So in this case, presumably the instance runs an application that
consists of several server processes, and this key-value pair might
configure the number of those processes.
Note that the property is also shown in the instance details.
It takes a moment to build the instance, and in the meantime,
I will configure its firewall and floating IP.
You have seen me do that already, so I think we can speed that up a little bit.
Yeah, that looks good. SSH using the key, whoops, the same mistake as
before, I forgot that I have already used this floating IP for
different instances with different host keys.
So let me remove the hosts file, and now it works.
So how does the instance find out what its metadata is?
It accesses the metadata API, that is a concept borrowed from Amazon Web Services.
Oh, I think I mistyped that, the correct URL is 254, not 245.
And here we go. This is the Amazon Web Services metadata API.
Let's look at the latest version of this API, it contains an entry
meta-data, and we can navigate down. So these are all the metadata
items defined in Amazon. We could look at one of those, for example,
the floating IP, so the instance using the metadata is able to see its
own float IP. But there is also an OpenStack-specific metadata API,
and the key-value pairs are in there. I will also check the latest
version of the API, and you can see here a meta_data.json file.
Let me download it, this is JavaScript Object Notation, known as JSON.
It's a format that is commonly used in clouds and other environments,
and it allows storing and exchanging data.
The metadata here is expressed as a so called JSON dictionary,
and that is a set of key-value pairs. And our key-value pair is here under meta.
You also see here the SSH keys, they also form part of the metadata,
but there is more. Let's say that I want to perform some action on
the instance when it starts up. I could, for example, write a little Shell script.
This script here just creates a file containing a silly message,
but you could think of perhaps more sophisticated activities.
Let's throw in the date, so this is our customization Shell script,
and I will now launch an instance that executes this script when it starts up.
For that, I need to add an option --user-data.
By the way, the property option can be repeated as much as you like,
but the user-data option, there can only be one.
So that instance seems to be running, again, I will make it accessible
by adding floating IP, well before I do that, I would like to remove
the old instance. So let's clean that up a little bit.
Both instances have the same name, I need to use the ID to delete the old instance.
It's the one that has a floating IP already.
Okay, so the security group and the floating IP.
So let's see whether my user data was successful, here we go.
Obviously the file was created, and it contains our silly message.
But we can do even better.