• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.flavor_create函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nova.db.flavor_create函数的典型用法代码示例。如果您正苦于以下问题:Python flavor_create函数的具体用法?Python flavor_create怎么用?Python flavor_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了flavor_create函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_flavor_create_frozen

 def test_flavor_create_frozen(self):
     ctx = context.get_admin_context()
     db.flavor_create(ctx, {
         'name': 'foo', 'memory_mb': 512, 'vcpus': 1,
         'root_gb': 1, 'ephemeral_gb': 0, 'flavorid': 'foo',
         'swap': 0, 'rxtx_factor': 1.0, 'vcpu_weight': 1,
         'disabled': False, 'is_public': True,
     })
     new_flav = {'flavor': rand_flavor()}
     resp = self.api.api_post('flavors', new_flav,
                              check_response_status=False)
     self.assertEqual(409, resp.status)
开发者ID:4everming,项目名称:nova,代码行数:12,代码来源:test_flavor_manage.py


示例2: create

 def create(self, context):
     if self.obj_attr_is_set("id"):
         raise exception.ObjectActionError(action="create", reason="already created")
     updates = self.obj_get_changes()
     expected_attrs = []
     for attr in OPTIONAL_FIELDS:
         if attr in updates:
             expected_attrs.append(attr)
     projects = updates.pop("projects", [])
     db_flavor = db.flavor_create(context, updates, projects=projects)
     self._from_db_object(context, self, db_flavor, expected_attrs=expected_attrs)
开发者ID:gilmeir,项目名称:nova,代码行数:11,代码来源:flavor.py


示例3: test_flavor_create_frozen

 def test_flavor_create_frozen(self):
     ctx = context.get_admin_context()
     db.flavor_create(
         ctx,
         {
             "name": "foo",
             "memory_mb": 512,
             "vcpus": 1,
             "root_gb": 1,
             "ephemeral_gb": 0,
             "flavorid": "foo",
             "swap": 0,
             "rxtx_factor": 1.0,
             "vcpu_weight": 1,
             "disabled": False,
             "is_public": True,
         },
     )
     new_flav = {"flavor": rand_flavor()}
     resp = self.api.api_post("flavors", new_flav, check_response_status=False)
     self.assertEqual(409, resp.status)
开发者ID:BU-NU-CLOUD-SP16,项目名称:Trusted-Platform-Module-nova,代码行数:21,代码来源:test_flavor_manage.py


示例4: _create_disabled_instance_type

    def _create_disabled_instance_type(self):
        inst_types = db.flavor_get_all(self.admin_context)

        inst_type = inst_types[0]

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

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

        return disabled_type
开发者ID:j-carpentier,项目名称:nova,代码行数:13,代码来源:test_flavors.py


示例5: _create_disabled_instance_type

    def _create_disabled_instance_type(self):
        inst_types = db.flavor_get_all(self.admin_context)

        inst_type = inst_types[0]

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

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

        return disabled_type
开发者ID:375670450,项目名称:nova,代码行数:15,代码来源:test_flavors.py


示例6: setUp

    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.flavor_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
开发者ID:iBeacons,项目名称:nova,代码行数:16,代码来源:test_nova_manage.py


示例7: setUp

 def setUp(self):
     super(InstanceTypeExtraSpecsTestCase, self).setUp()
     self.context = context.get_admin_context()
     values = dict(name="cg1.4xlarge",
                   memory_mb=22000,
                   vcpus=8,
                   root_gb=1690,
                   ephemeral_gb=2000,
                   flavorid=105)
     self.specs = dict(cpu_arch=arch.X86_64,
                       cpu_model="Nehalem",
                       xpu_arch="fermi",
                       xpus="2",
                       xpu_model="Tesla 2050")
     values['extra_specs'] = self.specs
     ref = db.flavor_create(self.context,
                            values)
     self.instance_type_id = ref["id"]
     self.flavorid = ref["flavorid"]
开发者ID:dlq84,项目名称:nova,代码行数:19,代码来源:test_instance_types_extra_specs.py


