snf-astakos.py 24.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
#   1. Redistributions of source code must retain the above
#      copyright notice, this list of conditions and the following
#      disclaimer.
#
#   2. Redistributions in binary form must reproduce the above
#      copyright notice, this list of conditions and the following
#      disclaimer in the documentation and/or other materials
#      provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.command

34
35
36
from json import loads, load
from sys import stdin
from os.path import abspath
37

38
from astakosclient import AstakosClient, AstakosClientException
39
40

from kamaki.cli import command
41
from kamaki.cli.errors import CLIBaseUrlError
42
43
from kamaki.cli.commands import (
    _command_init, errors, _optional_json, addLogSettings)
44
from kamaki.cli.command_tree import CommandTree
45
from kamaki.cli.utils import print_dict, format_size
46
from kamaki.cli.argument import FlagArgument, ValueArgument
47
from kamaki.cli.argument import CommaSeparatedListArgument
48
from kamaki.cli.logger import get_logger
49
50

snfastakos_cmds = CommandTree('astakos', 'astakosclient CLI')
51
52
snfproject_cmds = CommandTree('project', 'Synnefo project management CLI')
_commands = [snfastakos_cmds, snfproject_cmds]
53
54


55
56
57
58
59
60
61
62
63
64
65
66
67
68
def astakoserror(foo):
    def _raise(self, *args, **kwargs):
        try:
            return foo(self, *args, **kwargs)
        except AstakosClientException as ace:
            try:
                ace.details = ['%s' % ace.details]
            except Exception:
                pass
            finally:
                raise ace
    return _raise


69
70
class _astakos_init(_command_init):

71
72
    def __init__(self, arguments=dict(), auth_base=None, cloud=None):
        super(_astakos_init, self).__init__(arguments, auth_base, cloud)
73
74
        self['token'] = ValueArgument('Custom token', '--token')

75
    @errors.generic.all
76
    @astakoserror
77
    @addLogSettings
78
    def _run(self):
79
80
        self.cloud = self.cloud if self.cloud else 'default'
        self.token = self['token'] or self._custom_token('astakos')\
81
            or self.config.get_cloud(self.cloud, 'token')
82
83
        if getattr(self, 'auth_base', False):
            astakos_endpoints = self.auth_base.get_service_endpoints(
84
85
                self._custom_type('astakos') or 'identity',
                self._custom_version('astakos') or '')
86
            base_url = astakos_endpoints['SNF:uiURL']
87
88
            base_url = base_url[:-3]
            #base_url = ''.join(base_url.split('/ui'))
89
        else:
90
            base_url = self._custom_url('astakos')
91
92
        if not base_url:
            raise CLIBaseUrlError(service='astakos')
93
94
        self.client = AstakosClient(
            base_url, logger=get_logger('kamaki.clients'))
95
96
97
98
99
100

    def main(self):
        self._run()


@command(snfastakos_cmds)
101
class astakos_user_info(_astakos_init, _optional_json):
102
103
104
    """Authenticate a user
    Get user information (e.g. unique account name) from token
    Token should be set in settings:
105
106
    *  check if a token is set    /config get cloud.default.token
    *  permanently set a token    /config set cloud.default.token <token>
107
    Token can also be provided as a parameter
108
    (To use a named cloud, use its name instead of "default")
109
110
111
112
113
114
    """

    arguments = dict(
        usage=FlagArgument('also return usage information', ('--with-usage'))
    )

115
116
    @errors.generic.all
    @astakoserror
117
    def _run(self):
118
        self._print(
119
            self.client.get_user_info(self.token, self['usage']), print_dict)
120

121
122
123
124
125
126
    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfastakos_cmds)
127
class astakos_user_name(_astakos_init, _optional_json):
128
129
130
131
132
133
134
    """Get username(s) from uuid(s)"""

    arguments = dict(
        service_token=ValueArgument(
            'Use service token instead', '--service-token')
    )

135
136
    @errors.generic.all
    @astakoserror
137
138
139
140
141
142
    def _run(self, uuids):
        assert uuids and isinstance(uuids, list), 'No valid uuids'
        if 1 == len(uuids):
            self._print(self.client.get_username(self.token, uuids[0]))
        else:
            self._print(
143
                self.client.get_usernames(self.token, uuids), print_dict)
144
145
146
147
148
149
150

    def main(self, uuid, *more_uuids):
        super(self.__class__, self)._run()
        self._run([uuid] + list(more_uuids))


