Revision b2791a77 snf-cyclades-app/synnefo/logic/backend.py
b/snf-cyclades-app/synnefo/logic/backend.py | ||
---|---|---|
761 | 761 |
dry_run=settings.TEST) |
762 | 762 |
|
763 | 763 |
|
764 |
def set_firewall_profile(vm, profile): |
|
764 |
def set_firewall_profile(vm, profile, index=0):
|
|
765 | 765 |
try: |
766 |
tag = _firewall_tags[profile] |
|
766 |
tag = _firewall_tags[profile] % index
|
|
767 | 767 |
except KeyError: |
768 | 768 |
raise ValueError("Unsopported Firewall Profile: %s" % profile) |
769 | 769 |
|
770 |
log.debug("Setting tag of VM %s to %s", vm, profile)
|
|
770 |
log.debug("Setting tag of VM %s, NIC index %d, to %s", vm, index, profile)
|
|
771 | 771 |
|
772 | 772 |
with pooled_rapi_client(vm) as client: |
773 |
# Delete all firewall tags |
|
774 |
for t in _firewall_tags.values(): |
|
775 |
client.DeleteInstanceTags(vm.backend_vm_id, [t], |
|
773 |
# Delete previous firewall tags |
|
774 |
old_tags = client.GetInstanceTags(vm.backend_vm_id) |
|
775 |
delete_tags = [(t % index) for t in _firewall_tags.values() |
|
776 |
if (t % index) in old_tags] |
|
777 |
if delete_tags: |
|
778 |
client.DeleteInstanceTags(vm.backend_vm_id, delete_tags, |
|
776 | 779 |
dry_run=settings.TEST) |
777 | 780 |
|
778 | 781 |
client.AddInstanceTags(vm.backend_vm_id, [tag], dry_run=settings.TEST) |
Also available in: Unified diff