Merge "Add support for ephemeral_gb to novaclient."
This commit is contained in:
commit
39bfd0585b
@ -13,6 +13,13 @@ class Flavor(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<Flavor: %s>" % 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),
|
||||
}
|
||||
}
|
||||
|
@ -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='<disk>',
|
||||
help="Disk size in GB")
|
||||
@utils.arg('--ephemeral',
|
||||
metavar='<ephemeral>',
|
||||
help="Ephemeral space size in GB (default 0)",
|
||||
default=0)
|
||||
@utils.arg('vcpus',
|
||||
metavar='<vcpus>',
|
||||
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])
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user