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

b/snf-cyclades-app/synnefo/logic/backend.py
844 844

  
845 845
    with pooled_rapi_client(vm) as client:
846 846
        jobID = client.ModifyInstance(**kwargs)
847
        # If the NIC has a tag for a firewall profile it must be deleted,
848
        # otherwise it may affect another NIC. XXX: Deleting the tag should
849
        # depend on the removing the NIC, but currently RAPI client does not
850
        # support this, this may result in clearing the firewall profile
851
        # without successfully removing the NIC. This issue will be fixed with
852
        # use of NIC UUIDs.
853 847
        firewall_profile = nic.firewall_profile
854 848
        if firewall_profile and firewall_profile != "DISABLED":
855
            tag = _firewall_tags[firewall_profile] % nic.index
849
            tag = _firewall_tags[firewall_profile] % nic.backend_uuid
856 850
            client.DeleteInstanceTags(vm.backend_vm_id, [tag],
857 851
                                      dry_run=settings.TEST)
858 852

  
859 853
        return jobID
860 854

  
861 855

  
862
def set_firewall_profile(vm, profile, index=0):
856
def set_firewall_profile(vm, profile, nic):
857
    uuid = nic.backend_uuid
863 858
    try:
864
        tag = _firewall_tags[profile] % index
859
        tag = _firewall_tags[profile] % uuid
865 860
    except KeyError:
866 861
        raise ValueError("Unsopported Firewall Profile: %s" % profile)
867 862

  
868
    log.debug("Setting tag of VM %s, NIC index %d, to %s", vm, index, profile)
863
    log.debug("Setting tag of VM %s, NIC %s, to %s", vm, nic, profile)
869 864

  
870 865
    with pooled_rapi_client(vm) as client:
871 866
        # Delete previous firewall tags
872 867
        old_tags = client.GetInstanceTags(vm.backend_vm_id)
873
        delete_tags = [(t % index) for t in _firewall_tags.values()
874
                       if (t % index) in old_tags]
868
        delete_tags = [(t % uuid) for t in _firewall_tags.values()
869
                       if (t % uuid) in old_tags]
875 870
        if delete_tags:
876 871
            client.DeleteInstanceTags(vm.backend_vm_id, delete_tags,
877 872
                                      dry_run=settings.TEST)

Also available in: Unified diff