mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +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
|
@ -1197,15 +1197,10 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
function random_mac(net) {
|
function random_mac(net) {
|
||||||
var hexDigits = "0123456789abcdef";
|
$.getJSON('/instance/random_mac_address/', function(data) {
|
||||||
var macAddress="52:54:00:";
|
$('input[name="clone-net-mac-'+net+'"]').val(data['mac']);
|
||||||
for (var i=0; i<3; i++) {
|
});
|
||||||
macAddress+=hexDigits.charAt(Math.round(Math.random()*16));
|
|
||||||
macAddress+=hexDigits.charAt(Math.round(Math.random()*16));
|
|
||||||
if (i != 2) macAddress+=":";
|
|
||||||
}
|
|
||||||
$('input[name="clone-net-mac-'+net+'"]').val(macAddress);
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
@ -1305,7 +1300,11 @@
|
||||||
$("#console_select_listen_address option[value='" + console_listen_address + "']").prop('selected', true);
|
$("#console_select_listen_address option[value='" + console_listen_address + "']").prop('selected', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
{% if not request.user.is_superuser %}
|
{% if request.user.is_superuser %}
|
||||||
|
$(document).ready(function () {
|
||||||
|
random_mac(0);
|
||||||
|
});
|
||||||
|
{% else %}
|
||||||
$('#select_clone_name').on('change', function () {
|
$('#select_clone_name').on('change', function () {
|
||||||
update_clone_disk_name($(this).val());
|
update_clone_disk_name($(this).val());
|
||||||
guess_mac_address('#select_clone_name', 0);
|
guess_mac_address('#select_clone_name', 0);
|
||||||
|
@ -1328,7 +1327,6 @@
|
||||||
<script>
|
<script>
|
||||||
function network_select_enable(){
|
function network_select_enable(){
|
||||||
// set network button enabled
|
// set network button enabled
|
||||||
|
|
||||||
var selected = $('network_select').val();
|
var selected = $('network_select').val();
|
||||||
if (selected != "to Change") {
|
if (selected != "to Change") {
|
||||||
$('button[name="change_network"]').removeAttr('disabled');
|
$('button[name="change_network"]').removeAttr('disabled');
|
||||||
|
|
|
@ -2,18 +2,12 @@ from django.conf.urls import url
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$',
|
url(r'^(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$', views.instance, name='instance'),
|
||||||
views.instance, name='instance'),
|
url(r'^statistics/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$', views.inst_graph, name='inst_graph'),
|
||||||
url(r'^statistics/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$',
|
url(r'^status/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$', views.inst_status, name='inst_status'),
|
||||||
views.inst_graph, name='inst_graph'),
|
url(r'^guess_mac_address/(?P<vname>[\w\-\.]+)/$', views.guess_mac_address, name='guess_mac_address'),
|
||||||
url(r'^status/(?P<compute_id>[0-9]+)/(?P<vname>[\w\-\.]+)/$',
|
url(r'^guess_clone_name/$', views.guess_clone_name, name='guess_clone_name'),
|
||||||
views.inst_status, name='inst_status'),
|
url(r'^random_mac_address/$', views.random_mac_address, name='random_mac_address'),
|
||||||
url(r'^guess_mac_address/(?P<vname>[\w\-\.]+)/$',
|
url(r'^check_instance/(?P<vname>[\w\-\.]+)/$', views.check_instance, name='check_instance'),
|
||||||
views.guess_mac_address, name='guess_mac_address'),
|
url(r'^sshkeys/(?P<vname>[\w\-\.]+)/$', views.sshkeys, name='sshkeys'),
|
||||||
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'),
|
|
||||||
url(r'^sshkeys/(?P<vname>[\w\-\.]+)/$',
|
|
||||||
views.sshkeys, name='sshkeys'),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,7 +5,7 @@ import socket
|
||||||
import crypt
|
import crypt
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
from random import choice
|
import random
|
||||||
from bisect import insort
|
from bisect import insort
|
||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
@ -526,7 +526,7 @@ def instance(request, compute_id, vname):
|
||||||
cache = request.POST.get('cache', '')
|
cache = request.POST.get('cache', '')
|
||||||
target = get_new_disk_dev(disks, bus)
|
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)
|
conn.attach_disk(path, target, subdriver=format, cache=cache, targetbus=bus)
|
||||||
msg = _('Attach new disk')
|
msg = _('Attach new disk')
|
||||||
addlogmsg(request.user.username, instance.name, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
|
@ -909,10 +909,10 @@ def inst_graph(request, compute_id, vname):
|
||||||
response.write(data)
|
response.write(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@login_required
|
|
||||||
def guess_mac_address(request, vname):
|
def _get_dhcp_mac_address(vname):
|
||||||
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
|
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
|
||||||
data = {'vname': vname, 'mac': '52:54:00:'}
|
mac = ''
|
||||||
if os.path.isfile(dhcp_file):
|
if os.path.isfile(dhcp_file):
|
||||||
with open(dhcp_file, 'r') as f:
|
with open(dhcp_file, 'r') as f:
|
||||||
name_found = False
|
name_found = False
|
||||||
|
@ -920,10 +920,37 @@ def guess_mac_address(request, vname):
|
||||||
if "host %s." % vname in line:
|
if "host %s." % vname in line:
|
||||||
name_found = True
|
name_found = True
|
||||||
if name_found and "hardware ethernet" in line:
|
if name_found and "hardware ethernet" in line:
|
||||||
data['mac'] = line.split(' ')[-1].strip().strip(';')
|
mac = line.split(' ')[-1].strip().strip(';')
|
||||||
break
|
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))
|
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
|
@login_required
|
||||||
def guess_clone_name(request):
|
def guess_clone_name(request):
|
||||||
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
|
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({'name': hostname}))
|
||||||
return HttpResponse(json.dumps({}))
|
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