Add support for injecting extra-specs into flavors

Building on the ability to create flavors to describe the hardware
your cloud has available, we need the ability to inject extra_specs
into the flavors when they are created to save operators having to
do so by hand.

Change-Id: Ib1339d0dd60c5fb4669bb10c5543e5155e86fe1f
This commit is contained in:
Steve Kowalik 2014-10-14 17:13:17 +11:00
parent e90348f862
commit 3b07b96a06
3 changed files with 31 additions and 0 deletions

View File

@ -245,3 +245,19 @@ Where /tmp/one-flavor contains::
"cpu": "1"
}
]
The JSON file can also contain an 'extra_specs' parameter, which is a JSON
object describing the key-value pairs to add into the flavor metadata::
[
{
"name": "controller",
"memory": "2048",
"disk": "30",
"arch": "i386",
"cpu": "1",
"extra_specs": {
"key": "value"
}
}
]

View File

@ -74,4 +74,6 @@ def _create_flavor(client, flavor_desc):
flavor_metadata = {'cpu_arch': flavor_desc['arch'],
'%s_kernel_id' % bm_prefix: flavor_desc['kernel'],
'%s_ramdisk_id' % bm_prefix: flavor_desc['ramdisk']}
if flavor_desc.get('extra_specs'):
flavor_metadata.update(flavor_desc['extra_specs'])
flavor.set_keys(metadata=flavor_metadata)

View File

@ -91,3 +91,16 @@ class FlavorsTest(base.TestCase):
'baremetal:deploy_ramdisk_id': 'bbb'}
client.flavors.create.return_value.set_keys.assert_called_once_with(
metadata=metadata)
def test_create_flavor_with_extra_spec(self):
flavor = {'cpu': '1', 'memory': '2048', 'disk': '30', 'arch': 'i386',
'kernel': 'aaa', 'ramdisk': 'bbb', 'name': 'baremetal',
'ephemeral': None, 'extra_specs': {'key': 'value'}}
client = mock.MagicMock()
flavors._create_flavor(client, flavor)
client.flavors.create.assert_called_once_with(
'baremetal', '2048', '1', '30', None, ephemeral=None)
metadata = {'cpu_arch': 'i386', 'baremetal:deploy_kernel_id': 'aaa',
'baremetal:deploy_ramdisk_id': 'bbb', 'key': 'value'}
client.flavors.create.return_value.set_keys.assert_called_once_with(
metadata=metadata)