root / docs / dev-guide.rst @ 55faeced
History | View | Annotate | Download (12.2 kB)
1 |
.. _dev-guide: |
---|---|
2 |
|
3 |
Synnefo Developer's Guide |
4 |
^^^^^^^^^^^^^^^^^^^^^^^^^ |
5 |
|
6 |
This is the complete Synnefo Developer's Guide. |
7 |
|
8 |
Environment set up |
9 |
================== |
10 |
|
11 |
First of all you have to set up a developing environment for Synnefo. |
12 |
|
13 |
**1. Create a new VM** |
14 |
|
15 |
It has been tested on Debian Wheezy. It is expected to work with other |
16 |
releases (e.g., Squeeze) too, as long as they are supported by |
17 |
``snf-deploy``. |
18 |
|
19 |
**2. Build your own Synnefo installation** |
20 |
|
21 |
Follow the instructions `here <http://www.synnefo.org/docs/synnefo/latest/quick-install-guide.html>`_ |
22 |
to build Synnefo on a single node using ``snf-deploy``. |
23 |
|
24 |
**3. Install GitPython** |
25 |
|
26 |
.. code-block:: console |
27 |
|
28 |
# pip install gitpython |
29 |
|
30 |
**4. Install devflow** |
31 |
|
32 |
Devflow is a tool to manage versions, helps implement the git flow development process, |
33 |
and builds Python and Debian packages. You will need it to create your code's version. |
34 |
|
35 |
.. code-block:: console |
36 |
|
37 |
# pip install devflow |
38 |
|
39 |
**5. Get Synnefo code** |
40 |
|
41 |
First you need to install git |
42 |
|
43 |
.. code-block:: console |
44 |
|
45 |
# apt-get install git |
46 |
|
47 |
And now get the Synnefo code from the official Synnefo repository |
48 |
|
49 |
.. code-block:: console |
50 |
|
51 |
# su some_regular_user |
52 |
$ git clone https://code.grnet.gr/git/synnefo |
53 |
|
54 |
Make sure you clone the repository as a regular user. Otherwise you will |
55 |
have problems with file permissions when deploying. |
56 |
|
57 |
**6. Code and deploy** |
58 |
|
59 |
1. Configure the version |
60 |
|
61 |
.. code-block:: console |
62 |
|
63 |
$ devflow-update-version |
64 |
|
65 |
2. Code |
66 |
3. In every component you change, run as root |
67 |
|
68 |
.. code-block:: console |
69 |
|
70 |
# python setup.py develop -N |
71 |
|
72 |
This does not automatically install dependencies, in order to avoid |
73 |
confusion with synnefo packages installed by ``snf-deploy``. External |
74 |
dependencies have already been installed by ``snf-deploy``; if you introduce |
75 |
a new dependency, you will have to explicitly install it. |
76 |
|
77 |
4. You will need to restart the server with |
78 |
|
79 |
.. code-block:: console |
80 |
|
81 |
# service gunicorn restart |
82 |
|
83 |
5. If your changes affected ``snf-dispatcher`` (from package |
84 |
``snf-cyclades-app``) or ``snf-ganeti-eventd`` (from |
85 |
``snf-cyclades-gtools``) you will need to restart these daemons, too. |
86 |
Since step 3 installed the former under ``/usr/local/``, you need to |
87 |
make sure that the correct version is evoked. You can override the |
88 |
version installed by ``snf-deploy`` with |
89 |
|
90 |
.. code-block:: console |
91 |
|
92 |
# ln -sf /usr/local/bin/snf-dispatcher /usr/bin/snf-dispatcher |
93 |
|
94 |
and then restart the daemons |
95 |
|
96 |
.. code-block:: console |
97 |
|
98 |
# service snf-dispatcher restart |
99 |
# service snf-ganeti-eventd restart |
100 |
|
101 |
6. Refresh the web page and see your changes |
102 |
|
103 |
Synnefo REST APIs |
104 |
================= |
105 |
|
106 |
Here, we document all Synnefo |
107 |
REST APIs, to allow external developers write independent tools that interact |
108 |
with Synnefo. |
109 |
|
110 |
Synnefo exposes the OpenStack APIs for all its operations. Also, extensions |
111 |
have been written for advanced operations wherever needed, and minor changes |
112 |
for things that were missing or change frequently. |
113 |
|
114 |
Most Synnefo services have a corresponding OpenStack API: |
115 |
|
116 |
| Cyclades/Compute Service -> OpenStack Compute API |
117 |
| Cyclades/Network Service -> OpenStack Compute/Network API (not Quantum yet) |
118 |
| Cyclades/Image Service -> OpenStack Glance API |
119 |
| Pithos/Storage Service -> OpenStack Object Store API |
120 |
| Astakos/Identity Service -> Proprietary, moving to OpenStack Keystone API |
121 |
| Astakos/Quota Service -> Proprietary API |
122 |
| Astakos/Resource Service -> Proprietary API |
123 |
|
124 |
Below, we will describe all Synnefo APIs with conjuction to the OpenStack APIs. |
125 |
|
126 |
|
127 |
Identity Service API (Astakos) |
128 |
============================== |
129 |
|
130 |
Currently, Astakos which is the Identity Management Service of Synnefo, has a |
131 |
proprietary API, but we are moving to the OpenStack Keystone API. |
132 |
|
133 |
The current Identity Management API is: |
134 |
|
135 |
.. toctree:: |
136 |
:maxdepth: 2 |
137 |
|
138 |
Identity API <astakos-api-guide> |
139 |
|
140 |
|
141 |
Resource and Quota Service API (Astakos) |
142 |
======================================== |
143 |
|
144 |
.. toctree:: |
145 |
:maxdepth: 2 |
146 |
|
147 |
Resource and Quota API <quota-api-guide.rst> |
148 |
|
149 |
|
150 |
Compute Service API (Cyclades) |
151 |
============================== |
152 |
|
153 |
The Compute part of Cyclades exposes the OpenStack Compute API with minor |
154 |
changes wherever needed. |
155 |
|
156 |
This is the Cyclades/Compute API: |
157 |
|
158 |
.. toctree:: |
159 |
:maxdepth: 2 |
160 |
|
161 |
Compute API <cyclades-api-guide> |
162 |
|
163 |
|
164 |
Network Service API (Cyclades) |
165 |
============================== |
166 |
|
167 |
The Network Service is implemented inside Cyclades. It exposes the part of the |
168 |
OpenStack Compute API that has to do with Networks. The OpenStack Quantum API |
169 |
is not implemented yet. |
170 |
|
171 |
Please consult the :ref:`Cyclades/Network API <cyclades-api-guide>` for more |
172 |
details. |
173 |
|
174 |
|
175 |
Image Service API (Cyclades) |
176 |
============================ |
177 |
|
178 |
The Image Service is implemented inside Cyclades. It exposes the OpenStack |
179 |
Glance API with minor changes wherever needed. |
180 |
|
181 |
This is the Cyclades/Image API: |
182 |
|
183 |
.. toctree:: |
184 |
:maxdepth: 2 |
185 |
|
186 |
Image API <plankton-api-guide> |
187 |
|
188 |
|
189 |
Storage Service API (Pithos) |
190 |
============================ |
191 |
|
192 |
Pithos is the Storage Service of Synnefo and it exposes the OpenStack Object |
193 |
Storage API with extensions for advanced operations, e.g., syncing. |
194 |
|
195 |
This is the Pithos Object Storage API: |
196 |
|
197 |
.. toctree:: |
198 |
:maxdepth: 2 |
199 |
|
200 |
Object Storage API <pithos-api-guide> |
201 |
|
202 |
|
203 |
Implementing new clients |
204 |
======================== |
205 |
|
206 |
In this section we discuss implementation guidelines, that a developer should |
207 |
take into account before writing his own client for the above APIs. Before, |
208 |
starting your client implementation, make sure you have thoroughly read the |
209 |
corresponding Synnefo API. |
210 |
|
211 |
Pithos clients |
212 |
-------------- |
213 |
|
214 |
User Experience |
215 |
~~~~~~~~~~~~~~~ |
216 |
|
217 |
Hopefully this API will allow for a multitude of client implementations, each |
218 |
supporting a different device or operating system. All clients will be able to |
219 |
manipulate containers and objects - even software only designed for OOS API |
220 |
compatibility. But a Pithos interface should not be only about showing |
221 |
containers and folders. There are some extra user interface elements and |
222 |
functionalities that should be common to all implementations. |
223 |
|
224 |
Upon entrance to the service, a user is presented with the following elements - |
225 |
which can be represented as folders or with other related icons: |
226 |
|
227 |
* The ``home`` element, which is used as the default entry point to the user's |
228 |
"files". Objects under ``home`` are represented in the usual hierarchical |
229 |
organization of folders and files. |
230 |
* The ``trash`` element, which contains files that have been marked for |
231 |
deletion, but can still be recovered. |
232 |
* The ``shared`` element, which contains all objects shared by the user to |
233 |
other users of the system. |
234 |
* The ``others`` element, which contains all objects that other users share |
235 |
with the user. |
236 |
* The ``groups`` element, which contains the names of groups the user has |
237 |
defined. Each group consists of a user list. Group creation, deletion, and |
238 |
manipulation is carried out by actions originating here. |
239 |
* The ``history`` element, which allows browsing past instances of ``home`` |
240 |
and - optionally - ``trash``. |
241 |
|
242 |
Objects in Pithos can be: |
243 |
|
244 |
* Moved to trash and then deleted. |
245 |
* Shared with specific permissions. |
246 |
* Made public (shared with non-Pithos users). |
247 |
* Restored from previous versions. |
248 |
|
249 |
Some of these functions are performed by the client software and some by the |
250 |
Pithos server. |
251 |
|
252 |
In the first version of Pithos, objects could also be assigned custom tags. |
253 |
This is no longer supported. Existing deployments can migrate tags into a |
254 |
specific metadata value, i.e. ``X-Object-Meta-Tags``. |
255 |
|
256 |
Implementation Guidelines |
257 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
258 |
|
259 |
Pithos clients should use the ``pithos`` and ``trash`` containers for active |
260 |
and inactive objects respectively. If any of these containers is not found, the |
261 |
client software should create it, without interrupting the user's workflow. The |
262 |
``home`` element corresponds to ``pithos`` and the ``trash`` element to |
263 |
``trash``. Use ``PUT`` with the ``X-Move-From`` header, or ``MOVE`` to transfer |
264 |
objects from one container to the other. Use ``DELETE`` to remove from |
265 |
``pithos`` without trashing, or to remove from ``trash``. When moving objects, |
266 |
detect naming conflicts with the ``If-Match`` or ``If-None-Match`` headers. |
267 |
Such conflicts should be resolved by the user. |
268 |
|
269 |
Object names should use the ``/`` delimiter to impose a hierarchy of folders |
270 |
and files. |
271 |
|
272 |
The ``shared`` element should be implemented as a read-only view of the |
273 |
``pithos`` container, using the ``shared`` parameter when listing objects. The |
274 |
``others`` element, should start with a top-level ``GET`` to retrieve the list |
275 |
of accounts accessible to the user. It is suggested that the client software |
276 |
hides the next step of navigation - the container - if it only includes |
277 |
``pithos`` and forwards the user directly to the objects. |
278 |
|
279 |
Public objects are not included in ``shared`` and ``others`` listings. It is |
280 |
suggested that they are marked in a visually distinctive way in ``pithos`` |
281 |
listings (for example using an icon overlay). |
282 |
|
283 |
A special application menu, or a section in application preferences, should be |
284 |
devoted to managing groups (the ``groups`` element). All group-related actions |
285 |
are implemented at the account level. |
286 |
|
287 |
Browsing past versions of objects should be available both at the object and |
288 |
the container level. At the object level, a list of past versions can be |
289 |
included in the screen showing details or more information on the object |
290 |
(metadata, permissions, etc.). At the container level, it is suggested that |
291 |
clients use a ``history`` element, which presents to the user a read-only, |
292 |
time-variable view of ``pithos`` contents. This can be accomplished via the |
293 |
``until`` parameter in listings. Optionally, ``history`` may include ``trash``. |
294 |
|
295 |
Uploading and downloading data |
296 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
297 |
|
298 |
By using hashmaps to upload and download objects the corresponding operations |
299 |
can complete much faster. |
300 |
|
301 |
In the case of an upload, only the missing blocks will be submitted to the |
302 |
server: |
303 |
|
304 |
* Calculate the hash value for each block of the object to be uploaded. Use |
305 |
the hash algorithm and block size of the destination container. |
306 |
* Send a hashmap ``PUT`` request for the object. |
307 |
|
308 |
* Server responds with status ``201`` (Created): |
309 |
|
310 |
* Blocks are already on the server. The object has been created. Done. |
311 |
|
312 |
* Server responds with status ``409`` (Conflict): |
313 |
|
314 |
* Server's response body contains the hashes of the blocks that do not |
315 |
exist on the server. |
316 |
* For each hash value in the server's response (or all hashes together): |
317 |
|
318 |
* Send a ``POST`` request to the destination container with the |
319 |
corresponding data. |
320 |
|
321 |
* Repeat hashmap ``PUT``. Fail if the server's response is not ``201``. |
322 |
|
323 |
Consulting hashmaps when downloading allows for resuming partially transferred |
324 |
objects. The client should retrieve the hashmap from the server and compare it |
325 |
with the hashmap computed from the respective local file. Any missing parts can |
326 |
be downloaded with ``GET`` requests with the additional ``Range`` header. |
327 |
|
328 |
Syncing |
329 |
~~~~~~~ |
330 |
|
331 |
Consider the following algorithm for synchronizing a local folder with the |
332 |
server. The "state" is the complete object listing, with the corresponding |
333 |
attributes. |
334 |
|
335 |
.. code-block:: python |
336 |
|
337 |
# L: Local State, the last synced state of the object. |
338 |
# Stored locally (e.g. in an SQLite database) |
339 |
|
340 |
# C: Current State, the current local state of the object |
341 |
# Returned by the filesystem |
342 |
|
343 |
# S: Server State, the current server state of the object |
344 |
# Returned by the server (HTTP request) |
345 |
|
346 |
def sync(path): |
347 |
L = get_local_state(path) # Database action |
348 |
C = get_current_state(path) # Filesystem action |
349 |
S = get_server_state(path) # Network action |
350 |
|
351 |
if C == L: |
352 |
# No local changes |
353 |
if S == L: |
354 |
# No remote changes, nothing to do |
355 |
return |
356 |
else: |
357 |
# Update local state to match that of the server |
358 |
download(path) |
359 |
update_local_state(path, S) |
360 |
else: |
361 |
# Local changes exist |
362 |
if S == L: |
363 |
# No remote changes, update the server and the local state |
364 |
upload(path) |
365 |
update_local_state(path, C) |
366 |
else: |
367 |
# Both local and server changes exist |
368 |
if C == S: |
369 |
# We were lucky, both did the same |
370 |
update_local_state(path, C) |
371 |
else: |
372 |
# Conflicting changes exist |
373 |
conflict() |
374 |
|
375 |
|
376 |
Notes: |
377 |
|
378 |
* States represent file hashes (it is suggested to use Merkle). Deleted or |
379 |
non-existing files are assumed to have a magic hash (e.g. empty string). |