mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 12:04:15 +00:00
Check usage of filter refs from domains.
This commit is contained in:
parent
3f1acf09ef
commit
1802ad0413
3 changed files with 49 additions and 8 deletions
|
@ -65,7 +65,7 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>{% trans "Filter:" %}</label>
|
<label>{% trans "Filter:" %}</label>
|
||||||
<select id="nwfilter_select" name="nwfilters_select" class="form-control">
|
<select id="nwfilter_select" name="nwfilters_select" class="form-control">
|
||||||
<option value="None" selected>None</option>
|
<option value="" selected>None</option>
|
||||||
{% for nwf in nwfilters_all %}
|
{% for nwf in nwfilters_all %}
|
||||||
<option value="{{ nwf.name }}">{{ nwf.name }}</option>
|
<option value="{{ nwf.name }}">{{ nwf.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -10,7 +10,9 @@ from django.contrib.auth.decorators import login_required
|
||||||
from computes.models import Compute
|
from computes.models import Compute
|
||||||
from vrtManager import util
|
from vrtManager import util
|
||||||
from vrtManager.nwfilters import wvmNWFilters, wvmNWFilter
|
from vrtManager.nwfilters import wvmNWFilters, wvmNWFilter
|
||||||
|
from vrtManager.instance import wvmInstances, wvmInstance
|
||||||
from libvirt import libvirtError
|
from libvirt import libvirtError
|
||||||
|
from logs.views import addlogmsg
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -33,9 +35,6 @@ def nwfilters(request, compute_id):
|
||||||
compute.password,
|
compute.password,
|
||||||
compute.type)
|
compute.type)
|
||||||
|
|
||||||
for nwf in conn.get_nwfilters():
|
|
||||||
nwfilters_all.append(conn.get_nwfilter_info(nwf.name()))
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if 'create_nwfilter' in request.POST:
|
if 'create_nwfilter' in request.POST:
|
||||||
xml = request.POST.get('nwfilter_xml', '')
|
xml = request.POST.get('nwfilter_xml', '')
|
||||||
|
@ -56,29 +55,58 @@ def nwfilters(request, compute_id):
|
||||||
raise Exception(error_msg)
|
raise Exception(error_msg)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
msg = _("Creating NWFilter: %s" % name)
|
||||||
conn.create_nwfilter(xml)
|
conn.create_nwfilter(xml)
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
addlogmsg(request.user.username, compute.hostname, msg)
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err.message)
|
error_messages.append(lib_err.message)
|
||||||
|
addlogmsg(request.user.username, compute.hostname, lib_err.message)
|
||||||
|
|
||||||
if 'del_nwfilter' in request.POST:
|
if 'del_nwfilter' in request.POST:
|
||||||
name = request.POST.get('nwfiltername','')
|
name = request.POST.get('nwfiltername','')
|
||||||
|
msg = _("Deleting NWFilter: %s" % name)
|
||||||
|
in_use = False
|
||||||
nwfilter = conn.get_nwfilter(name)
|
nwfilter = conn.get_nwfilter(name)
|
||||||
if nwfilter:
|
|
||||||
|
is_conn = wvmInstances(compute.hostname, compute.login, compute.password, compute.type)
|
||||||
|
instances = is_conn.get_instances()
|
||||||
|
for inst in instances:
|
||||||
|
# if in_use: break
|
||||||
|
i_conn = wvmInstance(compute.hostname, compute.login, compute.password, compute.type, inst)
|
||||||
|
dom_filterrefs = i_conn.get_filterrefs()
|
||||||
|
|
||||||
|
if name in dom_filterrefs:
|
||||||
|
in_use = True
|
||||||
|
msg = _("NWFilter is in use by %s. Cannot be deleted." % inst)
|
||||||
|
error_messages.append(msg)
|
||||||
|
addlogmsg(request.user.username, compute.hostname, msg)
|
||||||
|
i_conn.close()
|
||||||
|
break
|
||||||
|
|
||||||
|
is_conn.close()
|
||||||
|
if nwfilter and not in_use:
|
||||||
nwfilter.undefine()
|
nwfilter.undefine()
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
addlogmsg(request.user.username, compute.hostname, msg)
|
||||||
|
|
||||||
if 'cln_nwfilter' in request.POST:
|
if 'cln_nwfilter' in request.POST:
|
||||||
|
|
||||||
name = request.POST.get('nwfiltername','')
|
name = request.POST.get('nwfiltername','')
|
||||||
cln_name = request.POST.get('cln_name', name + '-clone')
|
cln_name = request.POST.get('cln_name', name + '-clone')
|
||||||
|
|
||||||
conn.clone_nwfilter(name,cln_name)
|
conn.clone_nwfilter(name,cln_name)
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
msg = _("Cloning NWFilter %s as %s" % (name, cln_name))
|
||||||
|
addlogmsg(request.user.username, compute.hostname, msg)
|
||||||
|
|
||||||
|
for nwf in conn.get_nwfilters():
|
||||||
|
nwfilters_all.append(conn.get_nwfilter_info(nwf.name()))
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err)
|
error_messages.append(lib_err)
|
||||||
|
addlogmsg(request.user.username, compute.hostname, lib_err)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
error_messages.append(err)
|
error_messages.append(err)
|
||||||
|
addlogmsg(request.user.username, compute.hostname, err)
|
||||||
|
|
||||||
return render(request, 'nwfilters.html', {'error_messages': error_messages,
|
return render(request, 'nwfilters.html', {'error_messages': error_messages,
|
||||||
'nwfilters': nwfilters_all,
|
'nwfilters': nwfilters_all,
|
||||||
|
|
|
@ -187,6 +187,19 @@ class wvmInstance(wvmConnect):
|
||||||
title = util.get_xml_path(self._XMLDesc(0), "/domain/title")
|
title = util.get_xml_path(self._XMLDesc(0), "/domain/title")
|
||||||
return title if title else ''
|
return title if title else ''
|
||||||
|
|
||||||
|
def get_filterrefs(self):
|
||||||
|
|
||||||
|
def filterrefs(ctx):
|
||||||
|
result = []
|
||||||
|
for net in ctx.xpath('/domain/devices/interface'):
|
||||||
|
filterref = net.xpath('filterref/@filter')
|
||||||
|
if filterref:
|
||||||
|
result.append(filterref[0])
|
||||||
|
return result
|
||||||
|
|
||||||
|
return util.get_xml_path(self._XMLDesc(0), func=filterrefs)
|
||||||
|
|
||||||
|
|
||||||
def get_description(self):
|
def get_description(self):
|
||||||
description = util.get_xml_path(self._XMLDesc(0), "/domain/description")
|
description = util.get_xml_path(self._XMLDesc(0), "/domain/description")
|
||||||
return description if description else ''
|
return description if description else ''
|
||||||
|
|
Loading…
Reference in a new issue