mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +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
|
|
@ -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…
Add table
Add a link
Reference in a new issue