示例8: create

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
    valid_name = VALID_NAME_OR_ID_REGEX.search(name)
    if not valid_name:
        msg = _("names can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

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

    # ensure leading/trailing whitespaces not present.
    if flavorid.strip() != flavorid:
        msg = _("id cannot contain leading and/or trailing whitespace(s)")
        raise exception.InvalidInput(reason=msg)

    # ensure flavor id does not exceed 255 characters
    utils.check_string_length(flavorid, 'id', min_length=1,
                              max_length=255)

    # ensure flavor id does not contain any special characters
    valid_flavor_id = VALID_NAME_OR_ID_REGEX.search(flavorid)
    if not valid_flavor_id:
        msg = _("id can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

    # Some attributes are positive ( > 0) integers
    for option in ['memory_mb', 'vcpus']:
        kwargs[option] = utils.validate_integer(kwargs[option], option, 1,
                                                sys.maxint)

    # Some attributes are non-negative ( >= 0) integers
    for option in ['root_gb', 'ephemeral_gb', 'swap']:
        kwargs[option] = utils.validate_integer(kwargs[option], option, 0,
                                                sys.maxint)

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

    kwargs['name'] = name
    kwargs['flavorid'] = 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.flavor_create(context.get_admin_context(), kwargs)
    except db_exc.DBError as e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.InstanceTypeCreateFailed()
开发者ID:LeoDuo,项目名称:nova,代码行数:76,代码来源:flavors.py


示例9: create

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,
    }

    if isinstance(name, six.string_types):
        name = name.strip()
    # 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
    valid_name = VALID_NAME_REGEX.search(name)
    if not valid_name:
        msg = _("Flavor names can only contain alphanumeric characters, "
                "periods, dashes, underscores and spaces.")
        raise exception.InvalidInput(reason=msg)

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

    # ensure leading/trailing whitespaces not present.
    if flavorid.strip() != flavorid:
        msg = _("id cannot contain leading and/or trailing whitespace(s)")
        raise exception.InvalidInput(reason=msg)

    # ensure flavor id does not exceed 255 characters
    utils.check_string_length(flavorid, 'id', min_length=1,
                              max_length=255)

    # ensure flavor id does not contain any special characters
    valid_flavor_id = VALID_ID_REGEX.search(flavorid)
    if not valid_flavor_id:
        msg = _("Flavor id can only contain letters from A-Z (both cases), "
                "periods, dashes, underscores and spaces.")
        raise exception.InvalidInput(reason=msg)

    # NOTE(wangbo): validate attributes of the creating flavor.
    # ram and vcpus should be positive ( > 0) integers.
    # disk, ephemeral and swap should be non-negative ( >= 0) integers.
    flavor_attributes = {
        'memory_mb': ('ram', 1),
        'vcpus': ('vcpus', 1),
        'root_gb': ('disk', 0),
        'ephemeral_gb': ('ephemeral', 0),
        'swap': ('swap', 0)
    }

    for key, value in flavor_attributes.items():
        kwargs[key] = utils.validate_integer(kwargs[key], value[0], value[1],
                                             db.MAX_INT)

    # rxtx_factor should be a positive float
    try:
        kwargs['rxtx_factor'] = float(kwargs['rxtx_factor'])
        if (kwargs['rxtx_factor'] <= 0 or
                kwargs['rxtx_factor'] > SQL_SP_FLOAT_MAX):
            raise ValueError()
    except ValueError:
        msg = (_("'rxtx_factor' argument must be a float between 0 and %g") %
               SQL_SP_FLOAT_MAX)
        raise exception.InvalidInput(reason=msg)

    kwargs['name'] = name
    kwargs['flavorid'] = 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.flavor_create(context.get_admin_context(), kwargs)
    except db_exc.DBError as e:
        LOG.exception(_LE('DB error: %s'), e)
        raise exception.FlavorCreateFailed()
开发者ID:HybridCloud-dew,项目名称:hws,代码行数:87,代码来源:flavors.py


示例10: create

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:
            if int(str(kwargs[option])) <= 0:
                raise ValueError()
            kwargs[option] = int(kwargs[option])
        except (ValueError, 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:
            if int(str(kwargs[option])) < 0:
                raise ValueError()
            kwargs[option] = int(kwargs[option])
        except (ValueError, 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'])
        if kwargs['rxtx_factor'] <= 0:
            raise ValueError()
    except ValueError:
        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.flavor_create(context.get_admin_context(), kwargs)
    except db_exc.DBError as e:
        LOG.exception(_('DB error: %s') % e)
        raise exception.InstanceTypeCreateFailed()
开发者ID:polettix,项目名称:nova,代码行数:71,代码来源:flavors.py


示例11: create

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
    valid_name = VALID_NAME_OR_ID_REGEX.search(name)
    if not valid_name:
        msg = _("names can only contain [a-zA-Z0-9_.- ]")
        raise exception.InvalidInput(reason=msg)

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

    # ensure leading/trailing whitespaces not present.
    if flavorid.strip() != flavorid:
        msg = _("id cannot contain leading and/or trailing whitespace(s)")
        raise exception.InvalidInput(reason=msg)

    # ensure flavor id does not exceed 255 characters
    utils.check_string_length(flavorid, "id", min_length=1, max_length=255)

    # ensure flavor id does not contain any special characters
    valid_flavor_id = VALID_NAME_OR_ID_REGEX.search(flavorid)
    if not valid_flavor_id:
        msg = _("id 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:
            if int(str(kwargs[option])) <= 0:
                raise ValueError()
            kwargs[option] = int(kwargs[option])
        except (ValueError, 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:
            if int(str(kwargs[option])) < 0:
                raise ValueError()
            kwargs[option] = int(kwargs[option])
        except (ValueError, 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"])
        if kwargs["rxtx_factor"] <= 0:
            raise ValueError()
    except ValueError:
        msg = _("'rxtx_factor' argument must be a positive float")
        raise exception.InvalidInput(reason=msg)

    kwargs["name"] = name
    kwargs["flavorid"] = 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.flavor_create(context.get_admin_context(), kwargs)
    except db_exc.DBError as e:
        LOG.exception(_("DB error: %s") % e)
        raise exception.InstanceTypeCreateFailed()
开发者ID:kobtea,项目名称:nova,代码行数:83,代码来源:flavors.py



注:本文中的nova.db.flavor_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python db.flavor_destroy函数代码示例发布时间:2022-05-27
下一篇:
Python db.fixed_ips_by_virtual_interface函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap