Add a zaqar.queue custom constraint
This doesn't actually do anything, because any string is a valid queue name (the queue will be created automatically when you interact with it), but it at least allows us to annotate resource properties to indicate their type. Change-Id: Iff321ca8d8565f48e04a80b05e3f9610a6346737
This commit is contained in:
parent
c0f051b7e0
commit
626d7fc540
@ -11,6 +11,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from heat.common.i18n import _LE
|
||||
@ -21,6 +23,7 @@ from zaqarclient.queues.v2 import client as zaqarclient
|
||||
from zaqarclient.transport import errors as zaqar_errors
|
||||
|
||||
from heat.engine.clients import client_plugin
|
||||
from heat.engine import constraints
|
||||
|
||||
CLIENT_NAME = 'zaqar'
|
||||
|
||||
@ -75,6 +78,13 @@ class ZaqarClientPlugin(client_plugin.ClientPlugin):
|
||||
def is_not_found(self, ex):
|
||||
return isinstance(ex, zaqar_errors.ResourceNotFound)
|
||||
|
||||
def get_queue(self, queue_name):
|
||||
if not isinstance(queue_name, six.string_types):
|
||||
raise TypeError('Queue name must be a string')
|
||||
# Queues are created automatically starting with v1.1 of the Zaqar API,
|
||||
# so any queue name is valid for the purposes of constraint validation.
|
||||
return queue_name
|
||||
|
||||
|
||||
class ZaqarEventSink(object):
|
||||
|
||||
@ -88,3 +98,8 @@ class ZaqarEventSink(object):
|
||||
queue = zaqar.queue(self._target, auto_create=False)
|
||||
ttl = self._ttl if self._ttl is not None else zaqar_plugin.DEFAULT_TTL
|
||||
queue.post({'body': event, 'ttl': ttl})
|
||||
|
||||
|
||||
class QueueConstraint(constraints.BaseCustomConstraint):
|
||||
resource_client_name = CLIENT_NAME
|
||||
resource_getter_name = 'get_queue'
|
||||
|
@ -43,6 +43,7 @@ class ZaqarSubscription(resource.Resource):
|
||||
QUEUE_NAME: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_("Name of the queue to subscribe to."),
|
||||
constraints=[constraints.CustomConstraint('zaqar.queue')],
|
||||
required=True),
|
||||
SUBSCRIBER: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
|
@ -144,6 +144,7 @@ heat.constraints =
|
||||
senlin.profile = heat.engine.clients.os.senlin:ProfileConstraint
|
||||
senlin.profile_type = heat.engine.clients.os.senlin:ProfileTypeConstraint
|
||||
trove.flavor = heat.engine.clients.os.trove:FlavorConstraint
|
||||
zaqar.queue = heat.engine.clients.os.zaqar:QueueConstraint
|
||||
|
||||
heat.stack_lifecycle_plugins =
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user