diff options
| author | Sandy Walsh <sandy.walsh@rackspace.com> | 2011-09-12 07:42:28 -0700 |
|---|---|---|
| committer | Sandy Walsh <sandy.walsh@rackspace.com> | 2011-09-12 07:42:28 -0700 |
| commit | 6299edf0f240d46b3de1de4bf89f839b5737a7f2 (patch) | |
| tree | d385fe22f81b435e8cb56a774f5244db7b45637c | |
| parent | 5de08f3ac11d936979a3c08c27b3b19b72d58373 (diff) | |
| parent | 043a13690dc4f2ba20965cced85d705e59f7406b (diff) | |
| download | nova-6299edf0f240d46b3de1de4bf89f839b5737a7f2.tar.gz nova-6299edf0f240d46b3de1de4bf89f839b5737a7f2.tar.xz nova-6299edf0f240d46b3de1de4bf89f839b5737a7f2.zip | |
parent merge
| -rw-r--r-- | nova/compute/api.py | 6 | ||||
| -rw-r--r-- | nova/scheduler/abstract_scheduler.py | 3 | ||||
| -rw-r--r-- | nova/scheduler/api.py | 23 | ||||
| -rw-r--r-- | nova/scheduler/zone_manager.py | 14 |
4 files changed, 27 insertions, 19 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index b0ea044c5..7211c2cf0 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -908,10 +908,8 @@ class API(base.Base): if not recurse_zones: return instances - # Recurse zones. Need admin context for this. Send along - # the un-modified search options we received.. - admin_context = context.elevated() - children = scheduler_api.call_zone_method(admin_context, + # Recurse zones. Send along the un-modified search options we received. + children = scheduler_api.call_zone_method(context, "list", errors_to_ignore=[novaclient.exceptions.NotFound], novaclient_collection_name="servers", diff --git a/nova/scheduler/abstract_scheduler.py b/nova/scheduler/abstract_scheduler.py index 6e8c7d715..b121444f2 100644 --- a/nova/scheduler/abstract_scheduler.py +++ b/nova/scheduler/abstract_scheduler.py @@ -118,7 +118,8 @@ class AbstractScheduler(driver.Scheduler): ". ReservationID=%(reservation_id)s") % locals()) nova = None try: - nova = novaclient.Client(zone.username, zone.password, None, url) + nova = novaclient.Client(zone.username, zone.password, None, url, + token=context.auth_token) nova.authenticate() except novaclient_exceptions.BadRequest, e: raise exception.NotAuthorized(_("Bad credentials attempting " diff --git a/nova/scheduler/api.py b/nova/scheduler/api.py index 719437b73..6c5118751 100644 --- a/nova/scheduler/api.py +++ b/nova/scheduler/api.py @@ -117,13 +117,16 @@ def call_zone_method(context, method_name, errors_to_ignore=None, zones = db.zone_get_all(context) for zone in zones: try: + # Do this on behalf of the user ... nova = novaclient.Client(zone.username, zone.password, None, - zone.api_url) + zone.api_url, region_name=zone.name, + token = context.auth_token) nova.authenticate() except novaclient_exceptions.BadRequest, e: url = zone.api_url - LOG.warn(_("Failed request to zone; URL=%(url)s: %(e)s") - % locals()) + name = zone.name + LOG.warn(_("Authentication failed to zone " + "'%(name)s' URL=%(url)s: %(e)s") % locals()) #TODO (dabo) - add logic for failure counts per zone, # with escalation after a given number of failures. continue @@ -144,7 +147,7 @@ def call_zone_method(context, method_name, errors_to_ignore=None, return [(zone.id, res.wait()) for zone, res in results] -def child_zone_helper(zone_list, func): +def child_zone_helper(context, zone_list, func): """Fire off a command to each zone in the list. The return is [novaclient return objects] from each child zone. For example, if you are calling server.pause(), the list will @@ -157,12 +160,12 @@ def child_zone_helper(zone_list, func): return function(arg1, *args, **kwargs) return _wrap - def _process(func, zone): + def _process(func, context, zone): """Worker stub for green thread pool. Give the worker an authenticated nova client and zone info.""" try: nova = novaclient.Client(zone.username, zone.password, None, - zone.api_url) + zone.api_url, token=context.auth_token) nova.authenticate() except novaclient_exceptions.BadRequest, e: url = zone.api_url @@ -178,7 +181,7 @@ def child_zone_helper(zone_list, func): green_pool = greenpool.GreenPool() return [result for result in green_pool.imap( - _wrap_method(_process, func), zone_list)] + _wrap_method(_process, func, context), zone_list)] def _issue_novaclient_command(nova, zone, collection, @@ -278,7 +281,7 @@ class reroute_compute(object): # Ask the children to provide an answer ... LOG.debug(_("Asking child zones ...")) - result = self._call_child_zones(zones, + result = self._call_child_zones(context, zones, wrap_novaclient_function(_issue_novaclient_command, collection, self.method_name, item_uuid)) # Scrub the results and raise another exception @@ -318,10 +321,10 @@ class reroute_compute(object): return wrapped_f - def _call_child_zones(self, zones, function): + def _call_child_zones(self, context, zones, function): """Ask the child zones to perform this operation. Broken out for testing.""" - return child_zone_helper(zones, function) + return child_zone_helper(context, zones, function) def get_collection_context_and_id(self, args, kwargs): """Returns a tuple of (novaclient collection name, security diff --git a/nova/scheduler/zone_manager.py b/nova/scheduler/zone_manager.py index a15228182..16b4c7faf 100644 --- a/nova/scheduler/zone_manager.py +++ b/nova/scheduler/zone_manager.py @@ -51,9 +51,12 @@ class ZoneState(object): def update_credentials(self, zone): """Update zone credentials from db""" self.zone_id = zone.id + self.name = zone.name self.api_url = zone.api_url self.username = zone.username self.password = zone.password + self.weight_offset = zone.weight_offset + self.weight_scale = zone.weight_scale def update_metadata(self, zone_metadata): """Update zone metadata after successful communications with @@ -67,7 +70,8 @@ class ZoneState(object): def to_dict(self): return dict(name=self.name, capabilities=self.capabilities, is_active=self.is_active, api_url=self.api_url, - id=self.zone_id) + id=self.zone_id, weight_scale=self.weight_scale, + weight_offset=self.weight_offset) def log_error(self, exception): """Something went wrong. Check to see if zone should be @@ -88,15 +92,17 @@ class ZoneState(object): def _call_novaclient(zone): - """Call novaclient. Broken out for testing purposes.""" + """Call novaclient. Broken out for testing purposes. Note that + we have to use the admin credentials for this since there is no + available context.""" client = novaclient.Client(zone.username, zone.password, None, - zone.api_url, region_name = zone.name) + zone.api_url, region_name=zone.name) return client.zones.info()._info def _poll_zone(zone): """Eventlet worker to poll a zone.""" - logging.debug(_("Polling zone: %s") % zone.api_url) + logging.debug(_("Polling zone: %s @ %s") % (zone.name, zone.api_url)) try: zone.update_metadata(_call_novaclient(zone)) except Exception, e: |
