Refactor code from oslo_incubator

At some point, common code for this project
originated in the oslo_incubator project; and
we performed a final sync of this code in 2014 [1].

However, this sync'ed code was unused; so lets
delete this code and consolidate common code for
ease of use.

[1] https://review.opendev.org/c/openstack/python-manilaclient/+/98088

Change-Id: Ifd9c7516aab8e3c2d017a1ce421d2e65e76d5640
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
This commit is contained in:
Goutham Pacha Ravi 2021-08-03 23:08:10 -07:00
parent f9aee522ef
commit c7b1c6a1d3
33 changed files with 268 additions and 697 deletions

View File

@ -20,6 +20,7 @@ Base utilities to build API operation managers and objects on top of.
"""
import contextlib
import copy
import hashlib
import os
@ -28,12 +29,21 @@ from manilaclient import exceptions
from manilaclient import utils
# Python 2.4 compat
try:
all
except NameError:
def all(iterable):
return True not in (not x for x in iterable)
def getid(obj):
"""Return id if argument is a Resource.
Abstracts the common pattern of allowing both an object or an object's ID
(UUID) as a parameter when dealing with relationships.
"""
try:
if obj.uuid:
return obj.uuid
except AttributeError:
pass
try:
return obj.id
except AttributeError:
return obj
class Manager(utils.HookableMixin):
@ -53,6 +63,17 @@ class Manager(utils.HookableMixin):
return self.api.api_version
def _list(self, url, response_key, obj_class=None, body=None):
"""List the collection.
:param url: a partial URL, e.g., '/shares'
:param response_key: the key to be looked up in response dictionary,
e.g., 'shares'. If response_key is None - all response body
will be used.
: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)
"""
resp = None
if body:
resp, body = self.api.client.post(url, body=body)
@ -228,3 +249,98 @@ class ManagerWithFind(Manager):
def list(self, search_opts=None):
raise NotImplementedError
class Resource(object):
"""Base class for OpenStack resources (tenant, user, etc.).
This is pretty much just a bag for attributes.
"""
HUMAN_ID = False
NAME_ATTR = 'name'
def __init__(self, manager, info, loaded=False):
"""Populate and bind to a manager.
:param manager: BaseManager object
:param info: dictionary representing resource attributes
:param loaded: prevent lazy-loading if set to True
"""
self.manager = manager
self._info = info
self._add_details(info)
self._loaded = loaded
def __repr__(self):
reprkeys = sorted(k
for k in self.__dict__.keys()
if k[0] != '_' and k != 'manager')
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
return "<%s %s>" % (self.__class__.__name__, info)
@property
def human_id(self):
"""Human-readable ID which can be used for bash completion."""
if self.HUMAN_ID:
name = getattr(self, self.NAME_ATTR, None)
if name is not None:
return strutils.to_slug(name)
return None
def _add_details(self, info):
for (k, v) in info.items():
try:
setattr(self, k, v)
self._info[k] = v
except AttributeError:
# In this case we already defined the attribute on the class
pass
def __getattr__(self, k):
if k not in self.__dict__:
# NOTE(bcwaldon): disallow lazy-loading if already loaded once
if not self.is_loaded():
self.get()
return self.__getattr__(k)
raise AttributeError(k)
else:
return self.__dict__[k]
def get(self):
"""Support for lazy loading details.
Some clients, such as novaclient have the option to lazy load the
details, details which can be loaded with this function.
"""
# set_loaded() first ... so if we have to bail, we know we tried.
self.set_loaded(True)
if not hasattr(self.manager, 'get'):
return
new = self.manager.get(self.id)
if new:
self._add_details(new._info)
def __eq__(self, other):
if not isinstance(other, Resource):
return NotImplemented
# two resources of different types are not equal
if not isinstance(other, self.__class__):
return False
if hasattr(self, 'id') and hasattr(other, 'id'):
return self.id == other.id
return self._info == other._info
def __ne__(self, other):
return not self == other
def is_loaded(self):
return self._loaded
def set_loaded(self, val):
self._loaded = val
def to_dict(self):
return copy.deepcopy(self._info)

View File

@ -1,516 +0,0 @@
# Copyright 2010 Jacob Kaplan-Moss
# Copyright 2011 OpenStack Foundation
# Copyright 2012 Grid Dynamics
# Copyright 2013 OpenStack Foundation
# 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.
"""
# E1102: %s is not callable
# pylint: disable=E1102
import abc
import copy
from oslo_utils import strutils
from manilaclient.common._i18n import _
from manilaclient.common.apiclient import exceptions
from manilaclient import utils
def getid(obj):
"""Return id if argument is a Resource.
Abstracts the common pattern of allowing both an object or an object's ID
(UUID) as a parameter when dealing with relationships.
"""
try:
if obj.uuid:
return obj.uuid
except AttributeError:
pass
try:
return obj.id
except AttributeError:
return obj
# TODO(aababilov): call run_hooks() in HookableMixin's child classes
class HookableMixin(object):
"""Mixin so classes can register and run hooks."""
_hooks_map = {}
@classmethod
def add_hook(cls, hook_type, hook_func):
"""Add a new hook of specified type.
:param cls: class that registers hooks
:param hook_type: hook type, e.g., '__pre_parse_args__'
:param hook_func: hook function
"""
if hook_type not in cls._hooks_map:
cls._hooks_map[hook_type] = []
cls._hooks_map[hook_type].append(hook_func)
@classmethod
def run_hooks(cls, hook_type, *args, **kwargs):
"""Run all hooks of specified type.
:param cls: class that registers hooks
:param hook_type: hook type, e.g., '__pre_parse_args__'
:param args: args to be passed to every hook function
:param kwargs: kwargs to be passed to every hook function
"""
hook_funcs = cls._hooks_map.get(hook_type) or []
for hook_func in hook_funcs:
hook_func(*args, **kwargs)
class BaseManager(HookableMixin):
"""Basic manager type providing common operations.
Managers interact with a particular type of API (servers, flavors, images,
etc.) and provide CRUD operations for them.
"""
resource_class = None
def __init__(self, client):
"""Initializes BaseManager with `client`.
:param client: instance of BaseClient descendant for HTTP requests
"""
super(BaseManager, self).__init__()
self.client = client
def _list(self, url, response_key=None, obj_class=None, json=None):
"""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'. If response_key is None - all response body
will be used.
:param obj_class: class for constructing the returned objects
(self.resource_class will be used by default)
:param json: data that will be encoded as JSON and passed in POST
request (GET will be sent by default)
"""
if json:
body = self.client.post(url, json=json).json()
else:
body = self.client.get(url).json()
if obj_class is None:
obj_class = self.resource_class
data = body[response_key] if response_key is not None else body
# NOTE(ja): keystone returns values as list as {'values': [ ... ]}
# unlike other services which just return the list...
try:
data = data['values']
except (KeyError, TypeError):
pass
return [obj_class(self, res, loaded=True) for res in data if res]
def _get(self, url, response_key=None):
"""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'. If response_key is None - all response body
will be used.
"""
body = self.client.get(url).json()
data = body[response_key] if response_key is not None else body
return self.resource_class(self, data, loaded=True)
def _head(self, url):
"""Retrieve request headers for an object.
:param url: a partial URL, e.g., '/servers'
"""
resp = self.client.head(url)
return resp.status_code == 204
def _post(self, url, json, response_key=None, return_raw=False):
"""Create an object.
:param url: a partial URL, e.g., '/servers'
:param json: 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., 'server'. If response_key is None - all response body
will be used.
:param return_raw: flag to force returning raw JSON instead of
Python object of self.resource_class
"""
body = self.client.post(url, json=json).json()
data = body[response_key] if response_key is not None else body
if return_raw:
return data
return self.resource_class(self, data)
def _put(self, url, json=None, response_key=None):
"""Update an object with PUT method.
:param url: a partial URL, e.g., '/servers'
:param json: 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'. If response_key is None - all response body
will be used.
"""
resp = self.client.put(url, json=json)
# PUT requests may not return a body
if resp.content:
body = resp.json()
if response_key is not None:
return self.resource_class(self, body[response_key])
else:
return self.resource_class(self, body)
def _patch(self, url, json=None, response_key=None):
"""Update an object with PATCH method.
:param url: a partial URL, e.g., '/servers'
:param json: 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'. If response_key is None - all response body
will be used.
"""
body = self.client.patch(url, json=json).json()
if response_key is not None:
return self.resource_class(self, body[response_key])
else:
return self.resource_class(self, body)
def _delete(self, url):
"""Delete an object.
:param url: a partial URL, e.g., '/servers/my-server'
"""
return self.client.delete(url)
class ManagerWithFind(BaseManager, metaclass=abc.ABCMeta):
"""Manager with additional `find()`/`findall()` methods."""
@abc.abstractmethod
def list(self):
pass
def find(self, **kwargs):
"""Find a single item with attributes matching ``**kwargs``.
This isn't very efficient: it loads the entire list then filters on
the Python side.
"""
matches = self.findall(**kwargs)
num_matches = len(matches)
if num_matches == 0:
msg = _("No %(name)s matching %(args)s.") % {
'name': self.resource_class.__name__,
'args': kwargs
}
raise exceptions.NotFound(msg)
elif num_matches > 1:
raise exceptions.NoUniqueMatch()
else:
return matches[0]
def findall(self, **kwargs):
"""Find all items with attributes matching ``**kwargs``.
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
for (attr, value) in searches):
found.append(obj)
except AttributeError:
continue
return found
class CrudManager(BaseManager):
"""Base manager class for manipulating 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
def build_url(self, base_url=None, **kwargs):
"""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}
:param base_url: if provided, the generated URL will be appended to it
"""
url = base_url if base_url is not None else ''
url += '/%s' % self.collection_key
# do we have a specific entity?
entity_id = kwargs.get('%s_id' % self.key)
if entity_id is not None:
url += '/%s' % entity_id
return url
def _filter_kwargs(self, kwargs):
"""Drop null values and handle ids."""
for key, ref in kwargs.copy().items():
if ref is None:
kwargs.pop(key)
else:
if isinstance(ref, Resource):
kwargs.pop(key)
kwargs['%s_id' % key] = getid(ref)
return kwargs
def create(self, **kwargs):
kwargs = self._filter_kwargs(kwargs)
return self._post(
self.build_url(**kwargs),
{self.key: kwargs},
self.key)
def get(self, **kwargs):
kwargs = self._filter_kwargs(kwargs)
return self._get(
self.build_url(**kwargs),
self.key)
def head(self, **kwargs):
kwargs = self._filter_kwargs(kwargs)
return self._head(self.build_url(**kwargs))
def list(self, base_url=None, **kwargs):
"""List the collection.
:param base_url: if provided, the generated URL will be appended to it
"""
kwargs = self._filter_kwargs(kwargs)
return self._list(
'%(base_url)s%(query)s' % {
'base_url': self.build_url(base_url=base_url, **kwargs),
'query': '?%s' % utils.safe_urlencode(kwargs) if kwargs else ''
},
self.collection_key)
def put(self, base_url=None, **kwargs):
"""Update an element.
:param base_url: if provided, the generated URL will be appended to it
"""
kwargs = self._filter_kwargs(kwargs)
return self._put(self.build_url(base_url=base_url, **kwargs))
def update(self, **kwargs):
kwargs = self._filter_kwargs(kwargs)
params = kwargs.copy()
params.pop('%s_id' % self.key)
return self._patch(
self.build_url(**kwargs),
{self.key: params},
self.key)
def delete(self, **kwargs):
kwargs = self._filter_kwargs(kwargs)
return self._delete(
self.build_url(**kwargs))
def find(self, base_url=None, **kwargs):
"""Find a single item with attributes matching ``**kwargs``.
:param base_url: if provided, the generated URL will be appended to it
"""
kwargs = self._filter_kwargs(kwargs)
rl = self._list(
'%(base_url)s%(query)s' % {
'base_url': self.build_url(base_url=base_url, **kwargs),
'query': '?%s' % utils.safe_urlencode(kwargs) if kwargs else ''
},
self.collection_key)
num = len(rl)
if num == 0:
msg = _("No %(name)s matching %(args)s.") % {
'name': self.resource_class.__name__,
'args': kwargs
}
raise exceptions.NotFound(404, msg)
elif num > 1:
raise exceptions.NoUniqueMatch
else:
return rl[0]
class Extension(HookableMixin):
"""Extension descriptor."""
SUPPORTED_HOOKS = ('__pre_parse_args__', '__post_parse_args__')
manager_class = None
def __init__(self, name, module):
super(Extension, self).__init__()
self.name = name
self.module = module
self._parse_extension_module()
def _parse_extension_module(self):
self.manager_class = None
for attr_name, attr_value in self.module.__dict__.items():
if attr_name in self.SUPPORTED_HOOKS:
self.add_hook(attr_name, attr_value)
else:
try:
if issubclass(attr_value, BaseManager):
self.manager_class = attr_value
except TypeError:
pass
def __repr__(self):
return "<Extension '%s'>" % self.name
class Resource(object):
"""Base class for OpenStack resources (tenant, user, etc.).
This is pretty much just a bag for attributes.
"""
HUMAN_ID = False
NAME_ATTR = 'name'
def __init__(self, manager, info, loaded=False):
"""Populate and bind to a manager.
:param manager: BaseManager object
:param info: dictionary representing resource attributes
:param loaded: prevent lazy-loading if set to True
"""
self.manager = manager
self._info = info
self._add_details(info)
self._loaded = loaded
def __repr__(self):
reprkeys = sorted(k
for k in self.__dict__.keys()
if k[0] != '_' and k != 'manager')
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
return "<%s %s>" % (self.__class__.__name__, info)
@property
def human_id(self):
"""Human-readable ID which can be used for bash completion."""
if self.HUMAN_ID:
name = getattr(self, self.NAME_ATTR, None)
if name is not None:
return strutils.to_slug(name)
return None
def _add_details(self, info):
for (k, v) in info.items():
try:
setattr(self, k, v)
self._info[k] = v
except AttributeError:
# In this case we already defined the attribute on the class
pass
def __getattr__(self, k):
if k not in self.__dict__:
# NOTE(bcwaldon): disallow lazy-loading if already loaded once
if not self.is_loaded():
self.get()
return self.__getattr__(k)
raise AttributeError(k)
else:
return self.__dict__[k]
def get(self):
"""Support for lazy loading details.
Some clients, such as novaclient have the option to lazy load the
details, details which can be loaded with this function.
"""
# set_loaded() first ... so if we have to bail, we know we tried.
self.set_loaded(True)
if not hasattr(self.manager, 'get'):
return
new = self.manager.get(self.id)
if new:
self._add_details(new._info)
def __eq__(self, other):
if not isinstance(other, Resource):
return NotImplemented
# two resources of different types are not equal
if not isinstance(other, self.__class__):
return False
if hasattr(self, 'id') and hasattr(other, 'id'):
return self.id == other.id
return self._info == other._info
def __ne__(self, other):
return not self == other
def is_loaded(self):
return self._loaded
def set_loaded(self, val):
self._loaded = val
def to_dict(self):
return copy.deepcopy(self._info)

