def _ask_child_zone_to_create_instance(self, context, zone_info, request_spec, kwargs): """Once we have determined that the request should go to one of our children, we need to fabricate a new POST /servers/ call with the same parameters that were passed into us. Note that we have to reverse engineer from our args to get back the image, flavor, ipgroup, etc. since the original call could have come in from EC2 (which doesn't use these things). """ instance_type = request_spec['instance_type'] instance_properties = request_spec['instance_properties'] name = instance_properties['display_name'] image_ref = instance_properties['image_ref'] meta = instance_properties['metadata'] flavor_id = instance_type['flavorid'] reservation_id = instance_properties['reservation_id'] files = kwargs['injected_files'] child_zone = zone_info['child_zone'] child_blob = zone_info['child_blob'] zone = db.zone_get(context, child_zone) url = zone.api_url LOG.debug( _("Forwarding instance create call to child zone %(url)s" ". ReservationID=%(reservation_id)s") % locals()) nova = None try: nova = novaclient.Client(zone.username, zone.password, None, url) nova.authenticate() except novaclient_exceptions.BadRequest, e: raise exception.NotAuthorized( _("Bad credentials attempting " "to talk to zone at %(url)s.") % locals())
def _call_novaclient(zone): """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) return client.zones.info()._info
def call_novaclient(self): """Call novaclient. Broken out for testing purposes. Note that we have to use the admin credentials for this since there is no available context.""" username = self.zone_info['username'] password = self.zone_info['password'] api_url = self.zone_info['api_url'] region_name = self.zone_info['name'] client = novaclient.Client(username, password, None, api_url, region_name) return client.zones.info()._info
def call_zone_method(context, method_name, errors_to_ignore=None, novaclient_collection_name='zones', zones=None, *args, **kwargs): """Returns a list of (zone, call_result) objects.""" if not isinstance(errors_to_ignore, (list, tuple)): # This will also handle the default None errors_to_ignore = [errors_to_ignore] pool = greenpool.GreenPool() results = [] if zones is None: zones = db.zone_get_all(context.elevated()) for zone in zones: try: # Do this on behalf of the user ... nova = novaclient.Client(zone.username, zone.password, None, zone.api_url, region_name=zone.name, token=context.auth_token) nova.authenticate() except novaclient_exceptions.BadRequest, e: url = zone.api_url 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 novaclient_collection = getattr(nova, novaclient_collection_name) collection_method = getattr(novaclient_collection, method_name) def _error_trap(*args, **kwargs): try: return collection_method(*args, **kwargs) except Exception as e: if type(e) in errors_to_ignore: return None raise res = pool.spawn(_error_trap, *args, **kwargs) results.append((zone, res))
def _process(func, 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) nova.authenticate() except novaclient_exceptions.BadRequest, e: url = zone.api_url LOG.warn( _("Failed request to zone; URL=%(url)s: %(e)s") % locals()) # This is being returned instead of raised, so that when # results are processed in unmarshal_result() after the # greenpool.imap completes, the exception can be raised # there if no other zones had a response. return exception.ZoneRequestError()
def _process(func, zone): """Worker stub for green thread pool. Give the worker an authenticated nova client and zone info.""" nova = novaclient.Client(zone.username, zone.password, None, zone.api_url) nova.authenticate() return func(nova, zone)
def _call_novaclient(zone): """Call novaclient. Broken out for testing purposes.""" client = novaclient.Client(zone.username, zone.password, None, zone.api_url) return client.zones.info()._info