1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

Merge pull request #110 from nitmir/passwd-vnc

Create instances with a random generated vnc password by default
This commit is contained in:
Anatoliy Guskov 2016-05-08 20:22:18 +03:00
commit 4ce76f57c6
3 changed files with 10 additions and 3 deletions

View file

@ -15,6 +15,7 @@ from accounts.models import UserInstance, UserSSHKey
from vrtManager.hostdetails import wvmHostDetails from vrtManager.hostdetails import wvmHostDetails
from vrtManager.instance import wvmInstance, wvmInstances from vrtManager.instance import wvmInstance, wvmInstances
from vrtManager.connection import connection_manager from vrtManager.connection import connection_manager
from vrtManager.util import randomPasswd
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE
from webvirtcloud.settings import QEMU_KEYMAPS, QEMU_CONSOLE_TYPES from webvirtcloud.settings import QEMU_KEYMAPS, QEMU_CONSOLE_TYPES
from logs.views import addlogmsg from logs.views import addlogmsg
@ -419,7 +420,7 @@ def instance(request, compute_id, vname):
if 'set_console_passwd' in request.POST: if 'set_console_passwd' in request.POST:
if request.POST.get('auto_pass', ''): if request.POST.get('auto_pass', ''):
passwd = ''.join([choice(letters + digits) for i in xrange(12)]) passwd = randomPasswd()
else: else:
passwd = request.POST.get('console_passwd', '') passwd = request.POST.get('console_passwd', '')
clear = request.POST.get('clear_pass', False) clear = request.POST.get('clear_pass', False)

View file

@ -227,7 +227,7 @@ class wvmCreate(wvmConnect):
xml += """ <input type='mouse' bus='ps2'/> xml += """ <input type='mouse' bus='ps2'/>
<input type='tablet' bus='usb'/> <input type='tablet' bus='usb'/>
<graphics type='%s' port='-1' autoport='yes' listen='0.0.0.0'> <graphics type='%s' port='-1' autoport='yes' listen='0.0.0.0' passwd='%s'>
<listen type='address' address='0.0.0.0'/> <listen type='address' address='0.0.0.0'/>
</graphics> </graphics>
<console type='pty'/> <console type='pty'/>
@ -236,5 +236,5 @@ class wvmCreate(wvmConnect):
</video> </video>
<memballoon model='virtio'/> <memballoon model='virtio'/>
</devices> </devices>
</domain>""" % QEMU_CONSOLE_DEFAULT_TYPE </domain>""" % (QEMU_CONSOLE_DEFAULT_TYPE, util.randomPasswd())
self._defineXML(xml) self._defineXML(xml)

View file

@ -1,6 +1,7 @@
import random import random
import libxml2 import libxml2
import libvirt import libvirt
import string
def is_kvm_available(xml): def is_kvm_available(xml):
@ -29,6 +30,11 @@ def randomUUID():
return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2, "%02x" * 6]) % tuple(u) return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2, "%02x" * 6]) % tuple(u)
def randomPasswd(length=12, alphabet=string.letters + string.digits):
"""Generate a random password"""
return ''.join([random.choice(alphabet) for i in xrange(length)])
def get_max_vcpus(conn, type=None): def get_max_vcpus(conn, type=None):
"""@param conn: libvirt connection to poll for max possible vcpus """@param conn: libvirt connection to poll for max possible vcpus
@type type: optional guest type (kvm, etc.)""" @type type: optional guest type (kvm, etc.)"""