Statistics
| Branch: | Tag: | Revision:

root / astakosclient / docs / index.rst @ 4334d1c8

History | View | Annotate | Download (10.5 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
    **service_get_project_quotas(**\ project=None\ **)**
143
        It returns all projects' current quotas for the resources
144
        associated with the service (as dict of dicts).
145
        Optionally, one can query the quotas of a specific project with
146
        argument project=UUID. In case of error it raises an
147
        AstakosClientException exception.
148

    
149
    **issue_commission_generic(**\ user_provisions, project_provisions, name="", force=False, auto_accept=False\ **)**
150
        Issue a commission. User provisions are specified as a dict from
151
        (user, project, resource) to int; project provisions as a dict from
152
        (project, resource) to int.
153
        In case of success return commission's id (int).
154
        Otherwise raise an AstakosClientException exception.
155

    
156
    **issue_one_commission(**\ holder, source, provisions, name="", force=False, auto_accept=False\ **)**
157
        Issue a commission. We have to specify the holder, the source and the
158
        provisions (a dict from string to int) and astakosclient will create
159
        the corresponding commission. In case of success it returns
160
        commission's id (int). Otherwise it raises an AstakosClientException
161
        exception.
162

    
163
    **issue_resource_reassignment(**\ holder, from_source, to_source, provisions, name="", force=False, auto_accept=False\ **)**
164
        Change resource assignment to another project
165

    
166
    **get_pending_commissions()**
167
        It returns the pending commissions (list of integers). In case of
168
        error it raises an AstakosClientException exception.
169

    
170
    **get_commission_info(**\ serial\ **)**
171
        Given the id of a pending commission return a dict of dicts containting
172
        informations (details) about the requested commission.  In case of
173
        error it raises an AstakosClientException exception.
174

    
175
    **commission_action(**\ serial, action\ **)**
176
        Given the id of a pending commission, request the specified action
177
        (currently one of accept, reject).  In case of success it returns
178
        nothing.  Otherwise it raises an AstakosClientException exception.
179

    
180
    **accept_commission(**\ serial\ **)**
181
        Accept a pending commission (see commission_action).
182

    
183
    **reject_commission(**\ serial\ **)**
184
        Reject a pending commission (see commission_action).
185

    
186
    **resolve_commissions(**\ accept_serials, reject_serials\ **)**
187
        Accept or Reject many pending commissions at once.  In case of success
188
        return a dict of dicts describing which commissions accepted, which
189
        rejected and which failed to resolved. Otherwise raise an
190
        AstakosClientException exception.
191

    
192
    **get_projects(**\ name=None, state=None, owner=None\ **)**
193
        Retrieve all accessible projects
194

    
195
    **get_project(**\ project_id\ **)**
196
        Retrieve project description, if accessible
197

    
198
    **create_project(**\ specs\ **)**
199
        Submit application to create a new project
200

    
201
    **modify_project(**\ project_id, specs\ **)**
202
        Submit application to modify an existing project
203

    
204
    **project_action(**\ project_id, action, reason=""\ **)**
205
        Perform action on a project
206

    
207
    **application_action(**\ project_id, app_id, action, reason=""\ **)**
208
        Perform action on a project application
209

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

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

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

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

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

    
225
Public Functions
226
----------------
227

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

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

    
237

    
238
Exceptions and Errors
239
=====================
240

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

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

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

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

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

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

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

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

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

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

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