mirror of
https://github.com/retspen/webvirtcloud
synced 2025-01-12 08:25:18 +00:00
fix secret types sync with libvirt library
This commit is contained in:
parent
fe13e4dd66
commit
fc2662bd91
2 changed files with 83 additions and 62 deletions
|
@ -1,60 +1,61 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% if request.user.is_superuser %}
|
{% if request.user.is_superuser %}
|
||||||
<a href="#AddSecret" type="button" class="btn btn-success float-right" data-toggle="modal">
|
<a href="#AddSecret" type="button" class="btn btn-success float-right" data-toggle="modal">
|
||||||
<span class="fa fa-plus" aria-hidden="true"></span>
|
<span class="fa fa-plus" aria-hidden="true"></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- Modal Secret -->
|
<!-- Modal Secret -->
|
||||||
<div class="modal fade" id="AddSecret" tabindex="-1" role="dialog" aria-labelledby="AddSecret" aria-hidden="true">
|
<div class="modal fade" id="AddSecret" tabindex="-1" role="dialog" aria-labelledby="AddSecret" aria-hidden="true">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
<h5 class="modal-title">{% trans "Create New Secret" %}</h5>
|
||||||
<h5 class="modal-title">{% trans "Create New Secret" %}</h5>
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form method="post" action="" role="form" aria-label="Create Secret form">{% csrf_token %}
|
<form method="post" action="" role="form" aria-label="Create Secret form">{% csrf_token %}
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label class="col-sm-3 col-form-label">{% trans "Ephemeral" %}</label>
|
<label class="col-sm-3 col-form-label">{% trans "Ephemeral" %}</label>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<select name="ephemeral" class="form-control">
|
<select name="ephemeral" class="form-control">
|
||||||
<option value="no">{% trans "no" %}</option>
|
<option value="no">{% trans "no" %}</option>
|
||||||
<option value="yes">{% trans "yes" %}</option>
|
<option value="yes">{% trans "yes" %}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-3 col-form-label">{% trans "Private" %}</label>
|
|
||||||
<div class="col-sm-6">
|
|
||||||
<select name="private" class="form-control">
|
|
||||||
<option value="no">{% trans "no" %}</option>
|
|
||||||
<option value="yes">{% trans "yes" %}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-3 col-form-label">{% trans "Usage" %}</label>
|
|
||||||
<div class="col-sm-6">
|
|
||||||
<select name="usage_type" class="form-control">
|
|
||||||
<option value="ceph">{% trans "ceph" %}</option>
|
|
||||||
<option value="volume">{% trans "volume" %}</option>
|
|
||||||
<option value="iscsi">{% trans "iscsi" %}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-3 col-form-label">{% trans "Data" %}</label>
|
|
||||||
<div class="col-sm-6">
|
|
||||||
<input type="text" name="data" class="form-control" value="" required pattern="[a-z0-9\. ]+"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
|
|
||||||
<button type="submit" class="btn btn-primary" name="create">{% trans "Create" %}</button>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
<div class="form-group row">
|
||||||
</div> <!-- /.modal-content -->
|
<label class="col-sm-3 col-form-label">{% trans "Private" %}</label>
|
||||||
</div> <!-- /.modal-dialog -->
|
<div class="col-sm-6">
|
||||||
</div><!-- /.modal -->
|
<select name="private" class="form-control">
|
||||||
|
<option value="no">{% trans "no" %}</option>
|
||||||
|
<option value="yes">{% trans "yes" %}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-3 col-form-label">{% trans "Usage" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<select name="usage_type" class="form-control">
|
||||||
|
{% for key, usage_type in secret_usage_types.items %}
|
||||||
|
<option value="{{ usage_type }}">{{ usage_type }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-3 col-form-label">{% trans "Data" %}</label>
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input type="text" name="data" class="form-control" value="" required
|
||||||
|
pattern="[a-z0-9\. ]+" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
|
||||||
|
<button type="submit" class="btn btn-primary" name="create">{% trans "Create" %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div> <!-- /.modal-content -->
|
||||||
|
</div> <!-- /.modal-dialog -->
|
||||||
|
</div><!-- /.modal -->
|
||||||
{% endif %}
|
{% endif %}
|
|
@ -1,12 +1,17 @@
|
||||||
from secrets.forms import AddSecret
|
|
||||||
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from libvirt import libvirtError
|
from libvirt import libvirtError
|
||||||
|
from libvirt import (VIR_SECRET_USAGE_TYPE_NONE,
|
||||||
|
VIR_SECRET_USAGE_TYPE_CEPH,
|
||||||
|
VIR_SECRET_USAGE_TYPE_TLS,
|
||||||
|
VIR_SECRET_USAGE_TYPE_VOLUME,
|
||||||
|
VIR_SECRET_USAGE_TYPE_ISCSI)
|
||||||
|
|
||||||
from admin.decorators import superuser_only
|
from admin.decorators import superuser_only
|
||||||
from computes.models import Compute
|
from computes.models import Compute
|
||||||
|
from secrets.forms import AddSecret
|
||||||
from vrtManager.secrets import wvmSecrets
|
from vrtManager.secrets import wvmSecrets
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +26,14 @@ def secrets(request, compute_id):
|
||||||
secrets_all = []
|
secrets_all = []
|
||||||
error_messages = []
|
error_messages = []
|
||||||
compute = get_object_or_404(Compute, pk=compute_id)
|
compute = get_object_or_404(Compute, pk=compute_id)
|
||||||
|
secret_usage_types = {
|
||||||
|
VIR_SECRET_USAGE_TYPE_NONE: "none",
|
||||||
|
VIR_SECRET_USAGE_TYPE_VOLUME: "volume",
|
||||||
|
VIR_SECRET_USAGE_TYPE_CEPH: "ceph",
|
||||||
|
VIR_SECRET_USAGE_TYPE_ISCSI: "iscsi",
|
||||||
|
VIR_SECRET_USAGE_TYPE_TLS: "tls",
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = wvmSecrets(compute.hostname, compute.login, compute.password, compute.type)
|
conn = wvmSecrets(compute.hostname, compute.login, compute.password, compute.type)
|
||||||
secrets = conn.get_secrets()
|
secrets = conn.get_secrets()
|
||||||
|
@ -28,21 +41,25 @@ def secrets(request, compute_id):
|
||||||
for uuid in secrets:
|
for uuid in secrets:
|
||||||
secrt = conn.get_secret(uuid)
|
secrt = conn.get_secret(uuid)
|
||||||
try:
|
try:
|
||||||
secret_value = conn.get_secret_value(uuid)
|
secrt_value = conn.get_secret_value(uuid)
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
secret_value = None
|
secrt_value = None
|
||||||
secrets_all.append({
|
secrets_all.append({
|
||||||
'usage': secrt.usageID(),
|
'usage': secrt.usageID(),
|
||||||
'uuid': secrt.UUIDString(),
|
'uuid': secrt.UUIDString(),
|
||||||
'usageType': secrt.usageType(),
|
'usageType': secret_usage_types[secrt.usageType()],
|
||||||
'value': secret_value
|
'value': secrt_value
|
||||||
})
|
})
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if 'create' in request.POST:
|
if 'create' in request.POST:
|
||||||
form = AddSecret(request.POST)
|
form = AddSecret(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
data = form.cleaned_data
|
data = form.cleaned_data
|
||||||
conn.create_secret(data['ephemeral'], data['private'], data['usage_type'], data['data'])
|
conn.create_secret(
|
||||||
|
data['ephemeral'],
|
||||||
|
data['private'],
|
||||||
|
data['usage_type'],
|
||||||
|
data['data'])
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
else:
|
else:
|
||||||
for msg_err in form.errors.values():
|
for msg_err in form.errors.values():
|
||||||
|
@ -54,9 +71,12 @@ def secrets(request, compute_id):
|
||||||
if 'set_value' in request.POST:
|
if 'set_value' in request.POST:
|
||||||
uuid = request.POST.get('uuid', '')
|
uuid = request.POST.get('uuid', '')
|
||||||
value = request.POST.get('value', '')
|
value = request.POST.get('value', '')
|
||||||
conn.set_secret_value(uuid, value)
|
try:
|
||||||
|
conn.set_secret_value(uuid, value)
|
||||||
|
except Exception as err:
|
||||||
|
error_messages.append(err)
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
except libvirtError as err:
|
except libvirtError as err:
|
||||||
error_messages.append(err)
|
error_messages.append(err)
|
||||||
|
|
||||||
return render(request, 'secrets.html', locals())
|
return render(request, 'secrets.html', locals())
|
Loading…
Reference in a new issue