コード例 #1
0
ファイル: utils.py プロジェクト: KarimAllah/nova
def notify_usage_exists(instance_ref, current_period=False):
    """ Generates 'exists' notification for an instance for usage auditing
        purposes.

        Generates usage for last completed period, unless 'current_period'
        is True."""
    admin_context = context.get_admin_context()
    begin, end = utils.current_audit_period()
    bw = {}
    if current_period:
        audit_start = end
        audit_end = utils.utcnow()
    else:
        audit_start = begin
        audit_end = end
    for b in db.bw_usage_get_by_instance(admin_context,
                                         instance_ref['id'],
                                         audit_start):
        bw[b.network_label] = dict(bw_in=b.bw_in, bw_out=b.bw_out)
    usage_info = utils.usage_from_instance(instance_ref,
                          audit_period_beginning=str(audit_start),
                          audit_period_ending=str(audit_end),
                          bandwidth=bw)
    notifier_api.notify('compute.%s' % FLAGS.host,
                        'compute.instance.exists',
                        notifier_api.INFO,
                        usage_info)
コード例 #2
0
ファイル: utils.py プロジェクト: yamahata/nova
def notify_usage_exists(instance_ref, current_period=False):
    """ Generates 'exists' notification for an instance for usage auditing
        purposes.

        Generates usage for last completed period, unless 'current_period'
        is True."""
    admin_context = context.get_admin_context()
    begin, end = utils.current_audit_period()
    bw = {}
    if current_period:
        audit_start = end
        audit_end = utils.utcnow()
    else:
        audit_start = begin
        audit_end = end
    for b in db.bw_usage_get_by_instance(admin_context, instance_ref['id'],
                                         audit_start):
        bw[b.network_label] = dict(bw_in=b.bw_in, bw_out=b.bw_out)
    usage_info = utils.usage_from_instance(
        instance_ref,
        audit_period_beginning=str(audit_start),
        audit_period_ending=str(audit_end),
        bandwidth=bw)
    notifier_api.notify('compute.%s' % FLAGS.host, 'compute.instance.exists',
                        notifier_api.INFO, usage_info)
コード例 #3
0
ファイル: test_utils.py プロジェクト: derekhiggins/nova
 def test_year_with_offset_after_current(self):
     begin, end = utils.current_audit_period(unit='year@6')
     self.assertEquals(begin, datetime.datetime(
                                        day=1,
                                        month=6,
                                        year=2010))
     self.assertEquals(end, datetime.datetime(
                                        day=1,
                                        month=6,
                                        year=2011))
コード例 #4
0
ファイル: test_utils.py プロジェクト: derekhiggins/nova
 def test_year(self):
     begin, end = utils.current_audit_period(unit='year')
     self.assertEquals(begin, datetime.datetime(
                                        day=1,
                                        month=1,
                                        year=2011))
     self.assertEquals(end, datetime.datetime(
                                        day=1,
                                        month=1,
                                        year=2012))
コード例 #5
0
ファイル: test_utils.py プロジェクト: derekhiggins/nova
 def test_month_with_offset_after_current(self):
     begin, end = utils.current_audit_period(unit='month@15')
     self.assertEquals(begin, datetime.datetime(
                                        day=15,
                                        month=1,
                                        year=2012))
     self.assertEquals(end, datetime.datetime(
                                        day=15,
                                        month=2,
                                        year=2012))
コード例 #6
0
ファイル: test_utils.py プロジェクト: derekhiggins/nova
 def test_day(self):
     begin, end = utils.current_audit_period(unit='day')
     self.assertEquals(begin, datetime.datetime(
                                        day=4,
                                        month=3,
                                        year=2012))
     self.assertEquals(end, datetime.datetime(
                                        day=5,
                                        month=3,
                                        year=2012))
コード例 #7
0
 def test_hour_with_offset_after_current(self):
     begin, end = utils.current_audit_period(unit='hour@30')
     self.assertEquals(
         begin,
         datetime.datetime(minute=30, hour=6, day=5, month=3, year=2012))
     self.assertEquals(
         end, datetime.datetime(minute=30,
                                hour=7,
                                day=5,
                                month=3,
                                year=2012))
コード例 #8
0
ファイル: test_utils.py プロジェクト: derekhiggins/nova
 def test_hour(self):
     begin, end = utils.current_audit_period(unit='hour')
     self.assertEquals(begin, datetime.datetime(
                                        hour=7,
                                        day=5,
                                        month=3,
                                        year=2012))
     self.assertEquals(end, datetime.datetime(
                                        hour=8,
                                        day=5,
                                        month=3,
                                        year=2012))
コード例 #9
0
ファイル: test_utils.py プロジェクト: derekhiggins/nova
 def test_day_with_offset_after_current(self):
     begin, end = utils.current_audit_period(unit='day@10')
     self.assertEquals(begin, datetime.datetime(
                                        hour=10,
                                        day=3,
                                        month=3,
                                        year=2012))
     self.assertEquals(end, datetime.datetime(
                                        hour=10,
                                        day=4,
                                        month=3,
                                        year=2012))
