root / snf-cyclades-app / synnefo / api / management / commands / floating-ip-create.py @ 9835a70d
History | View | Annotate | Download (3.1 kB)
1 | f29f1326 | Marios Kogias | # Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | f29f1326 | Marios Kogias | #
|
3 | f29f1326 | Marios Kogias | # Redistribution and use in source and binary forms, with or
|
4 | f29f1326 | Marios Kogias | # without modification, are permitted provided that the following
|
5 | f29f1326 | Marios Kogias | # conditions are met:
|
6 | f29f1326 | Marios Kogias | #
|
7 | f29f1326 | Marios Kogias | # 1. Redistributions of source code must retain the above
|
8 | f29f1326 | Marios Kogias | # copyright notice, this list of conditions and the following
|
9 | f29f1326 | Marios Kogias | # disclaimer.
|
10 | f29f1326 | Marios Kogias | #
|
11 | f29f1326 | Marios Kogias | # 2. Redistributions in binary form must reproduce the above
|
12 | f29f1326 | Marios Kogias | # copyright notice, this list of conditions and the following
|
13 | f29f1326 | Marios Kogias | # disclaimer in the documentation and/or other materials
|
14 | f29f1326 | Marios Kogias | # provided with the distribution.
|
15 | f29f1326 | Marios Kogias | #
|
16 | f29f1326 | Marios Kogias | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | f29f1326 | Marios Kogias | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | f29f1326 | Marios Kogias | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | f29f1326 | Marios Kogias | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | f29f1326 | Marios Kogias | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | f29f1326 | Marios Kogias | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | f29f1326 | Marios Kogias | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | f29f1326 | Marios Kogias | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | f29f1326 | Marios Kogias | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | f29f1326 | Marios Kogias | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | f29f1326 | Marios Kogias | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | f29f1326 | Marios Kogias | # POSSIBILITY OF SUCH DAMAGE.
|
28 | f29f1326 | Marios Kogias | #
|
29 | f29f1326 | Marios Kogias | # The views and conclusions contained in the software and
|
30 | f29f1326 | Marios Kogias | # documentation are those of the authors and should not be
|
31 | f29f1326 | Marios Kogias | # interpreted as representing official policies, either expressed
|
32 | f29f1326 | Marios Kogias | # or implied, of GRNET S.A.
|
33 | f29f1326 | Marios Kogias | |
34 | f29f1326 | Marios Kogias | from optparse import make_option |
35 | f29f1326 | Marios Kogias | |
36 | f29f1326 | Marios Kogias | from django.core.management.base import BaseCommand, CommandError |
37 | f29f1326 | Marios Kogias | from synnefo.management.common import convert_api_faults |
38 | 0292883e | Christos Stavrakakis | from synnefo.logic import ips |
39 | f29f1326 | Marios Kogias | from synnefo.api import util |
40 | f29f1326 | Marios Kogias | |
41 | f29f1326 | Marios Kogias | |
42 | f29f1326 | Marios Kogias | class Command(BaseCommand): |
43 | f29f1326 | Marios Kogias | help = "Allocate a new floating IP"
|
44 | f29f1326 | Marios Kogias | |
45 | f29f1326 | Marios Kogias | option_list = BaseCommand.option_list + ( |
46 | f29f1326 | Marios Kogias | make_option( |
47 | f29f1326 | Marios Kogias | '--pool',
|
48 | f29f1326 | Marios Kogias | dest='pool',
|
49 | 0292883e | Christos Stavrakakis | help="The ID of the floating IP pool(network) to allocate the"
|
50 | 0292883e | Christos Stavrakakis | " address from"),
|
51 | f29f1326 | Marios Kogias | make_option( |
52 | f29f1326 | Marios Kogias | '--address',
|
53 | f29f1326 | Marios Kogias | dest='address',
|
54 | f29f1326 | Marios Kogias | help="The address to be allocated"),
|
55 | f29f1326 | Marios Kogias | make_option( |
56 | f29f1326 | Marios Kogias | '--owner',
|
57 | f29f1326 | Marios Kogias | dest='owner',
|
58 | f29f1326 | Marios Kogias | default=None,
|
59 | f29f1326 | Marios Kogias | help='The owner of the floating IP'),
|
60 | f29f1326 | Marios Kogias | ) |
61 | f29f1326 | Marios Kogias | |
62 | f29f1326 | Marios Kogias | @convert_api_faults
|
63 | f29f1326 | Marios Kogias | def handle(self, *args, **options): |
64 | f29f1326 | Marios Kogias | if args:
|
65 | f29f1326 | Marios Kogias | raise CommandError("Command doesn't accept any arguments") |
66 | f29f1326 | Marios Kogias | |
67 | 0292883e | Christos Stavrakakis | network_id = options['pool']
|
68 | f29f1326 | Marios Kogias | address = options['address']
|
69 | f29f1326 | Marios Kogias | owner = options['owner']
|
70 | f29f1326 | Marios Kogias | |
71 | f29f1326 | Marios Kogias | if not owner: |
72 | f29f1326 | Marios Kogias | raise CommandError("'owner' is required for floating IP creation") |
73 | f29f1326 | Marios Kogias | |
74 | 0292883e | Christos Stavrakakis | if network_id is not None: |
75 | f29f1326 | Marios Kogias | network = util.get_network(network_id, owner, for_update=True,
|
76 | f29f1326 | Marios Kogias | non_deleted=True)
|
77 | 0292883e | Christos Stavrakakis | else:
|
78 | 0292883e | Christos Stavrakakis | network = None
|
79 | f29f1326 | Marios Kogias | |
80 | 0292883e | Christos Stavrakakis | floating_ip = ips.create_floating_ip(userid=owner, |
81 | 0292883e | Christos Stavrakakis | network=network, |
82 | 0292883e | Christos Stavrakakis | address=address) |
83 | f29f1326 | Marios Kogias | |
84 | f29f1326 | Marios Kogias | self.stdout.write("Created floating IP '%s'.\n" % floating_ip) |