Revision d1eaa651 snf-cyclades-app/synnefo/logic/backend.py

b/snf-cyclades-app/synnefo/logic/backend.py
38 38
from django.conf import settings
39 39
from django.db import transaction
40 40

  
41
from synnefo.db.models import (VirtualMachine, Network, NetworkInterface,
42
                                NetworkLink)
41
from synnefo.db.models import (VirtualMachine, Network, NetworkLink)
43 42
from synnefo.logic import utils
44 43
from synnefo.util.rapi import GanetiRapiClient
45 44

  
......
268 267
        'img_format': image['format']}
269 268
    if personality:
270 269
        kw['osparams']['img_personality'] = json.dumps(personality)
271
    
270

  
272 271
    kw['osparams']['img_properties'] = json.dumps(image['metadata'])
273
    
272

  
274 273
    # Defined in settings.GANETI_CREATEINSTANCE_KWARGS
275 274
    # kw['hvparams'] = dict(serial_console=False)
276 275

  
......
388 387

  
389 388
def connect_to_network(vm, net):
390 389
    nic = {'mode': 'bridged', 'link': net.link.name}
391
    rapi.ModifyInstance(vm.backend_id,
392
        nics=[('add', nic)],
393
        dry_run=settings.TEST)
390
    rapi.ModifyInstance(vm.backend_id, nics=[('add', nic)],
391
                        dry_run=settings.TEST)
394 392

  
395 393

  
396 394
def disconnect_from_network(vm, net):
397 395
    nics = vm.nics.filter(network__public=False).order_by('index')
398
    new_nics = [nic for nic in nics if nic.network != net]
399
    if new_nics == nics:
400
        return      # Nothing to remove
401
    ops = [('remove', {})]
402
    for i, nic in enumerate(new_nics):
403
        ops.append((i + 1, {
404
            'mode': 'bridged',
405
            'link': nic.network.link.name}))
406
    rapi.ModifyInstance(vm.backend_id, nics=ops, dry_run=settings.TEST)
396
    ops = [('remove', nic.index, {}) for nic in nics if nic.network == net]
397
    if not ops: # Vm not connected to network
398
        return
399
    rapi.ModifyInstance(vm.backend_id, nics=ops[::-1], dry_run=settings.TEST)
407 400

  
408 401

  
409 402
def set_firewall_profile(vm, profile):

Also available in: Unified diff