def add_scope(scope, account, session=None):
""" add a scope for the given account name.
:param scope: the name for the new scope.
:param account: the account to add the scope to.
:param session: The database session in use.
"""
result = session.query(models.Account).filter_by(account=account, status=AccountStatus.ACTIVE).first()
if result is None:
raise AccountNotFound('Account ID \'%s\' does not exist' % account)
new_scope = models.Scope(scope=scope, account=account, status=ScopeStatus.OPEN)
try:
new_scope.save(session=session)
except IntegrityError, e:
if match('.*IntegrityError.*ORA-00001: unique constraint.*SCOPES_PK.*violated.*', e.args[0]) \
or match('.*IntegrityError.*1062, "Duplicate entry.*for key.*', e.args[0]) \
or match('.*IntegrityError.*UNIQUE constraint failed: scopes.scope.*', e.args[0]) \
or match('.*IntegrityError.*duplicate key value violates unique constraint.*', e.args[0])\
or match('.*sqlite3.IntegrityError.*is not unique.*', e.args[0]):
raise Duplicate('Scope \'%s\' already exists!' % scope)
except:
raise RucioException(str(format_exc()))
评论列表
文章目录