Add floating IP pollster
Change-Id: Ia5e71117f0e1bec7dcbbd5a9332c07297fcd5c1f Signed-off-by: Julien Danjou <julien.danjou@enovance.com>
This commit is contained in:
parent
dbccf0ce69
commit
d4635bede1
|
@ -0,0 +1,50 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 eNovance <licensing@enovance.com>
|
||||
#
|
||||
# Author: Julien Danjou <julien@danjou.info>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova import log as logging
|
||||
from nova import exception
|
||||
|
||||
from .. import counter
|
||||
from .. import plugin
|
||||
|
||||
|
||||
class FloatingIPPollster(plugin.PollsterBase):
|
||||
|
||||
LOG = logging.getLogger('nova.' + __name__ + '.floatingip')
|
||||
|
||||
def get_counters(self, manager, context):
|
||||
try:
|
||||
ips = manager.db.floating_ip_get_all_by_host(context, manager.host)
|
||||
except exception.FloatingIpNotFoundForHost:
|
||||
pass
|
||||
else:
|
||||
for ip in ips:
|
||||
self.LOG.info("FLOATING IP USAGE: %s" % ip.address)
|
||||
yield counter.Counter(source='?',
|
||||
type='floating_ip',
|
||||
volume=1,
|
||||
user_id=None,
|
||||
project_id=ip.project_id,
|
||||
resource_id=ip.id,
|
||||
datetime=None,
|
||||
duration=None,
|
||||
resource_metadata={'address': ip.address,
|
||||
'fixed_ip_id': ip.fixed_ip_id,
|
||||
'host': ip.host,
|
||||
'pool': ip.pool,
|
||||
'auto_assigned': ip.auto_assigned})
|
1
setup.py
1
setup.py
|
@ -38,6 +38,7 @@ setuptools.setup(
|
|||
'ceilometer.poll.compute': [
|
||||
'libvirt_diskio = ceilometer.compute.libvirt:DiskIOPollster',
|
||||
'libvirt_cpu = ceilometer.compute.libvirt:CPUPollster',
|
||||
'network_floatingip = ceilometer.compute.network:FloatingIPPollster',
|
||||
],
|
||||
},
|
||||
)
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 eNovance <licensing@enovance.com>
|
||||
#
|
||||
# Author: Julien Danjou <julien@danjou.info>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova import context
|
||||
from nova import test
|
||||
from nova import db
|
||||
|
||||
from ceilometer.compute import network
|
||||
from ceilometer.agent import manager
|
||||
|
||||
|
||||
class TestFloatingIPPollster(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.context = context.RequestContext('admin', 'admin', is_admin=True)
|
||||
self.manager = manager.AgentManager()
|
||||
self.pollster = network.FloatingIPPollster()
|
||||
super(TestFloatingIPPollster, self).setUp()
|
||||
|
||||
def test_get_counters(self):
|
||||
self.assertEqual(list(self.pollster.get_counters(self.manager, self.context)), [])
|
||||
|
||||
def test_get_counters_not_empty(self):
|
||||
db.floating_ip_create(self.context,
|
||||
{'address': '1.1.1.1',
|
||||
'host': self.manager.host })
|
||||
db.floating_ip_create(self.context,
|
||||
{'address': '1.1.1.2',
|
||||
'host': self.manager.host + "randomstring" })
|
||||
db.floating_ip_create(self.context,
|
||||
{'address': '1.1.1.3',
|
||||
'host': self.manager.host + "randomstring" })
|
||||
counters = list(self.pollster.get_counters(self.manager, self.context))
|
||||
self.assertEqual(len(counters), 1)
|
||||
self.assertEqual(counters[0].resource_metadata['address'], '1.1.1.1')
|
||||
|
Loading…
Reference in New Issue