mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Random mac address for cloned vm issue fixed by @honza801
This commit is contained in:
parent
1700ddf8f1
commit
340d93463e
3 changed files with 51 additions and 31 deletions
|
|
@ -5,7 +5,7 @@ import socket
|
|||
import crypt
|
||||
import re
|
||||
import string
|
||||
from random import choice
|
||||
import random
|
||||
from bisect import insort
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
|
|
@ -526,7 +526,7 @@ def instance(request, compute_id, vname):
|
|||
cache = request.POST.get('cache', '')
|
||||
target = get_new_disk_dev(disks, bus)
|
||||
|
||||
path = connCreate.create_volume(storage, name, size, format, meta_prealloc, extension)
|
||||
path = connCreate.create_volume(storage, name, size, format, meta_prealloc)
|
||||
conn.attach_disk(path, target, subdriver=format, cache=cache, targetbus=bus)
|
||||
msg = _('Attach new disk')
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
|
|
@ -909,10 +909,10 @@ def inst_graph(request, compute_id, vname):
|
|||
response.write(data)
|
||||
return response
|
||||
|
||||
@login_required
|
||||
def guess_mac_address(request, vname):
|
||||
|
||||
def _get_dhcp_mac_address(vname):
|
||||
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
|
||||
data = {'vname': vname, 'mac': '52:54:00:'}
|
||||
mac = ''
|
||||
if os.path.isfile(dhcp_file):
|
||||
with open(dhcp_file, 'r') as f:
|
||||
name_found = False
|
||||
|
|
@ -920,10 +920,37 @@ def guess_mac_address(request, vname):
|
|||
if "host %s." % vname in line:
|
||||
name_found = True
|
||||
if name_found and "hardware ethernet" in line:
|
||||
data['mac'] = line.split(' ')[-1].strip().strip(';')
|
||||
mac = line.split(' ')[-1].strip().strip(';')
|
||||
break
|
||||
return mac
|
||||
|
||||
|
||||
@login_required
|
||||
def guess_mac_address(request, vname):
|
||||
data = { 'vname': vname }
|
||||
mac = _get_dhcp_mac_address(vname)
|
||||
if not mac:
|
||||
mac = _get_random_mac_address()
|
||||
data['mac'] = mac
|
||||
return HttpResponse(json.dumps(data))
|
||||
|
||||
|
||||
def _get_random_mac_address():
|
||||
mac = '52:54:00:%02x:%02x:%02x' % (
|
||||
random.randint(0x00, 0xff),
|
||||
random.randint(0x00, 0xff),
|
||||
random.randint(0x00, 0xff)
|
||||
)
|
||||
return mac
|
||||
|
||||
|
||||
@login_required
|
||||
def random_mac_address(request):
|
||||
data = {}
|
||||
data['mac'] = _get_random_mac_address()
|
||||
return HttpResponse(json.dumps(data))
|
||||
|
||||
|
||||
@login_required
|
||||
def guess_clone_name(request):
|
||||
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
|
||||
|
|
@ -940,6 +967,7 @@ def guess_clone_name(request):
|
|||
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