2011-10-25 16:50:08 -07:00
|
|
|
# Copyright 2010 Jacob Kaplan-Moss
|
2013-09-20 04:30:41 +08:00
|
|
|
# Copyright 2011 OpenStack Foundation
|
2013-08-26 10:08:37 +03:00
|
|
|
# Copyright 2013 OpenStack Foundation
|
2011-10-25 16:50:08 -07:00
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Base utilities to build API operation managers and objects on top of.
|
|
|
|
"""
|
|
|
|
|
2013-05-19 18:19:56 +03:00
|
|
|
import abc
|
2013-07-08 12:00:37 +10:00
|
|
|
import functools
|
2012-09-11 11:12:37 -05:00
|
|
|
|
2013-08-26 10:08:37 +03:00
|
|
|
import six
|
2013-12-12 14:25:06 +01:00
|
|
|
from six.moves import urllib
|
2011-10-25 16:50:08 -07:00
|
|
|
|
2013-08-26 10:08:37 +03:00
|
|
|
from keystoneclient import exceptions
|
2014-02-17 12:36:38 +02:00
|
|
|
from keystoneclient.openstack.common.apiclient import base
|
2011-10-25 16:50:08 -07:00
|
|
|
|
|
|
|
|
|
|
|
def getid(obj):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Return id if argument is a Resource.
|
2011-10-25 16:50:08 -07:00
|
|
|
|
2013-08-26 10:08:37 +03:00
|
|
|
Abstracts the common pattern of allowing both an object or an object's ID
|
|
|
|
(UUID) as a parameter when dealing with relationships.
|
|
|
|
"""
|
2011-10-25 16:50:08 -07:00
|
|
|
try:
|
|
|
|
if obj.uuid:
|
|
|
|
return obj.uuid
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
return obj.id
|
|
|
|
except AttributeError:
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
def filter_kwargs(f):
|
|
|
|
@functools.wraps(f)
|
|
|
|
def func(*args, **kwargs):
|
2013-12-16 11:39:59 +01:00
|
|
|
new_kwargs = {}
|
|
|
|
for key, ref in six.iteritems(kwargs):
|
2013-07-08 12:00:37 +10:00
|
|
|
if ref is None:
|
|
|
|
# drop null values
|
|
|
|
continue
|
|
|
|
|
|
|
|
id_value = getid(ref)
|
2013-12-16 11:39:59 +01:00
|
|
|
if id_value != ref:
|
2014-05-02 16:12:20 +02:00
|
|
|
# If an object with an id was passed, then use the id, e.g.:
|
2013-12-16 11:39:59 +01:00
|
|
|
# user: user(id=1) becomes user_id: 1
|
|
|
|
key = '%s_id' % key
|
2013-07-08 12:00:37 +10:00
|
|
|
|
2013-12-16 11:39:59 +01:00
|
|
|
new_kwargs[key] = id_value
|
2013-07-08 12:00:37 +10:00
|
|
|
|
2013-12-16 11:39:59 +01:00
|
|
|
return f(*args, **new_kwargs)
|
2013-07-08 12:00:37 +10:00
|
|
|
return func
|
|
|
|
|
|
|
|
|
2011-10-25 16:50:08 -07:00
|
|
|
class Manager(object):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Basic manager type providing common operations.
|
|
|
|
|
|
|
|
Managers interact with a particular type of API (servers, flavors, images,
|
|
|
|
etc.) and provide CRUD operations for them.
|
2011-10-25 16:50:08 -07:00
|
|
|
"""
|
|
|
|
resource_class = None
|
|
|
|
|
2013-08-26 10:08:37 +03:00
|
|
|
def __init__(self, client):
|
|
|
|
"""Initializes Manager with `client`.
|
|
|
|
|
|
|
|
:param client: instance of BaseClient descendant for HTTP requests
|
|
|
|
"""
|
|
|
|
super(Manager, self).__init__()
|
|
|
|
self.client = client
|
|
|
|
|
|
|
|
@property
|
|
|
|
def api(self):
|
|
|
|
"""Deprecated. Use `client` instead.
|
|
|
|
"""
|
|
|
|
return self.client
|
2011-10-25 16:50:08 -07:00
|
|
|
|
2014-07-14 10:01:10 +10:00
|
|
|
def _list(self, url, response_key, obj_class=None, body=None, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""List the collection.
|
|
|
|
|
|
|
|
:param url: a partial URL, e.g., '/servers'
|
|
|
|
:param response_key: the key to be looked up in response dictionary,
|
|
|
|
e.g., 'servers'
|
|
|
|
:param obj_class: class for constructing the returned objects
|
|
|
|
(self.resource_class will be used by default)
|
|
|
|
:param body: data that will be encoded as JSON and passed in POST
|
|
|
|
request (GET will be sent by default)
|
2014-07-14 10:01:10 +10:00
|
|
|
:param kwargs: Additional arguments will be passed to the request.
|
2013-08-26 10:08:37 +03:00
|
|
|
"""
|
2011-10-25 16:50:08 -07:00
|
|
|
if body:
|
2014-07-14 10:01:10 +10:00
|
|
|
resp, body = self.client.post(url, body=body, **kwargs)
|
2011-10-25 16:50:08 -07:00
|
|
|
else:
|
2014-07-14 10:01:10 +10:00
|
|
|
resp, body = self.client.get(url, **kwargs)
|
2011-10-25 16:50:08 -07:00
|
|
|
|
|
|
|
if obj_class is None:
|
|
|
|
obj_class = self.resource_class
|
|
|
|
|
|
|
|
data = body[response_key]
|
|
|
|
# NOTE(ja): keystone returns values as list as {'values': [ ... ]}
|
|
|
|
# unlike other services which just return the list...
|
2013-08-26 10:08:37 +03:00
|
|
|
try:
|
2011-10-25 16:50:08 -07:00
|
|
|
data = data['values']
|
2013-08-26 10:08:37 +03:00
|
|
|
except (KeyError, TypeError):
|
|
|
|
pass
|
|
|
|
|
2011-10-25 16:50:08 -07:00
|
|
|
return [obj_class(self, res, loaded=True) for res in data if res]
|
|
|
|
|
2014-07-14 10:01:10 +10:00
|
|
|
def _get(self, url, response_key, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Get an object from collection.
|
|
|
|
|
|
|
|
:param url: a partial URL, e.g., '/servers'
|
|
|
|
:param response_key: the key to be looked up in response dictionary,
|
|
|
|
e.g., 'server'
|
2014-07-14 10:01:10 +10:00
|
|
|
:param kwargs: Additional arguments will be passed to the request.
|
2013-08-26 10:08:37 +03:00
|
|
|
"""
|
2014-07-14 10:01:10 +10:00
|
|
|
resp, body = self.client.get(url, **kwargs)
|
2012-09-11 08:43:22 -05:00
|
|
|
return self.resource_class(self, body[response_key], loaded=True)
|
2011-10-25 16:50:08 -07:00
|
|
|
|
2014-07-14 10:01:10 +10:00
|
|
|
def _head(self, url, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Retrieve request headers for an object.
|
|
|
|
|
|
|
|
:param url: a partial URL, e.g., '/servers'
|
2014-07-14 10:01:10 +10:00
|
|
|
:param kwargs: Additional arguments will be passed to the request.
|
2013-08-26 10:08:37 +03:00
|
|
|
"""
|
2014-07-14 10:01:10 +10:00
|
|
|
resp, body = self.client.head(url, **kwargs)
|
2012-11-16 17:43:05 -06:00
|
|
|
return resp.status_code == 204
|
2012-09-11 11:06:54 -05:00
|
|
|
|
2014-07-14 10:01:10 +10:00
|
|
|
def _create(self, url, body, response_key, return_raw=False, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Deprecated. Use `_post` instead.
|
|
|
|
"""
|
2014-07-14 10:01:10 +10:00
|
|
|
return self._post(url, body, response_key, return_raw, **kwargs)
|
2013-08-26 10:08:37 +03:00
|
|
|
|
2014-07-14 10:01:10 +10:00
|
|
|
def _post(self, url, body, response_key, return_raw=False, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Create an object.
|
|
|
|
|
|
|
|
:param url: a partial URL, e.g., '/servers'
|
|
|
|
:param body: data that will be encoded as JSON and passed in POST
|
|
|
|
request (GET will be sent by default)
|
|
|
|
:param response_key: the key to be looked up in response dictionary,
|
|
|
|
e.g., 'servers'
|
|
|
|
:param return_raw: flag to force returning raw JSON instead of
|
|
|
|
Python object of self.resource_class
|
2014-07-14 10:01:10 +10:00
|
|
|
:param kwargs: Additional arguments will be passed to the request.
|
2013-08-26 10:08:37 +03:00
|
|
|
"""
|
2014-07-14 10:01:10 +10:00
|
|
|
resp, body = self.client.post(url, body=body, **kwargs)
|
2011-10-25 16:50:08 -07:00
|
|
|
if return_raw:
|
|
|
|
return body[response_key]
|
2012-11-06 17:24:22 +00:00
|
|
|
return self.resource_class(self, body[response_key])
|
2011-10-25 16:50:08 -07:00
|
|
|
|
2014-07-14 10:01:10 +10:00
|
|
|
def _put(self, url, body=None, response_key=None, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Update an object with PUT method.
|
|
|
|
|
|
|
|
:param url: a partial URL, e.g., '/servers'
|
|
|
|
:param body: data that will be encoded as JSON and passed in POST
|
|
|
|
request (GET will be sent by default)
|
|
|
|
:param response_key: the key to be looked up in response dictionary,
|
|
|
|
e.g., 'servers'
|
2014-07-14 10:01:10 +10:00
|
|
|
:param kwargs: Additional arguments will be passed to the request.
|
2013-08-26 10:08:37 +03:00
|
|
|
"""
|
2014-07-14 10:01:10 +10:00
|
|
|
resp, body = self.client.put(url, body=body, **kwargs)
|
2013-08-26 10:08:37 +03:00
|
|
|
# PUT requests may not return a body
|
|
|
|
if body is not None:
|
|
|
|
if response_key is not None:
|
|
|
|
return self.resource_class(self, body[response_key])
|
|
|
|
else:
|
|
|
|
return self.resource_class(self, body)
|
|
|
|
|
2014-07-14 10:01:10 +10:00
|
|
|
def _patch(self, url, body=None, response_key=None, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Update an object with PATCH method.
|
|
|
|
|
|
|
|
:param url: a partial URL, e.g., '/servers'
|
|
|
|
:param body: data that will be encoded as JSON and passed in POST
|
|
|
|
request (GET will be sent by default)
|
|
|
|
:param response_key: the key to be looked up in response dictionary,
|
|
|
|
e.g., 'servers'
|
2014-07-14 10:01:10 +10:00
|
|
|
:param kwargs: Additional arguments will be passed to the request.
|
2013-08-26 10:08:37 +03:00
|
|
|
"""
|
2014-07-14 10:01:10 +10:00
|
|
|
resp, body = self.client.patch(url, body=body, **kwargs)
|
2013-08-26 10:08:37 +03:00
|
|
|
if response_key is not None:
|
|
|
|
return self.resource_class(self, body[response_key])
|
|
|
|
else:
|
|
|
|
return self.resource_class(self, body)
|
|
|
|
|
2014-07-14 10:01:10 +10:00
|
|
|
def _delete(self, url, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Delete an object.
|
|
|
|
|
|
|
|
:param url: a partial URL, e.g., '/servers/my-server'
|
2014-07-14 10:01:10 +10:00
|
|
|
:param kwargs: Additional arguments will be passed to the request.
|
2013-08-26 10:08:37 +03:00
|
|
|
"""
|
2014-07-14 10:01:10 +10:00
|
|
|
return self.client.delete(url, **kwargs)
|
2011-10-25 16:50:08 -07:00
|
|
|
|
2012-11-23 09:17:24 +00:00
|
|
|
def _update(self, url, body=None, response_key=None, method="PUT",
|
2014-07-14 10:01:10 +10:00
|
|
|
management=True, **kwargs):
|
2013-08-26 10:08:37 +03:00
|
|
|
methods = {"PUT": self.client.put,
|
|
|
|
"POST": self.client.post,
|
|
|
|
"PATCH": self.client.patch}
|
2012-02-01 16:01:06 +02:00
|
|
|
try:
|
2013-08-26 10:08:37 +03:00
|
|
|
resp, body = methods[method](url, body=body,
|
2014-07-14 10:01:10 +10:00
|
|
|
management=management,
|
|
|
|
**kwargs)
|
2012-02-01 16:01:06 +02:00
|
|
|
except KeyError:
|
|
|
|
raise exceptions.ClientException("Invalid update method: %s"
|
|
|
|
% method)
|
2012-01-28 18:35:46 -08:00
|
|
|
# PUT requests may not return a body
|
|
|
|
if body:
|
2012-11-06 17:24:22 +00:00
|
|
|
return self.resource_class(self, body[response_key])
|
2011-10-25 16:50:08 -07:00
|
|
|
|
|
|
|
|
2013-10-17 09:41:01 +09:00
|
|
|
@six.add_metaclass(abc.ABCMeta)
|
2011-10-25 16:50:08 -07:00
|
|
|
class ManagerWithFind(Manager):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Manager with additional `find()`/`findall()` methods."""
|
2013-05-19 18:19:56 +03:00
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
def list(self):
|
|
|
|
pass
|
|
|
|
|
2011-10-25 16:50:08 -07:00
|
|
|
def find(self, **kwargs):
|
2013-08-04 23:10:16 +02:00
|
|
|
"""Find a single item with attributes matching ``**kwargs``.
|
2011-10-25 16:50:08 -07:00
|
|
|
|
|
|
|
This isn't very efficient: it loads the entire list then filters on
|
|
|
|
the Python side.
|
|
|
|
"""
|
|
|
|
rl = self.findall(**kwargs)
|
2013-01-17 18:11:27 +09:00
|
|
|
num = len(rl)
|
|
|
|
|
|
|
|
if num == 0:
|
2011-10-25 16:50:08 -07:00
|
|
|
msg = "No %s matching %s." % (self.resource_class.__name__, kwargs)
|
|
|
|
raise exceptions.NotFound(404, msg)
|
2013-01-17 18:11:27 +09:00
|
|
|
elif num > 1:
|
|
|
|
raise exceptions.NoUniqueMatch
|
|
|
|
else:
|
|
|
|
return rl[0]
|
2011-10-25 16:50:08 -07:00
|
|
|
|
|
|
|
def findall(self, **kwargs):
|
2013-08-04 23:10:16 +02:00
|
|
|
"""Find all items with attributes matching ``**kwargs``.
|
2011-10-25 16:50:08 -07:00
|
|
|
|
|
|
|
This isn't very efficient: it loads the entire list then filters on
|
|
|
|
the Python side.
|
|
|
|
"""
|
|
|
|
found = []
|
|
|
|
searches = kwargs.items()
|
|
|
|
|
|
|
|
for obj in self.list():
|
|
|
|
try:
|
|
|
|
if all(getattr(obj, attr) == value
|
2012-06-01 18:07:26 -07:00
|
|
|
for (attr, value) in searches):
|
2011-10-25 16:50:08 -07:00
|
|
|
found.append(obj)
|
|
|
|
except AttributeError:
|
|
|
|
continue
|
|
|
|
|
|
|
|
return found
|
|
|
|
|
|
|
|
|
2012-09-11 11:12:37 -05:00
|
|
|
class CrudManager(Manager):
|
|
|
|
"""Base manager class for manipulating Keystone entities.
|
|
|
|
|
|
|
|
Children of this class are expected to define a `collection_key` and `key`.
|
|
|
|
|
|
|
|
- `collection_key`: Usually a plural noun by convention (e.g. `entities`);
|
|
|
|
used to refer collections in both URL's (e.g. `/v3/entities`) and JSON
|
|
|
|
objects containing a list of member resources (e.g. `{'entities': [{},
|
|
|
|
{}, {}]}`).
|
|
|
|
- `key`: Usually a singular noun by convention (e.g. `entity`); used to
|
|
|
|
refer to an individual member of the collection.
|
|
|
|
|
|
|
|
"""
|
|
|
|
collection_key = None
|
|
|
|
key = None
|
2013-07-08 12:00:37 +10:00
|
|
|
base_url = None
|
2012-09-11 11:12:37 -05:00
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
def build_url(self, dict_args_in_out=None):
|
2012-09-11 11:12:37 -05:00
|
|
|
"""Builds a resource URL for the given kwargs.
|
|
|
|
|
|
|
|
Given an example collection where `collection_key = 'entities'` and
|
|
|
|
`key = 'entity'`, the following URL's could be generated.
|
|
|
|
|
|
|
|
By default, the URL will represent a collection of entities, e.g.::
|
|
|
|
|
|
|
|
/entities
|
|
|
|
|
|
|
|
If kwargs contains an `entity_id`, then the URL will represent a
|
|
|
|
specific member, e.g.::
|
|
|
|
|
|
|
|
/entities/{entity_id}
|
|
|
|
|
|
|
|
If a `base_url` is provided, the generated URL will be appended to it.
|
|
|
|
|
|
|
|
"""
|
2013-07-08 12:00:37 +10:00
|
|
|
if dict_args_in_out is None:
|
|
|
|
dict_args_in_out = {}
|
2012-09-11 11:12:37 -05:00
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
url = dict_args_in_out.pop('base_url', None) or self.base_url or ''
|
2012-09-11 11:12:37 -05:00
|
|
|
url += '/%s' % self.collection_key
|
|
|
|
|
|
|
|
# do we have a specific entity?
|
2013-07-08 12:00:37 +10:00
|
|
|
entity_id = dict_args_in_out.pop('%s_id' % self.key, None)
|
2012-09-11 11:12:37 -05:00
|
|
|
if entity_id is not None:
|
|
|
|
url += '/%s' % entity_id
|
|
|
|
|
|
|
|
return url
|
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
@filter_kwargs
|
2012-09-11 11:12:37 -05:00
|
|
|
def create(self, **kwargs):
|
2013-07-08 12:00:37 +10:00
|
|
|
url = self.build_url(dict_args_in_out=kwargs)
|
2012-09-11 11:12:37 -05:00
|
|
|
return self._create(
|
2013-07-08 12:00:37 +10:00
|
|
|
url,
|
2012-09-11 11:12:37 -05:00
|
|
|
{self.key: kwargs},
|
|
|
|
self.key)
|
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
@filter_kwargs
|
2012-09-11 11:12:37 -05:00
|
|
|
def get(self, **kwargs):
|
|
|
|
return self._get(
|
2013-07-08 12:00:37 +10:00
|
|
|
self.build_url(dict_args_in_out=kwargs),
|
2012-09-11 11:12:37 -05:00
|
|
|
self.key)
|
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
@filter_kwargs
|
2012-09-11 11:12:37 -05:00
|
|
|
def head(self, **kwargs):
|
2013-07-08 12:00:37 +10:00
|
|
|
return self._head(self.build_url(dict_args_in_out=kwargs))
|
2012-09-11 11:12:37 -05:00
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
@filter_kwargs
|
|
|
|
def list(self, **kwargs):
|
|
|
|
url = self.build_url(dict_args_in_out=kwargs)
|
2012-09-11 11:12:37 -05:00
|
|
|
|
2013-12-12 14:25:06 +01:00
|
|
|
if kwargs:
|
|
|
|
query = '?%s' % urllib.parse.urlencode(kwargs)
|
|
|
|
else:
|
|
|
|
query = ''
|
2012-09-11 11:12:37 -05:00
|
|
|
return self._list(
|
2013-07-08 12:00:37 +10:00
|
|
|
'%(url)s%(query)s' % {
|
|
|
|
'url': url,
|
2013-12-12 14:25:06 +01:00
|
|
|
'query': query,
|
2012-09-11 11:12:37 -05:00
|
|
|
},
|
|
|
|
self.collection_key)
|
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
@filter_kwargs
|
|
|
|
def put(self, **kwargs):
|
2012-09-11 11:12:37 -05:00
|
|
|
return self._update(
|
2013-07-08 12:00:37 +10:00
|
|
|
self.build_url(dict_args_in_out=kwargs),
|
2012-09-11 11:12:37 -05:00
|
|
|
method='PUT')
|
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
@filter_kwargs
|
2012-09-11 11:12:37 -05:00
|
|
|
def update(self, **kwargs):
|
2013-07-08 12:00:37 +10:00
|
|
|
url = self.build_url(dict_args_in_out=kwargs)
|
2012-09-11 11:12:37 -05:00
|
|
|
|
|
|
|
return self._update(
|
2013-07-08 12:00:37 +10:00
|
|
|
url,
|
|
|
|
{self.key: kwargs},
|
2012-09-11 11:12:37 -05:00
|
|
|
self.key,
|
|
|
|
method='PATCH')
|
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
@filter_kwargs
|
2012-09-11 11:12:37 -05:00
|
|
|
def delete(self, **kwargs):
|
|
|
|
return self._delete(
|
2013-07-08 12:00:37 +10:00
|
|
|
self.build_url(dict_args_in_out=kwargs))
|
2012-09-11 11:12:37 -05:00
|
|
|
|
2013-07-08 12:00:37 +10:00
|
|
|
@filter_kwargs
|
|
|
|
def find(self, **kwargs):
|
2013-08-04 23:10:16 +02:00
|
|
|
"""Find a single item with attributes matching ``**kwargs``."""
|
2013-07-08 12:00:37 +10:00
|
|
|
url = self.build_url(dict_args_in_out=kwargs)
|
2013-04-05 17:36:32 -05:00
|
|
|
|
2013-12-12 14:25:06 +01:00
|
|
|
if kwargs:
|
|
|
|
query = '?%s' % urllib.parse.urlencode(kwargs)
|
|
|
|
else:
|
|
|
|
query = ''
|
2013-04-05 17:36:32 -05:00
|
|
|
rl = self._list(
|
2013-07-08 12:00:37 +10:00
|
|
|
'%(url)s%(query)s' % {
|
|
|
|
'url': url,
|
2013-12-12 14:25:06 +01:00
|
|
|
'query': query,
|
2013-04-05 17:36:32 -05:00
|
|
|
},
|
|
|
|
self.collection_key)
|
|
|
|
num = len(rl)
|
|
|
|
|
|
|
|
if num == 0:
|
|
|
|
msg = "No %s matching %s." % (self.resource_class.__name__, kwargs)
|
|
|
|
raise exceptions.NotFound(404, msg)
|
|
|
|
elif num > 1:
|
|
|
|
raise exceptions.NoUniqueMatch
|
|
|
|
else:
|
|
|
|
return rl[0]
|
|
|
|
|
2012-09-11 11:12:37 -05:00
|
|
|
|
2014-02-17 12:36:38 +02:00
|
|
|
class Resource(base.Resource):
|
2013-08-26 10:08:37 +03:00
|
|
|
"""Base class for OpenStack resources (tenant, user, etc.).
|
2011-10-25 16:50:08 -07:00
|
|
|
|
2013-08-26 10:08:37 +03:00
|
|
|
This is pretty much just a bag for attributes.
|
2011-10-25 16:50:08 -07:00
|
|
|
"""
|
2013-08-26 10:08:37 +03:00
|
|
|
|
2012-09-11 11:10:00 -05:00
|
|
|
def delete(self):
|
|
|
|
return self.manager.delete(self)
|