~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to ceilometer/network/statistics/__init__.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-03-06 14:44:28 UTC
  • mto: (28.1.1 utopic-proposed) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: package-import@ubuntu.com-20140306144428-rvphsh4igwyulzf0
Tags: upstream-2014.1~b3
ImportĀ upstreamĀ versionĀ 2014.1~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright 2014 NEC Corporation.  All rights reserved.
 
3
#
 
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
# not use this file except in compliance with the License. You may obtain
 
6
# a copy of the License at
 
7
#
 
8
#      http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
# Unless required by applicable law or agreed to in writing, software
 
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
# License for the specific language governing permissions and limitations
 
14
# under the License.
 
15
 
 
16
import abc
 
17
 
 
18
import six
 
19
from stevedore import extension
 
20
 
 
21
from ceilometer.central import plugin
 
22
from ceilometer import sample
 
23
 
 
24
 
 
25
@six.add_metaclass(abc.ABCMeta)
 
26
class _Base(plugin.CentralPollster):
 
27
 
 
28
    NAMESPACE = 'network.statistics.drivers'
 
29
    extension_manager = extension.ExtensionManager(namespace=NAMESPACE,
 
30
                                                   invoke_on_load=True)
 
31
 
 
32
    @abc.abstractproperty
 
33
    def meter_name(self):
 
34
        '''Return a Meter Name.'''
 
35
 
 
36
    @abc.abstractproperty
 
37
    def meter_type(self):
 
38
        '''Return a Meter Type.'''
 
39
 
 
40
    @abc.abstractproperty
 
41
    def meter_unit(self):
 
42
        '''Return a Meter Unit.'''
 
43
 
 
44
    def get_samples(self, manager, cache, resources=[]):
 
45
        for resource in resources:
 
46
            sample_data = self.extension_manager.map_method('get_sample_data',
 
47
                                                            self.meter_name,
 
48
                                                            resource,
 
49
                                                            cache)
 
50
            for data in sample_data:
 
51
                if data is None:
 
52
                    continue
 
53
                if not isinstance(data, list):
 
54
                    data = [data]
 
55
                for (volume, resource_id,
 
56
                     resource_metadata, timestamp) in data:
 
57
 
 
58
                    yield sample.Sample(
 
59
                        name=self.meter_name,
 
60
                        type=self.meter_type,
 
61
                        unit=self.meter_unit,
 
62
                        volume=volume,
 
63
                        user_id=None,
 
64
                        project_id=None,
 
65
                        resource_id=resource_id,
 
66
                        timestamp=timestamp,
 
67
                        resource_metadata=resource_metadata
 
68
                    )