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

b/snf-cyclades-app/synnefo/logic/backend.py
160 160
    """Process NIC dict from ganeti hooks."""
161 161
    new_nics = []
162 162
    for i, new_nic in enumerate(ganeti_nics):
163
        network = new_nic.get('network', '')
164
        n = str(network)
165
        pk = utils.id_from_network_name(n)
163
        network_name = new_nic.get('network', '')
164
        network_id = utils.id_from_network_name(network_name)
165
        net = Network.objects.get(id=network_id)
166 166

  
167
        net = Network.objects.get(pk=pk)
167
        nic_name = new_nic.get("name", None)
168
        nic_id = None
169
        if nic_name is not None:
170
            nic_id = utils.id_from_nic_name(nic_name)
168 171

  
169 172
        # Get the new nic info
170 173
        mac = new_nic.get('mac', '')
......
186 189
            'ipv4': ipv4,
187 190
            'ipv6': ipv6,
188 191
            'firewall_profile': firewall_profile,
189
            'state': 'ACTIVE'}
192
            'state': 'ACTIVE',
193
            'id': nic_id}
190 194

  
191 195
        new_nics.append(nic)
192 196
    return new_nics
......
410 414
        kw['disks'][0]['provider'] = provider
411 415
        kw['disks'][0]['origin'] = flavor.disk_origin
412 416

  
413
    kw['nics'] = [public_nic]
417
    kw['nics'] = [{"name": public_nic.backend_uuid,
418
                  "network": public_nic.network.backend_id,
419
                  "ip": public_nic.ipv4}]
414 420
    # Defined in settings.GANETI_CREATEINSTANCE_KWARGS
415 421
    # kw['os'] = settings.GANETI_OS_PROVIDER
416 422
    kw['ip_check'] = False
......
626 632
    return job_ids
627 633

  
628 634

  
629
def connect_to_network(vm, network, address=None):
635
def connect_to_network(vm, nic):
630 636
    backend = vm.backend
637
    network = nic.network
638
    address = nic.ipv4
631 639
    network = Network.objects.select_for_update().get(id=network.id)
632 640
    bnet, created = BackendNetwork.objects.get_or_create(backend=backend,
633 641
                                                         network=network)
......
637 645

  
638 646
    depends = [[job, ["success", "error", "canceled"]] for job in depend_jobs]
639 647

  
640
    nic = {'ip': address, 'network': network.backend_id}
648
    nic = {'ip': address,
649
           'network': network.backend_id,
650
           'name': nic.backend_uuid}
641 651

  
642 652
    log.debug("Connecting vm %s to network %s(%s)", vm, network, address)
643 653

  
......
666 676
    except KeyError:
667 677
        raise ValueError("Unsopported Firewall Profile: %s" % profile)
668 678

  
679
    try:
680
        public_nic = vm.nics.filter(network__public=True)[0]
681
    except IndexError:
682
        public_nic = None
683

  
669 684
    log.debug("Setting tag of VM %s to %s", vm, profile)
670 685

  
671 686
    with pooled_rapi_client(vm) as client:
......
673 688
        for t in _firewall_tags.values():
674 689
            client.DeleteInstanceTags(vm.backend_vm_id, [t],
675 690
                                      dry_run=settings.TEST)
691
            if public_nic is not None:
692
                tag_with_name = t.replace("0", public_nic.backend_uuid)
693
                client.DeleteInstanceTags(vm.backend_vm_id, [tag_with_name],
694
                                          dry_run=settings.TEST)
676 695

  
677 696
        client.AddInstanceTags(vm.backend_vm_id, [tag], dry_run=settings.TEST)
697
        if public_nic is not None:
698
            tag_with_name = tag.replace("0", public_nic.backend_uuid)
699
            client.AddInstanceTags(vm.backend_vm_id, [tag_with_name],
700
                                   dry_run=settings.TEST)
678 701

  
679 702
        # XXX NOP ModifyInstance call to force process_net_status to run
680 703
        # on the dispatcher

Also available in: Unified diff