From 8cfe15cf3988840512b9be580eb7ced08df2f828 Mon Sep 17 00:00:00 2001 From: Randall Burt Date: Wed, 28 May 2014 21:14:34 -0500 Subject: [PATCH] Account for differences in Rackspace Cloud Glance The Rackspace Cloud service catalog has a tenant-scoped URL for the image service so our client implementation needs to munge the URL a little to make it work. Change-Id: Ic5b3702aec8c4ab373dbcf6eb8e6f164d9fd48d0 --- contrib/rackspace/rackspace/clients.py | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/contrib/rackspace/rackspace/clients.py b/contrib/rackspace/rackspace/clients.py index 4037959d8c..ef09f82f3a 100644 --- a/contrib/rackspace/rackspace/clients.py +++ b/contrib/rackspace/rackspace/clients.py @@ -13,6 +13,8 @@ """Client Libraries for Rackspace Resources.""" +import urlparse + from oslo.config import cfg from heat.common import exception @@ -20,6 +22,8 @@ from heat.engine import clients from heat.openstack.common.gettextutils import _ from heat.openstack.common import log as logging +from glanceclient import client as glanceclient + LOG = logging.getLogger(__name__) try: @@ -119,6 +123,33 @@ class Clients(clients.OpenStackClients): # unwrap here and things just work return self._get_client("object_store").connection + def glance(self): + if "image" not in self._clients: + con = self.context + endpoint_type = self._get_client_option('glance', 'endpoint_type') + endpoint = self.url_for(service_type='image', + endpoint_type=endpoint_type, + region_name=cfg.CONF.region_name) + # Rackspace service catalog includes a tenant scoped glance + # endpoint so we have to munge the url a bit + glance_url = urlparse.urlparse(endpoint) + # remove the tenant and following from the url + endpoint = "%s://%s" % (glance_url.scheme, glance_url.hostname) + args = { + 'auth_url': con.auth_url, + 'service_type': 'image', + 'project_id': con.tenant, + 'token': self.auth_token, + 'endpoint_type': endpoint_type, + 'ca_file': self._get_client_option('glance', 'ca_file'), + 'cert_file': self._get_client_option('glance', 'cert_file'), + 'key_file': self._get_client_option('glance', 'key_file'), + 'insecure': self._get_client_option('glance', 'insecure') + } + client = glanceclient.Client('2', endpoint, **args) + self._clients["image"] = client + return self._clients["image"] + def __authenticate(self): """Create an authenticated client context.""" self.pyrax = pyrax.create_context("rackspace")