From 0ed410621b3c2d621aa3fa52ca7ac46c6a5f0b70 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Mon, 23 May 2011 16:19:12 -0700 Subject: getting closer to working select call --- nova/api/openstack/servers.py | 3 +++ nova/api/openstack/zones.py | 6 +----- nova/compute/api.py | 18 ++++++++++-------- nova/flags.py | 2 ++ nova/scheduler/api.py | 5 +++++ nova/scheduler/manager.py | 4 +++- nova/scheduler/zone_aware_scheduler.py | 17 +++++++++++++++-- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 738910bc8..474695d98 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -189,6 +189,9 @@ class Controller(common.OpenstackController): inst['instance_type'] = inst_type inst['image_id'] = requested_image_id + # TODO(sandy): REMOVE THIS + LOG.debug(_("***** INST = %(inst)s") % locals()) + builder = self._get_view_builder(req) server = builder.build(inst, is_detail=True) server['server']['adminPass'] = password diff --git a/nova/api/openstack/zones.py b/nova/api/openstack/zones.py index 70653dc0e..b9662761d 100644 --- a/nova/api/openstack/zones.py +++ b/nova/api/openstack/zones.py @@ -18,6 +18,7 @@ import urlparse from nova import crypto from nova import db +from nova import exception from nova import flags from nova import log as logging from nova.api.openstack import common @@ -25,11 +26,6 @@ from nova.scheduler import api FLAGS = flags.FLAGS -flags.DEFINE_string('build_plan_encryption_key', - None, - '128bit (hex) encryption key for scheduler build plans.') - - LOG = logging.getLogger('nova.api.openstack.zones') diff --git a/nova/compute/api.py b/nova/compute/api.py index 785aff397..301c777bb 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -257,19 +257,21 @@ class API(base.Base): # we'll be ripping this whole for-loop out and deferring the # creation of the Instance record. At that point all this will # change. + filter_driver = 'nova.scheduler.host_filter.InstanceTypeFilter' + request_spec = { + 'instance_properties': base_options, + 'instance_type': instance_type, + 'filter_driver': filter_driver, + 'blob': zone_blob + } + LOG.debug(_("**** REQUEST SPEC: %(request_spec)s") % locals()) + rpc.cast(context, FLAGS.scheduler_topic, {"method": "run_instance", "args": {"topic": FLAGS.compute_topic, "instance_id": instance_id, - "request_spec": { - 'instance_properties': instance, - 'instance_type': instance_type, - 'filter_driver': - 'nova.scheduler.host_filter.' - 'InstanceTypeFilter', - 'blob': zone_blob - }, + "request_spec": request_spec, "availability_zone": availability_zone, "injected_files": injected_files}}) diff --git a/nova/flags.py b/nova/flags.py index 519793643..0b7cd478e 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -376,3 +376,5 @@ DEFINE_string('zone_name', 'nova', 'name of this zone') DEFINE_list('zone_capabilities', ['hypervisor=xenserver;kvm', 'os=linux;windows'], 'Key/Multi-value list representng capabilities of this zone') +DEFINE_string('build_plan_encryption_key', None, + '128bit (hex) encryption key for scheduler build plans.') diff --git a/nova/scheduler/api.py b/nova/scheduler/api.py index 55f8e0a6d..f9a4f238b 100644 --- a/nova/scheduler/api.py +++ b/nova/scheduler/api.py @@ -18,6 +18,7 @@ Handles all requests relating to schedulers. """ import novaclient +import traceback #nuke from nova import db from nova import exception @@ -124,6 +125,7 @@ def call_zone_method(context, method, errors_to_ignore=None, *args, **kwargs): nova = novaclient.OpenStack(zone.username, zone.password, zone.api_url) nova.authenticate() + LOG.warn(_("*** AUTHENTICATED") % locals())#asdads except novaclient.exceptions.BadRequest, e: url = zone.api_url LOG.warn(_("Failed request to zone; URL=%(url)s: %(e)s") @@ -135,10 +137,13 @@ def call_zone_method(context, method, errors_to_ignore=None, *args, **kwargs): def _error_trap(*args, **kwargs): try: + LOG.warn(_("*** CALLING ZONE") % locals())#asdads return zone_method(*args, **kwargs) except Exception as e: if type(e) in errors_to_ignore: return None + ex = traceback.format_exc(e) + LOG.warn(_("*** CAUGHT EXCEPTION %(ex)s") % locals())#asdads # TODO (dabo) - want to be able to re-raise here. # Returning a string now; raising was causing issues. # raise e diff --git a/nova/scheduler/manager.py b/nova/scheduler/manager.py index bd40e73c0..96e69566d 100644 --- a/nova/scheduler/manager.py +++ b/nova/scheduler/manager.py @@ -80,7 +80,9 @@ class SchedulerManager(manager.Manager): try: host = getattr(self.driver, driver_method)(elevated, *args, **kwargs) - except AttributeError: + except AttributeError, e: + LOG.exception(_("Driver Method %(driver_method)s missing: %(e)s") + % locals()) host = self.driver.schedule(elevated, topic, *args, **kwargs) if not host: diff --git a/nova/scheduler/zone_aware_scheduler.py b/nova/scheduler/zone_aware_scheduler.py index 20f7694a1..6c666d1a8 100644 --- a/nova/scheduler/zone_aware_scheduler.py +++ b/nova/scheduler/zone_aware_scheduler.py @@ -23,12 +23,16 @@ across zones. There are two expansion points to this class for: import operator import M2Crypto +from nova import crypto from nova import db -from nova import rpc +from nova import flags from nova import log as logging +from nova import rpc + from nova.scheduler import api from nova.scheduler import driver +FLAGS = flags.FLAGS LOG = logging.getLogger('nova.scheduler.zone_aware_scheduler') @@ -51,7 +55,8 @@ class ZoneAwareScheduler(driver.Scheduler): # TODO(sandy): We'll have to look for richer specs at some point. - if 'blob' in request_spec: + blob = request_spec['blob'] + if blob: self.provision_resource(context, request_spec, instance_id, request_spec, kwargs) return None @@ -99,6 +104,8 @@ class ZoneAwareScheduler(driver.Scheduler): # 1. valid, # 2. intended for this zone or a child zone. # if 2 ... forward call to child zone. + LOG.debug(_("****** PROVISION IN CHILD %(item)s") % locals()) + blob = item['blob'] decryptor = crypto.decryptor(FLAGS.build_plan_encryption_key) host_info = None @@ -182,16 +189,21 @@ class ZoneAwareScheduler(driver.Scheduler): #TODO(sandy): how to infer this from OS API params? num_instances = 1 + LOG.debug(_("XXXXXXX - 1 - _SCHEDULE")) + # Filter local hosts based on requirements ... host_list = self.filter_hosts(num_instances, request_spec) + LOG.debug(_("XXXXXXX - 2 - _SCHEDULE")) # then weigh the selected hosts. # weighted = [{weight=weight, name=hostname}, ...] weighted = self.weigh_hosts(num_instances, request_spec, host_list) + LOG.debug(_("XXXXXXX - 3 - _SCHEDULE")) # Next, tack on the best weights from the child zones ... child_results = self._call_zone_method(context, "select", specs=request_spec) + LOG.debug(_("XXXXXXX - 4 - _SCHEDULE - CHILD RESULTS %(child_results)s") % locals()) for child_zone, result in child_results: for weighting in result: # Remember the child_zone so we can get back to @@ -203,6 +215,7 @@ class ZoneAwareScheduler(driver.Scheduler): "child_blob": weighting["blob"]} weighted.append(host_dict) + LOG.debug(_("XXXXXXX - 4 - _SCHEDULE")) weighted.sort(key=operator.itemgetter('weight')) return weighted -- cgit