root / snf-cyclades-app / synnefo / volume / management / commands / volume-modify.py @ a868c831
History | View | Annotate | Download (3.2 kB)
1 | a868c831 | Christos Stavrakakis | # Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | a868c831 | Christos Stavrakakis | #
|
3 | a868c831 | Christos Stavrakakis | # Redistribution and use in source and binary forms, with or
|
4 | a868c831 | Christos Stavrakakis | # without modification, are permitted provided that the following
|
5 | a868c831 | Christos Stavrakakis | # conditions are met:
|
6 | a868c831 | Christos Stavrakakis | #
|
7 | a868c831 | Christos Stavrakakis | # 1. Redistributions of source code must retain the above
|
8 | a868c831 | Christos Stavrakakis | # copyright notice, this list of conditions and the following
|
9 | a868c831 | Christos Stavrakakis | # disclaimer.
|
10 | a868c831 | Christos Stavrakakis | #
|
11 | a868c831 | Christos Stavrakakis | # 2. Redistributions in binary form must reproduce the above
|
12 | a868c831 | Christos Stavrakakis | # copyright notice, this list of conditions and the following
|
13 | a868c831 | Christos Stavrakakis | # disclaimer in the documentation and/or other materials
|
14 | a868c831 | Christos Stavrakakis | # provided with the distribution.
|
15 | a868c831 | Christos Stavrakakis | #
|
16 | a868c831 | Christos Stavrakakis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | a868c831 | Christos Stavrakakis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | a868c831 | Christos Stavrakakis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | a868c831 | Christos Stavrakakis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | a868c831 | Christos Stavrakakis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | a868c831 | Christos Stavrakakis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | a868c831 | Christos Stavrakakis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | a868c831 | Christos Stavrakakis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | a868c831 | Christos Stavrakakis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | a868c831 | Christos Stavrakakis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | a868c831 | Christos Stavrakakis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | a868c831 | Christos Stavrakakis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | a868c831 | Christos Stavrakakis | #
|
29 | a868c831 | Christos Stavrakakis | # The views and conclusions contained in the software and
|
30 | a868c831 | Christos Stavrakakis | # documentation are those of the authors and should not be
|
31 | a868c831 | Christos Stavrakakis | # interpreted as representing official policies, either expressed
|
32 | a868c831 | Christos Stavrakakis | # or implied, of GRNET S.A.
|
33 | a868c831 | Christos Stavrakakis | |
34 | a868c831 | Christos Stavrakakis | from optparse import make_option |
35 | a868c831 | Christos Stavrakakis | from django.core.management.base import BaseCommand, CommandError |
36 | a868c831 | Christos Stavrakakis | |
37 | a868c831 | Christos Stavrakakis | from snf_django.management.utils import parse_bool |
38 | a868c831 | Christos Stavrakakis | from synnefo.management.common import convert_api_faults |
39 | a868c831 | Christos Stavrakakis | from synnefo.management import pprint, common |
40 | a868c831 | Christos Stavrakakis | from synnefo.volume import volumes |
41 | a868c831 | Christos Stavrakakis | |
42 | a868c831 | Christos Stavrakakis | |
43 | a868c831 | Christos Stavrakakis | class Command(BaseCommand): |
44 | a868c831 | Christos Stavrakakis | help = "Modify a volume"
|
45 | a868c831 | Christos Stavrakakis | args = "<volume ID>"
|
46 | a868c831 | Christos Stavrakakis | |
47 | a868c831 | Christos Stavrakakis | option_list = BaseCommand.option_list + ( |
48 | a868c831 | Christos Stavrakakis | make_option( |
49 | a868c831 | Christos Stavrakakis | '--name',
|
50 | a868c831 | Christos Stavrakakis | dest='name',
|
51 | a868c831 | Christos Stavrakakis | help="Modify a volume's display name"),
|
52 | a868c831 | Christos Stavrakakis | make_option( |
53 | a868c831 | Christos Stavrakakis | '--description',
|
54 | a868c831 | Christos Stavrakakis | dest='description',
|
55 | a868c831 | Christos Stavrakakis | help="Modify a volume's display description"),
|
56 | a868c831 | Christos Stavrakakis | make_option( |
57 | a868c831 | Christos Stavrakakis | '--delete-on-termination',
|
58 | a868c831 | Christos Stavrakakis | dest='delete_on_termination',
|
59 | a868c831 | Christos Stavrakakis | default="True",
|
60 | a868c831 | Christos Stavrakakis | choices=["True", "False"], |
61 | a868c831 | Christos Stavrakakis | metavar="True|False",
|
62 | a868c831 | Christos Stavrakakis | help="Set whether volume will be preserved when the server"
|
63 | a868c831 | Christos Stavrakakis | " the volume is attached will be deleted"),
|
64 | a868c831 | Christos Stavrakakis | ) |
65 | a868c831 | Christos Stavrakakis | |
66 | a868c831 | Christos Stavrakakis | @convert_api_faults
|
67 | a868c831 | Christos Stavrakakis | def handle(self, *args, **options): |
68 | a868c831 | Christos Stavrakakis | if len(args) != 1: |
69 | a868c831 | Christos Stavrakakis | raise CommandError("Please provide a volume ID") |
70 | a868c831 | Christos Stavrakakis | |
71 | a868c831 | Christos Stavrakakis | volume = common.get_volume(args[0])
|
72 | a868c831 | Christos Stavrakakis | |
73 | a868c831 | Christos Stavrakakis | name = options.get("name")
|
74 | a868c831 | Christos Stavrakakis | description = options.get("description")
|
75 | a868c831 | Christos Stavrakakis | delete_on_termination = options.get("delete_on_termination")
|
76 | a868c831 | Christos Stavrakakis | if delete_on_termination is not None: |
77 | a868c831 | Christos Stavrakakis | delete_on_termination = parse_bool(delete_on_termination) |
78 | a868c831 | Christos Stavrakakis | |
79 | a868c831 | Christos Stavrakakis | volume = volumes.update(volume, name, description, |
80 | a868c831 | Christos Stavrakakis | delete_on_termination) |
81 | a868c831 | Christos Stavrakakis | |
82 | a868c831 | Christos Stavrakakis | pprint.pprint_volume(volume, stdout=self.stdout)
|
83 | a868c831 | Christos Stavrakakis | self.stdout.write('\n\n') |