From 97eaa1f56fd32c168f98d45e1d5464f9ca851a58 Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Tue, 21 Feb 2012 13:21:31 -0800 Subject: [PATCH] Add support for ephemeral_gb to novaclient. * Fixes bug 932423 Change-Id: I57620db469f34aaf1ae61c6ef116a21ac9787e40 --- novaclient/v1_1/flavors.py | 10 +++++++++- novaclient/v1_1/shell.py | 11 ++++++++--- tests/v1_1/fakes.py | 6 ++++-- tests/v1_1/test_flavors.py | 20 ++++++++++++++++++++ tests/v1_1/test_shell.py | 3 ++- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/novaclient/v1_1/flavors.py b/novaclient/v1_1/flavors.py index 8092598b1..b4c71743a 100644 --- a/novaclient/v1_1/flavors.py +++ b/novaclient/v1_1/flavors.py @@ -13,6 +13,13 @@ class Flavor(base.Resource): def __repr__(self): return "" % self.name + @property + def ephemeral(self): + """ + Provide a user-friendly accessor to OS-FLV-EXT-DATA:ephemeral + """ + return self._info["OS-FLV-EXT-DATA:ephemeral"] + class FlavorManager(base.ManagerWithFind): """ @@ -50,7 +57,7 @@ class FlavorManager(base.ManagerWithFind): self._delete("/flavors/%s" % base.getid(flavor)) def create(self, name, ram, vcpus, disk, flavorid, - swap=0, rxtx_factor=1): + ephemeral=0, swap=0, rxtx_factor=1): """ Create (allocate) a floating ip for a tenant @@ -72,6 +79,7 @@ class FlavorManager(base.ManagerWithFind): "disk": int(disk), "id": int(flavorid), "swap": int(swap), + "OS-FLV-EXT-DATA:ephemeral": int(ephemeral), "rxtx_factor": int(rxtx_factor), } } diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 1177344d4..ac6475d02 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -221,7 +221,7 @@ def do_boot(cs, args): def _translate_flavor_keys(collection): - convert = [('ram', 'memory_mb'), ('disk', 'local_gb')] + convert = [('ram', 'memory_mb')] for item in collection: keys = item.__dict__.keys() for from_key, to_key in convert: @@ -235,8 +235,9 @@ def _print_flavor_list(flavors): 'ID', 'Name', 'Memory_MB', + 'Disk', + 'Ephemeral', 'Swap', - 'Local_GB', 'VCPUs', 'RXTX_Factor']) @@ -267,6 +268,10 @@ def do_flavor_delete(cs, args): @utils.arg('disk', metavar='', help="Disk size in GB") +@utils.arg('--ephemeral', + metavar='', + help="Ephemeral space size in GB (default 0)", + default=0) @utils.arg('vcpus', metavar='', help="Number of vcpus") @@ -281,7 +286,7 @@ def do_flavor_delete(cs, args): def do_flavor_create(cs, args): """Create a new flavor""" f = cs.flavors.create(args.name, args.ram, args.vcpus, args.disk, args.id, - args.swap, args.rxtx_factor) + args.ephemeral, args.swap, args.rxtx_factor) _print_flavor_list([f]) diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py index c2880018e..86864dc6c 100644 --- a/tests/v1_1/fakes.py +++ b/tests/v1_1/fakes.py @@ -342,8 +342,10 @@ class FakeHTTPClient(base_client.HTTPClient): def get_flavors_detail(self, **kw): return (200, {'flavors': [ - {'id': 1, 'name': '256 MB Server', 'ram': 256, 'disk': 10}, - {'id': 2, 'name': '512 MB Server', 'ram': 512, 'disk': 20} + {'id': 1, 'name': '256 MB Server', 'ram': 256, 'disk': 10, + 'OS-FLV-EXT-DATA:ephemeral': 10}, + {'id': 2, 'name': '512 MB Server', 'ram': 512, 'disk': 20, + 'OS-FLV-EXT-DATA:ephemeral': 20} ]}) def get_flavors_1(self, **kw): diff --git a/tests/v1_1/test_flavors.py b/tests/v1_1/test_flavors.py index 1f9d5719f..7efa674ea 100644 --- a/tests/v1_1/test_flavors.py +++ b/tests/v1_1/test_flavors.py @@ -37,6 +37,25 @@ class FlavorsTest(utils.TestCase): self.assertRaises(exceptions.NotFound, cs.flavors.find, disk=12345) def test_create(self): + f = cs.flavors.create("flavorcreate", 512, 1, 10, 1234, ephemeral=10) + + body = { + "flavor": { + "name": "flavorcreate", + "ram": 512, + "vcpus": 1, + "disk": 10, + "OS-FLV-EXT-DATA:ephemeral": 10, + "id": 1234, + "swap": 0, + "rxtx_factor": 1, + } + } + + cs.assert_called('POST', '/flavors', body) + self.assertTrue(isinstance(f, flavors.Flavor)) + + def test_create_ephemeral_defaults_to_zero(self): f = cs.flavors.create("flavorcreate", 512, 1, 10, 1234) body = { @@ -45,6 +64,7 @@ class FlavorsTest(utils.TestCase): "ram": 512, "vcpus": 1, "disk": 10, + "OS-FLV-EXT-DATA:ephemeral": 0, "id": 1234, "swap": 0, "rxtx_factor": 1, diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py index 311234143..fe4301b22 100644 --- a/tests/v1_1/test_shell.py +++ b/tests/v1_1/test_shell.py @@ -306,7 +306,7 @@ class ShellTest(utils.TestCase): def test_flavor_create(self): self.run_command("flavor-create flavorcreate " - "1234 512 10 1 --swap 1024") + "1234 512 10 1 --swap 1024 --ephemeral 10") body = { "flavor": { @@ -314,6 +314,7 @@ class ShellTest(utils.TestCase): "ram": 512, "vcpus": 1, "disk": 10, + "OS-FLV-EXT-DATA:ephemeral": 10, "id": 1234, "swap": 1024, "rxtx_factor": 1,