Merge "Cleanups for create-flavor"
This commit is contained in:
commit
f124d50024
@ -58,18 +58,20 @@ class FlavorManageController(wsgi.Controller):
|
|||||||
vals = body['flavor']
|
vals = body['flavor']
|
||||||
name = vals['name']
|
name = vals['name']
|
||||||
flavorid = vals.get('id')
|
flavorid = vals.get('id')
|
||||||
memory_mb = vals.get('ram')
|
memory = vals.get('ram')
|
||||||
vcpus = vals.get('vcpus')
|
vcpus = vals.get('vcpus')
|
||||||
root_gb = vals.get('disk')
|
root_gb = vals.get('disk')
|
||||||
ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral')
|
ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral', 0)
|
||||||
swap = vals.get('swap')
|
swap = vals.get('swap', 0)
|
||||||
rxtx_factor = vals.get('rxtx_factor')
|
rxtx_factor = vals.get('rxtx_factor', 1.0)
|
||||||
is_public = vals.get('os-flavor-access:is_public', True)
|
is_public = vals.get('os-flavor-access:is_public', True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
flavor = flavors.create(name, memory_mb, vcpus,
|
flavor = flavors.create(name, memory, vcpus, root_gb,
|
||||||
root_gb, ephemeral_gb, flavorid,
|
ephemeral_gb=ephemeral_gb,
|
||||||
swap, rxtx_factor, is_public)
|
flavorid=flavorid, swap=swap,
|
||||||
|
rxtx_factor=rxtx_factor,
|
||||||
|
is_public=is_public)
|
||||||
req.cache_db_flavor(flavor)
|
req.cache_db_flavor(flavor)
|
||||||
except (exception.InstanceTypeExists,
|
except (exception.InstanceTypeExists,
|
||||||
exception.InstanceTypeIdExists) as err:
|
exception.InstanceTypeIdExists) as err:
|
||||||
|
@ -887,8 +887,9 @@ class InstanceTypeCommands(object):
|
|||||||
"""Creates instance types / flavors."""
|
"""Creates instance types / flavors."""
|
||||||
try:
|
try:
|
||||||
flavors.create(name, memory, vcpus, root_gb,
|
flavors.create(name, memory, vcpus, root_gb,
|
||||||
ephemeral_gb, flavorid, swap, rxtx_factor,
|
ephemeral_gb=ephemeral_gb, flavorid=flavorid,
|
||||||
is_public)
|
swap=swap, rxtx_factor=rxtx_factor,
|
||||||
|
is_public=is_public)
|
||||||
except exception.InvalidInput as e:
|
except exception.InvalidInput as e:
|
||||||
print _("Must supply valid parameters to create instance_type")
|
print _("Must supply valid parameters to create instance_type")
|
||||||
print e
|
print e
|
||||||
|
@ -65,18 +65,11 @@ system_metadata_instance_type_props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None,
|
def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
|
||||||
swap=None, rxtx_factor=None, is_public=True):
|
swap=0, rxtx_factor=1.0, is_public=True):
|
||||||
"""Creates instance types."""
|
"""Creates instance types."""
|
||||||
|
if not flavorid:
|
||||||
if flavorid is None or flavorid == '':
|
|
||||||
flavorid = uuid.uuid4()
|
flavorid = uuid.uuid4()
|
||||||
if swap is None:
|
|
||||||
swap = 0
|
|
||||||
if rxtx_factor is None:
|
|
||||||
rxtx_factor = 1.0
|
|
||||||
if ephemeral_gb is None:
|
|
||||||
ephemeral_gb = 0
|
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'memory_mb': memory,
|
'memory_mb': memory,
|
||||||
@ -96,13 +89,23 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None,
|
|||||||
msg = _("names can only contain [a-zA-Z0-9_.- ]")
|
msg = _("names can only contain [a-zA-Z0-9_.- ]")
|
||||||
raise exception.InvalidInput(reason=msg)
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
# ensure some attributes are integers and greater than or equal to 0
|
# Some attributes are positive ( > 0) integers
|
||||||
for option in ['memory_mb', 'vcpus', 'root_gb', 'ephemeral_gb', 'swap']:
|
for option in ['memory_mb', 'vcpus']:
|
||||||
|
try:
|
||||||
|
kwargs[option] = int(kwargs[option])
|
||||||
|
assert kwargs[option] > 0
|
||||||
|
except (ValueError, AssertionError):
|
||||||
|
msg = _("'%s' argument must be greater than 0") % option
|
||||||
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
|
# Some attributes are non-negative ( >= 0) integers
|
||||||
|
for option in ['root_gb', 'ephemeral_gb', 'swap']:
|
||||||
try:
|
try:
|
||||||
kwargs[option] = int(kwargs[option])
|
kwargs[option] = int(kwargs[option])
|
||||||
assert kwargs[option] >= 0
|
assert kwargs[option] >= 0
|
||||||
except (ValueError, AssertionError):
|
except (ValueError, AssertionError):
|
||||||
msg = _("'%s' argument must be a positive integer") % option
|
msg = _("'%s' argument must be greater than or equal"
|
||||||
|
" to 0") % option
|
||||||
raise exception.InvalidInput(reason=msg)
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
# rxtx_factor should be a positive float
|
# rxtx_factor should be a positive float
|
||||||
@ -113,14 +116,6 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None,
|
|||||||
msg = _("'rxtx_factor' argument must be a positive float")
|
msg = _("'rxtx_factor' argument must be a positive float")
|
||||||
raise exception.InvalidInput(reason=msg)
|
raise exception.InvalidInput(reason=msg)
|
||||||
|
|
||||||
# some value are required to be nonzero, not just positive
|
|
||||||
for option in ['memory_mb', 'vcpus']:
|
|
||||||
try:
|
|
||||||
assert kwargs[option] > 0
|
|
||||||
except AssertionError:
|
|
||||||
msg = _("'%s' argument must be greater than 0") % option
|
|
||||||
raise exception.InvalidInput(reason=msg)
|
|
||||||
|
|
||||||
kwargs['name'] = name
|
kwargs['name'] = name
|
||||||
# NOTE(vish): Internally, flavorid is stored as a string but it comes
|
# NOTE(vish): Internally, flavorid is stored as a string but it comes
|
||||||
# in through json as an integer, so we convert it here.
|
# in through json as an integer, so we convert it here.
|
||||||
|
@ -6050,11 +6050,8 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
|
|
||||||
name = 'test_resize_new_flavor'
|
name = 'test_resize_new_flavor'
|
||||||
flavorid = 11
|
flavorid = 11
|
||||||
memory_mb = 128
|
flavors.create(name, 128, 1, 0, ephemeral_gb=0, flavorid=flavorid,
|
||||||
root_gb = 0
|
swap=0, rxtx_factor=1.0, is_public=True)
|
||||||
vcpus = 1
|
|
||||||
flavors.create(name, memory_mb, vcpus, root_gb, 0,
|
|
||||||
flavorid, 0, 1.0, True)
|
|
||||||
flavors.destroy(name)
|
flavors.destroy(name)
|
||||||
self.assertRaises(exception.FlavorNotFound, self.compute_api.resize,
|
self.assertRaises(exception.FlavorNotFound, self.compute_api.resize,
|
||||||
self.context, instance, flavorid)
|
self.context, instance, flavorid)
|
||||||
@ -6082,11 +6079,8 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
|
|
||||||
name = 'test_resize_with_big_mem'
|
name = 'test_resize_with_big_mem'
|
||||||
flavorid = 11
|
flavorid = 11
|
||||||
memory_mb = 102400
|
flavors.create(name, 102400, 1, 0, ephemeral_gb=0, flavorid=flavorid,
|
||||||
root_gb = 0
|
swap=0, rxtx_factor=1.0, is_public=True)
|
||||||
vcpus = 1
|
|
||||||
flavors.create(name, memory_mb, vcpus, root_gb, 0,
|
|
||||||
flavorid, 0, 1.0, True)
|
|
||||||
self.assertRaises(exception.TooManyInstances, self.compute_api.resize,
|
self.assertRaises(exception.TooManyInstances, self.compute_api.resize,
|
||||||
self.context, instance, flavorid)
|
self.context, instance, flavorid)
|
||||||
|
|
||||||
@ -6096,11 +6090,9 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
def test_resize_revert_deleted_flavor_fails(self):
|
def test_resize_revert_deleted_flavor_fails(self):
|
||||||
orig_name = 'test_resize_revert_orig_flavor'
|
orig_name = 'test_resize_revert_orig_flavor'
|
||||||
orig_flavorid = 11
|
orig_flavorid = 11
|
||||||
memory_mb = 128
|
flavors.create(orig_name, 128, 1, 0, ephemeral_gb=0,
|
||||||
root_gb = 0
|
flavorid=orig_flavorid, swap=0, rxtx_factor=1.0,
|
||||||
vcpus = 1
|
is_public=True)
|
||||||
flavors.create(orig_name, memory_mb, vcpus, root_gb, 0,
|
|
||||||
orig_flavorid, 0, 1.0, True)
|
|
||||||
|
|
||||||
instance = self._create_fake_instance(type_name=orig_name)
|
instance = self._create_fake_instance(type_name=orig_name)
|
||||||
instance = db.instance_get_by_uuid(self.context, instance['uuid'])
|
instance = db.instance_get_by_uuid(self.context, instance['uuid'])
|
||||||
|
Loading…
Reference in New Issue
Block a user