Statistics
| Branch: | Tag: | Revision:

root / astakosclient / docs / index.rst @ 1f4a46dd

History | View | Annotate | Download (10.3 kB)

1
.. _astakosclient:
2

    
3
Component astakosclient
4
^^^^^^^^^^^^^^^^^^^^^^^
5

    
6
The Synnefo component astakosclient_ defines a
7
default client for the `Astakos <astakos>`_ service. It is designed to be
8
simple and minimal, hence easy to debug and test.
9

    
10
It uses the user's authentication token to query Astakos for:
11

    
12
    * User's info
13
    * Usernames for given UUIDs
14
    * UUIDs for given usernames
15
    * User's quotas
16

    
17
It can also query Astakos with another service's (Cyclades or Pithos)
18
authentication token for:
19

    
20
    * Usernames for given UUIDs
21
    * UUIDs for given usernames
22
    * Quotas for all related resources
23
    * Issue commissions
24
    * Get pending commissions
25
    * Accept or reject commissions
26

    
27
Additionally, there are options for using the `objpool
28
<https://github.com/grnet/objpool>`_ library to pool the http connections.
29

    
30

    
31
Basic example
32
=============
33

    
34
The ``astakosclient`` module provides the ``AstakosClient`` class. This section
35
demonstrates how to get user's info using ``astakosclient``.
36

    
37
.. code-block:: python
38

    
39
    from astakosclient import AstakosClient
40

    
41
    client = AstakosClient("UQpYas7ElzWGD5yCcEXtjw",
42
                           "https://accounts.example.com")
43
    user_info = client.authenticate()
44
    print user_info['access']['user']['id']
45

    
46
Another example where we ask for the username of a user with UUID:
47
``b3de8eb0-3958-477e-als9-789af8dd352c``
48

    
49
.. code-block:: python
50

    
51
    from astakosclient import AstakosClient
52

    
53
    client = AstakosClient("UQpYas7ElzWGD5yCcEXtjw",
54
                           "https://accounts.example.com")
55
    username = client.get_username("b3de8eb0-3958-477e-als9-789af8dd352c")
56
    print username
57

    
58

    
59
Classes and functions
60
=====================
61

    
62
This section describes in depth the API of ``astakosclient``.
63

    
64
Astakos Client
65
--------------
66

    
67
*class* astakosclient.\ **AstakosClient(**\ token, auth_url,
68
retry=0, use_pool=False, pool_size=8, logger=None\ **)**
69

    
70
    Initialize an instance of **AstakosClient** given the Authentication Url
71
    *auth_url* and the Token *token*.
72
    Optionally one can specify if we are going to use a pool, the pool_size
73
    and the number of retries if the connection fails.
74

    
75
    This class provides the following methods:
76

    
77
    **authenticate(**\ tenant_name=None\ **)**
78
        It authenticates the user and returns information about the user,
79
        their token as well as the service endpoints one can access. In
80
        case of error, it raises an AstakosClientException exception.
81

    
82
    **get_usernames(**\ uuids\ **)**
83
        Given a list of UUIDs it returns a uuid_catalog, that is a dictionary
84
        with the given UUIDs as keys and the corresponding user names as
85
        values.  Invalid UUIDs will not be in the dictionary.  In case of
86
        error, it raises an AstakosClientException exception.
87

    
88
    **get_username(**\ uuid\ **)**
89
        Given a UUID (as string) it returns the corresponding user name (as
90
        string).  In case of invalid UUID it raises NoUserName exception.  In
91
        case of error, it raises an AstakosClientException exception.
92

    
93
    **service_get_usernames(**\ uuids\ **)**
94
        Same as get_usernames but used with service tokens.
95

    
96
    **service_get_username(**\ uuid\ **)**
97
        Same as get_username but used with service tokens.
98

    
99
    **get_uuids(**\ display_names\ **)**
100
        Given a list of usernames it returns a displayname_catalog, that is a
101
        dictionary with the given usernames as keys and the corresponding UUIDs
102
        as values.  Invalid usernames will not be in the dictionary.  In case
103
        of error, it raises an AstakosClientException exception.
104

    
105
    **get_uuid(**\ display_name\ **)**
106
        Given a username (as string) it returns the corresponding UUID (as
107
        string).  In case of invalid user name it raises NoUUID exception.  In
108
        case of error, it raises an AstakosClientException exception.
109

    
110
    **service_get_uuids(**\ uuids\ **)**
111
        Same as get_uuids but used with service tokens.
112

    
113
    **service_get_uuid(**\ uuid\ **)**
114
        Same as get_uuid but used with service tokens.
115

    
116
    **get_services()**
117
        Return a list of dicts with the registered services.
118

    
119
    **get_resources()**
120
        Return a list of dicts with the available resources
121

    
122
    **send_feedback(**\ message, data\ **)**
123
        Send some feedback to astakos service. Additional information about the
124
        service client status can be given in the data variable.  In case of
125
        success it returns nothing.  Otherwise it raises an
126
        AstakosClientException exception.
127

    
128
    **get_endpoints()**
129
        It returns the services URLs one can access. In case of error it
130
        raises an AstakosClientException exception.
131

    
132
    **get_quotas()**
133
        It returns user's current quotas (as dict of dicts). In case of error
134
        it raises an AstakosClientException exception.
135

    
136
    **service_get_quotas(**\ user=None\ **)**
137
        It returns all users' current quotas for the resources associated with
138
        the service (as dict of dicts of dicts). Optionally, one can query the
139
        quotas of a specific user with argument user=UUID. In case of error it
