From 797a89586bf68a3145b32b40889624f14461d7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Magimel?= Date: Sat, 13 Sep 2014 14:12:35 +0200 Subject: [PATCH] Add the link between the client and panels Change-Id: I0efa7b9b91a2c0d97f1506a74d5b0c16bbb6c277 --- cloudkittydashboard/api/__init__.py | 0 cloudkittydashboard/api/cloudkitty.py | 48 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 cloudkittydashboard/api/__init__.py create mode 100644 cloudkittydashboard/api/cloudkitty.py diff --git a/cloudkittydashboard/api/__init__.py b/cloudkittydashboard/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cloudkittydashboard/api/cloudkitty.py b/cloudkittydashboard/api/cloudkitty.py new file mode 100644 index 0000000..037a9bc --- /dev/null +++ b/cloudkittydashboard/api/cloudkitty.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 Objectif Libre +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# @author: François Magimel (linkid) + +""" +The API for the CloudKitty Horizon plugin. +""" + +import logging + +from cloudkittyclient import client as cloudkitty_client + +from openstack_dashboard.api import base + + +LOG = logging.getLogger(__name__) + + +def cloudkittyclient(request): + """Initialization of CloudKitty client.""" + username = request.user.username + token = request.user.token.id + tenant_name = request.user.tenant_id + endpoint = base.url_for(request, 'billing') + auth_url = base.url_for(request, 'identity') + + LOG.debug('cloudkittyclient connection created using token "%s" ' + 'and endpoint "%s"' % (request.user.token.id, endpoint)) + + return cloudkitty_client.Client('1', + username=username, + token=token, + tenant_name=tenant_name, + auth_url=auth_url, + endpoint=endpoint)