mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-23 22:55:23 +00:00
add settings.CLONE_INSTANCE_AUTO_NAME. add mechanism that automatically selects new vname, mac, disk image names.
This commit is contained in:
parent
22d03da60f
commit
4404d5941b
3 changed files with 30 additions and 4 deletions
|
@ -843,6 +843,10 @@
|
|||
<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>
|
||||
</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 %}
|
||||
<div class="col-sm-4">
|
||||
<select id="select_clone_name" class="form-control" name="name" size="1"/>
|
||||
|
|
|
@ -348,6 +348,7 @@ def instance(request, compute_id, vname):
|
|||
default_bus = settings.INSTANCE_VOLUME_DEFAULT_BUS
|
||||
show_access_root_password = settings.SHOW_ACCESS_ROOT_PASSWORD
|
||||
show_access_ssh_keys = settings.SHOW_ACCESS_SSH_KEYS
|
||||
clone_instance_auto_name = settings.CLONE_INSTANCE_AUTO_NAME
|
||||
|
||||
try:
|
||||
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:
|
||||
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:
|
||||
msg = _("User %s quota reached, cannot create '%s'!" % (quota_msg, clone_data['name']))
|
||||
error_messages.append(msg)
|
||||
|
@ -883,10 +899,9 @@ 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 = '52:54:00:'
|
||||
if os.path.isfile(dhcp_file):
|
||||
with open(dhcp_file, 'r') as f:
|
||||
name_found = False
|
||||
|
@ -894,8 +909,14 @@ 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 }
|
||||
data['mac'] = _get_dhcp_mac_address(vname)
|
||||
return HttpResponse(json.dumps(data))
|
||||
|
||||
@login_required
|
||||
|
|
|
@ -125,6 +125,7 @@ LIBVIRT_KEEPALIVE_COUNT = 5
|
|||
ALLOW_INSTANCE_MULTIPLE_OWNER = True
|
||||
NEW_USER_DEFAULT_INSTANCES = []
|
||||
CLONE_INSTANCE_DEFAULT_PREFIX = 'instance'
|
||||
CLONE_INSTANCE_AUTO_NAME = False
|
||||
LOGS_PER_PAGE = 100
|
||||
QUOTA_DEBUG = True
|
||||
ALLOW_EMPTY_PASSWORD = True
|
||||
|
|
Loading…
Reference in a new issue