本文整理汇总了Python中neutron.objects.db.api.create_object函数的典型用法代码示例。如果您正苦于以下问题:Python create_object函数的具体用法?Python create_object怎么用?Python create_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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})
示例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)
示例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)
示例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'])
示例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)
示例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)
示例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'])
示例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)
示例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)
示例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)
示例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)
示例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'})
示例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)
示例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)
示例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)