diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-01-09 00:39:30 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-01-09 00:39:30 +0000 |
commit | e09a946ccfaf80a9bc4bbbbf327169c09974117c (patch) | |
tree | da32130666666d05641874069e6ec86fef809197 | |
parent | 14b897910bedde46edae1aa87118a42f162e080b (diff) | |
parent | 541a87587e1d5bd8c382b85debaa6f37bea6c13d (diff) | |
download | ceilometer-2015.1.3.tar.gz |
Merge "Instance Caching" into stable/kilo2015.1.3
-rw-r--r-- | ceilometer/compute/discovery.py | 16 | ||||
-rw-r--r-- | ceilometer/nova_client.py | 10 |
2 files changed, 21 insertions, 5 deletions
diff --git a/ceilometer/compute/discovery.py b/ceilometer/compute/discovery.py index ac6afafd..e85d067b 100644 --- a/ceilometer/compute/discovery.py +++ b/ceilometer/compute/discovery.py @@ -14,6 +14,7 @@ # under the License. from oslo_config import cfg +from oslo_utils import timeutils from ceilometer.agent import plugin_base from ceilometer import nova_client @@ -31,12 +32,21 @@ class InstanceDiscovery(plugin_base.DiscoveryBase): def __init__(self): super(InstanceDiscovery, self).__init__() self.nova_cli = nova_client.Client() + self.last_run = None + self.instances = {} def discover(self, manager, param=None): """Discover resources to monitor.""" - instances = self.nova_cli.instance_get_all_by_host(cfg.CONF.host) - return [i for i in instances - if getattr(i, 'OS-EXT-STS:vm_state', None) != 'error'] + instances = self.nova_cli.instance_get_all_by_host( + cfg.CONF.host, self.last_run) + for instance in instances: + if getattr(instance, 'OS-EXT-STS:vm_state', None) in ['deleted', + 'error']: + self.instances.pop(instance.id, None) + else: + self.instances[instance.id] = instance + self.last_run = timeutils.utcnow(True).isoformat() + return self.instances.values() @property def group_id(self): diff --git a/ceilometer/nova_client.py b/ceilometer/nova_client.py index 47f8ee59..3d6a4174 100644 --- a/ceilometer/nova_client.py +++ b/ceilometer/nova_client.py @@ -137,9 +137,15 @@ class Client(object): setattr(instance, attr, ameta) @logged - def instance_get_all_by_host(self, hostname): - """Returns list of instances on particular host.""" + def instance_get_all_by_host(self, hostname, since=None): + """Returns list of instances on particular host. + + If since is supplied, it will return the instances changed since that + datetime. since should be in ISO Format '%Y-%m-%dT%H:%M:%SZ' + """ search_opts = {'host': hostname, 'all_tenants': True} + if since: + search_opts['changes-since'] = since return self._with_flavor_and_image(self.nova_client.servers.list( detailed=True, search_opts=search_opts)) |