Revision 6b8dc47c snf-cyclades-app/synnefo/logic/servers.py
b/snf-cyclades-app/synnefo/logic/servers.py | ||
---|---|---|
276 | 276 |
return nics |
277 | 277 |
|
278 | 278 |
|
279 |
def create_nic(vm, network=None, ipaddress=None, address=None): |
|
279 |
def create_nic(vm, network=None, ipaddress=None, address=None, name=None):
|
|
280 | 280 |
"""Helper functions for create NIC objects. |
281 | 281 |
|
282 | 282 |
Create a NetworkInterface connecting a VirtualMachine to a network with the |
... | ... | |
292 | 292 |
ipaddress = util.allocate_ip(network, userid=userid, |
293 | 293 |
address=address) |
294 | 294 |
except pools.ValueNotAvailable: |
295 |
raise faults.badRequest("Address '%s' is not available." %
|
|
296 |
address)
|
|
295 |
raise faults.Conflict("Address '%s' is not available." %
|
|
296 |
address) |
|
297 | 297 |
|
298 | 298 |
if ipaddress is not None and ipaddress.nic is not None: |
299 | 299 |
raise faults.Conflict("IP address '%s' already in use" % |
... | ... | |
309 | 309 |
device_owner = "vm" |
310 | 310 |
nic = NetworkInterface.objects.create(machine=vm, network=network, |
311 | 311 |
state="BUILD", |
312 |
device_owner=device_owner) |
|
312 |
userid=vm.userid, |
|
313 |
device_owner=device_owner, |
|
314 |
name=name) |
|
313 | 315 |
if ipaddress is not None: |
314 | 316 |
ipaddress.nic = nic |
315 | 317 |
ipaddress.save() |
... | ... | |
381 | 383 |
|
382 | 384 |
|
383 | 385 |
@server_command("CONNECT") |
384 |
def connect(vm, network): |
|
385 |
nic, ipaddress = create_nic(vm, network) |
|
386 |
def connect(vm, network, port=None): |
|
387 |
if port is None: |
|
388 |
nic, ipaddress = create_nic(vm, network) |
|
389 |
else: |
|
390 |
nic = port |
|
391 |
ipaddress = port.ips.all()[0] |
|
386 | 392 |
|
387 | 393 |
log.info("Creating NIC %s with IPAddress %s", nic, ipaddress) |
388 | 394 |
|
Also available in: Unified diff