mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 07:35:22 +00:00
add guess button for cloned instance name. this reads dhcp conf and uses settings.CLONE_INSTANCE_DEFAULT_PREFIX.
This commit is contained in:
parent
0b80b030fe
commit
f484598414
3 changed files with 35 additions and 3 deletions
|
@ -713,17 +713,23 @@
|
|||
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label" style="font-weight:normal;">{% trans "Clone Name" %}</label>
|
||||
{% if request.user.is_superuser %}
|
||||
<div class="col-sm-4">
|
||||
{% if request.user.is_superuser %}
|
||||
<input id="clone_name" type="text" class="form-control" name="name" value="{{ vname }}-clone"/>
|
||||
{% else %}
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<button type="button" class="btn btn-sm btn-success pull-left" name="guess-clone-name"
|
||||
onclick="guess_clone_name()" style="margin-top: 2px;">{% trans "Guess" %}</button>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="col-sm-4">
|
||||
<select id="select_clone_name" class="form-control" name="name" size="1"/>
|
||||
{% for name in clone_free_names %}
|
||||
<option value="{{ name }}">{{ name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if request.user.is_superuser %}
|
||||
<p style="font-weight:bold;">{% trans "Network devices" %}</p>
|
||||
|
@ -1040,6 +1046,15 @@
|
|||
});
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function guess_clone_name() {
|
||||
$.getJSON('/instance/guess_clone_name/', function(data) {
|
||||
guessed_name = data['name'].split(".")[0];
|
||||
$('#clone_name').val(guessed_name);
|
||||
update_clone_disk_name(guessed_name);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function update_clone_disk_name(new_vname) {
|
||||
vname = '{{ vname }}-clone';
|
||||
|
|
|
@ -10,6 +10,8 @@ urlpatterns = [
|
|||
views.inst_status, name='inst_status'),
|
||||
url(r'^guess_mac_address/(?P<vname>[\w\-\.]+)/$',
|
||||
views.guess_mac_address, name='guess_mac_address'),
|
||||
url(r'^guess_clone_name/$',
|
||||
views.guess_clone_name, name='guess_clone_name'),
|
||||
url(r'^check_instance/(?P<vname>[\w\-\.]+)/$',
|
||||
views.check_instance, name='check_instance'),
|
||||
]
|
||||
|
|
|
@ -780,6 +780,21 @@ def guess_mac_address(request, vname):
|
|||
break
|
||||
return HttpResponse(json.dumps(data));
|
||||
|
||||
@login_required
|
||||
def guess_clone_name(request):
|
||||
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
|
||||
prefix = settings.CLONE_INSTANCE_DEFAULT_PREFIX
|
||||
if os.path.isfile(dhcp_file):
|
||||
instance_names = [i.name for i in Instance.objects.filter(name__startswith=prefix)]
|
||||
with open(dhcp_file, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if "host %s" % prefix in line:
|
||||
hostname = line.split(' ')[1]
|
||||
if hostname.startswith(prefix) and hostname not in instance_names:
|
||||
return HttpResponse(json.dumps({'name': hostname}))
|
||||
return HttpResponse(json.dumps({}));
|
||||
|
||||
@login_required
|
||||
def check_instance(request, vname):
|
||||
check_instance = Instance.objects.filter(name=vname)
|
||||
|
|
Loading…
Reference in a new issue