Implement trove client plugin

This moves the client creation code out of Clients._trove() into
its own client plugin.

Trove is an integrated project, and python-troveclient is a dependency,
so the import is now mandatory.

Change-Id: I89d290f6a38488779e77ff11bdfdd64c159a57e8
This commit is contained in:
Steve Baker 2014-06-04 15:25:24 +12:00
parent ce65e9bdb2
commit e247c291ed
5 changed files with 50 additions and 32 deletions

View File

@ -15,7 +15,6 @@ from ceilometerclient import client as ceilometerclient
from heatclient import client as heatclient
from oslo.config import cfg
from stevedore import extension
from troveclient import client as troveclient
import warnings
from heat.common import heat_keystoneclient as hkc
@ -120,29 +119,6 @@ class OpenStackClients(object):
'Replace with calls to client("trove")')
return self.client('trove')
def _trove(self):
con = self.context
endpoint_type = self._get_client_option('trove', 'endpoint_type')
args = {
'service_type': 'database',
'auth_url': con.auth_url,
'proxy_token': con.auth_token,
'username': None,
'password': None,
'cacert': self._get_client_option('trove', 'ca_file'),
'insecure': self._get_client_option('trove', 'insecure'),
'endpoint_type': endpoint_type
}
client = troveclient.Client('1.0', **args)
management_url = self.url_for(service_type='database',
endpoint_type=endpoint_type)
client.client.auth_token = con.auth_token
client.client.management_url = management_url
return client
def ceilometer(self):
warnings.warn('ceilometer() is deprecated. '
'Replace with calls to client("ceilometer")')

View File

@ -0,0 +1,42 @@
#
# 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 troveclient import client as tc
from heat.engine.clients import client_plugin
class TroveClientPlugin(client_plugin.ClientPlugin):
def _create(self):
con = self.context
endpoint_type = self._get_client_option('trove', 'endpoint_type')
args = {
'service_type': 'database',
'auth_url': con.auth_url,
'proxy_token': con.auth_token,
'username': None,
'password': None,
'cacert': self._get_client_option('trove', 'ca_file'),
'insecure': self._get_client_option('trove', 'insecure'),
'endpoint_type': endpoint_type
}
client = tc.Client('1.0', **args)
management_url = self.url_for(service_type='database',
endpoint_type=endpoint_type)
client.client.auth_token = con.auth_token
client.client.management_url = management_url
return client

View File

@ -15,7 +15,6 @@ from troveclient.openstack.common.apiclient import exceptions as troveexc
from heat.common import exception
from heat.engine import attributes
from heat.engine.clients import troveclient
from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
@ -265,7 +264,7 @@ class OSDBInstance(resource.Resource):
def _refresh_instance(self, instance):
try:
instance.get()
except troveclient.exceptions.RequestEntityTooLarge as exc:
except troveexc.RequestEntityTooLarge as exc:
msg = _("Stack %(name)s (%(id)s) received an OverLimit "
"response during instance.get(): %(exception)s")
LOG.warning(msg % {'name': self.stack.name,

View File

@ -11,13 +11,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from troveclient.openstack.common.apiclient import exceptions as troveexc
import uuid
import six
from heat.common import exception
from heat.common import template_format
from heat.engine.clients import troveclient
from heat.engine import parser
from heat.engine.resources import os_database
from heat.engine import scheduler
@ -181,7 +181,7 @@ class OSDBInstanceTest(HeatTestCase):
# Simulate an OverLimit exception
self.m.StubOutWithMock(fake_dbinstance, 'get')
fake_dbinstance.get().AndRaise(
troveclient.exceptions.RequestEntityTooLarge)
troveexc.RequestEntityTooLarge)
self.m.ReplayAll()
@ -211,7 +211,7 @@ class OSDBInstanceTest(HeatTestCase):
fake_dbinstance.delete().AndReturn(None)
self.m.StubOutWithMock(fake_dbinstance, 'get')
fake_dbinstance.get().AndReturn(None)
fake_dbinstance.get().AndRaise(troveclient.exceptions.NotFound(404))
fake_dbinstance.get().AndRaise(troveexc.NotFound(404))
self.m.ReplayAll()
scheduler.TaskRunner(instance.delete)()
@ -232,9 +232,9 @@ class OSDBInstanceTest(HeatTestCase):
# Simulate an OverLimit exception
self.m.StubOutWithMock(fake_dbinstance, 'get')
fake_dbinstance.get().AndRaise(
troveclient.exceptions.RequestEntityTooLarge)
troveexc.RequestEntityTooLarge)
fake_dbinstance.get().AndReturn(None)
fake_dbinstance.get().AndRaise(troveclient.exceptions.NotFound(404))
fake_dbinstance.get().AndRaise(troveexc.NotFound(404))
self.m.ReplayAll()
scheduler.TaskRunner(instance.delete)()
@ -262,7 +262,7 @@ class OSDBInstanceTest(HeatTestCase):
scheduler.TaskRunner(instance.create)()
self.m.StubOutWithMock(self.fc.instances, 'get')
self.fc.instances.get(12345).AndRaise(
troveclient.exceptions.NotFound(404))
troveexc.NotFound(404))
self.m.ReplayAll()
scheduler.TaskRunner(instance.delete)()

View File

@ -43,6 +43,7 @@ heat.clients =
nova = heat.engine.clients.os.nova:NovaClientPlugin
neutron = heat.engine.clients.os.neutron:NeutronClientPlugin
swift = heat.engine.clients.os.swift:SwiftClientPlugin
trove = heat.engine.clients.os.trove:TroveClientPlugin
heat.constraints =
nova.flavor = heat.engine.resources.server:FlavorConstraint