140
        raises an AstakosClientException exception.
141

    
142
    **issue_commission_generic(**\ user_provisions, project_provisions, name="", force=False, auto_accept=False\ **)**
143
        Issue a commission. User provisions are specified as a dict from
144
        (user, project, resource) to int; project provisions as a dict from
145
        (project, resource) to int.
146
        In case of success return commission's id (int).
147
        Otherwise raise an AstakosClientException exception.
148

    
149
    **issue_one_commission(**\ holder, source, provisions, name="", force=False, auto_accept=False\ **)**
150
        Issue a commission. We have to specify the holder, the source and the
151
        provisions (a dict from string to int) and astakosclient will create
152
        the corresponding commission. In case of success it returns
153
        commission's id (int). Otherwise it raises an AstakosClientException
154
        exception.
155

    
156
    **issue_resource_reassignment(**\ holder, from_source, to_source, provisions, name="", force=False, auto_accept=False\ **)**
157
        Change resource assignment to another project
158

    
159
    **get_pending_commissions()**
160
        It returns the pending commissions (list of integers). In case of
161
        error it raises an AstakosClientException exception.
162

    
163
    **get_commission_info(**\ serial\ **)**
164
        Given the id of a pending commission return a dict of dicts containting
165
        informations (details) about the requested commission.  In case of
166
        error it raises an AstakosClientException exception.
167

    
168
    **commission_action(**\ serial, action\ **)**
169
        Given the id of a pending commission, request the specified action
170
        (currently one of accept, reject).  In case of success it returns
171
        nothing.  Otherwise it raises an AstakosClientException exception.
172

    
173
    **accept_commission(**\ serial\ **)**
174
        Accept a pending commission (see commission_action).
175

    
176
    **reject_commission(**\ serial\ **)**
177
        Reject a pending commission (see commission_action).
178

    
179
    **resolve_commissions(**\ accept_serials, reject_serials\ **)**
180
        Accept or Reject many pending commissions at once.  In case of success
181
        return a dict of dicts describing which commissions accepted, which
182
        rejected and which failed to resolved. Otherwise raise an
183
        AstakosClientException exception.
184

    
185
    **get_projects(**\ name=None, state=None, owner=None\ **)**
186
        Retrieve all accessible projects
187

    
188
    **get_project(**\ project_id\ **)**
189
        Retrieve project description, if accessible
190

    
191
    **create_project(**\ specs\ **)**
192
        Submit application to create a new project
193

    
194
    **modify_project(**\ project_id, specs\ **)**
195
        Submit application to modify an existing project
196

    
197
    **project_action(**\ project_id, action, reason=""\ **)**
198
        Perform action on a project
199

    
200
    **get_applications(**\ project=None\ **)**
201
        Retrieve all accessible applications
202

    
203
    **get_application(**\ app_id\ **)**
204
        Retrieve application description, if accessible
205

    
206
    **application_action(**\ app_id, action, reason=""\ **)**
207
        Perform action on an application
208

    
209
    **get_memberships(**\ project=None\ **)**
210
        Retrieve all accessible memberships
211

    
212
    **get_membership(**\ memb_id\ **)**
213
        Retrieve membership description, if accessible
214

    
215
    **membership_action(**\ memb_id, action, reason=""\ **)**
216
        Perform action on a membership
217

    
218
    **join_project(**\ project_id\ **)**
219
        Join a project
220

    
221
    **enroll_member(**\ project_id, email\ **)**
222
        Enroll a user in a project
223

    
224
Public Functions
225
----------------
226

    
227
**get_token_from_cookie(**\ request, cookie_name\ **)**
228
    Given a Django request object and an Astakos cookie name
229
    extract the user's token from it.
230

    
231
**parse_endpoints(**\ endpoints, ep_name=None, ep_type=None, ep_region=None, ep_version_id=None\ **)**
232
    Parse the endpoints (acquired using *get_endpoints*) and extract the ones
233
    needed.  Return only the endpoints that match all of the given criterias.
234
    If no match is found then raise NoEndpoints exception.
235

    
236

    
237
Exceptions and Errors
238
=====================
239

    
240
*exception* **AstakosClientException**
241
    Raised in case of an error. It contains an error message and the
242
    corresponding http status code. Other exceptions raised by astakosclient
243
    module are derived from this one.
244

    
245
*exception* **BadValue**
246
    A redefinition of ValueError exception under AstakosClientException.
247

    
248
*exception* **InvalidResponse**
249
    This exception is raised whenever the server's response is not valid json
250
    (cannot be parsed by simplejson library).
251

    
252
*exception* **BadRequest**
253
    Raised in case of a Bad Request, with status 400.
254

    
255
*exception* **Unauthorized**
256
    Raised in case of Invalid token (unauthorized access), with status 401.
257

    
258
*exception* **Forbidden**
259
    The server understood the request, but is refusing to fulfill it. Status
260
    401.
261

    
262
*exception* **NotFound**
263
    The server has not found anything matching the Request-URI. Status 404.
264

    
265
*exception* **QuotaLimit**
266
    Quantity fell below zero or exceeded capacity in one of the holdings.
267

    
268
*exception* **NoUserName**
269
    Raised by getDisplayName and getServiceDisplayName when an invalid UUID was
270
    given.
271

    
272
*exception* **NoUUID**
273
    Raised by *getUUID* and *getServiceUUID* when an invalid username was
274
    given.
275

    
276
*exception* **NoEndpoints**
277
    Raised by *parse_endpoints* when no endpoints found matching the given
278
    criteria.