@command(snfastakos_cmds)
151
class astakos_user_uuid(_astakos_init, _optional_json):
152
153
    """Get uuid(s) from username(s)"""

154
155
    @errors.generic.all
    @astakoserror
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    def _run(self, usernames):
        assert usernames and isinstance(usernames, list), 'No valid usernames'
        if 1 == len(usernames):
            self._print(self.client.get_uuid(self.token, usernames[0]))
        else:
            self._print(
                self.client.get_uuids(self.token, usernames), print_dict)

    def main(self, usernames, *more_usernames):
        super(self.__class__, self)._run()
        self._run([usernames] + list(more_usernames))


@command(snfastakos_cmds)
class astakos_quotas(_astakos_init, _optional_json):
    """Get user (or service) quotas"""

173
174
175
176
177
178
179
180
181
182
183
184
185
    @staticmethod
    def _print_with_format(d):
        """ Print d with size formating when needed
        :param d: (dict) {system: {<service>: {usage: ..., limit: ..., }, ...}}
        """
        newd = dict()
        for k, service in d['system'].items():
            newd[k] = dict(service)
            for term in ('usage', 'limit'):
                if term in service:
                    newd[k][term] = format_size(service[term])
        print_dict(newd)

186
187
    @errors.generic.all
    @astakoserror
188
    def _run(self):
189
190
            self._print(
                self.client.get_quotas(self.token), self._print_with_format)
191
192
193
194
195
196
197
198
199
200
201
202

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfastakos_cmds)
class astakos_services(_astakos_init):
    """Astakos operations filtered by services"""


@command(snfastakos_cmds)
203
class astakos_services_list(_astakos_init, _optional_json):
204
205
    """List available services"""

206
207
    @errors.generic.all
    @astakoserror
208
209
210
211
212
213
214
215
216
217
218
219
    def _run(self):
        self._print(self.client.get_services())

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfastakos_cmds)
class astakos_services_username(_astakos_init, _optional_json):
    """Get service username(s) from uuid(s)"""

220
221
    @errors.generic.all
    @astakoserror
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
    def _run(self, stoken, uuids):
        assert uuids and isinstance(uuids, list), 'No valid uuids'
        if 1 == len(uuids):
            self._print(self.client.service_get_username(stoken, uuids[0]))
        else:
            self._print(
                self.client.service_get_usernames(stoken, uuids), print_dict)

    def main(self, service_token, uuid, *more_uuids):
        super(self.__class__, self)._run()
        self._run(service_token, [uuid] + list(more_uuids))


@command(snfastakos_cmds)
class astakos_services_uuid(_astakos_init, _optional_json):
    """Get service uuid(s) from username(s)"""

239
240
    @errors.generic.all
    @astakoserror
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
    def _run(self, stoken, usernames):
        assert usernames and isinstance(usernames, list), 'No valid usernames'
        if 1 == len(usernames):
            self._print(self.client.service_get_uuid(self.token, usernames[0]))
        else:
            self._print(
                self.client.service_get_uuids(self.token, usernames),
                print_dict)

    def main(self, service_token, usernames, *more_usernames):
        super(self.__class__, self)._run()
        self._run(service_token, [usernames] + list(more_usernames))


@command(snfastakos_cmds)
class astakos_services_quotas(_astakos_init, _optional_json):
    """Get user (or service) quotas"""

    arguments = dict(
        uuid=ValueArgument('A user unique id to get quotas for', '--uuid')
    )

263
264
    @errors.generic.all
    @astakoserror
265
266
267
268
    def _run(self, stoken):
        self._print(self.client.service_get_quotas(stoken, self['uuid']))

    def main(self, service_token):
269
        super(self.__class__, self)._run()
270
        self._run(service_token)
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293


@command(snfastakos_cmds)
class astakos_resources(_astakos_init, _optional_json):
    """List user resources"""

    @errors.generic.all
    @astakoserror
    def _run(self):
        self._print(self.client.get_resources(), print_dict)

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfastakos_cmds)
class astakos_feedback(_astakos_init):
    """Send feedback to astakos server"""

    @errors.generic.all
    @astakoserror
    def _run(self, msg, more_info=None):
294
        self.client.send_feedback(self.token, msg, more_info or '')
295
296
297
298
299
300
301
302
303
304

    def main(self, message, more_info=None):
        super(self.__class__, self)._run()
        self._run(message, more_info)


@command(snfastakos_cmds)
class astakos_endpoints(_astakos_init, _optional_json):
    """Get endpoints service endpoints"""

