'Create a trust using the trustor identity in the current context.
The trust is created with the trustee as the heat service user.
If the current context already contains a trust_id, we do nothing
and return the current context.
Returns a context containing the new trust_id.'

def create_trust_context(self):

    if self.context.trust_id:
        return self.context
    try:
        trustee_user_id = self.context.trusts_auth_plugin.get_user_id(self.session)
    except ks_exception.Unauthorized:
        LOG.error('Domain    admin    client    authentication    failed')
        raise exception.AuthorizationFailure()
    trustor_user_id = self.context.auth_plugin.get_user_id(self.session)
    trustor_proj_id = self.context.auth_plugin.get_project_id(self.session)
    if cfg.CONF.trusts_delegated_roles:
        roles = cfg.CONF.trusts_delegated_roles
    else:
        roles = self.context.roles
    try:
        trust = self.client.trusts.create(trustor_user=trustor_user_id, trustee_user=trustee_user_id, project=trustor_proj_id, impersonation=True, role_names=roles)
    except ks_exception.NotFound:
        LOG.debug(('Failed    to    find    roles    %s    for    user    %s' % (roles, trustor_user_id)))
        raise exception.MissingCredentialError(required=(_('roles    %s') % roles))
    context_data = self.context.to_dict()
    context_data['overwrite'] = False
    trust_context = context.RequestContext.from_dict(context_data)
    trust_context.trust_id = trust.id
    trust_context.trustor_user_id = trustor_user_id
    return trust_context
