18
18
# License for the specific language governing permissions and limitations
19
19
# under the License.
21
from oslo.config import cfg
22
from oslo.utils import timeutils
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
28
31
LOG = log.getLogger(__name__)
33
cfg.CONF.import_group('service_types', 'ceilometer.nova_client')
31
36
class FloatingIPPollster(plugin.CentralPollster):
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()
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'])
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.
51
type=sample.TYPE_GAUGE,
57
timestamp=timeutils.utcnow().isoformat(),
43
def _iter_floating_ips(self, ksclient, cache, endpoint):
44
key = '%s-floating_ips' % endpoint
46
cache[key] = list(self._get_floating_ips(ksclient, endpoint))
47
return iter(cache[key])
50
def default_discovery(self):
51
return 'endpoint:%s' % cfg.CONF.service_types.nova
53
def get_samples(self, manager, cache, resources):
54
for endpoint in resources:
55
for ip in self._iter_floating_ips(manager.keystone, cache,
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
65
type=sample.TYPE_GAUGE,
71
timestamp=timeutils.utcnow().isoformat(),