Revision 26563957 logic/backend.py

b/logic/backend.py
262 262
            'link': nic.network.link.name}))
263 263
    rapi.ModifyInstance(vm.backend_id, nics=ops, dry_run=settings.TEST)
264 264

  
265

  
266
_firewall_tags = {
267
    'ENABLED': settings.GANETI_FIREWALL_ENABLED_TAG,
268
    'DISABLED': settings.GANETI_FIREWALL_DISABLED_TAG,
269
    'PROTECTED': settings.GANETI_FIREWALL_PROTECTED_TAG}
270

  
265 271
def set_firewall_profile(vm, profile):
266
    if profile == 'ENABLED':
267
        to_delete = settings.GANETI_FIREWALL_DISABLED_TAG
268
        to_add = settings.GANETI_FIREWALL_ENABLED_TAG
269
    elif profile == 'DISABLED':
270
        to_delete = settings.GANETI_FIREWALL_ENABLED_TAG
271
        to_add = settings.GANETI_FIREWALL_DISABLED_TAG
272
    else:
272
    try:
273
        tag = _firewall_tags[profile]
274
    except KeyError:
273 275
        raise ValueError("Unsopported Firewall Profile: %s" % profile)
274 276
    
275
    rapi.DeleteInstanceTags(vm.backend_id, [to_delete], dry_run=settings.TEST)
276
    rapi.AddInstanceTags(vm.backend_id, [to_add], dry_run=settings.TEST)
277
    # Delete all firewall tags
278
    rapi.DeleteInstanceTags(vm.backend_id, _firewall_tags.values(),
279
                            dry_run=settings.TEST)
280
    
281
    rapi.AddInstanceTags(vm.backend_id, [tag], dry_run=settings.TEST)

Also available in: Unified diff