Skip to content

Commit dcec6bb

Browse files
giffelskwarunek
authored andcommitted
Cinder implementation (#27)
* Add Accept and Content Type headers to requests * Add cinder client implementation * Add .idea pycharm settings to .gitignore * Add documentaion for cinder client
1 parent 897a870 commit dcec6bb

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/.project
66
/.pydevproject
77
**/*.orig
8+
.idea
89

910
# Byte-compiled / optimized / DLL files
1011
__pycache__/

README.rst

+16-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Usage
2828

2929
.. code-block:: python
3030
31-
from asyncopenstackclient import NovaClient, GlanceClient, AuthPassword
31+
from asyncopenstackclient import NovaClient, GlanceClient, CinderClient, AuthPassword
3232
3333
# you can either pass credentials explicitly (as shown below)
3434
# or use enviormental variables from OpenStack RC file
@@ -42,13 +42,15 @@ Usage
4242
)
4343
nova = NovaClient(session=auth)
4444
glance = GlanceClient(session=auth)
45+
cinder = CinderClient(session=auth)
4546
4647
# api url for each service will be taken from catalog,
4748
# but you may pass `api_url` param to force custom url eg.
4849
# nova = NovaClient(session=auth, api_url='http://my-local-nova:9876/v2/')
4950
5051
await nova.init_api()
5152
await glance.init_api()
53+
await cinder.init_api()
5254
5355
5456
servers = await nova.servers.list(name='testvm')
@@ -65,6 +67,12 @@ Usage
6567
response = await nova.servers.create(server=specs)
6668
print(response)
6769
70+
volume = {"size": 200,
71+
"imageRef": "image_id",
72+
"name": "some_name"}
73+
74+
response = await cinder.volumes.create(volume=volume)
75+
print(response)
6876
6977
Available functions
7078
-------------------
@@ -85,6 +93,13 @@ Available functions
8593

8694
- images.list()
8795

96+
- Cinder (https://developer.openstack.org/api-ref/block-storage/v3/index.html)
97+
98+
- volumes.list(optional=filter) # params optional
99+
- volumes.get(id)
100+
- volumes.create(volume=volume_spec)
101+
- volumes.force_delete(id)
102+
88103

89104
License
90105
=======

src/asyncopenstackclient/cinder.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from .client import Client
2+
3+
4+
class CinderClient(Client):
5+
def __init__(self, session=None, api_url=None):
6+
super().__init__('cinder', ['volumes'], session, api_url)
7+
8+
async def init_api(self, timeout=60):
9+
await super().init_api(timeout)
10+
self.api.volumes.actions["force_delete"] = {"method": "DELETE", "url": "volumes/{}"}
11+
self.api.volumes.actions["get"] = {"method": "GET", "url": "volumes/{}"}
12+
self.api.volumes.actions["list"] = {"method": "GET", "url": "volumes/detail"}
13+
self.api.volumes.add_action("force_delete")
14+
self.api.volumes.add_action("get")

src/asyncopenstackclient/client.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ async def init_api(self, timeout=60):
2222
await self.get_credentials()
2323
self.api = API(
2424
api_root_url=self.api_url,
25-
headers={'X-Auth-Token': self.session.token},
25+
headers={'X-Auth-Token': self.session.token,
26+
'Accept': 'application/json',
27+
'Content-Type': 'application/json'
28+
},
2629
json_encode_body=True,
2730
timeout=timeout
2831
)

tests/test_client.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ async def test_init_api(self):
7575

7676
mock_api().assert_called_once_with(
7777
api_root_url='mock_url/',
78-
headers={'X-Auth-Token': 'mock_token'},
78+
headers={'X-Auth-Token': 'mock_token',
79+
'Accept': 'application/json',
80+
'Content-Type': 'application/json'
81+
},
7982
json_encode_body=True,
8083
timeout=client_timeout
8184
)

0 commit comments

Comments
 (0)