305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
    arguments = dict(uuid=ValueArgument('User uuid', '--uuid'))

    @errors.generic.all
    @astakoserror
    def _run(self):
        self._print(
            self.client.get_endpoints(self.token, self['uuid']),
            print_dict)

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfastakos_cmds)
class astakos_commission(_astakos_init):
    """Manage commissions (special privileges required)"""


@command(snfastakos_cmds)
class astakos_commission_pending(_astakos_init, _optional_json):
    """List pending commissions (special privileges required)"""

    @errors.generic.all
    @astakoserror
    def _run(self):
        self._print(self.client.get_pending_commissions(self.token))

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfastakos_cmds)
class astakos_commission_info(_astakos_init, _optional_json):
    """Get commission info (special privileges required)"""

    @errors.generic.all
    @astakoserror
    def _run(self, commission_id):
        commission_id = int(commission_id)
        self._print(
            self.client.get_commission_info(self.token, commission_id),
            print_dict)

    def main(self, commission_id):
        super(self.__class__, self)._run()
        self._run(commission_id)


@command(snfastakos_cmds)
class astakos_commission_action(_astakos_init, _optional_json):
    """Invoke an action in a commission (special privileges required)
    Actions can be accept or reject
    """

    actions = ('accept', 'reject')

    @errors.generic.all
    @astakoserror
    def _run(self, commission_id, action):
        commission_id = int(commission_id)
        action = action.lower()
        assert action in self.actions, 'Actions can be %s' % (
            ' or '.join(self.actions))
        self._print(
            self.client.commission_acction(self.token, commission_id, action),
            print_dict)

    def main(self, commission_id, action):
        super(self.__class__, self)._run()
        self._run(commission_id, action)


@command(snfastakos_cmds)
class astakos_commission_accept(_astakos_init):
    """Accept a pending commission  (special privileges required)"""

    @errors.generic.all
    @astakoserror
    def _run(self, commission_id):
        commission_id = int(commission_id)
        self.client.accept_commission(self.token, commission_id)

    def main(self, commission_id):
        super(self.__class__, self)._run()
        self._run(commission_id)


@command(snfastakos_cmds)
class astakos_commission_reject(_astakos_init):
    """Reject a pending commission  (special privileges required)"""

    @errors.generic.all
    @astakoserror
    def _run(self, commission_id):
        commission_id = int(commission_id)
        self.client.reject_commission(self.token, commission_id)

    def main(self, commission_id):
        super(self.__class__, self)._run()
        self._run(commission_id)


@command(snfastakos_cmds)
class astakos_commission_resolve(_astakos_init, _optional_json):
    """Resolve multiple commissions  (special privileges required)"""

413
    arguments = dict(
414
415
416
417
418
419
        accept=CommaSeparatedListArgument(
            'commission ids to accept (e.g. --accept=11,12,13,...',
            '--accept'),
        reject=CommaSeparatedListArgument(
            'commission ids to reject (e.g. --reject=11,12,13,...',
            '--reject'),
420
421
422
423
424
    )

    @errors.generic.all
    @astakoserror
    def _run(self):
425
426
        print 'accepted ', self['accept']
        print 'rejected ', self['reject']
427
        self._print(
428
429
            self.client.resolve_commissions(
                self.token, self['accept'], self['reject']),
430
431
432
433
434
435
            print_dict)

    def main(self):
        super(self.__class__, self)._run()
        self._run()

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478

@command(snfastakos_cmds)
class astakos_commission_issue(_astakos_init, _optional_json):
    """Issue commissions as a json string (special privileges required)
    Parameters:
    holder      -- user's id (string)
    source      -- commission's source (ex system) (string)
    provisions  -- resources with their quantity (json-dict from string to int)
    name        -- description of the commission (string)
    """

    arguments = dict(
        force=FlagArgument('Force commission', '--force'),
        accept=FlagArgument('Do not wait for verification', '--accept')
    )

    @errors.generic.all
    @astakoserror
    def _run(
            self, holder, source, provisions, name=''):
        provisions = loads(provisions)
        self._print(self.client.issue_one_commission(
            self.token, holder, source, provisions, name,
            self['force'], self['accept']))

    def main(self, holder, source, provisions, name=''):
        super(self.__class__, self)._run()
        self._run(holder, source, provisions, name)


