本文整理汇总了Python中neutron.objects.db.api.create_object函数的典型用法代码示例。如果您正苦于以下问题:Python create_object函数的具体用法?Python create_object怎么用?Python create_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_object函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_delete_objects_removes_all_matching_objects
def test_delete_objects_removes_all_matching_objects(self):
# create some objects with identical description
for i in range(10):
api.create_object(
self.ctxt, self.model,
{'name': 'foo%d' % i, 'description': 'bar'})
# create some more objects with a different description
descriptions = set()
for i in range(10, 20):
desc = 'bar%d' % i
descriptions.add(desc)
api.create_object(
self.ctxt, self.model,
{'name': 'foo%d' % i, 'description': desc})
# make sure that all objects are in the database
self.assertEqual(20, api.count(self.ctxt, self.model))
# now delete just those with the 'bar' description
api.delete_objects(self.ctxt, self.model, description='bar')
# check that half of objects are gone, and remaining have expected
# descriptions
objs = api.get_objects(self.ctxt, self.model)
self.assertEqual(10, len(objs))
self.assertEqual(
descriptions,
{obj.description for obj in objs})
开发者ID:sebrandon1,项目名称:neutron,代码行数:26,代码来源:test_api.py
示例2: _create_shared_network_rbac_entry
def _create_shared_network_rbac_entry(self, network):
attrs = {
'object_id': network['id'],
'target_tenant': '*',
'action': rbac_db_models.ACCESS_SHARED
}
obj_db_api.create_object(net_obj.NetworkRBAC, self.context, attrs)
开发者ID:cubeek,项目名称:neutron,代码行数:7,代码来源:test_subnet.py
示例3: test_get_objects_with_string_matching_filters_ends
def test_get_objects_with_string_matching_filters_ends(self):
obj1 = api.create_object(self.ctxt, self.model, {'name': 'obj1_end'})
obj2 = api.create_object(self.ctxt, self.model, {'name': 'obj2_end'})
obj3 = api.create_object(self.ctxt, self.model, {'name': 'obj_3'})
objs = api.get_objects(
self.ctxt, self.model, name=obj_utils.StringEnds('end'))
self.assertEqual(2, len(objs))
self.assertIn(obj1, objs)
self.assertIn(obj2, objs)
self.assertNotIn(obj3, objs)
开发者ID:eayunstack,项目名称:neutron,代码行数:11,代码来源:test_api.py
示例4: _set_dns_domain
def _set_dns_domain(self, dns_domain):
obj_db_api.delete_objects(
self.obj_context, dns_db.NetworkDNSDomain, network_id=self.id,
)
if dns_domain:
obj_db_api.create_object(
self.obj_context, dns_db.NetworkDNSDomain,
{'network_id': self.id, 'dns_domain': dns_domain}
)
self.dns_domain = dns_domain
self.obj_reset_changes(['dns_domain'])
开发者ID:sebrandon1,项目名称:neutron,代码行数:11,代码来源:network.py
示例5: test_populate_id
def test_populate_id(self, populate_id=True):
ctxt = context.get_admin_context()
model_cls = mock.Mock()
values = {'x': 1, 'y': 2, 'z': 3}
with mock.patch.object(ctxt.__class__, 'session'):
api.create_object(ctxt, model_cls, values,
populate_id=populate_id)
expected = copy.copy(values)
if populate_id:
expected['id'] = mock.ANY
model_cls.assert_called_with(**expected)
开发者ID:eayunstack,项目名称:neutron,代码行数:11,代码来源:test_api.py
示例6: test_get_objects_with_string_matching_filters_starts
def test_get_objects_with_string_matching_filters_starts(self):
obj1 = api.create_object(self.obj_cls, self.ctxt, {'name': 'pre_obj1'})
obj2 = api.create_object(self.obj_cls, self.ctxt, {'name': 'pre_obj2'})
obj3 = api.create_object(self.obj_cls, self.ctxt, {'name': 'obj_3'})
objs = api.get_objects(
self.obj_cls, self.ctxt, name=obj_utils.StringStarts('pre'))
self.assertEqual(2, len(objs))
self.assertIn(obj1, objs)
self.assertIn(obj2, objs)
self.assertNotIn(obj3, objs)
开发者ID:igordcard,项目名称:neutron,代码行数:11,代码来源:test_api.py
示例7: _attach_qos_policy
def _attach_qos_policy(self, qos_policy_id):
# TODO(ihrachys): introduce an object for the binding to isolate
# database access in a single place, currently scattered between port
# and policy objects
obj_db_api.delete_objects(
self.obj_context, qos_models.QosPortPolicyBinding, port_id=self.id)
if qos_policy_id:
obj_db_api.create_object(
self.obj_context, qos_models.QosPortPolicyBinding,
{'port_id': self.id, 'policy_id': qos_policy_id}
)
self.qos_policy_id = qos_policy_id
self.obj_reset_changes(['qos_policy_id'])
开发者ID:SUSE-Cloud,项目名称:neutron,代码行数:13,代码来源:ports.py
示例8: test_get_object_create_update_delete
def test_get_object_create_update_delete(self):
obj = api.create_object(self.ctxt, self.model, {'name': 'foo'})
new_obj = api.get_object(self.ctxt, self.model, id=obj.id)
self.assertEqual(obj, new_obj)
obj = new_obj
api.update_object(self.ctxt, self.model, {'name': 'bar'}, id=obj.id)
new_obj = api.get_object(self.ctxt, self.model, id=obj.id)
self.assertEqual(obj, new_obj)
obj = new_obj
api.delete_object(self.ctxt, self.model, id=obj.id)
new_obj = api.get_object(self.ctxt, self.model, id=obj.id)
self.assertIsNone(new_obj)
# delete_object raises an exception on missing object
self.assertRaises(
n_exc.ObjectNotFound,
api.delete_object, self.ctxt, self.model, id=obj.id)
# but delete_objects does not not
api.delete_objects(self.ctxt, self.model, id=obj.id)
开发者ID:sebrandon1,项目名称:neutron,代码行数:25,代码来源:test_api.py
示例9: _create_test_segment
def _create_test_segment(self, network):
test_segment = {
'network_id': network['id'],
'network_type': 'vxlan',
}
# TODO(korzen): replace with segment.create() once we get an object
# implementation for segments
self._segment = obj_db_api.create_object(self.context,
segments_db.NetworkSegment,
test_segment)
开发者ID:electrocucaracha,项目名称:neutron,代码行数:10,代码来源:test_base.py
示例10: create
def create(self):
fields = self._get_changed_persistent_fields()
try:
db_obj = obj_db_api.create_object(self._context, self.db_model,
fields)
except obj_exc.DBDuplicateEntry as db_exc:
raise NeutronDbObjectDuplicateEntry(object_class=self.__class__,
db_exception=db_exc)
self.from_db_object(db_obj)
开发者ID:FedericoRessi,项目名称:neutron,代码行数:10,代码来源:base.py
示例11: create
def create(self):
fields = self._get_changed_persistent_fields()
with self.db_context_writer(self.obj_context):
try:
db_obj = obj_db_api.create_object(
self, self.obj_context, self.modify_fields_to_db(fields))
except obj_exc.DBDuplicateEntry as db_exc:
raise o_exc.NeutronDbObjectDuplicateEntry(
object_class=self.__class__, db_exception=db_exc)
self.from_db_object(db_obj)
开发者ID:noironetworks,项目名称:neutron,代码行数:11,代码来源:base.py
示例12: _create_test_port
def _create_test_port(self, network):
# TODO(ihrachys): replace with port.create() once we get an object
# implementation for ports
self._port = obj_db_api.create_object(self.context, models_v2.Port,
{'tenant_id': 'fake_tenant_id',
'name': 'test-port1',
'network_id': network['id'],
'mac_address': 'fake_mac',
'admin_state_up': True,
'status': 'ACTIVE',
'device_id': 'fake_device',
'device_owner': 'fake_owner'})
开发者ID:yedan2010,项目名称:neutron,代码行数:12,代码来源:test_base.py
示例13: test_attach_and_get_multiple_policy_networks
def test_attach_and_get_multiple_policy_networks(self):
net1_id = self._network['id']
net2 = db_api.create_object(self.context,
models_v2.Network,
{'name': 'test-network2'})
net2_id = net2['id']
obj = self._create_test_policy()
obj.attach_network(net1_id)
obj.attach_network(net2_id)
networks = obj.get_bound_networks()
self.assertEqual(2, len(networks))
self.assertTrue(net1_id in networks)
self.assertTrue(net2_id in networks)
开发者ID:HoratiusTang,项目名称:neutron,代码行数:16,代码来源:test_policy.py
示例14: test_get_values_with_string_matching_filters_ends
def test_get_values_with_string_matching_filters_ends(self):
api.create_object(self.obj_cls, self.ctxt, {'name': 'obj1_end'})
api.create_object(self.obj_cls, self.ctxt, {'name': 'obj2_end'})
api.create_object(self.obj_cls, self.ctxt, {'name': 'obj_3'})
values = api.get_values(
self.obj_cls, self.ctxt, 'name', name=obj_utils.StringEnds('end'))
self.assertEqual(2, len(values))
self.assertIn('obj1_end', values)
self.assertIn('obj2_end', values)
self.assertNotIn('obj_3', values)
开发者ID:igordcard,项目名称:neutron,代码行数:11,代码来源:test_api.py
示例15: test_get_values_with_string_matching_filters_contains
def test_get_values_with_string_matching_filters_contains(self):
api.create_object(
self.obj_cls, self.ctxt, {'name': 'obj_con_1'})
api.create_object(
self.obj_cls, self.ctxt, {'name': 'obj_con_2'})
api.create_object(
self.obj_cls, self.ctxt, {'name': 'obj_3'})
values = api.get_values(
self.obj_cls, self.ctxt, 'name',
name=obj_utils.StringContains('con'))
self.assertEqual(2, len(values))
self.assertIn('obj_con_1', values)
self.assertIn('obj_con_2', values)
self.assertNotIn('obj_3', values)
开发者ID:igordcard,项目名称:neutron,代码行数:15,代码来源:test_api.py
示例16: test_attach_and_get_multiple_policy_ports
def test_attach_and_get_multiple_policy_ports(self):
port1_id = self._port['id']
port2 = db_api.create_object(port_obj.Port, self.context,
{'tenant_id': 'fake_tenant_id',
'name': 'test-port2',
'network_id': self._network_id,
'mac_address': 'fake_mac2',
'admin_state_up': True,
'status': 'ACTIVE',
'device_id': 'fake_device',
'device_owner': 'fake_owner'})
port2_id = port2['id']
obj = self._create_test_policy()
obj.attach_port(port1_id)
obj.attach_port(port2_id)
ports = obj.get_bound_ports()
self.assertEqual(2, len(ports))
self.assertIn(port1_id, ports)
self.assertIn(port2_id, ports)
开发者ID:igordcard,项目名称:neutron,代码行数:22,代码来源:test_policy.py
示例17: _create_port
def _create_port(self, **port_attrs):
if not hasattr(self, '_mac_address_generator'):
self._mac_address_generator = (":".join(["%02x" % i] * 6)
for i in itertools.count())
if not hasattr(self, '_port_name_generator'):
self._port_name_generator = ("test-port%d" % i
for i in itertools.count(1))
attrs = {'tenant_id': 'fake_tenant_id',
'admin_state_up': True,
'status': 'ACTIVE',
'device_id': 'fake_device',
'device_owner': 'fake_owner'}
attrs.update(port_attrs)
if 'name' not in attrs:
attrs['name'] = next(self._port_name_generator)
if 'mac_address' not in attrs:
attrs['mac_address'] = next(self._mac_address_generator)
# TODO(ihrachys): replace with port.create() once we get an object
# implementation for ports
return obj_db_api.create_object(self.context, models_v2.Port, attrs)
开发者ID:electrocucaracha,项目名称:neutron,代码行数:24,代码来源:test_base.py
示例18: test_get_values_with_None_value_in_filters
def test_get_values_with_None_value_in_filters(self):
api.create_object(self.obj_cls, self.ctxt, {'name': 'foo'})
values = api.get_values(
self.obj_cls, self.ctxt, 'name', name='foo', status=None)
self.assertEqual('foo', values[0])
开发者ID:igordcard,项目名称:neutron,代码行数:5,代码来源:test_api.py
示例19: _create_test_network
def _create_test_network(self):
# TODO(ihrachys): replace with network.create() once we get an object
# implementation for networks
self._network = obj_db_api.create_object(self.context,
models_v2.Network,
{'name': 'test-network1'})
开发者ID:yedan2010,项目名称:neutron,代码行数:6,代码来源:test_base.py
示例20: _attach_security_group
def _attach_security_group(self, sg_id):
obj_db_api.create_object(
self.obj_context, sg_models.SecurityGroupPortBinding,
{'port_id': self.id, 'security_group_id': sg_id}
)
开发者ID:eayunstack,项目名称:neutron,代码行数:5,代码来源:ports.py
注:本文中的neutron.objects.db.api.create_object函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论