Exemple #1
0
 def serialize_context(self, context):
     _context = context.to_dict()
     prof = profiler.get()
     if prof:
         trace_info = {"hmac_key": prof.hmac_key, "base_id": prof.get_base_id(), "parent_id": prof.get_id()}
         _context.update({"trace_info": trace_info})
     return _context
    def _get_cascaded_cinder_client(self, context=None):
        try:
            if context is None:
                cinderclient = cinder_client.Client(
                    auth_url=CONF.keystone_auth_url,
                    region_name=CONF.cascaded_region_name,
                    tenant_id=self.tenant_id,
                    api_key=CONF.admin_password,
                    username=CONF.cinder_username,
                    insecure=True,
                    timeout=30,
                    retries=3)
            else:
                ctx_dict = context.to_dict()

                kwargs = {
                    'auth_url': CONF.keystone_auth_url,
                    'tenant_name': CONF.cinder_tenant_name,
                    'username': CONF.cinder_username,
                    'password': CONF.admin_password,
                    'insecure': True
                }
                keystoneclient = kc.Client(**kwargs)
                management_url = self._get_management_url(keystoneclient, service_type='volumev2',
                                                      attr='region',
                                                      endpoint_type='publicURL',
                                                      filter_value=CONF.cascaded_region_name)

                LOG.info("before replace: management_url:%s", management_url)
                url = management_url.rpartition("/")[0]
                management_url = url+ '/' + ctx_dict.get("project_id")

                LOG.info("after replace: management_url:%s", management_url)

                cinderclient = cinder_client.Client(
                username=ctx_dict.get('user_id'),
                auth_url=cfg.CONF.keystone_auth_url,
                insecure=True,
                timeout=30,
                retries=3)
                cinderclient.client.auth_token = ctx_dict.get('auth_token')
                cinderclient.client.management_url = management_url

            LOG.info(_("cascade info: os_region_name:%s"), CONF.cascaded_region_name)
            return cinderclient
        except keystone_exception.Unauthorized:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Token unauthorized failed for keystoneclient '
                            'constructed when get cascaded admin client'))
        except cinder_exception.Unauthorized:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Token unauthorized failed for cascaded '
                            'cinderClient constructed'))
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Failed to get cinder python client.'))
Exemple #3
0
    def _get_cascaded_cinder_client(self, context=None):
        try:
            if context is None:
                cinderclient = cinder_client.Client(
                    auth_url=CONF.keystone_auth_url,
                    region_name=CONF.cascaded_region_name,
                    tenant_id=self.tenant_id,
                    api_key=CONF.admin_password,
                    username=CONF.cinder_username,
                    insecure=True,
                    timeout=30,
                    retries=3)
            else:
                ctx_dict = context.to_dict()

                kwargs = {
                    'auth_url': CONF.keystone_auth_url,
                    'tenant_name': CONF.cinder_tenant_name,
                    'username': CONF.cinder_username,
                    'password': CONF.admin_password,
                    'insecure': True
                }
                keystoneclient = kc.Client(**kwargs)
                management_url = self._get_management_url(keystoneclient, service_type='volumev2',
                                                      attr='region',
                                                      endpoint_type='publicURL',
                                                      filter_value=CONF.cascaded_region_name)

                LOG.info("before replace: management_url:%s", management_url)
                url = management_url.rpartition("/")[0]
                management_url = url+ '/' + ctx_dict.get("project_id")

                LOG.info("after replace: management_url:%s", management_url)

                cinderclient = cinder_client.Client(
                username=ctx_dict.get('user_id'),
                auth_url=cfg.CONF.keystone_auth_url,
                insecure=True,
                timeout=30,
                retries=3)
                cinderclient.client.auth_token = ctx_dict.get('auth_token')
                cinderclient.client.management_url = management_url

            LOG.info(_("cascade info: os_region_name:%s"), CONF.cascaded_region_name)
            return cinderclient
        except keystone_exception.Unauthorized:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Token unauthorized failed for keystoneclient '
                            'constructed when get cascaded admin client'))
        except cinder_exception.Unauthorized:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Token unauthorized failed for cascaded '
                            'cinderClient constructed'))
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Failed to get cinder python client.'))
Exemple #4
0
 def serialize_context(self, context):
     _context = context.to_dict()
     prof = profiler.get()
     if prof:
         trace_info = {
             "hmac_key": prof.hmac_key,
             "base_id": prof.get_base_id(),
             "parent_id": prof.get_id()
         }
         _context.update({"trace_info": trace_info})
     return _context
Exemple #5
0
def pack_context(msg, context):
    """Pack context into msg.

    Values for message keys need to be less than 255 chars, so we pull
    context out into a bunch of separate keys. If we want to support
    more arguments in rabbit messages, we may want to do the same
    for args at some point.

    """
    context_d = dict([('_context_%s' % key, value)
                      for (key, value) in context.to_dict().iteritems()])
    msg.update(context_d)
Exemple #6
0
    def _get_cinder_cascaded_user_client(self, context):

        try:
            ctx_dict = context.to_dict()
            cinderclient = cinder_client.Client(
                username=ctx_dict.get('user_id'),
                api_key=ctx_dict.get('auth_token'),
                project_id=ctx_dict.get('project_name'),
                auth_url=cfg.CONF.keystone_auth_url)
            cinderclient.client.auth_token = ctx_dict.get('auth_token')
            cinderclient.client.management_url = \
                cfg.CONF.cascaded_cinder_url % ctx_dict
            return cinderclient

        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Failed to get cinder python client.'))
Exemple #7
0
 def _inner():
     ctxt = RpcContext.from_dict(context.to_dict())
     try:
         rval = node_func(context=ctxt, **node_args)
         res = []
         # Caller might have called ctxt.reply() manually
         for (reply, failure) in ctxt._response:
             if failure:
                 raise failure[0], failure[1], failure[2]
             res.append(reply)
         # if ending not 'sent'...we might have more data to
         # return from the function itself
         if not ctxt._done:
             if inspect.isgenerator(rval):
                 for val in rval:
                     res.append(val)
             else:
                 res.append(rval)
         done.send(res)
     except Exception as e:
         done.send_exception(e)
Exemple #8
0
 def context(context, value):
     """Returns dictionary version of context."""
     LOG.debug(_("Received %s"), context)
     return context.to_dict()
Exemple #9
0
 def serialize_context(self, context):
     return context.to_dict()