Revision 3785b737 snf-cyclades-app/synnefo/api/management/commands/network-create.py
b/snf-cyclades-app/synnefo/api/management/commands/network-create.py | ||
---|---|---|
38 | 38 |
from snf_django.management.utils import parse_bool |
39 | 39 |
|
40 | 40 |
from synnefo.db.models import Network, Backend |
41 |
from synnefo.logic import networks |
|
41 |
from synnefo.logic import networks, subnets
|
|
42 | 42 |
from synnefo.management import pprint |
43 | 43 |
|
44 | 44 |
NETWORK_FLAVORS = Network.FLAVORS.keys() |
... | ... | |
54 | 54 |
make_option( |
55 | 55 |
'--name', |
56 | 56 |
dest='name', |
57 |
help="Name of network"), |
|
57 |
help="Name of the network"), |
|
58 |
make_option( |
|
59 |
'--name4', |
|
60 |
dest='name4', |
|
61 |
help="Name of the IPv4 subnet"), |
|
62 |
make_option( |
|
63 |
'--name6', |
|
64 |
dest='name6', |
|
65 |
help="Name of the IPv6 subnet"), |
|
58 | 66 |
make_option( |
59 | 67 |
'--owner', |
60 | 68 |
dest='owner', |
... | ... | |
64 | 72 |
dest='subnet', |
65 | 73 |
default=None, |
66 | 74 |
# required=True, |
67 |
help='Subnet of the network'),
|
|
75 |
help='IPv4 subnet of the network'),
|
|
68 | 76 |
make_option( |
69 | 77 |
'--gateway', |
70 | 78 |
dest='gateway', |
71 | 79 |
default=None, |
72 |
help='Gateway of the network'),
|
|
80 |
help='IPv4 gateway of the network'),
|
|
73 | 81 |
make_option( |
74 | 82 |
'--subnet6', |
75 | 83 |
dest='subnet6', |
... | ... | |
88 | 96 |
metavar="True|False", |
89 | 97 |
help='Automatically assign IPs'), |
90 | 98 |
make_option( |
99 |
'--slaac', |
|
100 |
dest='slaac', |
|
101 |
default="False", |
|
102 |
choices=["True", "False"], |
|
103 |
metavar="True|False", |
|
104 |
help='Automatically assign IPs for the IPv6 subnet'), |
|
105 |
make_option( |
|
91 | 106 |
'--public', |
92 | 107 |
dest='public', |
93 | 108 |
action='store_true', |
... | ... | |
142 | 157 |
raise CommandError("Command doesn't accept any arguments") |
143 | 158 |
|
144 | 159 |
name = options['name'] |
160 |
name4 = options['name4'] |
|
161 |
name6 = options['name6'] |
|
145 | 162 |
subnet = options['subnet'] |
146 | 163 |
gateway = options['gateway'] |
147 | 164 |
subnet6 = options['subnet6'] |
... | ... | |
156 | 173 |
userid = options["owner"] |
157 | 174 |
floating_ip_pool = parse_bool(options["floating_ip_pool"]) |
158 | 175 |
dhcp = parse_bool(options["dhcp"]) |
176 |
slaac = parse_bool(options["slaac"]) |
|
159 | 177 |
|
160 | 178 |
if name is None: |
161 | 179 |
name = "" |
... | ... | |
166 | 184 |
raise CommandError("subnet or subnet6 is required") |
167 | 185 |
if subnet is None and gateway is not None: |
168 | 186 |
raise CommandError("Cannot use gateway without subnet") |
187 |
if subnet is None and dhcp is not None: |
|
188 |
raise CommandError("Cannot use dhcp without subnet") |
|
189 |
if subnet is None and name4 is not None: |
|
190 |
raise CommandError("Cannot use name without subnet") |
|
191 |
|
|
169 | 192 |
if subnet6 is None and gateway6 is not None: |
170 | 193 |
raise CommandError("Cannot use gateway6 without subnet6") |
194 |
if subnet6 is None and slaac is not None: |
|
195 |
raise CommandError("Cannot use slaac without subnet6") |
|
171 | 196 |
if public and not (backend_ids or floating_ip_pool): |
172 | 197 |
raise CommandError("backend-ids is required") |
198 |
if subnet6 is None and name6 is not None: |
|
199 |
raise CommandError("Cannot use name6 without subnet6") |
|
173 | 200 |
if not userid and not public: |
174 | 201 |
raise CommandError("'owner' is required for private networks") |
175 | 202 |
|
... | ... | |
188 | 215 |
backends.append(backend) |
189 | 216 |
|
190 | 217 |
network = networks.create(userid=userid, name=name, flavor=flavor, |
191 |
subnet=subnet, gateway=gateway, |
|
192 |
subnet6=subnet6, gateway6=gateway6, |
|
193 |
dhcp=dhcp, public=public, mode=mode, |
|
218 |
public=public, mode=mode, |
|
194 | 219 |
link=link, mac_prefix=mac_prefix, tags=tags, |
195 | 220 |
floating_ip_pool=floating_ip_pool, |
196 | 221 |
backends=backends, lazy_create=False) |
197 | 222 |
|
223 |
sub4 = subnets._create_subnet(network.id, cidr=subnet, name=name4, |
|
224 |
ipversion=4, gateway=gateway, dhcp=dhcp, |
|
225 |
user_id=userid) |
|
226 |
|
|
227 |
sub6 = subnets._create_subnet(network.id, cidr=subnet6, name=name6, |
|
228 |
ipversion=6, gateway=gateway6, |
|
229 |
dhcp=slaac, user_id=userid) |
|
230 |
|
|
198 | 231 |
self.stdout.write("Created network '%s' in DB:\n" % network) |
199 | 232 |
pprint.pprint_network(network, stdout=self.stdout) |
200 | 233 |
pprint.pprint_network_subnets(network, stdout=self.stdout) |
Also available in: Unified diff