1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 12:04:15 +00:00

add settings.CLONE_INSTANCE_AUTO_NAME. add mechanism that automatically selects new vname, mac, disk image names.

This commit is contained in:
Ing. Jan KRCMAR 2018-06-19 13:06:57 +02:00
parent 22d03da60f
commit 4404d5941b
3 changed files with 30 additions and 4 deletions

View file

@ -843,6 +843,10 @@
<button type="button" class="btn btn-sm btn-success pull-left" name="guess-clone-name" <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> onclick="guess_clone_name()" style="margin-top: 2px;">{% trans "Guess" %}</button>
</div> </div>
{% elif clone_instance_auto_name %}
<div class="col-sm-4">
<input id="clone_instance_auto_name" type="text" class="form-control" name="auto_name" value="Automatic" disabled/>
</div>
{% else %} {% else %}
<div class="col-sm-4"> <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"/>

View file

@ -348,6 +348,7 @@ def instance(request, compute_id, vname):
default_bus = settings.INSTANCE_VOLUME_DEFAULT_BUS default_bus = settings.INSTANCE_VOLUME_DEFAULT_BUS
show_access_root_password = settings.SHOW_ACCESS_ROOT_PASSWORD show_access_root_password = settings.SHOW_ACCESS_ROOT_PASSWORD
show_access_ssh_keys = settings.SHOW_ACCESS_SSH_KEYS show_access_ssh_keys = settings.SHOW_ACCESS_SSH_KEYS
clone_instance_auto_name = settings.CLONE_INSTANCE_AUTO_NAME
try: try:
instance = Instance.objects.get(compute_id=compute_id, name=vname) instance = Instance.objects.get(compute_id=compute_id, name=vname)
@ -705,6 +706,21 @@ def instance(request, compute_id, vname):
for post in request.POST: for post in request.POST:
clone_data[post] = request.POST.get(post, '').strip() clone_data[post] = request.POST.get(post, '').strip()
if clone_instance_auto_name:
auto_vname = clone_free_names[0]
clone_data['name'] = auto_vname
clone_data['clone-net-mac-0'] = _get_dhcp_mac_address(auto_vname)
for post in clone_data.keys():
if post.startswith('disk-'):
disk_name = clone_data[post]
if "-" in disk_name:
suffix = disk_name.split("-")[-1]
disk_name = '-'.join((auto_vname, suffix))
else:
suffix = disk_name.split(".")[-1]
disk_name = '.'.join((auto_vname, suffix))
clone_data[post] = disk_name
if not request.user.is_superuser and quota_msg: if not request.user.is_superuser and quota_msg:
msg = _("User %s quota reached, cannot create '%s'!" % (quota_msg, clone_data['name'])) msg = _("User %s quota reached, cannot create '%s'!" % (quota_msg, clone_data['name']))
error_messages.append(msg) error_messages.append(msg)
@ -883,10 +899,9 @@ def inst_graph(request, compute_id, vname):
response.write(data) response.write(data)
return response return response
@login_required def _get_dhcp_mac_address(vname):
def guess_mac_address(request, vname):
dhcp_file = '/srv/webvirtcloud/dhcpd.conf' dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
data = { 'vname': vname, 'mac': '52:54:00:' } mac = '52:54:00:'
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
@ -894,8 +909,14 @@ 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 }
data['mac'] = _get_dhcp_mac_address(vname)
return HttpResponse(json.dumps(data)) return HttpResponse(json.dumps(data))
@login_required @login_required

View file

@ -125,6 +125,7 @@ LIBVIRT_KEEPALIVE_COUNT = 5
ALLOW_INSTANCE_MULTIPLE_OWNER = True ALLOW_INSTANCE_MULTIPLE_OWNER = True
NEW_USER_DEFAULT_INSTANCES = [] NEW_USER_DEFAULT_INSTANCES = []
CLONE_INSTANCE_DEFAULT_PREFIX = 'instance' CLONE_INSTANCE_DEFAULT_PREFIX = 'instance'
CLONE_INSTANCE_AUTO_NAME = False
LOGS_PER_PAGE = 100 LOGS_PER_PAGE = 100
QUOTA_DEBUG = True QUOTA_DEBUG = True
ALLOW_EMPTY_PASSWORD = True ALLOW_EMPTY_PASSWORD = True