| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
""" |
| 14 |
Pool interface. |
| 15 |
""" |
| 16 |
|
| 17 |
|
| 18 |
from seamicroclient import base |
| 19 |
|
| 20 |
|
| 21 |
class Pool(base.Resource): |
| 22 |
HUMAN_ID = True |
| 23 |
|
| 24 |
def delete(self, **kwargs): |
| 25 |
return self.manager.delete(self, **kwargs) |
| 26 |
|
| 27 |
def mount(self, **kwargs): |
| 28 |
return self.manager.mount(self, **kwargs) |
| 29 |
|
| 30 |
|
| 31 |
class PoolManager(base.ManagerWithFind): |
| 32 |
resource_class = Pool |
| 33 |
|
| 34 |
def get(self, pool): |
| 35 |
""" |
| 36 |
Get a pool. |
| 37 |
|
| 38 |
:param pool: ID of the :class:`Pool` to get. |
| 39 |
:rtype: :class:`Pool` |
| 40 |
""" |
| 41 |
return self._get(base.getid(pool), |
| 42 |
"/storage/pools/%s" % base.getid(pool)) |
| 43 |
|
| 44 |
def list(self, filters=None): |
| 45 |
""" |
| 46 |
Get a list of pools. |
| 47 |
|
| 48 |
:rtype: list of :class:`Pool` |
| 49 |
""" |
| 50 |
return self._list("/storage/pools", filters=filters) |
| 51 |
|
| 52 |
def create(self, slot, pool_name, disks, raid_level=0, **kwargs): |
| 53 |
""" |
| 54 |
Create a pool on the given scard slot using disks of that slot. |
| 55 |
|
| 56 |
:rtype: Instance of :class:`Pool` |
| 57 |
""" |
| 58 |
disks = map(lambda x: str(x), disks) |
| 59 |
body = {'disks': ','.join(disks), 'raidLevel': raid_level} |
| 60 |
url = '/storage/pools/%s/%s' % (base.getid(slot), pool_name) |
| 61 |
return self.api.client.put(url, body=body) |
| 62 |
|
| 63 |
def delete(self, pool, **kwargs): |
| 64 |
""" |
| 65 |
Delete the specified pool. |
| 66 |
""" |
| 67 |
url = '/storage/pools/%s' % base.getid(pool) |
| 68 |
return self.api.client.delete(url) |
| 69 |
|
| 70 |
def mount(self, pool, **kwargs): |
| 71 |
""" |
| 72 |
Mount the specified Pool |
| 73 |
""" |
| 74 |
return self._action("mount", pool, **kwargs) |
| 75 |
|
| 76 |
def unmount(self, pool, **kwargs): |
| 77 |
""" |
| 78 |
UnMount the specified Pool |
| 79 |
""" |
| 80 |
return self._action("unmount", pool, **kwargs) |
| 81 |
|
| 82 |
def _action(self, action, pool, info=None, **kwargs): |
| 83 |
""" |
| 84 |
Perform a pool "action" -- . |
| 85 |
""" |
| 86 |
body = {"action": action} |
| 87 |
self.run_hooks('modify_body_for_action', body, **kwargs) |
| 88 |
url = '/storage/pools/%s' % base.getid(pool) |
| 89 |
return self.api.client.put(url, body=body) |