changeset 32:4bd7d676e608

add debugvm.py to method for manage port.
author taiki
date Tue, 16 Dec 2014 03:24:00 +0900
parents ea7578513baa
children 83d66786f576
files Makefile ie-virsh.c newvm.py
diffstat 3 files changed, 35 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Oct 21 17:54:43 2014 +0900
+++ b/Makefile	Tue Dec 16 03:24:00 2014 +0900
@@ -15,7 +15,6 @@
 	install ie-virsh $(INSTALL_DIR)
 	install newvm.py $(INSTALL_DIR)
 	chmod 4711 $(INSTALL_DIR)/ie-virsh
-	chmod 4711 $(INSTALL_DIR)/ie-vagrant
 	chmod 755 $(INSTALL_DIR)/newvm.py
 
 clean:
--- a/ie-virsh.c	Tue Oct 21 17:54:43 2014 +0900
+++ b/ie-virsh.c	Tue Dec 16 03:24:00 2014 +0900
@@ -23,16 +23,17 @@
 #define undefine_command "undefine"
 #define dumpxml_command "dumpxml"
 #define console_command "console"
+#define debug_command "debug"
 
 
 const char *guests[] = {"mata"};
-const char *managers[] = {"taiki"};
+const char *managers[] = {"taira"};
 const char students_sym[] = "students";
 const char managers_sym[] = "managers";
 const char guests_sym[] = "guests";
 const char delimiter[] = "_";
 
-static char bad_name[] = "Bad vmname. Try 01 or 02 ... 04";
+static char bad_name[] = "Bad vmname. Try 01 or 02 ... 04\n";
 
 enum {
     NAME_LENGTH = 50,
@@ -124,7 +125,7 @@
 usage()
 {
     printf("Usage: COMMAND [define|list|start|destroy|xmldump|undefine|console] [vm-name]\n");
-    printf("   vm-name should be 01 - 02\n");
+    printf("   vm-name should be 01 - 04\n");
 }
 
 int
@@ -242,7 +243,7 @@
 
     char *vm_name = (char *)malloc(sizeof(char) * VM_NAME_LENGTH);
     vm_name[0] = '\0';
-    if (strncmp(argv[1], "list", 4) != 0) {
+    if (!(strncmp(argv[1], "list", 4) == 0 || strncmp(argv[1], debug_command, 5) == 0)) {
         const char *regex = "0[1-4]";
         regex_t *num_pattern = NEW(regex_t);
 
@@ -344,6 +345,24 @@
         if (execl(command, command, undefine_command, vm_name, NULL) < 0) {
             perror("Execl:");
         }
+    } else if (strncmp(argv[1], debug_command, 5) == 0) {
+        char *user_name = (char *)malloc(sizeof(char) * VM_NAME_LENGTH);
+        strncpy(user_name,  "\0", 1);
+        make_vm_name(user_name, account_type, name, debug_command);
+
+        char str_uid[1024];
+        sprintf(str_uid, "%d", uid);
+
+        char debug_exec[1026];
+        sprintf(debug_exec, "/usr/local/bin/debugvm.py --name %s --uid %s --config %s", user_name, str_uid, "/etc/libvirt/qemu/debugvm.xml");
+        free(user_name);
+
+        printf("debug_exec::%s \n", debug_exec);
+
+        char gdb_exec[1024];
+        strncpy(gdb_exec, "/usr/bin/gdb",900);
+//      strncat(gdb_exec, " /usr/lib/debug/lib/modules/3.17.4-200.fc20.x86_64/vmlinux", 900);
+//      system(gdb_exec);
     } else {
         usage();
         exit(1);
--- a/newvm.py	Tue Oct 21 17:54:43 2014 +0900
+++ b/newvm.py	Tue Dec 16 03:24:00 2014 +0900
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # Used to create a vm from template
 # By Curu Wong contact: prinbra(at)gmail(dot)com
-import sys,os,string
+import sys,os,string,re
 from optparse import OptionParser
 from virtinst.util import *
 
@@ -10,6 +10,8 @@
 else:
     import xml.etree.ElementTree as ET
 
+mount_point = '/media/fcs/' # root directory
+
 # vm_name should be
 #     students/e10/e105730/01
 #     teachers/kono/01
@@ -17,7 +19,7 @@
 #     guests/name/01
 #     bad name returns 1
 def ie_check_name(name):
-    m=re.match('^students/e(\d\d)/e(\d\d)5\d\d\d/0[1-4]$',name)
+    m=re.match('^students/[ek](\d\d)/[ek](\d\d)[58]\d\d\d/0[1-4]$',name)
     if m is not None:
         if m.group(1)==m.group(2):
             return 0
@@ -41,8 +43,11 @@
     if not os.path.exists(name):
         os.makedirs(name);
 
+
+# sample : students/e14/k145740/01
+#        : master students/k13/k138582/01
 def ie_mkdir(name):
-    m=re.match('^(students/e\d\d/e\d\d5\d\d\d)/0[1-4]$',name)
+    m=re.match('^(students/[ek]\d\d/[ek]\d\d[58]\d\d\d)/0[1-4]$',name)
     if m is None:
         m=re.match('^(teachers/[-a-z0-9]+)/0[1-4]$',name)
     if m is None:
@@ -51,7 +56,7 @@
         m=re.match('^(guests/[-a-z0-9]+)/0[1-4]$',name)
     if m is not None:
         dir=m.group(1)
-        ie_mkdir1('/media/fcs/'+dir)
+        ie_mkdir1(mount_point+dir)
 #        ie_mkdir1('/usr/local/etc/libvirt/qemu/'+dir)
 #        ie_mkdir1('/usr/local/var/log/libvirt/qemu/'+dir)
 #        ie_mkdir1('/usr/local/var/run/libvirt/qemu/'+dir)
@@ -60,14 +65,13 @@
         ie_mkdir1('/var/log/libvirt/qemu/'+dir)
         ie_mkdir1('/var/run/libvirt/qemu/'+dir)
         ie_mkdir1('/var/lib/libvirt/qemu/'+dir)
-        os.system("/bin/chown "+os.getlogin()+" /media/fcs/"+dir)
+        os.system("/bin/chown "+os.getlogin()+" "+ mount_point+dir)
 
 parser = OptionParser();
 parser.add_option("-n", "--name", dest="name",
         help="VM name");
 parser.add_option("-c", "--config", dest="config",
         help="Template VM XML config file");
-
 parser.add_option("-i", "--iso", dest="iso",
         help="When boot VM from ISO");
 
@@ -81,7 +85,7 @@
 vm_name = options.name
 print(options.config)
 if ie_check_name(vm_name):
-    print "Bad vmname %s. Try 01 - 04" % vm_name
+    print "Can't make new vm. Bad vmname %s. Try 01 - 04" % vm_name
     sys.exit(1)
 
 ie_mkdir(vm_name)
@@ -105,6 +109,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)
 config.write('/etc/libvirt/qemu/' + vm_name + '.xml')
 print "Created vm config file %s.xml" % vm_name
 print "Use disk image %s, you must create it from the template disk: %s" % (disk_image, disk_old)