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

Merge remote-tracking branch 'remotes/retspen/master'

This commit is contained in:
catborise 2018-09-17 11:54:48 +03:00
commit 1bf99b796f
4 changed files with 72 additions and 43 deletions

View file

@ -213,6 +213,17 @@ Done!!
Go to http://serverip and you should see the login screen. 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 ### Default credentials
<pre> <pre>
login: admin login: admin

View file

@ -1,4 +1,18 @@
#!/bin/sh #!/bin/sh
# `/sbin/setuser www-data` runs the given command as the user `www-data`. # `/sbin/setuser www-data` runs the given command as the user `www-data`.
cd /srv/webvirtcloud RUNAS=`which setuser`
exec /sbin/setuser www-data /srv/webvirtcloud/venv/bin/python /srv/webvirtcloud/console/novncd >> /var/log/novncd.log 2>&1 [ -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

View file

@ -919,7 +919,7 @@
{% endif %} {% endif %}
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
<p style="font-weight:bold;">{% trans "Storage devices" %}</p> <p style="font-weight:bold;">{% trans "Storage devices" %}</p>
{% for disk in clone_disks %} {% for disk in disks %}
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label" style="font-weight:normal;">{{ disk.dev }} ({{ disk.storage }})</label> <label class="col-sm-3 control-label" style="font-weight:normal;">{{ disk.dev }} ({{ disk.storage }})</label>
<div class="col-sm-4"> <div class="col-sm-4">
@ -934,7 +934,7 @@
</div> </div>
{% endfor %} {% endfor %}
{% else %} {% 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 }}"/> <input id="disk_name-{{ disk.dev }}" type="hidden" class="form-control" name="disk-{{ disk.dev }}" value="{{ disk.image }}"/>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
@ -1271,17 +1271,13 @@
</script> </script>
<script> <script>
function update_clone_disk_name(new_vname) { function update_clone_disk_name(new_vname) {
vname = '{{ vname }}-clone'; vname = '{{ vname }}';
{% for disk in clone_disks %} {% for disk in disks %}
disk_name = '{{ disk.image }}'; 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 = disk_name.split('.')
disk_dot_suffix = disk_dot[disk_dot.length-1]; disk_dot_suffix = disk_dot[disk_dot.length-1];
if (disk_name.lastIndexOf('-') > -1 && disk_minus_name == vname) { if (disk_name.startsWith(vname)) {
image = new_vname + "-" + disk_minus_suffix; image = disk_name.replace(vname, new_vname);
} else if (disk_name.lastIndexOf('.') > -1 && disk_dot_suffix.length <= 7) { } else if (disk_name.lastIndexOf('.') > -1 && disk_dot_suffix.length <= 7) {
image = new_vname + "." + disk_dot_suffix image = new_vname + "." + disk_dot_suffix
} else if (new_vname != disk_name) { } else if (new_vname != disk_name) {
@ -1352,6 +1348,7 @@
$(document).ready(function () { $(document).ready(function () {
random_mac('clone-net-mac-0'); random_mac('clone-net-mac-0');
random_mac('add-net-mac'); random_mac('add-net-mac');
update_clone_disk_name($('#clone_name').val());
}); });
{% else %} {% else %}
$('#select_clone_name').on('change', function () { $('#select_clone_name').on('change', function () {

View file

@ -226,24 +226,6 @@ def instance(request, compute_id, vname):
if not userinstance: if not userinstance:
return HttpResponseRedirect(reverse('index')) 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): def filesizefstr(size_str):
if size_str == '': if size_str == '':
return 0 return 0
@ -274,6 +256,12 @@ def instance(request, compute_id, vname):
return free_names return free_names
def check_user_quota(instance, cpu, memory, disk_size): 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) user_instances = UserInstance.objects.filter(user_id=request.user.id, instance__is_template=False)
instance += user_instances.count() instance += user_instances.count()
for usr_inst in user_instances: for usr_inst in user_instances:
@ -290,8 +278,6 @@ def instance(request, compute_id, vname):
if disk['size']: if disk['size']:
disk_size += int(disk['size'])>>30 disk_size += int(disk['size'])>>30
ua = request.user.userattributes
msg = ""
if ua.max_instances > 0 and instance > ua.max_instances: if ua.max_instances > 0 and instance > ua.max_instances:
msg = "instance" msg = "instance"
if settings.QUOTA_DEBUG: 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']) snapshots = sorted(conn.get_snapshot(), reverse=True, key=lambda k:k['date'])
inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE) inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE)
has_managed_save_image = conn.get_managed_save_image() has_managed_save_image = conn.get_managed_save_image()
clone_disks = show_clone_disk(disks, vname)
console_passwd = conn.get_console_passwd() console_passwd = conn.get_console_passwd()
clone_free_names = get_clone_free_names() clone_free_names = get_clone_free_names()
user_quota_msg = check_user_quota(0, 0, 0, 0) 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] auto_vname = clone_free_names[0]
clone_data['name'] = auto_vname clone_data['name'] = auto_vname
clone_data['clone-net-mac-0'] = _get_dhcp_mac_address(auto_vname) clone_data['clone-net-mac-0'] = _get_dhcp_mac_address(auto_vname)
for post in clone_data.keys(): for disk in disks:
if post.startswith('disk-'): disk_dev = "disk-{}".format(disk['dev'])
disk_name = clone_data[post] disk_name = get_clone_disk_name(disk, vname, auto_vname)
if "-" in disk_name: clone_data[disk_dev] = 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']))
@ -1019,6 +998,34 @@ def check_instance(request, vname):
return HttpResponse(json.dumps(data)) 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): def sshkeys(request, vname):
""" """
:param request: :param request: