Repository URL to install this package:
Version:
6.0.19 ▾
|
# Copyright 2020 TrilioData Inc.
# All Rights Reserved.
"""Functionality related to notifications common to multiple layers of
the system.
"""
import datetime
from keystoneauth1 import exceptions as ks_exc
from oslo_log import log
from oslo_utils import excutils
from oslo_utils import timeutils
import contego.conf
import contego.context
from contego import exception
from contego.notifications.objects import base as notification_base
from contego import objects
from contego.objects import base as obj_base
from contego.objects import fields
from contego import rpc
from contego import utils
LOG = log.getLogger(__name__)
CONF = contego.conf.CONF
def audit_period_bounds(current_period=False):
"""Get the start and end of the relevant audit usage period
:param current_period: if True, this will generate a usage for the
current usage period; if False, this will generate a usage for the
previous audit period.
"""
begin, end = utils.last_completed_audit_period()
if current_period:
audit_start = end
audit_end = timeutils.utcnow()
else:
audit_start = begin
audit_end = end
return (audit_start, audit_end)
def null_safe_str(s):
return str(s) if s else ''
def null_safe_isotime(s):
if isinstance(s, datetime.datetime):
return utils.strtime(s)
else:
return str(s) if s else ''