diff --git a/instances/views.py b/instances/views.py
index 8d9afd9..0109631 100644
--- a/instances/views.py
+++ b/instances/views.py
@@ -15,6 +15,7 @@ from accounts.models import UserInstance, UserSSHKey
from vrtManager.hostdetails import wvmHostDetails
from vrtManager.instance import wvmInstance, wvmInstances
from vrtManager.connection import connection_manager
+from vrtManager.util import randomPasswd
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE
from webvirtcloud.settings import QEMU_KEYMAPS, QEMU_CONSOLE_TYPES
from logs.views import addlogmsg
@@ -419,7 +420,7 @@ def instance(request, compute_id, vname):
if 'set_console_passwd' in request.POST:
if request.POST.get('auto_pass', ''):
- passwd = ''.join([choice(letters + digits) for i in xrange(12)])
+ passwd = randomPasswd()
else:
passwd = request.POST.get('console_passwd', '')
clear = request.POST.get('clear_pass', False)
diff --git a/vrtManager/create.py b/vrtManager/create.py
index cc1f7f2..59496c2 100644
--- a/vrtManager/create.py
+++ b/vrtManager/create.py
@@ -227,7 +227,7 @@ class wvmCreate(wvmConnect):
xml += """
-
+
@@ -236,5 +236,5 @@ class wvmCreate(wvmConnect):
- """ % QEMU_CONSOLE_DEFAULT_TYPE
+ """ % (QEMU_CONSOLE_DEFAULT_TYPE, util.randomPasswd())
self._defineXML(xml)
diff --git a/vrtManager/util.py b/vrtManager/util.py
index 939e5b7..23e9498 100644
--- a/vrtManager/util.py
+++ b/vrtManager/util.py
@@ -1,6 +1,7 @@
import random
import libxml2
import libvirt
+import string
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)
+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):
"""@param conn: libvirt connection to poll for max possible vcpus
@type type: optional guest type (kvm, etc.)"""