mirror of
https://github.com/retspen/webvirtcloud.git
synced 2026-06-08 05:14:36 +00:00
guess_mac checks for existing dhcp_file
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
import socket
|
||||
@@ -676,14 +677,15 @@ def inst_graph(request, compute_id, vname):
|
||||
def guess_mac_address(request, vname):
|
||||
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
|
||||
data = { 'vname': vname, 'mac': '52:54:00:' }
|
||||
with open(dhcp_file, 'r') as f:
|
||||
name_found = False
|
||||
for line in f:
|
||||
if "host %s." % vname in line:
|
||||
name_found = True
|
||||
if name_found and "hardware ethernet" in line:
|
||||
data['mac'] = line.split(' ')[-1].strip().strip(';')
|
||||
break
|
||||
if os.path.isfile(dhcp_file):
|
||||
with open(dhcp_file, 'r') as f:
|
||||
name_found = False
|
||||
for line in f:
|
||||
if "host %s." % vname in line:
|
||||
name_found = True
|
||||
if name_found and "hardware ethernet" in line:
|
||||
data['mac'] = line.split(' ')[-1].strip().strip(';')
|
||||
break
|
||||
return HttpResponse(json.dumps(data));
|
||||
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user