~ubuntu-branches/ubuntu/utopic/ceilometer/utopic

« back to all changes in this revision

Viewing changes to ceilometer/network/floatingip.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-10-16 14:07:11 UTC
  • mfrom: (1.2.1) (28.1.5 utopic-proposed)
  • Revision ID: package-import@ubuntu.com-20141016140711-95mki6bdkivvfr2x
Tags: 2014.2-0ubuntu1
New upstream release. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# License for the specific language governing permissions and limitations
19
19
# under the License.
20
20
 
 
21
from oslo.config import cfg
 
22
from oslo.utils import timeutils
 
23
 
21
24
from ceilometer.central import plugin
22
25
from ceilometer import nova_client
23
26
from ceilometer.openstack.common.gettextutils import _
24
27
from ceilometer.openstack.common import log
25
 
from ceilometer.openstack.common import timeutils
26
28
from ceilometer import sample
27
29
 
 
30
 
28
31
LOG = log.getLogger(__name__)
29
32
 
 
33
cfg.CONF.import_group('service_types', 'ceilometer.nova_client')
 
34
 
30
35
 
31
36
class FloatingIPPollster(plugin.CentralPollster):
32
37
 
33
 
    def _get_floating_ips(self):
34
 
        nv = nova_client.Client()
 
38
    def _get_floating_ips(self, ksclient, endpoint):
 
39
        nv = nova_client.Client(
 
40
            auth_token=ksclient.auth_token, bypass_url=endpoint)
35
41
        return nv.floating_ip_get_all()
36
42
 
37
 
    def _iter_floating_ips(self, cache):
38
 
        if 'floating_ips' not in cache:
39
 
            cache['floating_ips'] = list(self._get_floating_ips())
40
 
        return iter(cache['floating_ips'])
41
 
 
42
 
    def get_samples(self, manager, cache, resources=None):
43
 
        for ip in self._iter_floating_ips(cache):
44
 
            LOG.info(_("FLOATING IP USAGE: %s") % ip.ip)
45
 
            # FIXME (flwang) Now Nova API /os-floating-ips can't provide those
46
 
            # attributes were used by Ceilometer, such as project id, host.
47
 
            # In this fix, those attributes usage will be removed temporarily.
48
 
            # And they will be back after fix the Nova bug 1174802.
49
 
            yield sample.Sample(
50
 
                name='ip.floating',
51
 
                type=sample.TYPE_GAUGE,
52
 
                unit='ip',
53
 
                volume=1,
54
 
                user_id=None,
55
 
                project_id=None,
56
 
                resource_id=ip.id,
57
 
                timestamp=timeutils.utcnow().isoformat(),
58
 
                resource_metadata={
59
 
                    'address': ip.ip,
60
 
                    'pool': ip.pool
61
 
                })
 
43
    def _iter_floating_ips(self, ksclient, cache, endpoint):
 
44
        key = '%s-floating_ips' % endpoint
 
45
        if key not in cache:
 
46
            cache[key] = list(self._get_floating_ips(ksclient, endpoint))
 
47
        return iter(cache[key])
 
48
 
 
49
    @property
 
50
    def default_discovery(self):
 
51
        return 'endpoint:%s' % cfg.CONF.service_types.nova
 
52
 
 
53
    def get_samples(self, manager, cache, resources):
 
54
        for endpoint in resources:
 
55
            for ip in self._iter_floating_ips(manager.keystone, cache,
 
56
                                              endpoint):
 
57
                LOG.info(_("FLOATING IP USAGE: %s") % ip.ip)
 
58
                # FIXME (flwang) Now Nova API /os-floating-ips can't provide
 
59
                # those attributes were used by Ceilometer, such as project
 
60
                # id, host. In this fix, those attributes usage will be
 
61
                # removed temporarily. And they will be back after fix the
 
62
                # Nova bug 1174802.
 
63
                yield sample.Sample(
 
64
                    name='ip.floating',
 
65
                    type=sample.TYPE_GAUGE,
 
66
                    unit='ip',
 
67
                    volume=1,
 
68
                    user_id=None,
 
69
                    project_id=None,
 
70
                    resource_id=ip.id,
 
71
                    timestamp=timeutils.utcnow().isoformat(),
 
72
                    resource_metadata={
 
73
                        'address': ip.ip,
 
74
                        'pool': ip.pool
 
75
                    })