View File

@ -12,7 +12,7 @@
from unittest import mock
from manilaclient.common.apiclient import base as common_base
from manilaclient import base
from manilaclient import exceptions
from manilaclient.tests.unit import utils
from manilaclient.tests.unit.v2 import fakes
@ -25,7 +25,7 @@ cs = fakes.FakeClient()
class BaseTest(utils.TestCase):
def test_resource_repr(self):
r = common_base.Resource(None, dict(foo="bar", baz="spam"))
r = base.Resource(None, dict(foo="bar", baz="spam"))
self.assertEqual(repr(r), "<Resource baz=spam, foo=bar>")
def test_eq(self):
@ -33,13 +33,13 @@ class BaseTest(utils.TestCase):
# The truth of r1==r2 does not imply that r1!=r2 is false in PY2.
# Test that inequality operator is defined and that comparing equal
# items returns False.
r1 = common_base.Resource(None, {'id': 1, 'name': 'hi'})
r2 = common_base.Resource(None, {'id': 1, 'name': 'hello'})
r1 = base.Resource(None, {'id': 1, 'name': 'hi'})
r2 = base.Resource(None, {'id': 1, 'name': 'hello'})
self.assertTrue(r1 == r2)
self.assertFalse(r1 != r2)
# Two resources of different types: never equal
r1 = common_base.Resource(None, {'id': 1})
r1 = base.Resource(None, {'id': 1})
r2 = shares.Share(None, {'id': 1})
self.assertNotEqual(r1, r2)
self.assertTrue(r1 != r2)
@ -48,8 +48,8 @@ class BaseTest(utils.TestCase):
# The truth of r1==r2 does not imply that r1!=r2 is false in PY2.
# Test that inequality operator is defined and that comparing equal
# items returns False.
r1 = common_base.Resource(None, {'name': 'joe', 'age': 12})
r2 = common_base.Resource(None, {'name': 'joe', 'age': 12})
r1 = base.Resource(None, {'name': 'joe', 'age': 12})
r2 = base.Resource(None, {'name': 'joe', 'age': 12})
self.assertTrue(r1 == r2)
self.assertFalse(r1 != r2)

