Commit db42819a authored by Giorgos Verigakis's avatar Giorgos Verigakis
Browse files

Add initial support for firewall profiles

Refs #659
parent f8be064c
......@@ -264,6 +264,14 @@ def get_console(request, vm, args):
return HttpResponse(data, mimetype=mimetype, status=200)
@server_action('firewallProfile')
def set_firewall_profile(request, vm, args):
profile = args.get('profile', '')
if profile not in ('ENABLED', 'DISABLED'):
raise BadRequest("Unsupported firewall profile")
backend.set_firewall_profile(vm, profile)
return HttpResponse(status=202)
@network_action('add')
def add(request, net, args):
......
......@@ -247,3 +247,16 @@ def disconnect_from_network(vm, net):
'mode': 'bridged',
'link': nic.network.link.name}))
rapi.ModifyInstance(vm.backend_id, nics=ops, dry_run=settings.TEST)
def set_firewall_profile(vm, profile):
if profile == 'ENABLED':
to_delete = settings.GANETI_FIREWALL_DISABLED_TAG
to_add = settings.GANETI_FIREWALL_ENABLED_TAG
elif profile == 'DISABLED':
to_delete = settings.GANETI_FIREWALL_ENABLED_TAG
to_add = settings.GANETI_FIREWALL_DISABLED_TAG
else:
raise ValueError("Unsopported Firewall Profile: %s" % profile)
rapi.DeleteInstanceTags(vm.backend_id, [to_delete], dry_run=settings.TEST)
rapi.AddInstanceTags(vm.backend_id, [to_add], dry_run=settings.TEST)
......@@ -243,3 +243,5 @@ GANETI_PUBLIC_LINK = 'snf_public'
GANETI_NULL_LINK = 'snf_null' # This value is also hardcoded in the fixture
GANETI_LINK_PREFIX = 'prv'
GANETI_MAX_LINK_NUMBER = 100
GANETI_FIREWALL_ENABLED_TAG = 'firewall_enabled'
GANETI_FIREWALL_DISABLED_TAG = 'firewall_disabled'
......@@ -289,9 +289,6 @@ class ServerConsole(Command):
description = 'get VNC console'
syntax = '<server id>'
def add_options(self, parser):
pass
def execute(self, server_id):
path = '/api/%s/servers/%d/action' % (self.api, int(server_id))
body = json.dumps({'console': {'type': 'vnc'}})
......@@ -299,6 +296,17 @@ class ServerConsole(Command):
print_dict(reply['console'])
@command_name('profile')
class SetFirewallProfile(Command):
description = 'set the firewall profile'
syntax = '<server id> <profile>'
def execute(self, server_id, profile):
path = '/api/%s/servers/%d/action' % (self.api, int(server_id))
body = json.dumps({'firewallProfile': {'profile': profile}})
self.http_cmd('POST', path, body, 202)
@command_name('lsaddr')
class ListAddresses(Command):
description = 'list server addresses'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment