本文整理汇总了Python中oslo_db.exception.DBDuplicateEntry方法的典型用法代码示例。如果您正苦于以下问题:Python exception.DBDuplicateEntry方法的具体用法?Python exception.DBDuplicateEntry怎么用?Python exception.DBDuplicateEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_db.exception
的用法示例。
在下文中一共展示了exception.DBDuplicateEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_archive_policy_rule
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def create_archive_policy_rule(self, name, metric_pattern,
archive_policy_name):
apr = ArchivePolicyRule(
name=name,
archive_policy_name=archive_policy_name,
metric_pattern=metric_pattern
)
try:
with self.facade.writer() as session:
session.add(apr)
except exception.DBReferenceError as e:
if e.constraint == 'fk_apr_ap_name_ap_name':
raise indexer.NoSuchArchivePolicy(archive_policy_name)
raise
except exception.DBDuplicateEntry:
raise indexer.ArchivePolicyRuleAlreadyExists(name)
return apr
示例2: create_container
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def create_container(self, context, values):
# ensure defaults are present for new containers
if not values.get('uuid'):
values['uuid'] = uuidutils.generate_uuid()
if values.get('name'):
self._validate_unique_container_name(context, values['name'])
container = models.Container()
container.update(values)
try:
container.save()
except db_exc.DBDuplicateEntry:
raise exception.ContainerAlreadyExists(field='UUID',
value=values['uuid'])
return container
示例3: create_registry
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def create_registry(self, context, values):
# ensure defaults are present for new registries
if not values.get('uuid'):
values['uuid'] = uuidutils.generate_uuid()
original_password = values.get('password')
if original_password:
values['password'] = crypt.encrypt(values.get('password'))
registry = models.Registry()
registry.update(values)
try:
registry.save()
except db_exc.DBDuplicateEntry:
raise exception.RegistryAlreadyExists(
field='UUID', value=values['uuid'])
if original_password:
# the password is encrypted but we want to return the original
# password
registry['password'] = original_password
return registry
示例4: add_item
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def add_item(context, kind, data):
item_ref = models.Item()
item_ref.update({
"project_id": context.project_id,
"id": _new_id(kind),
})
item_ref.update(_pack_item_data(data))
try:
item_ref.save()
except db_exception.DBDuplicateEntry as ex:
if (models.ITEMS_OS_ID_INDEX_NAME not in ex.columns and
'os_id' not in ex.columns):
raise
item_ref = (model_query(context, models.Item).
filter_by(os_id=data["os_id"]).
filter(or_(models.Item.project_id == context.project_id,
models.Item.project_id.is_(None))).
filter(models.Item.id.like('%s-%%' % kind)).
one())
item_data = _unpack_item_data(item_ref)
item_data.update(data)
item_ref.update(_pack_item_data(item_data))
item_ref.project_id = context.project_id
item_ref.save()
return _unpack_item_data(item_ref)
示例5: add_item_id
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def add_item_id(context, kind, os_id, project_id=None):
item_ref = models.Item()
item_ref.update({
"id": _new_id(kind),
"os_id": os_id,
})
if project_id:
item_ref.project_id = project_id
try:
item_ref.save()
except db_exception.DBDuplicateEntry as ex:
if (models.ITEMS_OS_ID_INDEX_NAME not in ex.columns and
ex.columns != ['os_id']):
raise
item_ref = (model_query(context, models.Item).
filter_by(os_id=os_id).
one())
return item_ref.id
示例6: add_tags
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def add_tags(context, tags):
session = get_session()
get_query = (model_query(context, models.Tag, session=session).
filter_by(project_id=context.project_id,
# NOTE(ft): item_id param name is reserved for
# sqlalchemy internal use
item_id=bindparam('tag_item_id'),
key=bindparam('tag_key')))
with session.begin():
for tag in tags:
tag_ref = models.Tag(project_id=context.project_id,
item_id=tag['item_id'],
key=tag['key'],
value=tag['value'])
try:
with session.begin(nested=True):
tag_ref.save(session)
except db_exception.DBDuplicateEntry as ex:
if ('PRIMARY' not in ex.columns and
ex.columns != ['project_id', 'item_id', 'key']):
raise
(get_query.params(tag_item_id=tag['item_id'],
tag_key=tag['key']).
update({'value': tag['value']}))
示例7: _validate_create_member
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def _validate_create_member(self, lock_session, member_dict):
"""Validate creating member on pool."""
try:
return self.repositories.member.create(lock_session, **member_dict)
except odb_exceptions.DBDuplicateEntry as de:
column_list = ['pool_id', 'ip_address', 'protocol_port']
constraint_list = ['uq_member_pool_id_address_protocol_port']
if ['id'] == de.columns:
raise exceptions.IDAlreadyExists()
if (set(column_list) == set(de.columns) or
set(constraint_list) == set(de.columns)):
raise exceptions.DuplicateMemberEntry(
ip_address=member_dict.get('ip_address'),
port=member_dict.get('protocol_port'))
except odb_exceptions.DBError:
# TODO(blogan): will have to do separate validation protocol
# before creation or update since the exception messages
# do not give any information as to what constraint failed
raise exceptions.InvalidOption(value='', option='')
示例8: _validate_create_l7policy
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def _validate_create_l7policy(self, lock_session, l7policy_dict):
try:
# Set the default HTTP redirect code here so it's explicit
if ((l7policy_dict.get('redirect_url') or
l7policy_dict.get('redirect_prefix')) and
not l7policy_dict.get('redirect_http_code')):
l7policy_dict['redirect_http_code'] = 302
return self.repositories.l7policy.create(lock_session,
**l7policy_dict)
except odb_exceptions.DBDuplicateEntry:
raise exceptions.IDAlreadyExists()
except odb_exceptions.DBError:
# TODO(blogan): will have to do separate validation protocol
# before creation or update since the exception messages
# do not give any information as to what constraint failed
raise exceptions.InvalidOption(value='', option='')
示例9: execute
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def execute(self, loadbalancer_id):
"""Create a VRRP group for a load balancer.
:param loadbalancer_id: Load balancer ID for which a VRRP group
should be created
"""
try:
self.repos.vrrpgroup.create(
db_apis.get_session(),
load_balancer_id=loadbalancer_id,
vrrp_group_name=str(loadbalancer_id).replace('-', ''),
vrrp_auth_type=constants.VRRP_AUTH_DEFAULT,
vrrp_auth_pass=uuidutils.generate_uuid().replace('-', '')[0:7],
advert_int=CONF.keepalived_vrrp.vrrp_advert_int)
except odb_exceptions.DBDuplicateEntry:
LOG.debug('VRRP_GROUP entry already exists for load balancer, '
'skipping create.')
示例10: execute
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def execute(self, loadbalancer):
"""Create a VRRP group for a load balancer.
:param loadbalancer: Load balancer for which a VRRP group
should be created
:returns: Updated load balancer
"""
try:
self.repos.vrrpgroup.create(
db_apis.get_session(),
load_balancer_id=loadbalancer[constants.LOADBALANCER_ID],
vrrp_group_name=str(
loadbalancer[constants.LOADBALANCER_ID]).replace('-', ''),
vrrp_auth_type=constants.VRRP_AUTH_DEFAULT,
vrrp_auth_pass=uuidutils.generate_uuid().replace('-', '')[0:7],
advert_int=CONF.keepalived_vrrp.vrrp_advert_int)
except odb_exceptions.DBDuplicateEntry:
LOG.debug('VRRP_GROUP entry already exists for load balancer, '
'skipping create.')
return loadbalancer
示例11: test_create_vrrp_group_for_lb
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def test_create_vrrp_group_for_lb(self,
mock_vrrp_group_create,
mock_generate_uuid,
mock_LOG,
mock_get_session,
mock_loadbalancer_repo_update,
mock_listener_repo_update,
mock_amphora_repo_update,
mock_amphora_repo_delete):
mock_get_session.side_effect = ['TEST',
odb_exceptions.DBDuplicateEntry]
create_vrrp_group = database_tasks.CreateVRRPGroupForLB()
create_vrrp_group.execute(_loadbalancer_mock.id)
mock_vrrp_group_create.assert_called_once_with(
'TEST', load_balancer_id=LB_ID,
vrrp_group_name=LB_ID.replace('-', ''),
vrrp_auth_type=constants.VRRP_AUTH_DEFAULT,
vrrp_auth_pass=mock_generate_uuid.return_value.replace('-',
'')[0:7],
advert_int=1)
create_vrrp_group.execute(_loadbalancer_mock)
示例12: test_create_vrrp_group_for_lb
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def test_create_vrrp_group_for_lb(self,
mock_vrrp_group_create,
mock_generate_uuid,
mock_LOG,
mock_get_session,
mock_loadbalancer_repo_update,
mock_listener_repo_update,
mock_amphora_repo_update,
mock_amphora_repo_delete):
mock_get_session.side_effect = ['TEST',
odb_exceptions.DBDuplicateEntry]
create_vrrp_group = database_tasks.CreateVRRPGroupForLB()
create_vrrp_group.execute(self.loadbalancer_mock)
mock_vrrp_group_create.assert_called_once_with(
'TEST', load_balancer_id=LB_ID,
vrrp_group_name=LB_ID.replace('-', ''),
vrrp_auth_type=constants.VRRP_AUTH_DEFAULT,
vrrp_auth_pass=mock_generate_uuid.return_value.replace('-',
'')[0:7],
advert_int=1)
create_vrrp_group.execute(self.loadbalancer_mock)
示例13: create_gateway_device_remote_mac_entry
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def create_gateway_device_remote_mac_entry(self, context,
gateway_device_id,
remote_mac_entry):
rme = remote_mac_entry['remote_mac_entry']
try:
with context.session.begin(subtransactions=True):
gw_rmt_db = GatewayRemoteMacTable(
id=uuidutils.generate_uuid(),
device_id=gateway_device_id,
mac_address=rme['mac_address'],
segmentation_id=rme['segmentation_id'],
vtep_address=rme['vtep_address'])
context.session.add(gw_rmt_db)
except db_exc.DBDuplicateEntry:
raise gw_device_ext.DuplicateRemoteMacEntry(
mac_address=rme['mac_address'])
return self._make_remote_mac_dict(gw_rmt_db)
示例14: share_type_access_add
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def share_type_access_add(context, type_id, project_id):
"""Add given tenant to the share type access list."""
share_type_id = _share_type_get_id_from_share_type(context, type_id)
access_ref = models.ShareTypeProjects()
access_ref.update({"share_type_id": share_type_id,
"project_id": project_id})
session = get_session()
with session.begin():
try:
access_ref.save(session=session)
except db_exception.DBDuplicateEntry:
raise exception.ShareTypeAccessExists(share_type_id=type_id,
project_id=project_id)
return access_ref
示例15: create_net_assoc
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDuplicateEntry [as 别名]
def create_net_assoc(self, context, bgpvpn_id, net_assoc):
try:
with db_api.CONTEXT_WRITER.using(context):
net_assoc_db = BGPVPNNetAssociation(
tenant_id=net_assoc['tenant_id'],
bgpvpn_id=bgpvpn_id,
network_id=net_assoc['network_id'])
context.session.add(net_assoc_db)
return self._make_net_assoc_dict(net_assoc_db)
except db_exc.DBDuplicateEntry:
LOG.warning("network %(net_id)s is already associated to "
"BGPVPN %(bgpvpn_id)s",
{'net_id': net_assoc['network_id'],
'bgpvpn_id': bgpvpn_id})
raise bgpvpn_ext.BGPVPNNetAssocAlreadyExists(
bgpvpn_id=bgpvpn_id, net_id=net_assoc['network_id'])