diff --git a/openstack/exceptions.py b/openstack/exceptions.py index 8efb42e8..6ebef301 100644 --- a/openstack/exceptions.py +++ b/openstack/exceptions.py @@ -60,3 +60,8 @@ class HttpException(SdkException): def __init__(self, message, details=None): super(HttpException, self).__init__(message) self.details = details + + +class MethodNotSupported(SdkException): + """The resource does not support this operation type.""" + pass diff --git a/openstack/resource.py b/openstack/resource.py index 7e43f156..36fc0c97 100644 --- a/openstack/resource.py +++ b/openstack/resource.py @@ -16,13 +16,10 @@ import collections import six from six.moves.urllib import parse as url_parse +from openstack import exceptions from openstack import utils -class MethodNotSupported(Exception): - """The resource does not support this operation type.""" - - class prop(object): """A helper for defining properties on a Resource. @@ -205,7 +202,7 @@ class Resource(collections.MutableMapping): @classmethod def create_by_id(cls, session, attrs, r_id=None): if not cls.allow_create: - raise MethodNotSupported('create') + raise exceptions.MethodNotSupported('create') if cls.resource_key: body = {cls.resource_key: attrs} @@ -232,7 +229,7 @@ class Resource(collections.MutableMapping): @classmethod def get_data_by_id(cls, session, r_id): if not cls.allow_retrieve: - raise MethodNotSupported('retrieve') + raise exceptions.MethodNotSupported('retrieve') url = utils.urljoin(cls.base_path, r_id) body = session.get(url, service=cls.service).body @@ -255,7 +252,7 @@ class Resource(collections.MutableMapping): @classmethod def update_by_id(cls, session, r_id, attrs): if not cls.allow_update: - raise MethodNotSupported('update') + raise exceptions.MethodNotSupported('update') if cls.resource_key: body = {cls.resource_key: attrs} @@ -289,7 +286,7 @@ class Resource(collections.MutableMapping): @classmethod def delete_by_id(cls, session, r_id): if not cls.allow_delete: - raise MethodNotSupported('delete') + raise exceptions.MethodNotSupported('delete') session.delete(utils.urljoin(cls.base_path, r_id), service=cls.service, accept=None) @@ -302,7 +299,7 @@ class Resource(collections.MutableMapping): # NOTE(jamielennox): Is it possible we can return a generator from here # and allow us to keep paging rather than limit and marker? if not cls.allow_list: - raise MethodNotSupported('retrieve') + raise exceptions.MethodNotSupported('retrieve') filters = {}