~gandelman-a/ubuntu/precise/nova/UCA_2012.2.1

« back to all changes in this revision

Viewing changes to nova/scheduler/host_manager.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2012-08-16 14:04:11 UTC
  • mfrom: (1.1.59)
  • Revision ID: package-import@ubuntu.com-20120816140411-8dvudjblnx1w0mwx
Tags: 2012.2~f3-0ubuntu1
[ Chuck Short ]
* New upstream version.
* debian/rules: Re-enable testsuite.
* debian/control:
  - Add python-quantumclient as a build depends.
  - Bump standards to 3.9.3
  - Fix lintian warnings.
  - Recommend python-glanceclient and python-keystoneclient.
  - Add dependency of iptables for nova-network.
* debian/watch: Update
* debian/rules: Do not run pep8 tests since upstream is still using an
  older pep8.
* debian/patches/0001-Update-tools-hacking-for-pep8-1.2-and-
  beyond.patch: Get the testsuite running again.
* debian/nova-volume.install, debian/nova_tgt: Add support for
  persistent volumes.

[ Adam Gandelman ]
* debian/{nova-api.install, nova-api-metadata.install}: Install
  api-metadata.filters. (LP: #1002111)
* debian/control: Added python-glanceclient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
Manage hosts in the current zone.
18
18
"""
19
19
 
20
 
import datetime
21
20
import UserDict
22
21
 
23
22
from nova import db
44
43
                    'maps to all filters included with nova.'),
45
44
    cfg.ListOpt('scheduler_default_filters',
46
45
                default=[
 
46
                  'RetryFilter',
47
47
                  'AvailabilityZoneFilter',
48
48
                  'RamFilter',
49
 
                  'ComputeFilter'
 
49
                  'ComputeFilter',
 
50
                  'ComputeCapabilitiesFilter'
50
51
                  ],
51
52
                help='Which filter class names to use for filtering hosts '
52
53
                      'when not specified in the request.'),
221
222
                filtered_hosts.append(host)
222
223
        return filtered_hosts
223
224
 
224
 
    def get_host_list(self):
225
 
        """Returns a list of dicts for each host that the Zone Manager
226
 
        knows about. Each dict contains the host_name and the service
227
 
        for that host.
228
 
        """
229
 
        all_hosts = self.service_states.keys()
230
 
        ret = []
231
 
        for host in self.service_states:
232
 
            for svc in self.service_states[host]:
233
 
                ret.append({"service": svc, "host_name": host})
234
 
        return ret
235
 
 
236
 
    def get_service_capabilities(self):
237
 
        """Roll up all the individual host info to generic 'service'
238
 
           capabilities. Each capability is aggregated into
239
 
           <cap>_min and <cap>_max values."""
240
 
        hosts_dict = self.service_states
241
 
 
242
 
        # TODO(sandy) - be smarter about fabricating this structure.
243
 
        # But it's likely to change once we understand what the Best-Match
244
 
        # code will need better.
245
 
        combined = {}  # { <service>_<cap> : (min, max), ... }
246
 
        stale_host_services = {}  # { host1 : [svc1, svc2], host2 :[svc1]}
247
 
        for host, host_dict in hosts_dict.iteritems():
248
 
            for service_name, service_dict in host_dict.iteritems():
249
 
                if not service_dict.get("enabled", True):
250
 
                    # Service is disabled; do no include it
251
 
                    continue
252
 
 
253
 
                # Check if the service capabilities became stale
254
 
                if self.host_service_caps_stale(host, service_name):
255
 
                    if host not in stale_host_services:
256
 
                        stale_host_services[host] = []  # Adding host key once
257
 
                    stale_host_services[host].append(service_name)
258
 
                    continue
259
 
                for cap, value in service_dict.iteritems():
260
 
                    if cap == "timestamp":  # Timestamp is not needed
261
 
                        continue
262
 
                    key = "%s_%s" % (service_name, cap)
263
 
                    min_value, max_value = combined.get(key, (value, value))
264
 
                    min_value = min(min_value, value)
265
 
                    max_value = max(max_value, value)
266
 
                    combined[key] = (min_value, max_value)
267
 
 
268
 
        # Delete the expired host services
269
 
        self.delete_expired_host_services(stale_host_services)
270
 
        return combined
271
 
 
272
225
    def update_service_capabilities(self, service_name, host, capabilities):
273
226
        """Update the per-service capabilities based on this notification."""
274
227
        LOG.debug(_("Received %(service_name)s service update from "
280
233
        service_caps[service_name] = capab_copy
281
234
        self.service_states[host] = service_caps
282
235
 
283
 
    def host_service_caps_stale(self, host, service):
284
 
        """Check if host service capabilites are not recent enough."""
285
 
        allowed_time_diff = FLAGS.periodic_interval * 3
286
 
        caps = self.service_states[host][service]
287
 
        if ((timeutils.utcnow() - caps["timestamp"]) <=
288
 
            datetime.timedelta(seconds=allowed_time_diff)):
289
 
            return False
290
 
        return True
291
 
 
292
 
    def delete_expired_host_services(self, host_services_dict):
293
 
        """Delete all the inactive host services information."""
294
 
        for host, services in host_services_dict.iteritems():
295
 
            service_caps = self.service_states[host]
296
 
            for service in services:
297
 
                del service_caps[service]
298
 
                if len(service_caps) == 0:  # Delete host if no services
299
 
                    del self.service_states[host]
300
 
 
301
236
    def get_all_host_states(self, context, topic):
302
237
        """Returns a dict of all the hosts the HostManager
303
238
        knows about. Also, each of the consumable resources in HostState