mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
commit
53d7d1365d
4 changed files with 72 additions and 43 deletions
11
README.md
11
README.md
|
@ -213,6 +213,17 @@ Done!!
|
|||
|
||||
Go to http://serverip and you should see the login screen.
|
||||
|
||||
### Alternative running novncd via runit
|
||||
Alternative to running nonvcd via supervisor is runit.
|
||||
|
||||
On Debian systems install runit and configure novncd service
|
||||
```
|
||||
apt install runit runit-systemd
|
||||
mkdir /etc/service/novncd/
|
||||
ln -s /srv/webvirtcloud/conf/runit/novncd.sh /etc/service/novncd/run
|
||||
systemctl start runit.service
|
||||
```
|
||||
|
||||
### Default credentials
|
||||
<pre>
|
||||
login: admin
|
||||
|
|
|
@ -1,4 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
# `/sbin/setuser www-data` runs the given command as the user `www-data`.
|
||||
cd /srv/webvirtcloud
|
||||
exec /sbin/setuser www-data /srv/webvirtcloud/venv/bin/python /srv/webvirtcloud/console/novncd >> /var/log/novncd.log 2>&1
|
||||
RUNAS=`which setuser`
|
||||
[ -z $RUNAS ] && RUNAS="`which sudo` -u"
|
||||
USER=www-data
|
||||
|
||||
DJANGO_PROJECT=/srv/webvirtcloud
|
||||
PYTHON=$DJANGO_PROJECT/venv/bin/python
|
||||
NOVNCD=$DJANGO_PROJECT/console/novncd
|
||||
|
||||
# make novncd debug, verbose
|
||||
#PARAMS="-d -v"
|
||||
|
||||
LOG=/var/log/novncd.log
|
||||
|
||||
cd $DJANGO_PROJECT
|
||||
exec $RUNAS $USER $PYTHON $NOVNCD $PARAMS >> $LOG 2>&1
|
||||
|
|
|
@ -914,7 +914,7 @@
|
|||
{% endif %}
|
||||
{% if request.user.is_superuser %}
|
||||
<p style="font-weight:bold;">{% trans "Storage devices" %}</p>
|
||||
{% for disk in clone_disks %}
|
||||
{% for disk in disks %}
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label" style="font-weight:normal;">{{ disk.dev }} ({{ disk.storage }})</label>
|
||||
<div class="col-sm-4">
|
||||
|
@ -929,7 +929,7 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for disk in clone_disks %}
|
||||
{% for disk in disks %}
|
||||
<input id="disk_name-{{ disk.dev }}" type="hidden" class="form-control" name="disk-{{ disk.dev }}" value="{{ disk.image }}"/>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
@ -1266,17 +1266,13 @@
|
|||
</script>
|
||||
<script>
|
||||
function update_clone_disk_name(new_vname) {
|
||||
vname = '{{ vname }}-clone';
|
||||
{% for disk in clone_disks %}
|
||||
vname = '{{ vname }}';
|
||||
{% for disk in disks %}
|
||||
disk_name = '{{ disk.image }}';
|
||||
disk_minus = disk_name.split('-');
|
||||
disk_minus_suffix = disk_minus[disk_minus.length-1];
|
||||
disk_minus.pop();
|
||||
disk_minus_name = disk_minus.join('-');
|
||||
disk_dot = disk_name.split('.')
|
||||
disk_dot_suffix = disk_dot[disk_dot.length-1];
|
||||
if (disk_name.lastIndexOf('-') > -1 && disk_minus_name == vname) {
|
||||
image = new_vname + "-" + disk_minus_suffix;
|
||||
if (disk_name.startsWith(vname)) {
|
||||
image = disk_name.replace(vname, new_vname);
|
||||
} else if (disk_name.lastIndexOf('.') > -1 && disk_dot_suffix.length <= 7) {
|
||||
image = new_vname + "." + disk_dot_suffix
|
||||
} else if (new_vname != disk_name) {
|
||||
|
@ -1346,6 +1342,7 @@
|
|||
$(document).ready(function () {
|
||||
random_mac('clone-net-mac-0');
|
||||
random_mac('add-net-mac');
|
||||
update_clone_disk_name($('#clone_name').val());
|
||||
});
|
||||
{% else %}
|
||||
$('#select_clone_name').on('change', function () {
|
||||
|
|
|
@ -226,24 +226,6 @@ def instance(request, compute_id, vname):
|
|||
if not userinstance:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
def show_clone_disk(disks, vname=''):
|
||||
clone_disk = []
|
||||
for disk in disks:
|
||||
if disk['image'] is None:
|
||||
continue
|
||||
if disk['image'].count("-") and disk['image'].rsplit("-", 1)[0] == vname:
|
||||
name, suffix = disk['image'].rsplit("-", 1)
|
||||
image = name + "-clone" + "-" + suffix
|
||||
elif disk['image'].count(".") and len(disk['image'].rsplit(".", 1)[1]) <= 7:
|
||||
name, suffix = disk['image'].rsplit(".", 1)
|
||||
image = name + "-clone" + "." + suffix
|
||||
else:
|
||||
image = disk['image'] + "-clone"
|
||||
clone_disk.append(
|
||||
{'dev': disk['dev'], 'storage': disk['storage'],
|
||||
'image': image, 'format': disk['format']})
|
||||
return clone_disk
|
||||
|
||||
def filesizefstr(size_str):
|
||||
if size_str == '':
|
||||
return 0
|
||||
|
@ -274,6 +256,12 @@ def instance(request, compute_id, vname):
|
|||
return free_names
|
||||
|
||||
def check_user_quota(instance, cpu, memory, disk_size):
|
||||
ua = request.user.userattributes
|
||||
msg = ""
|
||||
|
||||
if request.user.is_superuser:
|
||||
return msg
|
||||
|
||||
user_instances = UserInstance.objects.filter(user_id=request.user.id, instance__is_template=False)
|
||||
instance += user_instances.count()
|
||||
for usr_inst in user_instances:
|
||||
|
@ -290,8 +278,6 @@ def instance(request, compute_id, vname):
|
|||
if disk['size']:
|
||||
disk_size += int(disk['size'])>>30
|
||||
|
||||
ua = request.user.userattributes
|
||||
msg = ""
|
||||
if ua.max_instances > 0 and instance > ua.max_instances:
|
||||
msg = "instance"
|
||||
if settings.QUOTA_DEBUG:
|
||||
|
@ -369,7 +355,6 @@ def instance(request, compute_id, vname):
|
|||
snapshots = sorted(conn.get_snapshot(), reverse=True, key=lambda k:k['date'])
|
||||
inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||
has_managed_save_image = conn.get_managed_save_image()
|
||||
clone_disks = show_clone_disk(disks, vname)
|
||||
console_passwd = conn.get_console_passwd()
|
||||
clone_free_names = get_clone_free_names()
|
||||
user_quota_msg = check_user_quota(0, 0, 0, 0)
|
||||
|
@ -762,16 +747,10 @@ def instance(request, compute_id, vname):
|
|||
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
|
||||
for disk in disks:
|
||||
disk_dev = "disk-{}".format(disk['dev'])
|
||||
disk_name = get_clone_disk_name(disk, vname, auto_vname)
|
||||
clone_data[disk_dev] = disk_name
|
||||
|
||||
if not request.user.is_superuser and quota_msg:
|
||||
msg = _("User %s quota reached, cannot create '%s'!" % (quota_msg, clone_data['name']))
|
||||
|
@ -1019,6 +998,34 @@ def check_instance(request, vname):
|
|||
return HttpResponse(json.dumps(data))
|
||||
|
||||
|
||||
def get_clone_disk_name(disk, prefix, clone_name=''):
|
||||
if not disk['image']:
|
||||
return None
|
||||
if disk['image'].startswith(prefix) and clone_name:
|
||||
suffix = disk['image'][len(prefix):]
|
||||
image = "{}{}".format(clone_name, suffix)
|
||||
elif "." in disk['image'] and len(disk['image'].rsplit(".", 1)[1]) <= 7:
|
||||
name, suffix = disk['image'].rsplit(".", 1)
|
||||
image = "{}-clone.{}".format(name, suffix)
|
||||
else:
|
||||
image = "{}-clone".format(disk['image'])
|
||||
return image
|
||||
|
||||
def _get_clone_disks(disks, vname=''):
|
||||
clone_disks = []
|
||||
for disk in disks:
|
||||
new_image = get_clone_disk_name(disk, vname)
|
||||
if not new_image:
|
||||
continue
|
||||
new_disk = {
|
||||
'dev': disk['dev'],
|
||||
'storage': disk['storage'],
|
||||
'image': new_image,
|
||||
'format': disk['format']
|
||||
}
|
||||
clone_disks.append(new_disk)
|
||||
return clone_disks
|
||||
|
||||
def sshkeys(request, vname):
|
||||
"""
|
||||
:param request:
|
||||
|
|
Loading…
Reference in a new issue