View File

@ -17,7 +17,7 @@ from unittest import mock
import ddt
from manilaclient.common.apiclient import base as common_base
from manilaclient import base
from manilaclient.common import constants
from manilaclient.tests.unit import utils
from manilaclient.tests.unit.v2 import fakes
@ -143,7 +143,7 @@ class ShareServerManagerTest(utils.TestCase):
with mock.patch.object(self.manager.api.client, 'post',
mock.Mock(return_value='fake')):
self.mock_object(common_base, 'getid',
self.mock_object(base, 'getid',
mock.Mock(return_value=share_server['id']))
result = self.manager._action(action, share_server, info)
self.manager.api.client.post.assert_called_once_with(

View File

@ -15,14 +15,13 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCE_PATH_LEGACY = '/os-availability-zone'
RESOURCE_PATH = '/availability-zones'
RESOURCE_NAME = 'availability_zones'
class AvailabilityZone(common_base.Resource):
class AvailabilityZone(base.Resource):
def __repr__(self):
return "<AvailabilityZone: %s>" % self.id

View File

@ -14,11 +14,10 @@
# under the License.
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import cliutils
class ListExtResource(common_base.Resource):
class ListExtResource(base.Resource):
@property
def summary(self):
descr = self.description.strip()

View File

@ -15,10 +15,9 @@
# under the License.
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
class Limits(common_base.Resource):
class Limits(base.Resource):
"""A collection of RateLimit and AbsoluteLimit objects."""
def __repr__(self):

View File

@ -13,7 +13,6 @@
"""Asynchronous User Message interface."""
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import constants
RESOURCES_PATH = '/messages'
@ -22,7 +21,7 @@ RESOURCES_NAME = 'messages'
RESOURCE_NAME = 'message'
class Message(common_base.Resource):
class Message(base.Resource):
NAME_ATTR = 'id'
def __repr__(self):
@ -79,6 +78,6 @@ class MessageManager(base.ManagerWithFind):
def delete(self, message):
"""Delete a message."""
loc = RESOURCE_PATH % common_base.getid(message)
loc = RESOURCE_PATH % base.getid(message)
return self._delete(loc)

View File

@ -15,14 +15,13 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCE_PATH_LEGACY = '/os-quota-class-sets'
RESOURCE_PATH = '/quota-class-sets'
REPLICA_QUOTAS_MICROVERSION = "2.53"
class QuotaClassSet(common_base.Resource):
class QuotaClassSet(base.Resource):
@property
def id(self):

View File

@ -15,14 +15,13 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCE_PATH_LEGACY = '/os-quota-sets'
RESOURCE_PATH = '/quota-sets'
REPLICA_QUOTAS_MICROVERSION = "2.53"
class QuotaSet(common_base.Resource):
class QuotaSet(base.Resource):
@property
def id(self):

View File

@ -13,13 +13,12 @@
# under the License.
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCES_PATH = '/scheduler-stats/pools'
RESOURCES_NAME = 'pools'
class Pool(common_base.Resource):
class Pool(base.Resource):
def __repr__(self):
return "<Pool: %s>" % self.name

View File

@ -14,7 +14,6 @@
# under the License.
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient import exceptions
RESOURCES_PATH = '/security-services'
@ -23,7 +22,7 @@ RESOURCE_NAME = 'security_service'
RESOURCES_NAME = 'security_services'
class SecurityService(common_base.Resource):
class SecurityService(base.Resource):
"""Security service for Manila shares."""
def __repr__(self):
return "<SecurityService: %s>" % self.id
@ -88,7 +87,7 @@ class SecurityServiceManager(base.ManagerWithFind):
:rtype: :class:`SecurityService`
"""
return self._get(
RESOURCE_PATH % common_base.getid(security_service),
RESOURCE_PATH % base.getid(security_service),
RESOURCE_NAME,
)
@ -138,7 +137,7 @@ class SecurityServiceManager(base.ManagerWithFind):
body = {RESOURCE_NAME: values}
return self._update(
RESOURCE_PATH % common_base.getid(security_service),
RESOURCE_PATH % base.getid(security_service),
body,
RESOURCE_NAME,
)
@ -148,7 +147,7 @@ class SecurityServiceManager(base.ManagerWithFind):
:param security_service: security service to be deleted.
"""
self._delete(RESOURCE_PATH % common_base.getid(security_service))
self._delete(RESOURCE_PATH % base.getid(security_service))
def list(self, detailed=True, search_opts=None):
"""Get a list of all security services.

View File

@ -15,14 +15,13 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCE_PATH_LEGACY = '/os-services'
RESOURCE_PATH = '/services'
RESOURCE_NAME = 'services'
class Service(common_base.Resource):
class Service(base.Resource):
def __repr__(self):
return "<Service: %s>" % self.id

View File

@ -19,7 +19,6 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCE_PATH = '/share-access-rules/%s'
RESOURCE_NAME = 'access'
@ -29,7 +28,7 @@ RESOURCE_METADATA_PATH = '/share-access-rules/%s/metadata/%s'
RESOURCE_LIST_PATH = '/share-access-rules'
class ShareAccessRule(common_base.Resource):
class ShareAccessRule(base.Resource):
"""A Share Access Rule."""
def __repr__(self):
@ -53,7 +52,7 @@ class ShareAccessRuleManager(base.ManagerWithFind):
with UUID
:rtype: :class:`ShareAccessRule`
"""
share_access_rule_id = common_base.getid(share_access_rule)
share_access_rule_id = base.getid(share_access_rule)
url = RESOURCE_PATH % share_access_rule_id
return self._get(url, RESOURCE_NAME)
@ -66,7 +65,7 @@ class ShareAccessRuleManager(base.ManagerWithFind):
:param metadata: A list of keys to be set.
"""
body = {'metadata': metadata}
access_id = common_base.getid(access)
access_id = base.getid(access)
url = RESOURCES_METADATA_PATH % access_id
return self._update(url, body, "metadata")
@ -78,13 +77,13 @@ class ShareAccessRuleManager(base.ManagerWithFind):
:return: None if successful, else API response on failure
"""
for k in keys:
url = RESOURCE_METADATA_PATH % (common_base.getid(access), k)
url = RESOURCE_METADATA_PATH % (base.getid(access), k)
self._delete(url)
@api_versions.wraps("2.45")
def access_list(self, share, search_opts=None):
search_opts = search_opts or {}
search_opts['share_id'] = common_base.getid(share)
search_opts['share_id'] = base.getid(share)
query_string = self._build_query_string(search_opts)
url = RESOURCE_LIST_PATH + query_string
return self._list(url, 'access_list')

View File

@ -15,10 +15,9 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
class ShareExportLocation(common_base.Resource):
class ShareExportLocation(base.Resource):
"""Resource class for a share export location."""
def __repr__(self):
@ -35,15 +34,15 @@ class ShareExportLocationManager(base.ManagerWithFind):
@api_versions.wraps("2.9")
def list(self, share, search_opts=None):
"""List all share export locations."""
share_id = common_base.getid(share)
share_id = base.getid(share)
return self._list("/shares/%s/export_locations" % share_id,
"export_locations")
@api_versions.wraps("2.9")
def get(self, share, export_location):
"""Get a share export location."""
share_id = common_base.getid(share)
export_location_id = common_base.getid(export_location)
share_id = base.getid(share)
export_location_id = base.getid(export_location)
return self._get(
"/shares/%(share_id)s/export_locations/%(export_location_id)s" % {
"share_id": share_id,

View File

@ -16,7 +16,6 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import constants
RESOURCES_PATH = '/share-group-snapshots'
@ -27,7 +26,7 @@ RESOURCE_NAME = 'share_group_snapshot'
SG_GRADUATION_VERSION = "2.55"
class ShareGroupSnapshot(common_base.Resource):
class ShareGroupSnapshot(base.Resource):
"""A snapshot of a share group."""
def __repr__(self):
@ -59,7 +58,7 @@ class ShareGroupSnapshotManager(base.ManagerWithFind):
:param description: text - description of the group snapshot
:rtype: :class:`ShareGroupSnapshot`
"""
share_group_id = common_base.getid(share_group)
share_group_id = base.getid(share_group)
body = {'share_group_id': share_group_id}
if name:
body['name'] = name
@ -87,7 +86,7 @@ class ShareGroupSnapshotManager(base.ManagerWithFind):
with its UUID
:rtype: :class:`ShareGroupSnapshot`
"""
share_group_snapshot_id = common_base.getid(share_group_snapshot)
share_group_snapshot_id = base.getid(share_group_snapshot)
url = RESOURCE_PATH % share_group_snapshot_id
return self._get(url, RESOURCE_NAME)
@ -167,7 +166,7 @@ class ShareGroupSnapshotManager(base.ManagerWithFind):
with its UUID
:rtype: :class:`ShareGroupSnapshot`
"""
share_group_snapshot_id = common_base.getid(share_group_snapshot)
share_group_snapshot_id = base.getid(share_group_snapshot)
url = RESOURCE_PATH % share_group_snapshot_id
if not kwargs:
return self._get(url, RESOURCE_NAME)
@ -193,7 +192,7 @@ class ShareGroupSnapshotManager(base.ManagerWithFind):
with its UUID
:param force: True to force the deletion
"""
share_group_snapshot_id = common_base.getid(share_group_snapshot)
share_group_snapshot_id = base.getid(share_group_snapshot)
if force:
url = RESOURCE_PATH_ACTION % share_group_snapshot_id
body = {'force_delete': None}
@ -218,7 +217,7 @@ class ShareGroupSnapshotManager(base.ManagerWithFind):
with its UUID
:param state: The new state for the share group snapshot
"""
share_group_snapshot_id = common_base.getid(share_group_snapshot)
share_group_snapshot_id = base.getid(share_group_snapshot)
url = RESOURCE_PATH_ACTION % share_group_snapshot_id
body = {'reset_status': {'status': state}}
self.api.client.post(url, body=body)

View File

@ -15,7 +15,6 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCES_PATH = '/share-group-types'
RESOURCE_PATH = '/share-group-types/%s/access'
@ -24,7 +23,7 @@ RESOURCE_NAME = 'share_group_type_access'
SG_GRADUATION_VERSION = "2.55"
class ShareGroupTypeAccess(common_base.Resource):
class ShareGroupTypeAccess(base.Resource):
def __repr__(self):
return "<Share Group Type Access: %s>" % self.share_group_type_id
@ -37,7 +36,7 @@ class ShareGroupTypeAccessManager(base.ManagerWithFind):
search_opts=None):
if share_group_type.is_public:
return None
share_group_type_id = common_base.getid(share_group_type)
share_group_type_id = base.getid(share_group_type)
url = RESOURCE_PATH % share_group_type_id
return self._list(url, RESOURCE_NAME)
@ -82,6 +81,6 @@ class ShareGroupTypeAccessManager(base.ManagerWithFind):
"""Perform a share group type action."""
body = {action: info}
self.run_hooks('modify_body_for_action', body, **kwargs)
share_group_type_id = common_base.getid(share_group_type)
share_group_type_id = base.getid(share_group_type)
url = RESOURCE_PATH_ACTION % share_group_type_id
return self.api.client.post(url, body=body)

View File

@ -16,7 +16,6 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCES_PATH = '/share-group-types'
RESOURCE_PATH = '/share-group-types/%s'
@ -30,7 +29,7 @@ GROUP_SPECS_RESOURCES_NAME = 'group_specs'
SG_GRADUATION_VERSION = "2.55"
class ShareGroupType(common_base.Resource):
class ShareGroupType(base.Resource):
"""A Share Group Type is the type of share group to be created."""
def __init__(self, manager, info, loaded=False):
@ -56,7 +55,7 @@ class ShareGroupType(common_base.Resource):
if prefer_resource_data:
return self._group_specs
else:
share_group_type_id = common_base.getid(self)
share_group_type_id = base.getid(self)
url = GROUP_SPECS_RESOURCES_PATH % share_group_type_id
_resp, body = self.manager.api.client.get(url)
self._group_specs = body.get(GROUP_SPECS_RESOURCES_NAME, {})
@ -68,7 +67,7 @@ class ShareGroupType(common_base.Resource):
:param extra_specs: A dict of key/value pairs to be set on this object
:return: dict with group specs
"""
share_group_type_id = common_base.getid(self)
share_group_type_id = base.getid(self)
url = GROUP_SPECS_RESOURCES_PATH % share_group_type_id
body = {GROUP_SPECS_RESOURCES_NAME: group_specs}
return self.manager._create(
@ -80,7 +79,7 @@ class ShareGroupType(common_base.Resource):
:param keys: A list of keys on this object to be unset
:return: None if successful, else API response on failure
"""
share_group_type_id = common_base.getid(self)
share_group_type_id = base.getid(self)
for k in keys:
url = GROUP_SPECS_RESOURCE_PATH % (share_group_type_id, k)
resp = self.manager._delete(url)
@ -110,7 +109,7 @@ class ShareGroupTypeManager(base.ManagerWithFind):
'name': name,
'is_public': is_public,
'group_specs': group_specs or {},
'share_types': [common_base.getid(share_type)
'share_types': [base.getid(share_type)
for share_type in share_types],
}
return self._create(
@ -134,7 +133,7 @@ class ShareGroupTypeManager(base.ManagerWithFind):
with UUID, or 'default'
:rtype: :class:`ShareGroupType`
"""
share_group_type_id = common_base.getid(share_group_type)
share_group_type_id = base.getid(share_group_type)
url = RESOURCE_PATH % share_group_type_id
return self._get(url, RESOURCE_NAME)
@ -174,7 +173,7 @@ class ShareGroupTypeManager(base.ManagerWithFind):
:param share_group_type: either instance of ShareGroupType, or text
with UUID
"""
share_group_type_id = common_base.getid(share_group_type)
share_group_type_id = base.getid(share_group_type)
url = RESOURCE_PATH % share_group_type_id
self._delete(url)

View File

@ -17,7 +17,6 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import constants
RESOURCES_PATH = '/share-groups'
@ -28,7 +27,7 @@ RESOURCE_NAME = 'share_group'
SG_GRADUATION_VERSION = "2.55"
class ShareGroup(common_base.Resource):
class ShareGroup(base.Resource):
"""A share group is a logical grouping of shares on a single backend."""
def __repr__(self):
@ -88,15 +87,15 @@ class ShareGroupManager(base.ManagerWithFind):
if availability_zone:
body['availability_zone'] = availability_zone
if share_group_type:
body['share_group_type_id'] = common_base.getid(share_group_type)
body['share_group_type_id'] = base.getid(share_group_type)
if share_network:
body['share_network_id'] = common_base.getid(share_network)
body['share_network_id'] = base.getid(share_network)
if source_share_group_snapshot:
body['source_share_group_snapshot_id'] = common_base.getid(
body['source_share_group_snapshot_id'] = base.getid(
source_share_group_snapshot)
elif share_types:
body['share_types'] = [common_base.getid(share_type)
body['share_types'] = [base.getid(share_type)
for share_type in share_types]
return self._create(
@ -129,7 +128,7 @@ class ShareGroupManager(base.ManagerWithFind):
:param share_group: either ShareGroup object or text with its UUID
:rtype: :class:`ShareGroup`
"""
share_group_id = common_base.getid(share_group)
share_group_id = base.getid(share_group)
url = RESOURCE_PATH % share_group_id
return self._get(url, RESOURCE_NAME)
@ -217,7 +216,7 @@ class ShareGroupManager(base.ManagerWithFind):
:param share_group: either ShareGroup object or text with its UUID
:rtype: :class:`ShareGroup`
"""
share_group_id = common_base.getid(share_group)
share_group_id = base.getid(share_group)
url = RESOURCE_PATH % share_group_id
if not kwargs:
return self._get(url, RESOURCE_NAME)
@ -239,7 +238,7 @@ class ShareGroupManager(base.ManagerWithFind):
:param share_group: either ShareGroup object or text with its UUID
:param force: True to force the deletion
"""
share_group_id = common_base.getid(share_group)
share_group_id = base.getid(share_group)
if force:
url = RESOURCE_PATH_ACTION % share_group_id
body = {'force_delete': None}
@ -264,7 +263,7 @@ class ShareGroupManager(base.ManagerWithFind):
:param state: The new state for the share group
"""
share_group_id = common_base.getid(share_group)
share_group_id = base.getid(share_group)
url = RESOURCE_PATH_ACTION % share_group_id
body = {'reset_status': {'status': state}}
self.api.client.post(url, body=body)

View File

@ -15,10 +15,9 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
class ShareInstanceExportLocation(common_base.Resource):
class ShareInstanceExportLocation(base.Resource):
"""Resource class for a share export location."""
def __repr__(self):
@ -35,7 +34,7 @@ class ShareInstanceExportLocationManager(base.ManagerWithFind):
@api_versions.wraps("2.9")
def list(self, share_instance, search_opts=None):
"""List all share export locations."""
share_instance_id = common_base.getid(share_instance)
share_instance_id = base.getid(share_instance)
return self._list(
"/share_instances/%s/export_locations" % share_instance_id,
"export_locations")
@ -43,8 +42,8 @@ class ShareInstanceExportLocationManager(base.ManagerWithFind):
@api_versions.wraps("2.9")
def get(self, share_instance, export_location):
"""Get a share export location."""
share_instance_id = common_base.getid(share_instance)
export_location_id = common_base.getid(export_location)
share_instance_id = base.getid(share_instance)
export_location_id = base.getid(export_location)
return self._get(
("/share_instances/%(share_instance_id)s/export_locations/"
"%(export_location_id)s") % {

View File

@ -17,10 +17,9 @@ from oslo_utils import uuidutils
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
class ShareInstance(common_base.Resource):
class ShareInstance(base.Resource):
"""A share is an extra block level storage to the OpenStack instances."""
def __repr__(self):
return "<Share: %s>" % self.id
@ -45,7 +44,7 @@ class ShareInstanceManager(base.ManagerWithFind):
:param instance: either share object or text with its ID.
:rtype: :class:`ShareInstance`
"""
share_id = common_base.getid(instance)
share_id = base.getid(instance)
return self._get("/share_instances/%s" % share_id, "share_instance")
@api_versions.wraps("2.3", "2.34")
@ -79,7 +78,7 @@ class ShareInstanceManager(base.ManagerWithFind):
"""
body = {action: info}
self.run_hooks('modify_body_for_action', body, **kwargs)
url = '/share_instances/%s/action' % common_base.getid(instance)
url = '/share_instances/%s/action' % base.getid(instance)
return self.api.client.post(url, body=body)
def _do_force_delete(self, instance, action_name="force_delete"):
@ -87,7 +86,7 @@ class ShareInstanceManager(base.ManagerWithFind):
:param instance: either share instance object or text with its ID.
"""
return self._action(action_name, common_base.getid(instance))
return self._action(action_name, base.getid(instance))
@api_versions.wraps("2.3", "2.6")
def force_delete(self, instance):

View File

@ -14,14 +14,13 @@
# under the License.
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCES_PATH = '/share-networks/%(share_network_id)s/subnets'
RESOURCE_PATH = RESOURCES_PATH + '/%(share_network_subnet_id)s'
RESOURCE_NAME = 'share_network_subnet'
class ShareNetworkSubnet(common_base.Resource):
class ShareNetworkSubnet(base.Resource):
"""Network subnet info for Manila share networks."""
def __repr__(self):
return "<ShareNetworkSubnet: %s>" % self.id
@ -69,8 +68,8 @@ class ShareNetworkSubnetManager(base.ManagerWithFind):
:param policy: share network subnet to get.
:rtype: :class:`NetworkSubnetInfo`
"""
share_network_id = common_base.getid(share_network)
share_network_subnet_id = common_base.getid(share_network_subnet)
share_network_id = base.getid(share_network)
share_network_subnet_id = base.getid(share_network_subnet)
url = ('/share-networks/%(share_network_id)s/subnets'
'/%(share_network_subnet)s') % {
'share_network_id': share_network_id,
@ -86,7 +85,7 @@ class ShareNetworkSubnetManager(base.ManagerWithFind):
"""
url = ('/share-networks/%(share_network_id)s/subnets'
'/%(share_network_subnet)s') % {
'share_network_id': common_base.getid(share_network),
'share_network_id': base.getid(share_network),
'share_network_subnet': share_network_subnet
}
self._delete(url)

View File

@ -15,7 +15,6 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient import exceptions
RESOURCES_PATH = '/share-networks'
@ -25,7 +24,7 @@ RESOURCES_NAME = 'share_networks'
ACTION_PATH = RESOURCE_PATH + '/action'
class ShareNetwork(common_base.Resource):
class ShareNetwork(base.Resource):
"""Network info for Manila shares."""
def __repr__(self):
return "<ShareNetwork: %s>" % self.id
@ -125,11 +124,11 @@ class ShareNetworkManager(base.ManagerWithFind):
"""
body = {
'remove_security_service': {
'security_service_id': common_base.getid(security_service),
'security_service_id': base.getid(security_service),
},
}
return self._create(
RESOURCE_PATH % common_base.getid(share_network) + '/action',
RESOURCE_PATH % base.getid(share_network) + '/action',
body,
RESOURCE_NAME,
)
@ -140,7 +139,7 @@ class ShareNetworkManager(base.ManagerWithFind):
:param policy: share network to get.
:rtype: :class:`NetworkInfo`
"""
return self._get(RESOURCE_PATH % common_base.getid(share_network),
return self._get(RESOURCE_PATH % base.getid(share_network),
RESOURCE_NAME)
@api_versions.wraps("1.0", "2.25")
@ -173,7 +172,7 @@ class ShareNetworkManager(base.ManagerWithFind):
raise exceptions.CommandError(msg)
body = {RESOURCE_NAME: values}
return self._update(RESOURCE_PATH % common_base.getid(share_network),
return self._update(RESOURCE_PATH % base.getid(share_network),
body,
RESOURCE_NAME)
@ -205,7 +204,7 @@ class ShareNetworkManager(base.ManagerWithFind):
raise exceptions.CommandError(msg)
body = {RESOURCE_NAME: values}
return self._update(RESOURCE_PATH % common_base.getid(share_network),
return self._update(RESOURCE_PATH % base.getid(share_network),
body,
RESOURCE_NAME)
@ -214,7 +213,7 @@ class ShareNetworkManager(base.ManagerWithFind):
:param share_network: share network to be deleted.
"""
self._delete(RESOURCE_PATH % common_base.getid(share_network))
self._delete(RESOURCE_PATH % base.getid(share_network))
def list(self, detailed=True, search_opts=None):
"""Get a list of all share network.
@ -239,7 +238,7 @@ class ShareNetworkManager(base.ManagerWithFind):
"""
body = {action: info}
self.run_hooks('modify_body_for_action', body)
url = ACTION_PATH % common_base.getid(share_network)
url = ACTION_PATH % base.getid(share_network)
return self.api.client.post(url, body=body)
def add_security_service(self, share_network, security_service):
@ -250,7 +249,7 @@ class ShareNetworkManager(base.ManagerWithFind):
:rtype: :class:`ShareNetwork`
"""
info = {
'security_service_id': common_base.getid(security_service),
'security_service_id': base.getid(security_service),
}
return self._action('add_security_service', share_network, info)
@ -265,7 +264,7 @@ class ShareNetworkManager(base.ManagerWithFind):
:rtype: :class:`ShareNetwork`
"""
info = {
'security_service_id': common_base.getid(security_service),
'security_service_id': base.getid(security_service),
'reset_operation': reset_operation,
}
return self._action('add_security_service_check', share_network, info)
@ -284,8 +283,8 @@ class ShareNetworkManager(base.ManagerWithFind):
:rtype: :class:`ShareNetwork`
"""
info = {
'current_service_id': common_base.getid(current_security_service),
'new_service_id': common_base.getid(new_security_service)}
'current_service_id': base.getid(current_security_service),
'new_service_id': base.getid(new_security_service)}
return self._action('update_security_service', share_network, info)
@ -304,8 +303,8 @@ class ShareNetworkManager(base.ManagerWithFind):
:rtype: :class:`ShareNetwork`
"""
info = {
'current_service_id': common_base.getid(current_security_service),
'new_service_id': common_base.getid(new_security_service),
'current_service_id': base.getid(current_security_service),
'new_service_id': base.getid(new_security_service),
'reset_operation': reset_operation
}

View File

@ -14,11 +14,10 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import constants
class ShareReplicaExportLocation(common_base.Resource):
class ShareReplicaExportLocation(base.Resource):
"""Resource class for a share replica export location."""
def __repr__(self):
@ -36,7 +35,7 @@ class ShareReplicaExportLocationManager(base.ManagerWithFind):
@api_versions.experimental_api
def list(self, share_replica, search_opts=None):
"""List all share replica export locations."""
share_replica_id = common_base.getid(share_replica)
share_replica_id = base.getid(share_replica)
return self._list(
"/share-replicas/%s/export-locations" % share_replica_id,
"export_locations")
@ -44,7 +43,7 @@ class ShareReplicaExportLocationManager(base.ManagerWithFind):
@api_versions.wraps(constants.REPLICA_GRADUATION_VERSION) # noqa
def list(self, share_replica, search_opts=None): # noqa F811
"""List all share replica export locations."""
share_replica_id = common_base.getid(share_replica)
share_replica_id = base.getid(share_replica)
return self._list(
"/share-replicas/%s/export-locations" % share_replica_id,
"export_locations")
@ -62,8 +61,8 @@ class ShareReplicaExportLocationManager(base.ManagerWithFind):
def _get_replica_export_location(self, share_replica, export_location):
"""Get a share replica export location."""
share_replica_id = common_base.getid(share_replica)
export_location_id = common_base.getid(export_location)
share_replica_id = base.getid(share_replica)
export_location_id = base.getid(export_location)
return self._get(
("/share-replicas/%(share_replica_id)s/export-locations/"
"%(export_location_id)s") % {

View File

@ -15,7 +15,6 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import constants
RESOURCES_PATH = '/share-replicas'
@ -25,7 +24,7 @@ RESOURCES_NAME = 'share_replicas'
RESOURCE_NAME = 'share_replica'
class ShareReplica(common_base.Resource):
class ShareReplica(base.Resource):
"""A replica is 'mirror' instance of a share at some point in time."""
def __repr__(self):
return "<Share Replica: %s>" % self.id
@ -66,7 +65,7 @@ class ShareReplicaManager(base.ManagerWithFind):
:param replica: either replica object or its UUID.
:rtype: :class:`ShareReplica`
"""
replica_id = common_base.getid(replica)
replica_id = base.getid(replica)
return self._get(RESOURCE_PATH % replica_id, RESOURCE_NAME)
@api_versions.wraps("2.11", constants.REPLICA_PRE_GRADUATION_VERSION)
@ -87,7 +86,7 @@ class ShareReplicaManager(base.ManagerWithFind):
"""
if share:
share_id = '?share_id=' + common_base.getid(share)
share_id = '?share_id=' + base.getid(share)
url = RESOURCES_PATH + '/detail' + share_id
return self._list(url, RESOURCES_NAME)
else:
@ -129,11 +128,11 @@ class ShareReplicaManager(base.ManagerWithFind):
:param availability_zone: The 'availability_zone' object or its UUID.
"""
share_id = common_base.getid(share)
share_id = base.getid(share)
body = {'share_id': share_id}
if availability_zone:
body['availability_zone'] = common_base.getid(availability_zone)
body['availability_zone'] = base.getid(availability_zone)
return self._create(RESOURCES_PATH,
{RESOURCE_NAME: body},
@ -223,7 +222,7 @@ class ShareReplicaManager(base.ManagerWithFind):
"""
body = {action: info}
self.run_hooks('modify_body_for_action', body, **kwargs)
replica_id = common_base.getid(replica)
replica_id = base.getid(replica)
url = RESOURCE_PATH_ACTION % replica_id
return self.api.client.post(url, body=body)
@ -232,7 +231,7 @@ class ShareReplicaManager(base.ManagerWithFind):
:param replica: either share replica object or its UUID.
"""
replica_id = common_base.getid(replica)
replica_id = base.getid(replica)
url = RESOURCE_PATH % replica_id
if force:
@ -245,7 +244,7 @@ class ShareReplicaManager(base.ManagerWithFind):
:param replica: either share replica object or its UUID.
"""
return self._action(action_name, common_base.getid(replica))
return self._action(action_name, base.getid(replica))
def _do_reset_state(self, replica, state, action_name):
"""Update the provided share replica with the provided state.

View File

@ -15,7 +15,6 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
RESOURCES_NAME = 'share_servers'
RESOURCES_PATH = '/share-servers'
@ -24,7 +23,7 @@ RESOURCE_NAME = 'share_server'
ACTION_PATH = RESOURCE_PATH + '/action'
class ShareServer(common_base.Resource):
class ShareServer(base.Resource):
def __repr__(self):
return "<ShareServer: %s>" % self.id
@ -87,7 +86,7 @@ class ShareServerManager(base.ManagerWithFind):
:param server: ID of the :class:`ShareServer` to get.
:rtype: :class:`ShareServer`
"""
server_id = common_base.getid(server)
server_id = base.getid(server)
server = self._get("%s/%s" % (RESOURCES_PATH, server_id),
RESOURCE_NAME)
# Split big dict 'backend_details' to separated strings
@ -107,7 +106,7 @@ class ShareServerManager(base.ManagerWithFind):
:param server: ID of the :class:`ShareServer` to get details from.
:rtype: list of :class:`ShareServerBackendDetails
"""
server_id = common_base.getid(server)
server_id = base.getid(server)
return self._get("%s/%s/details" % (RESOURCES_PATH, server_id),
"details")
@ -116,7 +115,7 @@ class ShareServerManager(base.ManagerWithFind):
:param server: ID of the :class:`ShareServer` to delete.
"""
server_id = common_base.getid(server)
server_id = base.getid(server)
self._delete(RESOURCE_PATH % server_id)
def list(self, search_opts=None):
@ -181,7 +180,7 @@ class ShareServerManager(base.ManagerWithFind):
"""
body = {action: info}
self.run_hooks('modify_body_for_action', body)
url = ACTION_PATH % common_base.getid(share_server)
url = ACTION_PATH % base.getid(share_server)
return self.api.client.post(url, body=body)
@api_versions.wraps("2.57")

View File

@ -15,10 +15,9 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
class ShareSnapshotExportLocation(common_base.Resource):
class ShareSnapshotExportLocation(base.Resource):
"""Represent an export location snapshot of a snapshot."""
def __repr__(self):
@ -35,14 +34,14 @@ class ShareSnapshotExportLocationManager(base.ManagerWithFind):
@api_versions.wraps("2.32")
def list(self, snapshot=None, search_opts=None):
return self._list("/snapshots/%s/export-locations" %
common_base.getid(snapshot),
base.getid(snapshot),
'share_snapshot_export_locations')
@api_versions.wraps("2.32")
def get(self, export_location, snapshot=None):
params = {
"snapshot_id": common_base.getid(snapshot),
"export_location_id": common_base.getid(export_location),
"snapshot_id": base.getid(snapshot),
"export_location_id": base.getid(export_location),
}
return self._get("/snapshots/%(snapshot_id)s/export-locations/"

View File

@ -15,10 +15,9 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
class ShareSnapshotInstanceExportLocation(common_base.Resource):
class ShareSnapshotInstanceExportLocation(base.Resource):
"""Represent an export location from a snapshot instance."""
def __repr__(self):
@ -35,14 +34,14 @@ class ShareSnapshotInstanceExportLocationManager(base.ManagerWithFind):
@api_versions.wraps("2.32")
def list(self, snapshot_instance=None, search_opts=None):
return self._list("/snapshot-instances/%s/export-locations" %
common_base.getid(snapshot_instance),
base.getid(snapshot_instance),
'share_snapshot_export_locations')
@api_versions.wraps("2.32")
def get(self, export_location, snapshot_instance=None):
params = {
"snapshot_instance_id": common_base.getid(snapshot_instance),
"export_location_id": common_base.getid(export_location),
"snapshot_instance_id": base.getid(snapshot_instance),
"export_location_id": base.getid(export_location),
}
return self._get("/snapshot-instances/%(snapshot_instance_id)s/"

View File

@ -15,10 +15,9 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
class ShareSnapshotInstance(common_base.Resource):
class ShareSnapshotInstance(base.Resource):
"""A snapshot instance is an instance of a snapshot."""
def __repr__(self):
@ -40,7 +39,7 @@ class ShareSnapshotInstanceManager(base.ManagerWithFind):
:param instance: either snapshot instance object or text with its ID.
:rtype: :class:`ShareSnapshotInstance`
"""
snapshot_instance_id = common_base.getid(instance)
snapshot_instance_id = base.getid(instance)
return self._get("/snapshot-instances/%s" % snapshot_instance_id,
"snapshot_instance")
@ -53,7 +52,7 @@ class ShareSnapshotInstanceManager(base.ManagerWithFind):
url = '/snapshot-instances'
if snapshot:
url += '?snapshot_id=%s' % common_base.getid(snapshot)
url += '?snapshot_id=%s' % base.getid(snapshot)
return self._list(url, 'snapshot_instances')
@api_versions.wraps("2.19")
@ -70,5 +69,5 @@ class ShareSnapshotInstanceManager(base.ManagerWithFind):
body = {action: info}
self.run_hooks('modify_body_for_action', body, **kwargs)
url = ('/snapshot-instances/%s/action' %
common_base.getid(instance))
base.getid(instance))
return self.api.client.post(url, body=body)

View File

@ -16,11 +16,10 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import constants
class ShareSnapshot(common_base.Resource):
class ShareSnapshot(base.Resource):
"""Represent a snapshot of a share."""
def __repr__(self):
@ -72,7 +71,7 @@ class ShareSnapshotManager(base.ManagerWithFind):
:param description: Description of the snapshot
:rtype: :class:`ShareSnapshot`
"""
body = {'snapshot': {'share_id': common_base.getid(share),
body = {'snapshot': {'share_id': base.getid(share),
'force': force,
'name': name,
'description': description}}
@ -93,7 +92,7 @@ class ShareSnapshotManager(base.ManagerWithFind):
"""
driver_options = driver_options if driver_options else {}
body = {
'share_id': common_base.getid(share),
'share_id': base.getid(share),
'provider_location': provider_location,
'driver_options': driver_options,
'name': name,
@ -117,7 +116,7 @@ class ShareSnapshotManager(base.ManagerWithFind):
of snapshot to delete.
:rtype: :class:`ShareSnapshot`
"""
snapshot_id = common_base.getid(snapshot)
snapshot_id = base.getid(snapshot)
return self._get('/snapshots/%s' % snapshot_id, 'snapshot')
def list(self, detailed=True, search_opts=None, sort_key=None,
@ -161,11 +160,11 @@ class ShareSnapshotManager(base.ManagerWithFind):
:param snapshot: The :class:`ShareSnapshot` to delete.
"""
self._delete("/snapshots/%s" % common_base.getid(snapshot))
self._delete("/snapshots/%s" % base.getid(snapshot))
def _do_force_delete(self, snapshot, action_name="force_delete"):
"""Delete the specified snapshot ignoring its current state."""
return self._action(action_name, common_base.getid(snapshot))
return self._action(action_name, base.getid(snapshot))
@api_versions.wraps("1.0", "2.6")
def force_delete(self, snapshot):
@ -186,7 +185,7 @@ class ShareSnapshotManager(base.ManagerWithFind):
return
body = {'snapshot': kwargs, }
snapshot_id = common_base.getid(snapshot)
snapshot_id = base.getid(snapshot)
return self._update("/snapshots/%s" % snapshot_id, body)
def _do_reset_state(self, snapshot, state, action_name="reset_status"):
@ -222,7 +221,7 @@ class ShareSnapshotManager(base.ManagerWithFind):
return self._do_deny(snapshot, id)
def _do_access_list(self, snapshot):
snapshot_id = common_base.getid(snapshot)
snapshot_id = base.getid(snapshot)
access_list = self._list("/snapshots/%s/access-list" % snapshot_id,
'snapshot_access_list')
return access_list
@ -235,5 +234,5 @@ class ShareSnapshotManager(base.ManagerWithFind):
"""Perform a snapshot 'action'."""
body = {action: info}
self.run_hooks('modify_body_for_action', body, **kwargs)
url = '/snapshots/%s/action' % common_base.getid(snapshot)
url = '/snapshots/%s/action' % base.getid(snapshot)
return self.api.client.post(url, body=body)

View File

@ -16,10 +16,9 @@
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
class ShareTypeAccess(common_base.Resource):
class ShareTypeAccess(base.Resource):
def __repr__(self):
return "<ShareTypeAccess: %s>" % self.id
@ -35,7 +34,7 @@ class ShareTypeAccessManager(base.ManagerWithFind):
return self._list(
"/types/%(st_id)s/%(action_name)s" % {
"st_id": common_base.getid(share_type),
"st_id": base.getid(share_type),
"action_name": action_name},
"share_type_access")
@ -61,5 +60,5 @@ class ShareTypeAccessManager(base.ManagerWithFind):
"""Perform a share type action."""
body = {action: info}
self.run_hooks('modify_body_for_action', body, **kwargs)
url = '/types/%s/action' % common_base.getid(share_type)
url = '/types/%s/action' % base.getid(share_type)
return self.api.client.post(url, body=body)

View File

@ -20,11 +20,10 @@ Share Type interface.
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient import exceptions
class ShareType(common_base.Resource):
class ShareType(base.Resource):
"""A Share Type is the type of share to be created."""
def __init__(self, manager, info, loaded=False):
@ -57,7 +56,7 @@ class ShareType(common_base.Resource):
return extra_specs
_resp, body = self.manager.api.client.get(
"/types/%s/extra_specs" % common_base.getid(self))
"/types/%s/extra_specs" % base.getid(self))
self.extra_specs = body["extra_specs"]
@ -77,7 +76,7 @@ class ShareType(common_base.Resource):
"""
body = {'extra_specs': metadata}
return self.manager._create(
"/types/%s/extra_specs" % common_base.getid(self),
"/types/%s/extra_specs" % base.getid(self),
body,
"extra_specs",
return_raw=True,
@ -97,7 +96,7 @@ class ShareType(common_base.Resource):
resp = None
for k in keys:
resp = self.manager._delete(
"/types/%s/extra_specs/%s" % (common_base.getid(self), k))
"/types/%s/extra_specs/%s" % (base.getid(self), k))
if resp is not None:
return resp
@ -128,7 +127,7 @@ class ShareTypeManager(base.ManagerWithFind):
:param share: either share object or text with its ID.
:rtype: :class:`Share`
"""
type_id = common_base.getid(share_type)
type_id = base.getid(share_type)
return self._get("/types/%s" % type_id, "share_type")
def get(self, share_type="default"):
@ -137,7 +136,7 @@ class ShareTypeManager(base.ManagerWithFind):
:param share_type: The ID of the :class:`ShareType` to get.
:rtype: :class:`ShareType`
"""
return self._get("/types/%s" % common_base.getid(share_type),
return self._get("/types/%s" % base.getid(share_type),
"share_type")
def delete(self, share_type):
@ -145,7 +144,7 @@ class ShareTypeManager(base.ManagerWithFind):
:param share_type: The name or ID of the :class:`ShareType` to get.
"""
self._delete("/types/%s" % common_base.getid(share_type))
self._delete("/types/%s" % base.getid(share_type))
def _do_create(self, name, extra_specs, is_public,
is_public_keyname="share_type_access:is_public",
@ -189,7 +188,7 @@ class ShareTypeManager(base.ManagerWithFind):
body["share_type"][is_public_keyname] = is_public
if description or description == "":
body["share_type"]["description"] = description
return self._update("/types/%s" % common_base.getid(share_type),
return self._update("/types/%s" % base.getid(share_type),
body, "share_type")
@api_versions.wraps("1.0", "2.6")

View File

@ -22,13 +22,12 @@ import string
from manilaclient import api_versions
from manilaclient import base
from manilaclient.common.apiclient import base as common_base
from manilaclient.common import constants
from manilaclient import exceptions
from manilaclient.v2 import share_instances
class Share(common_base.Resource):
class Share(base.Resource):
"""A share is an extra block level storage to the OpenStack instances."""
def __repr__(self):
return "<Share: %s>" % self.id
@ -150,8 +149,8 @@ class ShareManager(base.ManagerWithFind):
'description': description,
'metadata': share_metadata,
'share_proto': share_proto,
'share_network_id': common_base.getid(share_network),
'share_type': common_base.getid(share_type),
'share_network_id': base.getid(share_network),
'share_type': base.getid(share_type),
'is_public': is_public,
'availability_zone': availability_zone,
'scheduler_hints': scheduler_hints,
@ -291,7 +290,7 @@ class ShareManager(base.ManagerWithFind):
:param share: either share object or text with its ID.
"""
return self.api.client.post(
"/os-share-unmanage/%s/unmanage" % common_base.getid(share))
"/os-share-unmanage/%s/unmanage" % base.getid(share))
@api_versions.wraps("2.7") # noqa
def unmanage(self, share): # noqa
@ -310,7 +309,7 @@ class ShareManager(base.ManagerWithFind):
:param snapshot: either snapshot object or text with its ID.
"""
snapshot_id = common_base.getid(snapshot)
snapshot_id = base.getid(snapshot)
info = {'snapshot_id': snapshot_id}
return self._action('revert', share, info=info)
@ -320,7 +319,7 @@ class ShareManager(base.ManagerWithFind):
:param share: either share object or text with its ID.
:rtype: :class:`Share`
"""
share_id = common_base.getid(share)
share_id = base.getid(share)
return self._get("/shares/%s" % share_id, "share")
def update(self, share, **kwargs):
@ -333,7 +332,7 @@ class ShareManager(base.ManagerWithFind):
return
body = {'share': kwargs, }
share_id = common_base.getid(share)
share_id = base.getid(share)
return self._update("/shares/%s" % share_id, body)
@api_versions.wraps("1.0", "2.34")
@ -432,7 +431,7 @@ class ShareManager(base.ManagerWithFind):
:param share_group_id: text - ID of the share group to which the share
belongs
"""
url = "/shares/%s" % common_base.getid(share)
url = "/shares/%s" % base.getid(share)
if share_group_id:
url += "?share_group_id=%s" % share_group_id
self._delete(url)
@ -631,7 +630,7 @@ class ShareManager(base.ManagerWithFind):
:param share: either share object or text with its ID.
"""
return self._get("/shares/%s/metadata" % common_base.getid(share),
return self._get("/shares/%s/metadata" % base.getid(share),
"metadata")
def set_metadata(self, share, metadata):
@ -641,7 +640,7 @@ class ShareManager(base.ManagerWithFind):
:param metadata: A list of keys to be set.
"""
body = {'metadata': metadata}
return self._create("/shares/%s/metadata" % common_base.getid(share),
return self._create("/shares/%s/metadata" % base.getid(share),
body, "metadata")
def delete_metadata(self, share, keys):
@ -650,7 +649,7 @@ class ShareManager(base.ManagerWithFind):
:param share: either share object or text with its ID.
:param keys: A list of keys to be removed.
"""
share_id = common_base.getid(share)
share_id = base.getid(share)
for key in keys:
self._delete("/shares/%(share_id)s/metadata/%(key)s" % {
'share_id': share_id, 'key': key})
@ -662,7 +661,7 @@ class ShareManager(base.ManagerWithFind):
:param metadata: A list of keys to be updated.
"""
body = {'metadata': metadata}
return self._update("/shares/%s/metadata" % common_base.getid(share),
return self._update("/shares/%s/metadata" % base.getid(share),
body)
def _action(self, action, share, info=None, **kwargs):
@ -675,7 +674,7 @@ class ShareManager(base.ManagerWithFind):
"""
body = {action: info}
self.run_hooks('modify_body_for_action', body, **kwargs)
url = '/shares/%s/action' % common_base.getid(share)
url = '/shares/%s/action' % base.getid(share)
return self.api.client.post(url, body=body)
def _do_reset_state(self, share, state, action_name):
@ -742,7 +741,7 @@ class ShareManager(base.ManagerWithFind):
:param share: either share object or text with its ID.
"""
return self._list(
'/shares/%s/instances' % common_base.getid(share),
'/shares/%s/instances' % base.getid(share),
'share_instances',
obj_class=share_instances.ShareInstance
)