Separate the Marconi client from the resource
Move Marconi client into its own module for consistency. Change-Id: If240c1ddfc4ef3af3332c280da507d832a8b3246
This commit is contained in:
@@ -12,7 +12,7 @@ directive.
|
||||
|
||||
To install the Marconi plugin, one needs to first make sure the
|
||||
python-marconiclient package is installed - pip install -r requirements.txt, and
|
||||
copy the plugin implementation, e.g. queue.py to wherever plugin_dirs points to.
|
||||
copy the plugin folder, e.g. marconi to wherever plugin_dirs points to.
|
||||
|
||||
|
||||
### 2. Restart heat
|
||||
|
56
contrib/marconi/clients.py
Normal file
56
contrib/marconi/clients.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# 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.
|
||||
|
||||
from heat.engine import clients
|
||||
from heat.openstack.common import log as logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
from marconiclient.queues.v1 import client as marconiclient
|
||||
except ImportError:
|
||||
marconiclient = None
|
||||
logger.info(_('marconiclient not available'))
|
||||
|
||||
|
||||
class Clients(clients.OpenStackClients):
|
||||
'''
|
||||
Convenience class to create and cache client instances.
|
||||
'''
|
||||
def __init__(self, context):
|
||||
super(Clients, self).__init__(context)
|
||||
self._marconi = None
|
||||
|
||||
def marconi(self, service_type="queuing"):
|
||||
if self._marconi:
|
||||
return self._marconi
|
||||
|
||||
con = self.context
|
||||
if self.auth_token is None:
|
||||
logger.error(_("Marconi connection failed, no auth_token!"))
|
||||
return None
|
||||
|
||||
opts = {
|
||||
'os_auth_token': con.auth_token,
|
||||
'os_auth_url': con.auth_url,
|
||||
'os_project_id': con.tenant,
|
||||
'os_service_type': service_type,
|
||||
}
|
||||
auth_opts = {'backend': 'keystone',
|
||||
'options': opts}
|
||||
conf = {'auth_opts': auth_opts}
|
||||
endpoint = self.url_for(service_type=service_type)
|
||||
|
||||
self._marconi = marconiclient.Client(url=endpoint, conf=conf)
|
||||
|
||||
return self._marconi
|
@@ -12,21 +12,17 @@
|
||||
# under the License.
|
||||
|
||||
from heat.common import exception
|
||||
from heat.engine import clients
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.openstack.common import log as logging
|
||||
|
||||
from .. import clients # noqa
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
try:
|
||||
from marconiclient.queues.v1 import client as marconiclient
|
||||
except ImportError:
|
||||
marconiclient = None
|
||||
logger.info(_('marconiclient not available'))
|
||||
|
||||
if clients.marconiclient is None:
|
||||
def resource_mapping():
|
||||
return {}
|
||||
else:
|
||||
@@ -36,39 +32,6 @@ else:
|
||||
}
|
||||
|
||||
|
||||
class Clients(clients.OpenStackClients):
|
||||
'''
|
||||
Convenience class to create and cache client instances.
|
||||
'''
|
||||
def __init__(self, context):
|
||||
super(Clients, self).__init__(context)
|
||||
self._marconi = None
|
||||
|
||||
def marconi(self, service_type="queuing"):
|
||||
if self._marconi:
|
||||
return self._marconi
|
||||
|
||||
con = self.context
|
||||
if self.auth_token is None:
|
||||
logger.error(_("Marconi connection failed, no auth_token!"))
|
||||
return None
|
||||
|
||||
opts = {
|
||||
'os_auth_token': con.auth_token,
|
||||
'os_auth_url': con.auth_url,
|
||||
'os_project_id': con.tenant,
|
||||
'os_service_type': service_type,
|
||||
}
|
||||
auth_opts = {'backend': 'keystone',
|
||||
'options': opts}
|
||||
conf = {'auth_opts': auth_opts}
|
||||
endpoint = self.url_for(service_type=service_type)
|
||||
|
||||
self._marconi = marconiclient.Client(url=endpoint, conf=conf)
|
||||
|
||||
return self._marconi
|
||||
|
||||
|
||||
class MarconiQueue(resource.Resource):
|
||||
|
||||
PROPERTIES = (
|
||||
@@ -98,7 +61,7 @@ class MarconiQueue(resource.Resource):
|
||||
|
||||
def __init__(self, name, json_snippet, stack):
|
||||
super(MarconiQueue, self).__init__(name, json_snippet, stack)
|
||||
self.clients = Clients(self.context)
|
||||
self.clients = clients.Clients(self.context)
|
||||
|
||||
def marconi(self):
|
||||
return self.clients.marconi()
|
||||
|
Reference in New Issue
Block a user