示例#1
0
def create(name,
           memory,
           vcpus,
           local_gb,
           flavorid,
           swap=0,
           rxtx_quota=0,
           rxtx_cap=0):
    """Creates instance types / flavors
       arguments: name memory vcpus local_gb flavorid swap rxtx_quota rxtx_cap
    """
    for option in [memory, vcpus, local_gb, flavorid]:
        try:
            int(option)
        except ValueError:
            raise exception.InvalidInputException(
                _("create arguments must be positive integers"))
    if (int(memory) <= 0) or (int(vcpus) <= 0) or (int(local_gb) < 0):
        raise exception.InvalidInputException(
            _("create arguments must be positive integers"))

    try:
        db.instance_type_create(
            context.get_admin_context(),
            dict(name=name,
                 memory_mb=memory,
                 vcpus=vcpus,
                 local_gb=local_gb,
                 flavorid=flavorid,
                 swap=swap,
                 rxtx_quota=rxtx_quota,
                 rxtx_cap=rxtx_cap))
    except exception.DBError, e:
        LOG.exception(_('DB error: %s' % e))
        raise exception.ApiError(_("Cannot create instance type: %s" % name))
示例#2
0
def create(name, memory, vcpus, local_gb, flavorid, swap=0,
           rxtx_quota=0, rxtx_cap=0):
    """Creates instance types / flavors
       arguments: name memory vcpus local_gb flavorid swap rxtx_quota rxtx_cap
    """
    for option in [memory, vcpus, local_gb, flavorid]:
        try:
            int(option)
        except ValueError:
            raise exception.InvalidInputException(
                    _("create arguments must be positive integers"))
    if (int(memory) <= 0) or (int(vcpus) <= 0) or (int(local_gb) < 0):
        raise exception.InvalidInputException(
                _("create arguments must be positive integers"))

    try:
        db.instance_type_create(
                context.get_admin_context(),
                dict(name=name,
                    memory_mb=memory,
                    vcpus=vcpus,
                    local_gb=local_gb,
                    flavorid=flavorid,
                    swap=swap,
                    rxtx_quota=rxtx_quota,
                    rxtx_cap=rxtx_cap))
    except exception.DBError, e:
        LOG.exception(_('DB error: %s' % e))
        raise exception.ApiError(_("Cannot create instance type: %s" % name))
示例#3
0
def create(name,
           memory,
           vcpus,
           local_gb,
           flavorid,
           swap=0,
           rxtx_quota=0,
           rxtx_cap=0):
    """Creates instance types."""
    for option in [memory, vcpus, local_gb, flavorid]:
        try:
            int(option)
        except ValueError:
            raise exception.InvalidInput(reason=_("create arguments must "
                                                  "be positive integers"))
    if (int(memory) <= 0) or (int(vcpus) <= 0) or (int(local_gb) < 0):
        raise exception.InvalidInput(reason=_("create arguments must "
                                              "be positive integers"))

    try:
        db.instance_type_create(
            context.get_admin_context(),
            dict(name=name,
                 memory_mb=memory,
                 vcpus=vcpus,
                 local_gb=local_gb,
                 flavorid=flavorid,
                 swap=swap,
                 rxtx_quota=rxtx_quota,
                 rxtx_cap=rxtx_cap))
    except exception.DBError, e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.ApiError(
            _("Cannot create instance_type with "
              "name %(name)s and flavorid %(flavorid)s") % locals())
