Adding metadata to a host aggregate

The power of host aggregates comes from the ability to use them to logically group hosts based on their properties. This can be used, for example, to enable load balancing, enforce physical separation, or keep instances that are insecure from being scheduled into a secured environment. We will show this by matching the metadata of a host aggregate with that of an instance flavor.

Getting ready

To add metadata to a host aggregate, you will need the following information:

  • The openstack command-line client
  • The openrc file containing appropriate credentials
  • The name or ID of the aggregate
  • The metadata property to add

In our example, these values will be the following:

  • Host aggregate: cookbook-ssd-hosts
  • Metadata: ssd=true

How to do it…

To add metadata to host aggregate, use the following process:

  1. Show the existing metadata associated with an aggregate:
    openstack aggregate show cookbook-ssd-hosts
    

    This will bring back an output like the following. Note that the properties field is blank if no metadata is associated yet:

    How to do it…
  2. Add the metadata with the following command:
    openstack aggregate set --property ssd=true cookbook-ssd-hosts
    

    Tip

    This command displays no output when successful.

  3. Now confirm the addition of the metadata with the following command again:
    openstack aggregate show cookbook-ssd-hosts
    

    You will see that the properties field has been updated with this information:

    How to do it…
  4. Now that we have set the metadata of our host aggregate, we can now associate this with a flavor so that when that flavor is specified by a user during the boot process, Nova will match the property to only the hosts within that host aggregate group. For example, we may have a flavor that is called cookbook.ssd that sets the expectation, which when a user select, the host will have SSDs available. This is the power of host aggregates. In the example here, compute-02 has SSDs available as we have specified this in the host aggregate named cookbook-ssd-hosts. To take advantage of this, let's create a new flavor called cookbook.ssd with the ssd=true property:
    openstack flavor create
        --vcpus 1
        --ram 512
        --disk 5
        --public
        cookbook.ssd
    

    Tip

    Creating flavors is described in more detail in the Creating a flavor recipe.

  5. We now need to set the flavor extra specs, so that on choosing the flavor it is associated with the relevant host aggregate. For this, we use the nova command:
    nova flavor-key cookbook.ssd set ssd=true
    

    Tip

    You may need to use the UUID of the flavor instead of the name. If so, list the flavors with the following command and not the UUID of the cookbook.ssd flavor:

    openstack flavor list
    
  6. Now when a user selects the cookbook.ssd flavor, unknown to them, the instance will be restricted to the hosts within the host aggregate group that has this key/value pair set.

How it works…

Metadata is specified as a key/value pairing, which is then associated with a host aggregate in the Nova database. These key/value pairs are arbitrary and can be defined to match a given environment. A host aggregate can have any number of key/value pairs stored; however, this may adversely affect instance scheduling because of potentially conflicting or confusing key/value pairs.

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

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