From 4b57d1455910b59af0def6fe3dde83ce697aed51 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Sat, 26 Apr 2014 17:30:03 +0800 Subject: [PATCH] Add glanceclient to heat To enable implementation of a glance image resource, we first need to add access to glanceclient in heat. Change-Id: Ie0623e0307f6d3163ae584ceab89453f71f48053 Implements: blueprint glance-image --- etc/heat/heat.conf.sample | 27 +++++++++++++++++++++++++++ heat/engine/clients.py | 32 ++++++++++++++++++++++++++++++++ heat/engine/resource.py | 3 +++ requirements.txt | 1 + test-requirements.txt | 1 - 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/etc/heat/heat.conf.sample b/etc/heat/heat.conf.sample index d1d397328..fe9570079 100644 --- a/etc/heat/heat.conf.sample +++ b/etc/heat/heat.conf.sample @@ -698,6 +698,33 @@ #insecure=false +[clients_glance] + +# +# Options defined in heat.common.config +# + +# Type of endpoint in Identity service catalog to use for +# communication with the OpenStack service. (string value) +#endpoint_type=publicURL + +# Optional CA cert file to use in SSL connections. (string +# value) +#ca_file= + +# Optional PEM-formatted certificate chain file. (string +# value) +#cert_file= + +# Optional PEM-formatted file that contains the private key. +# (string value) +#key_file= + +# If set, then the server's certificate will not be verified. +# (boolean value) +#insecure=false + + [clients_nova] # diff --git a/heat/engine/clients.py b/heat/engine/clients.py index 72aebceeb..bc9d06974 100644 --- a/heat/engine/clients.py +++ b/heat/engine/clients.py @@ -52,6 +52,12 @@ except ImportError: ceilometerclient = None logger.info(_('ceilometerclient not available')) +try: + from glanceclient import client as glanceclient +except ImportError: + glanceclient = None + logger.info(_('glanceclient not available')) + _default_backend = "heat.engine.clients.OpenStackClients" cloud_opts = [ @@ -76,6 +82,7 @@ class OpenStackClients(object): self._trove = None self._ceilometer = None self._heat = None + self._glance = None @property def auth_token(self): @@ -148,6 +155,31 @@ class OpenStackClients(object): self._swift = swiftclient.Connection(**args) return self._swift + def glance(self): + if glanceclient is None: + return None + if self._glance: + return self._glance + + con = self.context + endpoint_type = self._get_client_option('glance', 'endpoint_type') + endpoint = self.url_for(service_type='image', + endpoint_type=endpoint_type) + 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') + } + + self._glance = glanceclient.Client('1', endpoint, **args) + return self._glance + def neutron(self): if neutronclient is None: return None diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 00fe10241..9e937b605 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -358,6 +358,9 @@ class Resource(object): def heat(self): return self.stack.clients.heat() + def glance(self): + return self.stack.clients.glance() + def _do_action(self, action, pre_func=None, resource_data=None): ''' Perform a transition to a new state via a specified action diff --git a/requirements.txt b/requirements.txt index 2616ba741..0aa5d356c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ posix_ipc pycrypto>=2.6 python-ceilometerclient>=1.0.6 python-cinderclient>=1.0.6 +python-glanceclient>=0.9.0 python-heatclient>=0.2.3 python-keystoneclient>=0.7.0 python-neutronclient>=2.3.4,<3 diff --git a/test-requirements.txt b/test-requirements.txt index 507a51c81..2d611a987 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,7 +7,6 @@ mock>=1.0 mox>=0.5.3 oslosphinx oslotest -python-glanceclient>=0.9.0 sphinx>=1.1.2,<1.2 testrepository>=0.0.18 testscenarios>=0.4