mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 15:45:23 +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 %}
|
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-3 control-label" style="font-weight:normal;">{% trans "Clone Name" %}</label>
|
<label class="col-sm-3 control-label" style="font-weight:normal;">{% trans "Clone Name" %}</label>
|
||||||
<div class="col-sm-4">
|
|
||||||
{% if request.user.is_superuser %}
|
{% if request.user.is_superuser %}
|
||||||
|
<div class="col-sm-4">
|
||||||
<input id="clone_name" type="text" class="form-control" name="name" value="{{ vname }}-clone"/>
|
<input id="clone_name" type="text" class="form-control" name="name" value="{{ vname }}-clone"/>
|
||||||
|
</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 %}
|
{% else %}
|
||||||
|
<div class="col-sm-4">
|
||||||
<select id="select_clone_name" class="form-control" name="name" size="1"/>
|
<select id="select_clone_name" class="form-control" name="name" size="1"/>
|
||||||
{% for name in clone_free_names %}
|
{% for name in clone_free_names %}
|
||||||
<option value="{{ name }}">{{ name }}</option>
|
<option value="{{ name }}">{{ name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if request.user.is_superuser %}
|
{% if request.user.is_superuser %}
|
||||||
<p style="font-weight:bold;">{% trans "Network devices" %}</p>
|
<p style="font-weight:bold;">{% trans "Network devices" %}</p>
|
||||||
|
@ -1040,6 +1046,15 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</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>
|
<script>
|
||||||
function update_clone_disk_name(new_vname) {
|
function update_clone_disk_name(new_vname) {
|
||||||
vname = '{{ vname }}-clone';
|
vname = '{{ vname }}-clone';
|
||||||
|
|
|
@ -10,6 +10,8 @@ urlpatterns = [
|
||||||
views.inst_status, name='inst_status'),
|
views.inst_status, name='inst_status'),
|
||||||
url(r'^guess_mac_address/(?P<vname>[\w\-\.]+)/$',
|
url(r'^guess_mac_address/(?P<vname>[\w\-\.]+)/$',
|
||||||
views.guess_mac_address, name='guess_mac_address'),
|
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\-\.]+)/$',
|
url(r'^check_instance/(?P<vname>[\w\-\.]+)/$',
|
||||||
views.check_instance, name='check_instance'),
|
views.check_instance, name='check_instance'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -780,6 +780,21 @@ def guess_mac_address(request, vname):
|
||||||
break
|
break
|
||||||
return HttpResponse(json.dumps(data));
|
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
|
@login_required
|
||||||
def check_instance(request, vname):
|
def check_instance(request, vname):
|
||||||
check_instance = Instance.objects.filter(name=vname)
|
check_instance = Instance.objects.filter(name=vname)
|
||||||
|
|
Loading…
Reference in a new issue