changeset 50:7a02dee972c4

easy fix randomUUID
author kono
date Tue, 30 Jan 2018 22:13:22 +0900
parents b8887c40f8b8
children fecd206e005f
files ie-virsh.c newvm.py
diffstat 2 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ie-virsh.c	Mon Dec 12 16:55:28 2016 +0900
+++ b/ie-virsh.c	Tue Jan 30 22:13:22 2018 +0900
@@ -31,7 +31,7 @@
 #define define_gdb_command "define-gdb"
 
 
-const char *guests[] = {};
+const char *guests[] = {"145165B"};
 const char *managers[] = {"atton"};
 const char *students_identifier = "student";
 const char *teachers_identifier = "teacher";
@@ -170,8 +170,7 @@
     const int guests_num = sizeof(guests) / sizeof(guests[0]);
     int j = 0;
     for (; j < guests_num; j++) {
-        if (strncmp(account_name, guests[j], NAME_LENGTH) == 0) {
-            return GUESTS;
+        if (strncmp(account_name, guests[j], NAME_LENGTH) == 0) { return GUESTS;
         }
     }
 
--- a/newvm.py	Mon Dec 12 16:55:28 2016 +0900
+++ b/newvm.py	Tue Jan 30 22:13:22 2018 +0900
@@ -30,7 +30,9 @@
         return 0
     elif re.match('^managers/[-a-z0-9]+/0[1-4]$',name):
         return 0
-    elif re.match('^guests/[-a-z0-9]+/0[1-4]$',name):
+    elif re.match('^guests/[-a-zA-Z0-9]+/0[1-4]$',name):
+        return 0
+    elif re.match('^others/[-a-z0-9]+/0[1-4]$',name):
         return 0
     else:
         return 1
@@ -54,7 +56,9 @@
     if m is None:
         m=re.match('^(managers/[-a-z0-9]+)/0[1-4]$',name)
     if m is None:
-        m=re.match('^(guests/[-a-z0-9]+)/0[1-4]$',name)
+        m=re.match('^(guests/[-a-zA-Z0-9]+)/0[1-4]$',name)
+    if m is None:
+        m=re.match('^(others/[-a-z0-9]+)/0[1-4]$',name)
     if m is not None:
         dir=m.group(1)
         ie_mkdir1(mount_point+dir)
@@ -78,6 +82,14 @@
             random.randint(0x00, 0xff) ]
     return ':'.join(map(lambda x: "%02x" % x, mac))
 
+def randomUUID():
+    u = [random.randint(0, 255) for ignore in range(0, 16)]
+    u[6] = (u[6] & 0x0F) | (4 << 4)
+    u[8] = (u[8] & 0x3F) | (2 << 6)
+    return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2,
+                     "%02x" * 6]) % tuple(u)
+
+
 def genPassword():
     chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
     echars = "!@#$%^&*-,./"
@@ -118,7 +130,8 @@
 
 name.text = new_name
 uuid = config.find('uuid')
-uuid.text = randomUUID(0)
+("qemu:///system")
+uuid.text = randomUUID()
 mac = config.find('devices/interface/mac')
 mac.attrib['address'] = randomMAC()
 disk = config.find('devices/disk/source')
@@ -145,7 +158,7 @@
     print "File %s.xml exists, abort" % vm_name
     sys.exit(1)
 # config.write('/usr/local/etc/libvirt/qemu/' + vm_name + '.xml')
-print("VM_NAME:" + vm_name)
+print("VM_NAME:" + new_name)
 config.write('/etc/libvirt/qemu/' + vm_name + '.xml')
 print "Created vm config file %s.xml" % vm_name
 print "Use disk image %s" % disk_image