@command(snfastakos_cmds)
class astakos_commission_issuejson(_astakos_init, _optional_json):
    """Issue commissions as a json string (special privileges required)"""

    @errors.generic.all
    @astakoserror
    def _run(self, info_json):
        infodict = loads(info_json)
        self._print(self.client.issue_commission(self.token, infodict))

    def main(self, info_json):
        super(self.__class__, self)._run()
        self._run(info_json)
479
480
481

# XXX issue_commission, issue_one_commission

482

483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# Project commands


_project_specs = """
    {
        "name": name,
        "owner": uuid,
        "homepage": homepage,         # optional
        "description": description,   # optional
        "comments": comments,         # optional
        "start_date": date,           # optional
        "end_date": date,
        "join_policy": "auto" | "moderated" | "closed",  # default: "moderated"
        "leave_policy": "auto" | "moderated" | "closed", # default: "auto"
        "resources": {
            "cyclades.vm": {
                "project_capacity": int or null,
                 "member_capacity": int
            }
        }
  }
  """


def apply_notification(foo):
    def wrap(self, *args, **kwargs):
        r = foo(self, *args, **kwargs)
        print 'Application is submitted successfully'
        return r
    return wrap


@command(snfproject_cmds)
class project_list(_astakos_init, _optional_json):
    """List all projects"""

    arguments = dict(
        name=ValueArgument('Filter by name', ('--with-name', )),
        state=ValueArgument('Filter by state', ('--with-state', )),
        owner=ValueArgument('Filter by owner', ('--with-owner', ))
    )

    @errors.generic.all
    @astakoserror
    def _run(self):
        self._print(self.client.get_projects(
            self.token, self['name'], self['state'], self['owner']))

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfproject_cmds)
class project_info(_astakos_init, _optional_json):
    """Get details for a project"""

    @errors.generic.all
    @astakoserror
    def _run(self, project_id):
        self._print(
Giorgos Korfiatis's avatar
Giorgos Korfiatis committed
544
            self.client.get_project(self.token, project_id), print_dict)
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741

    def main(self, project_id):
        super(self.__class__, self)._run()
        self._run(project_id)


@command(snfproject_cmds)
class project_create(_astakos_init, _optional_json):
    """Apply for a new project (input a json-dict)
    Project details must be provided as a json-formated dict from the standard
    input, or through a file
    """

    __doc__ += _project_specs

    arguments = dict(
        specs_path=ValueArgument(
            'Specification file path (content must be in json)', '--spec-file')
    )

    @errors.generic.all
    @astakoserror
    @apply_notification
    def _run(self):
        input_stream = open(abspath(self['specs_path'])) if (
            self['specs_path']) else stdin
        specs = load(input_stream)
        self._print(self.client.create_project(self.token, specs), print_dict)

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfproject_cmds)
class project_modify(_astakos_init, _optional_json):
    """Modify a project (input a json-dict)
    Project details must be provided as a json-formated dict from the standard
    input, or through a file
    """

    __doc__ += _project_specs

    arguments = dict(
        specs_path=ValueArgument(
            'Specification file path (content must be in json)', '--spec-file')
    )

    @errors.generic.all
    @astakoserror
    @apply_notification
    def _run(self, project_id):
        input_stream = open(abspath(self['specs_path'])) if (
            self['specs_path']) else stdin
        specs = load(input_stream)
        self._print(
            self.client.modify_project(self.token, project_id, specs),
            print_dict)

    def main(self, project_id):
        super(self.__class__, self)._run()
        self._run(project_id)


class _project_action(_astakos_init):

    action = ''

    @errors.generic.all
    @astakoserror
    @apply_notification
    def _run(self, project_id, quote_a_reason):
        self.client.project_action(
            self.token, project_id, self.action, quote_a_reason)

    def main(self, project_id, quote_a_reason=''):
        super(_project_action, self)._run()
        self._run(project_id, quote_a_reason)


@command(snfproject_cmds)
class project_suspend(_project_action):
    """Apply for a project suspension"""
    action = 'suspend'


@command(snfproject_cmds)
class project_unsuspend(_project_action):
    """Apply for a project un-suspension"""
    action = 'unsuspend'


@command(snfproject_cmds)
class project_terminate(_project_action):
    """Apply for a project termination"""
    action = 'terminate'


@command(snfproject_cmds)
class project_reinstate(_project_action):
    """Apply for a project reinstatement"""
    action = 'reinstate'


@command(snfproject_cmds)
class project_application(_project_action):
    """Application management commands"""


