Revision c75ab92e snf-cyclades-app/synnefo/logic/networks.py
b/snf-cyclades-app/synnefo/logic/networks.py | ||
---|---|---|
62 | 62 |
|
63 | 63 |
|
64 | 64 |
@transaction.commit_on_success |
65 |
def create(user_id, name, flavor, subnet, gateway=None, subnet6=None, |
|
66 |
gateway6=None, public=False, dhcp=True): |
|
65 |
def create(user_id, name, flavor, subnet=None, gateway=None, subnet6=None, |
|
66 |
gateway6=None, public=False, dhcp=True, link=None, mac_prefix=None, |
|
67 |
mode=None, floating_ip_pool=False, tags=None): |
|
67 | 68 |
if flavor is None: |
68 | 69 |
raise faults.BadRequest("Missing request parameter 'type'") |
69 | 70 |
elif flavor not in Network.FLAVORS.keys(): |
70 | 71 |
raise faults.BadRequest("Invalid network type '%s'" % flavor) |
71 | 72 |
|
73 |
if mac_prefix is not None and flavor == "MAC_FILTERED": |
|
74 |
raise faults.BadRequest("Can not override MAC_FILTERED mac-prefix") |
|
75 |
if link is not None and flavor == "PHYSICAL_VLAN": |
|
76 |
raise faults.BadRequest("Can not override PHYSICAL_VLAN link") |
|
77 |
|
|
78 |
if subnet is None and floating_ip_pool: |
|
79 |
raise faults.BadRequest("IPv6 only networks can not be" |
|
80 |
" pools.") |
|
72 | 81 |
# Check that network parameters are valid |
73 | 82 |
util.validate_network_params(subnet, gateway, subnet6, gateway6) |
74 | 83 |
|
75 | 84 |
try: |
76 |
mode, link, mac_prefix, tags = util.values_from_flavor(flavor)
|
|
85 |
fmode, flink, fmac_prefix, ftags = util.values_from_flavor(flavor)
|
|
77 | 86 |
except EmptyPool: |
78 | 87 |
log.error("Failed to allocate resources for network of type: %s", |
79 | 88 |
flavor) |
80 | 89 |
msg = "Failed to allocate resources for network." |
81 | 90 |
raise faults.ServiceUnavailable(msg) |
91 |
|
|
92 |
mode = mode or fmode |
|
93 |
link = link or flink |
|
94 |
mac_prefix = mac_prefix or fmac_prefix |
|
95 |
tags = tags or ftags |
|
96 |
|
|
82 | 97 |
validate_mac(mac_prefix + "0:00:00:00") |
83 | 98 |
|
84 | 99 |
network = Network.objects.create( |
... | ... | |
94 | 109 |
link=link, |
95 | 110 |
mac_prefix=mac_prefix, |
96 | 111 |
tags=tags, |
112 |
public=public, |
|
113 |
floating_ip_pool=floating_ip_pool, |
|
97 | 114 |
action='CREATE', |
98 | 115 |
state='ACTIVE') |
99 | 116 |
|
Also available in: Unified diff