示例#4
0
def create(name, memory, vcpus, local_gb, flavorid, swap=0, rxtx_quota=0, rxtx_cap=0):
    """Creates instance types."""
    for option in [memory, vcpus, local_gb, flavorid]:
        try:
            int(option)
        except ValueError:
            raise exception.InvalidInput(reason=_("create arguments must " "be positive integers"))
    if (int(memory) <= 0) or (int(vcpus) <= 0) or (int(local_gb) < 0):
        raise exception.InvalidInput(reason=_("create arguments must " "be positive integers"))

    try:
        db.instance_type_create(
            context.get_admin_context(),
            dict(
                name=name,
                memory_mb=memory,
                vcpus=vcpus,
                local_gb=local_gb,
                flavorid=flavorid,
                swap=swap,
                rxtx_quota=rxtx_quota,
                rxtx_cap=rxtx_cap,
            ),
        )
    except exception.DBError, e:
        LOG.exception(_("DB error: %s") % e)
        raise exception.ApiError(
            _("Cannot create instance_type with " "name %(name)s and flavorid %(flavorid)s") % locals()
        )
示例#5
0
def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None,
           swap=None, rxtx_factor=None, is_public=True):
    """Creates instance types."""

    if flavorid is None:
        flavorid = utils.gen_uuid()
    if swap is None:
        swap = 0
    if rxtx_factor is None:
        rxtx_factor = 1
    if ephemeral_gb is None:
        ephemeral_gb = 0

    kwargs = {
        'memory_mb': memory,
        'vcpus': vcpus,
        'root_gb': root_gb,
        'ephemeral_gb': ephemeral_gb,
        'swap': swap,
        'rxtx_factor': rxtx_factor,
    }

    # ensure name does not contain any special characters
    invalid_name = INVALID_NAME_REGEX.search(name)
    if invalid_name:
        msg = _("names can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

    # ensure some attributes are integers and greater than or equal to 0
    for option in kwargs:
        try:
            kwargs[option] = int(kwargs[option])
            assert kwargs[option] >= 0
        except (ValueError, AssertionError):
            msg = _("create arguments must be positive integers")
            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 = _("create arguments must be positive integers")
            raise exception.InvalidInput(reason=msg)

    kwargs['name'] = name
    # NOTE(vish): Internally, flavorid is stored as a string but it comes
    #             in through json as an integer, so we convert it here.
    kwargs['flavorid'] = unicode(flavorid)

    # ensure is_public attribute is boolean
    kwargs['is_public'] = utils.bool_from_str(is_public)

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except exception.DBError, e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.InstanceTypeCreateFailed()
示例#6
0
def create(name,
           memory,
           vcpus,
           root_gb,
           ephemeral_gb,
           flavorid,
           swap=None,
           rxtx_factor=None):
    """Creates instance types."""

    if swap is None:
        swap = 0
    if rxtx_factor is None:
        rxtx_factor = 1

    kwargs = {
        'memory_mb': memory,
        'vcpus': vcpus,
        'root_gb': root_gb,
        'ephemeral_gb': ephemeral_gb,
        'swap': swap,
        'rxtx_factor': rxtx_factor,
    }

    # ensure name does not contain any special characters
    invalid_name = INVALID_NAME_REGEX.search(name)
    if invalid_name:
        msg = _("names can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

    # ensure some attributes are integers and greater than or equal to 0
    for option in kwargs:
        try:
            kwargs[option] = int(kwargs[option])
            assert kwargs[option] >= 0
        except (ValueError, AssertionError):
            msg = _("create arguments must be positive integers")
            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 = _("create arguments must be positive integers")
            raise exception.InvalidInput(reason=msg)

    kwargs['name'] = name
    # NOTE(vish): Internally, flavorid is stored as a string but it comes
    #             in through json as an integer, so we convert it here.
    kwargs['flavorid'] = unicode(flavorid)

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except exception.DBError, e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.InstanceTypeCreateFailed()
示例#7
0
    def setUp(self):
        super(InstanceTypeCommandsTestCase, self).setUp()

        values = dict(name="test.small", memory_mb=220, vcpus=1, root_gb=16, ephemeral_gb=32, flavorid=105)
        ref = db.instance_type_create(context.get_admin_context(), values)
        self.instance_type_name = ref["name"]
        self.instance_type_id = ref["id"]
        self.instance_type_flavorid = ref["flavorid"]
        self.set_key = nova_manage.InstanceTypeCommands().set_key
        self.unset_key = nova_manage.InstanceTypeCommands().unset_key
示例#8
0
def create(name,
           memory,
           vcpus,
           root_gb,
           ephemeral_gb,
           flavorid,
           swap=None,
           rxtx_factor=None):
    """Creates instance types."""

    if swap is None:
        swap = 0
    if rxtx_factor is None:
        rxtx_factor = 1

    kwargs = {
        'memory_mb': memory,
        'vcpus': vcpus,
        'root_gb': root_gb,
        'ephemeral_gb': ephemeral_gb,
        'swap': swap,
        'rxtx_factor': rxtx_factor,
    }

    # ensure some attributes are integers and greater than or equal to 0
    for option in kwargs:
        try:
            kwargs[option] = int(kwargs[option])
            assert kwargs[option] >= 0
        except (ValueError, AssertionError):
            msg = _("create arguments must be positive integers")
            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 = _("create arguments must be positive integers")
            raise exception.InvalidInput(reason=msg)

    kwargs['name'] = name
    kwargs['flavorid'] = flavorid

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except exception.DBError, e:
        LOG.exception(_('DB error: %s') % e)
        msg = _("Cannot create instance_type with name %(name)s and "
                "flavorid %(flavorid)s") % locals()
        raise exception.ApiError(msg)
示例#9
0
    def _create_disabled_instance_type(self):
        inst_types = db.instance_type_get_all(self.admin_context)

        inst_type = inst_types[0]

        del inst_type['id']
        inst_type['name'] += '.disabled'
        inst_type['flavorid'] = unicode(
            max([int(flavor['flavorid']) for flavor in inst_types]) + 1)
        inst_type['disabled'] = True

        disabled_type = db.instance_type_create(self.admin_context, inst_type)

        return disabled_type
示例#10
0
 def _create_instance_type(self, params={}):
     """Create a test instance"""
     context = self.context.elevated()
     inst = {}
     inst['name'] = 'm1.small'
     inst['memory_mb'] = '1024'
     inst['vcpus'] = '1'
     inst['local_gb'] = '20'
     inst['flavorid'] = '1'
     inst['swap'] = '2048'
     inst['rxtx_quota'] = 100
     inst['rxtx_cap'] = 200
     inst.update(params)
     return db.instance_type_create(context, inst)['id']
示例#11
0
 def _create_instance_type(self, params={}):
     """Create a test instance"""
     context = self.context.elevated()
     inst = {}
     inst['name'] = 'm1.small'
     inst['memory_mb'] = '1024'
     inst['vcpus'] = '1'
     inst['local_gb'] = '20'
     inst['flavorid'] = '1'
     inst['swap'] = '2048'
     inst['rxtx_quota'] = 100
     inst['rxtx_cap'] = 200
     inst.update(params)
     return db.instance_type_create(context, inst)['id']
示例#12
0
def create(name,
           memory,
           vcpus,
           root_gb,
           ephemeral_gb,
           flavorid,
           swap=None,
           rxtx_factor=None):
    """Creates instance types."""

    if swap is None:
        swap = 0
    if rxtx_factor is None:
        rxtx_factor = 1

    kwargs = {
        'memory_mb': memory,
        'vcpus': vcpus,
        'root_gb': root_gb,
        'ephemeral_gb': ephemeral_gb,
        'swap': swap,
        'rxtx_factor': rxtx_factor,
    }

    # ensure some attributes are integers and greater than or equal to 0
    for option in kwargs:
        try:
            kwargs[option] = int(kwargs[option])
            assert kwargs[option] >= 0
        except (ValueError, AssertionError):
            msg = _("create arguments must be positive integers")
            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 = _("create arguments must be positive integers")
            raise exception.InvalidInput(reason=msg)

    kwargs['name'] = name
    kwargs['flavorid'] = flavorid

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except exception.DBError, e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.InstanceTypeCreateFailed()
示例#13
0
    def setUp(self):
        super(InstanceTypeCommandsTestCase, self).setUp()

        values = dict(name="test.small",
                      memory_mb=220,
                      vcpus=1,
                      root_gb=16,
                      ephemeral_gb=32,
                      flavorid=105)
        ref = db.instance_type_create(context.get_admin_context(), values)
        self.instance_type_name = ref["name"]
        self.instance_type_id = ref["id"]
        self.instance_type_flavorid = ref["flavorid"]
        self.set_key = manage.InstanceTypeCommands().set_key
        self.unset_key = manage.InstanceTypeCommands().unset_key
示例#14
0
    def _create_disabled_instance_type(self):
        inst_types = db.instance_type_get_all(self.admin_context)

        inst_type = inst_types[0]

        del inst_type['id']
        inst_type['name'] += '.disabled'
        inst_type['flavorid'] = unicode(max(
                [int(flavor['flavorid']) for flavor in inst_types]) + 1)
        inst_type['disabled'] = True

        disabled_type = db.instance_type_create(
                self.admin_context, inst_type)

        return disabled_type
 def setUp(self):
     super(InstanceTypeExtraSpecsTestCase, self).setUp()
     self.context = context.get_admin_context()
     values = dict(name="cg1.4xlarge",
                   memory_mb=22000,
                   vcpus=8,
                   local_gb=1690,
                   flavorid=105)
     specs = dict(cpu_arch="x86_64",
                  cpu_model="Nehalem",
                  xpu_arch="fermi",
                  xpus=2,
                  xpu_model="Tesla 2050")
     values['extra_specs'] = specs
     ref = db.instance_type_create(self.context, values)
     self.instance_type_id = ref.id
 def setUp(self):
     super(InstanceTypeExtraSpecsTestCase, self).setUp()
     self.context = context.get_admin_context()
     values = dict(name="cg1.4xlarge",
                   memory_mb=22000,
                   vcpus=8,
                   local_gb=1690,
                   flavorid=105)
     specs = dict(cpu_arch="x86_64",
                     cpu_model="Nehalem",
                     xpu_arch="fermi",
                     xpus=2,
                     xpu_model="Tesla 2050")
     values['extra_specs'] = specs
     ref = db.instance_type_create(self.context,
                                       values)
     self.instance_type_id = ref.id
示例#17
0
def create(name, memory, vcpus, local_gb, flavorid, swap=0,
           rxtx_quota=0, rxtx_cap=0):
    """Creates instance types."""
    kwargs = {
        'memory_mb': memory,
        'vcpus': vcpus,
        'local_gb': local_gb,
        'swap': swap,
        'rxtx_quota': rxtx_quota,
        'rxtx_cap': rxtx_cap,
    }

    # ensure some attributes are integers and greater than or equal to 0
    for option in kwargs:
        try:
            kwargs[option] = int(kwargs[option])
            assert kwargs[option] >= 0
        except (ValueError, AssertionError):
            msg = _("create arguments must be positive integers")
            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 = _("create arguments must be positive integers")
            raise exception.InvalidInput(reason=msg)

    kwargs['name'] = name
    kwargs['flavorid'] = flavorid

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except exception.DBError, e:
        LOG.exception(_('DB error: %s') % e)
        msg = _("Cannot create instance_type with name %(name)s and "
                "flavorid %(flavorid)s") % locals()
        raise exception.ApiError(msg)
示例#18
0
def create(name,
           memory,
           vcpus,
           root_gb,
           ephemeral_gb=0,
           flavorid=None,
           swap=0,
           rxtx_factor=1.0,
           is_public=True):
    """Creates flavors."""
    if not flavorid:
        flavorid = uuid.uuid4()

    kwargs = {
        'memory_mb': memory,
        'vcpus': vcpus,
        'root_gb': root_gb,
        'ephemeral_gb': ephemeral_gb,
        'swap': swap,
        'rxtx_factor': rxtx_factor,
    }

    # ensure name do not exceed 255 characters
    utils.check_string_length(name, 'name', min_length=1, max_length=255)

    # ensure name does not contain any special characters
    invalid_name = INVALID_NAME_REGEX.search(name)
    if invalid_name:
        msg = _("names can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

    # Some attributes are positive ( > 0) integers
    for option in ['memory_mb', 'vcpus']:
        try:
            assert int(str(kwargs[option])) > 0
            kwargs[option] = int(kwargs[option])
        except (ValueError, AssertionError, TypeError):
            msg = _("'%s' argument must be a positive integer") % option
            raise exception.InvalidInput(reason=msg)

    # Some attributes are non-negative ( >= 0) integers
    for option in ['root_gb', 'ephemeral_gb', 'swap']:
        try:
            assert int(str(kwargs[option])) >= 0
            kwargs[option] = int(kwargs[option])
        except (ValueError, AssertionError, TypeError):
            msg = _("'%s' argument must be an integer greater than or"
                    " equal to 0") % option
            raise exception.InvalidInput(reason=msg)

    # rxtx_factor should be a positive float
    try:
        kwargs['rxtx_factor'] = float(kwargs['rxtx_factor'])
        assert kwargs['rxtx_factor'] > 0
    except (ValueError, AssertionError):
        msg = _("'rxtx_factor' argument must be a positive float")
        raise exception.InvalidInput(reason=msg)

    kwargs['name'] = name
    # NOTE(vish): Internally, flavorid is stored as a string but it comes
    #             in through json as an integer, so we convert it here.
    kwargs['flavorid'] = unicode(flavorid)

    # ensure is_public attribute is boolean
    try:
        kwargs['is_public'] = strutils.bool_from_string(is_public, strict=True)
    except ValueError:
        raise exception.InvalidInput(reason=_("is_public must be a boolean"))

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except db_exc.DBError as e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.InstanceTypeCreateFailed()
示例#19
0
文件: flavors.py 项目: hloeung/nova
def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None, swap=0, rxtx_factor=1.0, is_public=True):
    """Creates flavors."""
    if not flavorid:
        flavorid = uuid.uuid4()

    kwargs = {
        "memory_mb": memory,
        "vcpus": vcpus,
        "root_gb": root_gb,
        "ephemeral_gb": ephemeral_gb,
        "swap": swap,
        "rxtx_factor": rxtx_factor,
    }

    # ensure name do not exceed 255 characters
    utils.check_string_length(name, "name", min_length=1, max_length=255)

    # ensure name does not contain any special characters
    invalid_name = INVALID_NAME_REGEX.search(name)
    if invalid_name:
        msg = _("names can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

    # Some attributes are positive ( > 0) integers
    for option in ["memory_mb", "vcpus"]:
        try:
            assert int(str(kwargs[option])) > 0
            kwargs[option] = int(kwargs[option])
        except (ValueError, AssertionError, TypeError):
            msg = _("'%s' argument must be a positive integer") % option
            raise exception.InvalidInput(reason=msg)

    # Some attributes are non-negative ( >= 0) integers
    for option in ["root_gb", "ephemeral_gb", "swap"]:
        try:
            assert int(str(kwargs[option])) >= 0
            kwargs[option] = int(kwargs[option])
        except (ValueError, AssertionError, TypeError):
            msg = _("'%s' argument must be an integer greater than or" " equal to 0") % option
            raise exception.InvalidInput(reason=msg)

    # rxtx_factor should be a positive float
    try:
        kwargs["rxtx_factor"] = float(kwargs["rxtx_factor"])
        assert kwargs["rxtx_factor"] > 0
    except (ValueError, AssertionError):
        msg = _("'rxtx_factor' argument must be a positive float")
        raise exception.InvalidInput(reason=msg)

    kwargs["name"] = name
    # NOTE(vish): Internally, flavorid is stored as a string but it comes
    #             in through json as an integer, so we convert it here.
    kwargs["flavorid"] = unicode(flavorid)

    # ensure is_public attribute is boolean
    try:
        kwargs["is_public"] = strutils.bool_from_string(is_public, strict=True)
    except ValueError:
        raise exception.InvalidInput(reason=_("is_public must be a boolean"))

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except db_exc.DBError as e:
        LOG.exception(_("DB error: %s") % e)
        raise exception.InstanceTypeCreateFailed()
示例#20
0
def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None, swap=None, rxtx_factor=None, is_public=True):
    """Creates instance types."""

    if flavorid is None:
        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 = {
        "memory_mb": memory,
        "vcpus": vcpus,
        "root_gb": root_gb,
        "ephemeral_gb": ephemeral_gb,
        "swap": swap,
        "rxtx_factor": rxtx_factor,
    }

    # ensure name does not contain any special characters
    invalid_name = INVALID_NAME_REGEX.search(name)
    if invalid_name:
        msg = _("names can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

    # ensure some attributes are integers and greater than or equal to 0
    for option in ["memory_mb", "vcpus", "root_gb", "ephemeral_gb", "swap"]:
        try:
            kwargs[option] = int(kwargs[option])
            assert kwargs[option] >= 0
        except (ValueError, AssertionError):
            msg = _("'%s' argument must be a positive integer") % option
            raise exception.InvalidInput(reason=msg)

    # rxtx_factor should be a positive float
    try:
        kwargs["rxtx_factor"] = float(kwargs["rxtx_factor"])
        assert kwargs["rxtx_factor"] > 0
    except (ValueError, AssertionError):
        msg = _("'rxtx_factor' argument must be a positive float")
        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
    # NOTE(vish): Internally, flavorid is stored as a string but it comes
    #             in through json as an integer, so we convert it here.
    kwargs["flavorid"] = unicode(flavorid)

    # ensure is_public attribute is boolean
    if not utils.is_valid_boolstr(is_public):
        msg = _("is_public must be a boolean")
        raise exception.InvalidInput(reason=msg)
    kwargs["is_public"] = utils.bool_from_str(is_public)

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except exception.DBError, e:
        LOG.exception(_("DB error: %s") % e)
        raise exception.InstanceTypeCreateFailed()
示例#21
0
def create(name, memory, vcpus, root_gb, ephemeral_gb=None, flavorid=None,
           swap=None, rxtx_factor=None, is_public=True):
    """Creates instance types."""

    if flavorid is None:
        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 = {
        'memory_mb': memory,
        'vcpus': vcpus,
        'root_gb': root_gb,
        'ephemeral_gb': ephemeral_gb,
        'swap': swap,
        'rxtx_factor': rxtx_factor,
    }

    # ensure name does not contain any special characters
    invalid_name = INVALID_NAME_REGEX.search(name)
    if invalid_name:
        msg = _("names can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

    # ensure some attributes are integers and greater than or equal to 0
    for option in ['memory_mb', 'vcpus', 'root_gb', 'ephemeral_gb', 'swap']:
        try:
            kwargs[option] = int(kwargs[option])
            assert kwargs[option] >= 0
        except (ValueError, AssertionError):
            msg = _("'%s' argument must be a positive integer") % option
            raise exception.InvalidInput(reason=msg)

    # rxtx_factor should be a positive float
    try:
        kwargs['rxtx_factor'] = float(kwargs['rxtx_factor'])
        assert kwargs['rxtx_factor'] > 0
    except (ValueError, AssertionError):
        msg = _("'rxtx_factor' argument must be a positive float")
        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
    # NOTE(vish): Internally, flavorid is stored as a string but it comes
    #             in through json as an integer, so we convert it here.
    kwargs['flavorid'] = unicode(flavorid)

    # ensure is_public attribute is boolean
    if not utils.is_valid_boolstr(is_public):
        msg = _("is_public must be a boolean")
        raise exception.InvalidInput(reason=msg)
    kwargs['is_public'] = utils.bool_from_str(is_public)

    try:
        return db.instance_type_create(context.get_admin_context(), kwargs)
    except exception.DBError, e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.InstanceTypeCreateFailed()