@command(snfproject_cmds)
class project_application_list(_astakos_init, _optional_json):
    """List all applications (old and new)"""

    arguments = dict(
        project=ValueArgument('Filter by project id', '--with-project-id')
    )

    @errors.generic.all
    @astakoserror
    def _run(self):
        self._print(self.client.get_applications(self.token, self['project']))

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfproject_cmds)
class project_application_info(_astakos_init, _optional_json):
    """Get details on an application"""

    @errors.generic.all
    @astakoserror
    def _run(self, app_id):
        self._print(
            self.client.get_application(self.token, app_id), print_dict)

    def main(self, application_id):
        super(self.__class__, self)._run()
        self._run(application_id)


class _application_action(_astakos_init):

    action = ''

    @errors.generic.all
    @astakoserror
    def _run(self, app_id, quote_a_reason):
        self.client.application_action(
            self.token, app_id, self.action, quote_a_reason)

    def main(self, application_id, quote_a_reason=''):
        super(_application_action, self)._run()
        self._run(application_id, quote_a_reason)


@command(snfproject_cmds)
class project_application_approve(_application_action):
    """Approve an application (special privileges needed)"""
    action = 'approve'


@command(snfproject_cmds)
class project_application_deny(_application_action):
    """Deny an application (special privileges needed)"""
    action = 'deny'


@command(snfproject_cmds)
class project_application_dismiss(_application_action):
    """Dismiss your denied application"""
    action = 'dismiss'


@command(snfproject_cmds)
class project_application_cancel(_application_action):
    """Cancel your application"""
    action = 'cancel'


@command(snfproject_cmds)
class project_membership(_astakos_init):
    """Project membership management commands"""


@command(snfproject_cmds)
class project_membership_list(_astakos_init, _optional_json):
    """List all memberships"""

    arguments = dict(
        project=ValueArgument('Filter by project id', '--with-project-id')
    )

    @errors.generic.all
    @astakoserror
    def _run(self):
742
743
744
745
        project = self['project']
        if project is not None:
            project = int(project)
        self._print(self.client.get_memberships(self.token, project))
746
747
748
749
750
751
752
753
754

    def main(self):
        super(self.__class__, self)._run()
        self._run()


@command(snfproject_cmds)
class project_membership_info(_astakos_init, _optional_json):
    """Details on a membership"""
755
756
757

    @errors.generic.all
    @astakoserror
758
    def _run(self, memb_id):
Giorgos Korfiatis's avatar
Giorgos Korfiatis committed
759
760
        self._print(self.client.get_membership(self.token, memb_id),
                    print_dict)
761

762
    def main(self, membership_id):
763
        super(self.__class__, self)._run()
764
765
766
767
768
769
770
771
772
773
        self._run(membership_id)


class _membership_action(_astakos_init, _optional_json):

    action = ''

    @errors.generic.all
    @astakoserror
    def _run(self, memb_id, quote_a_reason):
774
775
        self._print(self.client.membership_action(
            self.token, memb_id, self.action, quote_a_reason))
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837

    def main(self, membership_id, quote_a_reason=''):
        super(_membership_action, self)._run()
        self._run(membership_id, quote_a_reason)


@command(snfproject_cmds)
class project_membership_leave(_membership_action):
    """Leave a project you have membership to"""
    action = 'leave'


@command(snfproject_cmds)
class project_membership_cancel(_membership_action):
    """Cancel your (probably pending) membership to a project"""
    action = 'cancel'


@command(snfproject_cmds)
class project_membership_accept(_membership_action):
    """Accept a membership for a project you manage"""
    action = 'accept'


@command(snfproject_cmds)
class project_membership_reject(_membership_action):
    """Reject a membership for project you manage"""
    action = 'reject'


@command(snfproject_cmds)
class project_membership_remove(_membership_action):
    """Remove a membership for a project you manage"""
    action = 'remove'


@command(snfproject_cmds)
class project_membership_join(_astakos_init):
    """Get a membership to a project"""

    @errors.generic.all
    @astakoserror
    def _run(self, project_id):
        print self.client.join_project(self.token, project_id)

    def main(self, project_id):
        super(_membership_action, self)._run()
        self._run(project_id)


@command(snfproject_cmds)
class project_membership_enroll(_astakos_init):
    """Enroll somebody to a project you manage"""

    @errors.generic.all
    @astakoserror
    def _run(self, project_id, email):
        print self.client.enroll_member(self.token, project_id, email)

    def main(self, project_id, email):
        super(_membership_action, self)._run()
        self._run(project_id, email)