Statistics
| Branch: | Tag: | Revision:

root / astakosclient / docs / index.rst @ da9bcceb

History | View | Annotate | Download (10.1 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
    **get_pending_commissions()**
157
        It returns the pending commissions (list of integers). In case of
158
        error it raises an AstakosClientException exception.
159

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

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

    
170
    **accept_commission(**\ serial\ **)**
171
        Accept a pending commission (see commission_action).
172

    
173
    **reject_commission(**\ serial\ **)**
174
        Reject a pending commission (see commission_action).
175

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

    
182
    **get_projects(**\ name=None, state=None, owner=None\ **)**
183
        Retrieve all accessible projects
184

    
185
    **get_project(**\ project_id\ **)**
186
        Retrieve project description, if accessible
187

    
188
    **create_project(**\ specs\ **)**
189
        Submit application to create a new project
190

    
191
    **modify_project(**\ project_id, specs\ **)**
192
        Submit application to modify an existing project
193

    
194
    **project_action(**\ project_id, action, reason=""\ **)**
195
        Perform action on a project
196

    
197
    **get_applications(**\ project=None\ **)**
198
        Retrieve all accessible applications
199

    
200
    **get_application(**\ app_id\ **)**
201
        Retrieve application description, if accessible
202

    
203
    **application_action(**\ app_id, action, reason=""\ **)**
204
        Perform action on an application
205

    
206
    **get_memberships(**\ project=None\ **)**
207
        Retrieve all accessible memberships
208

    
209
    **get_membership(**\ memb_id\ **)**
210
        Retrieve membership description, if accessible
211

    
212
    **membership_action(**\ memb_id, action, reason=""\ **)**
213
        Perform action on a membership
214

    
215
    **join_project(**\ project_id\ **)**
216
        Join a project
217

    
218
    **enroll_member(**\ project_id, email\ **)**
219
        Enroll a user in a project
220

    
221
Public Functions
222
----------------
223

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

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

    
233

    
234
Exceptions and Errors
235
=====================
236

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

    
242
*exception* **BadValue**
243
    A redefinition of ValueError exception under AstakosClientException.
244

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

    
249
*exception* **BadRequest**
250
    Raised in case of a Bad Request, with status 400.
251

    
252
*exception* **Unauthorized**
253
    Raised in case of Invalid token (unauthorized access), with status 401.
254

    
255
*exception* **Forbidden**
256
    The server understood the request, but is refusing to fulfill it. Status
257
    401.
258

    
259
*exception* **NotFound**
260
    The server has not found anything matching the Request-URI. Status 404.
261

    
262
*exception* **QuotaLimit**
263
    Quantity fell below zero or exceeded capacity in one of the holdings.
264

    
265
*exception* **NoUserName**
266
    Raised by getDisplayName and getServiceDisplayName when an invalid UUID was
267
    given.
268

    
269
*exception* **NoUUID**
270
    Raised by *getUUID* and *getServiceUUID* when an invalid username was
271
    given.
272

    
273
*exception* **NoEndpoints**
274
    Raised by *parse_endpoints* when no endpoints found matching the given
275
    criteria.