本文整理汇总了Python中nova.compute.instance_types.create函数的典型用法代码示例。如果您正苦于以下问题:Python create函数的具体用法?Python create怎么用?Python create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_duplicate_names_fail
def test_duplicate_names_fail(self):
"""Ensures that name duplicates raise ApiError"""
name = 'some_name'
instance_types.create(name, 256, 1, 120, 'flavor1')
self.assertRaises(exception.ApiError,
instance_types.create,
name, 256, 1, 120, 'flavor2')
示例2: test_duplicate_flavorids_fail
def test_duplicate_flavorids_fail(self):
"""Ensures that flavorid duplicates raise InstanceTypeCreateFailed"""
flavorid = 'flavor1'
instance_types.create('name one', 256, 1, 120, 200, flavorid)
self.assertRaises(exception.InstanceTypeIdExists,
instance_types.create,
'name two', 256, 1, 120, 200, flavorid)
示例3: test_duplicate_names_fail
def test_duplicate_names_fail(self):
"""Ensures that name duplicates raise InstanceTypeCreateFailed"""
name = 'some_name'
instance_types.create(name, 256, 1, 120, 200, 'flavor1')
self.assertRaises(exception.InstanceTypeExists,
instance_types.create,
name, 256, 1, 120, 200, 'flavor2')
示例4: test_duplicate_flavorids_fail
def test_duplicate_flavorids_fail(self):
"""Ensures that flavorid duplicates raise ApiError"""
flavorid = 'flavor1'
instance_types.create('name one', 256, 1, 120, flavorid)
self.assertRaises(exception.ApiError,
instance_types.create,
'name two', 256, 1, 120, flavorid)
示例5: test_repeated_inst_types_should_raise_api_error
def test_repeated_inst_types_should_raise_api_error(self):
"""Ensures that instance duplicates raises ApiError"""
new_name = self.name + "dup"
instance_types.create(new_name, 256, 1, 120, self.flavorid + 1)
instance_types.destroy(new_name)
self.assertRaises(
exception.ApiError,
instance_types.create, new_name, 256, 1, 120, self.flavorid)
示例6: create
def create(self, name, memory, vcpus, root_gb, ephemeral_gb=0,
flavorid=None, swap=0, rxtx_factor=1.0, is_public=True):
"""Creates instance types / flavors."""
try:
instance_types.create(name, memory, vcpus, root_gb,
ephemeral_gb, flavorid, swap, rxtx_factor,
is_public)
except exception.InvalidInput, e:
print _("Must supply valid parameters to create instance_type")
print e
return(1)
示例7: test_instance_type_create_then_delete
def test_instance_type_create_then_delete(self):
"""Ensure instance types can be created"""
starting_inst_list = instance_types.get_all_types()
instance_types.create(self.name, 256, 1, 120, self.flavorid)
new = instance_types.get_all_types()
self.assertNotEqual(len(starting_inst_list), len(new), "instance type was not created")
instance_types.destroy(self.name)
self.assertEqual(1, instance_types.get_instance_type(self.id)["deleted"])
self.assertEqual(starting_inst_list, instance_types.get_all_types())
instance_types.purge(self.name)
self.assertEqual(len(starting_inst_list), len(instance_types.get_all_types()), "instance type not purged")
示例8: test_read_deleted_false_converting_flavorid
def test_read_deleted_false_converting_flavorid(self):
"""
Ensure deleted instance types are not returned when not needed (for
example when creating a server and attempting to translate from
flavorid to instance_type_id.
"""
instance_types.create("instance_type1", 256, 1, 120, 100, "test1")
instance_types.destroy("instance_type1")
instance_types.create("instance_type1_redo", 256, 1, 120, 100, "test1")
instance_type = instance_types.get_instance_type_by_flavor_id("test1", read_deleted="no")
self.assertEqual("instance_type1_redo", instance_type["name"])
示例9: test_instance_type_create_then_delete
def test_instance_type_create_then_delete(self):
# Ensure instance types can be created.
name = "Small Flavor"
flavorid = "flavor1"
original_list = instance_types.get_all_types()
# create new type and make sure values stick
inst_type = instance_types.create(name, 256, 1, 120, 100, flavorid)
inst_type_id = inst_type["id"]
self.assertEqual(inst_type["flavorid"], flavorid)
self.assertEqual(inst_type["name"], name)
self.assertEqual(inst_type["memory_mb"], 256)
self.assertEqual(inst_type["vcpus"], 1)
self.assertEqual(inst_type["root_gb"], 120)
self.assertEqual(inst_type["ephemeral_gb"], 100)
self.assertEqual(inst_type["swap"], 0)
self.assertEqual(inst_type["rxtx_factor"], 1.0)
# make sure new type shows up in list
new_list = instance_types.get_all_types()
self.assertNotEqual(len(original_list), len(new_list), "instance type was not created")
instance_types.destroy(name)
self.assertRaises(exception.InstanceTypeNotFound, instance_types.get_instance_type, inst_type_id)
# deleted instance should not be in list anymoer
new_list = instance_types.get_all_types()
self.assertEqual(original_list, new_list)
示例10: test_instance_type_create_then_delete
def test_instance_type_create_then_delete(self):
"""Ensure instance types can be created"""
name = 'Small Flavor'
flavorid = 'flavor1'
original_list = instance_types.get_all_types()
# create new type and make sure values stick
inst_type = instance_types.create(name, 256, 1, 120, 100, flavorid)
inst_type_id = inst_type['id']
self.assertEqual(inst_type['flavorid'], flavorid)
self.assertEqual(inst_type['name'], name)
self.assertEqual(inst_type['memory_mb'], 256)
self.assertEqual(inst_type['vcpus'], 1)
self.assertEqual(inst_type['root_gb'], 120)
self.assertEqual(inst_type['ephemeral_gb'], 100)
self.assertEqual(inst_type['swap'], 0)
self.assertEqual(inst_type['rxtx_factor'], 1)
# make sure new type shows up in list
new_list = instance_types.get_all_types()
self.assertNotEqual(len(original_list), len(new_list),
'instance type was not created')
instance_types.destroy(name)
self.assertRaises(exception.InstanceTypeNotFound,
instance_types.get_instance_type, inst_type_id)
# deleted instance should not be in list anymoer
new_list = instance_types.get_all_types()
self.assertEqual(original_list, new_list)
示例11: _create
def _create(self, req, body):
context = req.environ['nova.context']
authorize(context)
vals = body['flavor']
name = vals['name']
flavorid = vals.get('id')
memory_mb = vals.get('ram')
vcpus = vals.get('vcpus')
root_gb = vals.get('disk')
ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral')
swap = vals.get('swap')
rxtx_factor = vals.get('rxtx_factor')
is_public = vals.get('os-flavor-access:is_public', True)
try:
flavor = instance_types.create(name, memory_mb, vcpus,
root_gb, ephemeral_gb, flavorid,
swap, rxtx_factor, is_public)
req.cache_db_flavor(flavor)
except (exception.InstanceTypeExists,
exception.InstanceTypeIdExists) as err:
raise webob.exc.HTTPConflict(explanation=str(err))
return self._view_builder.show(req, flavor)
示例12: test_remove_instance_type_access_doesnt_exists
def test_remove_instance_type_access_doesnt_exists(self):
user_id = "fake"
project_id = "fake"
ctxt = context.RequestContext(user_id, project_id, is_admin=True)
flavor_id = "flavor1"
type_ref = instance_types.create("some flavor", 256, 1, 120, 100, flavorid=flavor_id)
self.assertRaises(
exception.FlavorAccessNotFound, instance_types.remove_instance_type_access, flavor_id, project_id, ctxt=ctxt
)
示例13: test_add_instance_type_access
def test_add_instance_type_access(self):
user_id = "fake"
project_id = "fake"
ctxt = context.RequestContext(user_id, project_id, is_admin=True)
flavor_id = "flavor1"
type_ref = instance_types.create("some flavor", 256, 1, 120, 100, flavorid=flavor_id)
access_ref = instance_types.add_instance_type_access(flavor_id, project_id, ctxt=ctxt)
self.assertEqual(access_ref["project_id"], project_id)
self.assertEqual(access_ref["instance_type_id"], type_ref["id"])
示例14: test_instance_type_create_with_long_flavor_name
def test_instance_type_create_with_long_flavor_name(self):
# Flavor name with 255 characters or less is valid.
name = "a" * 255
inst_type = instance_types.create(name, 64, 1, 120, flavorid=11)
self.assertEqual(inst_type["name"], name)
# Flavor name which is more than 255 characters will cause error.
name = "a" * 256
self.assertRaises(exception.InvalidInput, instance_types.create, name, 64, 1, 120, flavorid=11)
示例15: test_add_instance_type_access_already_exists
def test_add_instance_type_access_already_exists(self):
user_id = "fake"
project_id = "fake"
ctxt = context.RequestContext(user_id, project_id, is_admin=True)
flavor_id = "flavor1"
type_ref = instance_types.create("some flavor", 256, 1, 120, 100, flavorid=flavor_id)
access_ref = instance_types.add_instance_type_access(flavor_id, project_id, ctxt=ctxt)
self.assertRaises(
exception.FlavorAccessExists, instance_types.add_instance_type_access, flavor_id, project_id, ctxt
)