root / snf-cyclades-app / synnefo / api / management / commands / subnet-modify.py @ 8b178e6b
History | View | Annotate | Download (2.7 kB)
1 | 65566d61 | Dionysis Grigoropoulos | # Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 65566d61 | Dionysis Grigoropoulos | #
|
3 | 65566d61 | Dionysis Grigoropoulos | # Redistribution and use in source and binary forms, with or
|
4 | 65566d61 | Dionysis Grigoropoulos | # without modification, are permitted provided that the following
|
5 | 65566d61 | Dionysis Grigoropoulos | # conditions are met:
|
6 | 65566d61 | Dionysis Grigoropoulos | #
|
7 | 65566d61 | Dionysis Grigoropoulos | # 1. Redistributions of source code must retain the above
|
8 | 65566d61 | Dionysis Grigoropoulos | # copyright notice, this list of conditions and the following
|
9 | 65566d61 | Dionysis Grigoropoulos | # disclaimer.
|
10 | 65566d61 | Dionysis Grigoropoulos | #
|
11 | 65566d61 | Dionysis Grigoropoulos | # 2. Redistributions in binary form must reproduce the above
|
12 | 65566d61 | Dionysis Grigoropoulos | # copyright notice, this list of conditions and the following
|
13 | 65566d61 | Dionysis Grigoropoulos | # disclaimer in the documentation and/or other materials
|
14 | 65566d61 | Dionysis Grigoropoulos | # provided with the distribution.
|
15 | 65566d61 | Dionysis Grigoropoulos | #
|
16 | 65566d61 | Dionysis Grigoropoulos | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 65566d61 | Dionysis Grigoropoulos | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 65566d61 | Dionysis Grigoropoulos | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 65566d61 | Dionysis Grigoropoulos | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 65566d61 | Dionysis Grigoropoulos | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 65566d61 | Dionysis Grigoropoulos | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 65566d61 | Dionysis Grigoropoulos | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 65566d61 | Dionysis Grigoropoulos | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 65566d61 | Dionysis Grigoropoulos | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 65566d61 | Dionysis Grigoropoulos | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 65566d61 | Dionysis Grigoropoulos | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 65566d61 | Dionysis Grigoropoulos | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 65566d61 | Dionysis Grigoropoulos | #
|
29 | 65566d61 | Dionysis Grigoropoulos | # The views and conclusions contained in the software and
|
30 | 65566d61 | Dionysis Grigoropoulos | # documentation are those of the authors and should not be
|
31 | 65566d61 | Dionysis Grigoropoulos | # interpreted as representing official policies, either expressed
|
32 | 65566d61 | Dionysis Grigoropoulos | # or implied, of GRNET S.A.
|
33 | 65566d61 | Dionysis Grigoropoulos | |
34 | 65566d61 | Dionysis Grigoropoulos | from optparse import make_option |
35 | 65566d61 | Dionysis Grigoropoulos | |
36 | 65566d61 | Dionysis Grigoropoulos | from django.core.management.base import BaseCommand, CommandError |
37 | 65566d61 | Dionysis Grigoropoulos | from synnefo.management import common |
38 | 65566d61 | Dionysis Grigoropoulos | |
39 | 65566d61 | Dionysis Grigoropoulos | from synnefo.logic import subnets |
40 | 65566d61 | Dionysis Grigoropoulos | |
41 | 65566d61 | Dionysis Grigoropoulos | HELP_MSG = """
|
42 | 65566d61 | Dionysis Grigoropoulos |
|
43 | 65566d61 | Dionysis Grigoropoulos | Update a subnet without authenticating the user. Only the name of a subnet can
|
44 | 65566d61 | Dionysis Grigoropoulos | be updated.
|
45 | 65566d61 | Dionysis Grigoropoulos | """
|
46 | 65566d61 | Dionysis Grigoropoulos | |
47 | 65566d61 | Dionysis Grigoropoulos | |
48 | 65566d61 | Dionysis Grigoropoulos | class Command(BaseCommand): |
49 | 65566d61 | Dionysis Grigoropoulos | help = "Update a Subnet." + HELP_MSG
|
50 | 65566d61 | Dionysis Grigoropoulos | |
51 | 65566d61 | Dionysis Grigoropoulos | option_list = BaseCommand.option_list + ( |
52 | 65566d61 | Dionysis Grigoropoulos | make_option("--name", dest="name", |
53 | 65566d61 | Dionysis Grigoropoulos | help="The new subnet name."),
|
54 | 65566d61 | Dionysis Grigoropoulos | ) |
55 | 65566d61 | Dionysis Grigoropoulos | |
56 | 65566d61 | Dionysis Grigoropoulos | @common.convert_api_faults
|
57 | 65566d61 | Dionysis Grigoropoulos | def handle(self, *args, **options): |
58 | b7311f3d | Dionysis Grigoropoulos | if len(args) != 1: |
59 | b7311f3d | Dionysis Grigoropoulos | raise CommandError("Command accepts only the subnet ID as an" |
60 | b7311f3d | Dionysis Grigoropoulos | " argument. Use snf-manage subnet-modify --help"
|
61 | b7311f3d | Dionysis Grigoropoulos | " for more info.")
|
62 | 65566d61 | Dionysis Grigoropoulos | |
63 | b7311f3d | Dionysis Grigoropoulos | subnet_id = args[0]
|
64 | 65566d61 | Dionysis Grigoropoulos | name = options["name"]
|
65 | 65566d61 | Dionysis Grigoropoulos | |
66 | 65566d61 | Dionysis Grigoropoulos | if not name: |
67 | b7311f3d | Dionysis Grigoropoulos | raise CommandError("--name is mandatory") |
68 | 65566d61 | Dionysis Grigoropoulos | |
69 | 65566d61 | Dionysis Grigoropoulos | subnet = common.get_subnet(subnet_id) |
70 | 65566d61 | Dionysis Grigoropoulos | user_id = common.get_network(subnet.network.id).userid |
71 | 65566d61 | Dionysis Grigoropoulos | |
72 | 65566d61 | Dionysis Grigoropoulos | subnets.update_subnet(sub_id=subnet_id, |
73 | 65566d61 | Dionysis Grigoropoulos | name=name, |
74 | 65566d61 | Dionysis Grigoropoulos | user_id=user_id) |