コード例 #10
0
ファイル: test_utils.py プロジェクト: derekhiggins/nova
 def test_hour_with_offset_after_current(self):
     begin, end = utils.current_audit_period(unit='hour@30')
     self.assertEquals(begin, datetime.datetime(
                                        minute=30,
                                        hour=6,
                                        day=5,
                                        month=3,
                                        year=2012))
     self.assertEquals(end, datetime.datetime(
                                        minute=30,
                                        hour=7,
                                        day=5,
                                        month=3,
                                        year=2012))
コード例 #11
0
ファイル: utils.py プロジェクト: altai/nova
def notify_usage_exists(instance_ref, current_period=False):
    """ Generates 'exists' notification for an instance for usage auditing
        purposes.

        Generates usage for last completed period, unless 'current_period'
        is True."""
    admin_context = context.get_admin_context(read_deleted='yes')
    begin, end = utils.current_audit_period()
    bw = {}
    if current_period:
        audit_start = end
        audit_end = utils.utcnow()
    else:
        audit_start = begin
        audit_end = end

    if (instance_ref.get('info_cache') and
        instance_ref['info_cache'].get('network_info')):

        cached_info = instance_ref['info_cache']['network_info']
        nw_info = network_model.NetworkInfo.hydrate(cached_info)
    else:
        nw_info = network.API().get_instance_nw_info(admin_context,
                                                         instance_ref)

    macs = [vif['address'] for vif in nw_info]
    for b in db.bw_usage_get_by_macs(admin_context,
                                     macs,
                                     audit_start):
        label = 'net-name-not-found-%s' % b['mac']
        for vif in nw_info:
            if vif['address'] == b['mac']:
                label = vif['network']['label']
                break

        bw[label] = dict(bw_in=b.bw_in, bw_out=b.bw_out)
    usage_info = utils.usage_from_instance(instance_ref,
                          audit_period_beginning=str(audit_start),
                          audit_period_ending=str(audit_end),
                          bandwidth=bw)
    notifier_api.notify('compute.%s' % FLAGS.host,
                        'compute.instance.exists',
                        notifier_api.INFO,
                        usage_info)
コード例 #12
0
def notify_usage_exists(instance_ref, current_period=False):
    """ Generates 'exists' notification for an instance for usage auditing
        purposes.

        Generates usage for last completed period, unless 'current_period'
        is True."""
    admin_context = context.get_admin_context(read_deleted='yes')
    begin, end = utils.current_audit_period()
    bw = {}
    if current_period:
        audit_start = end
        audit_end = utils.utcnow()
    else:
        audit_start = begin
        audit_end = end

    if (instance_ref.get('info_cache') and
        instance_ref['info_cache'].get('network_info')):

        cached_info = instance_ref['info_cache']['network_info']
        nw_info = network_model.NetworkInfo.hydrate(cached_info)
    else:
        nw_info = network.API().get_instance_nw_info(admin_context,
                                                         instance_ref)

    for b in db.bw_usage_get_by_instance(admin_context,
                                         instance_ref['id'],
                                         audit_start):
        label = 'net-name-not-found-%s' % b['mac']
        for vif in nw_info:
            if vif['address'] == b['mac']:
                label = vif['network']['label']
                break

        bw[label] = dict(bw_in=b.bw_in, bw_out=b.bw_out)
    usage_info = utils.usage_from_instance(instance_ref,
                          audit_period_beginning=str(audit_start),
                          audit_period_ending=str(audit_end),
                          bandwidth=bw)
    notifier_api.notify('compute.%s' % FLAGS.host,
                        'compute.instance.exists',
                        notifier_api.INFO,
                        usage_info)
コード例 #13
0
 def test_year_with_offset_after_current(self):
     begin, end = utils.current_audit_period(unit='year@6')
     self.assertEquals(begin, datetime.datetime(day=1, month=6, year=2010))
     self.assertEquals(end, datetime.datetime(day=1, month=6, year=2011))
コード例 #14
0
 def test_year(self):
     begin, end = utils.current_audit_period(unit='year')
     self.assertEquals(begin, datetime.datetime(day=1, month=1, year=2011))
     self.assertEquals(end, datetime.datetime(day=1, month=1, year=2012))
コード例 #15
0
 def test_month_with_offset_after_current(self):
     begin, end = utils.current_audit_period(unit='month@15')
     self.assertEquals(begin, datetime.datetime(day=15, month=1, year=2012))
     self.assertEquals(end, datetime.datetime(day=15, month=2, year=2012))
コード例 #16
0
 def test_day_with_offset_after_current(self):
     begin, end = utils.current_audit_period(unit='day@10')
     self.assertEquals(
         begin, datetime.datetime(hour=10, day=3, month=3, year=2012))
     self.assertEquals(
         end, datetime.datetime(hour=10, day=4, month=3, year=2012))
コード例 #17
0
 def test_day(self):
     begin, end = utils.current_audit_period(unit='day')
     self.assertEquals(begin, datetime.datetime(day=4, month=3, year=2012))
     self.assertEquals(end, datetime.datetime(day=5, month=3, year=2012))
コード例 #18
0
 def test_hour(self):
     begin, end = utils.current_audit_period(unit='hour')
     self.assertEquals(begin,
                       datetime.datetime(hour=7, day=5, month=3, year=2012))
     self.assertEquals(end,
                       datetime.datetime(hour=8, day=5, month=3, year=2012))