Mercurial > hg > Applications > virsh-wrapper
changeset 7:bff4054ed58f
looks like working...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Nov 2012 11:14:34 +0900 |
parents | 25c14d1144a8 |
children | b2e2eec87764 |
files | Makefile ie-virsh.c newvm.py |
diffstat | 3 files changed, 20 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Tue Nov 13 10:36:15 2012 +0900 +++ b/Makefile Tue Nov 13 11:14:34 2012 +0900 @@ -6,5 +6,11 @@ sudo chown root $(TARGET) sudo chmod 4711 $(TARGET) +install: $(TARGET) newvm.py + install ie-virsh /usr/local/bin/ + install newvm.py /usr/local/bin/ + chmod 4711 /usr/local/bin/ie-virsh + chmod 755 /usr/local/bin/newvm.py + clean: rm $(TARGET)
--- a/ie-virsh.c Tue Nov 13 10:36:15 2012 +0900 +++ b/ie-virsh.c Tue Nov 13 11:14:34 2012 +0900 @@ -136,6 +136,7 @@ setgid(0); setuid(0); + if (argc>=3) { if ( strncmp(argv[1], "define", 6) == 0 ) { if (regexec(pattern, argv[2], (size_t) 0, NULL, 0)) { @@ -147,8 +148,9 @@ exit(0); } char exec[1024]; - strncpy("/usr/local/bin/newvm.py ",exec,1024); - strncpy(argv[2],exec,1000); + strncpy(exec, "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/fedora16.xml -n ",900); + strncat(exec, argv[2],1000); + fprintf(stdout, "excuting %s\n",exec ); system(exec); } } @@ -156,8 +158,12 @@ VMLISTPTR vmlist = get_vmlist(pattern); + char name_xml[1024]; + name_xml[0] = 0; if (argc>=3) { if ( strncmp(argv[1], "define", 6) == 0 ) { + strncpy(name_xml,argv[2],900); + strncat(name_xml,".xml",1000); } else if (check_vmlist_name(vmlist, argv[2])==0) { fprintf(stderr, "bad vmname\n"); print_vmlist(vmlist); @@ -188,7 +194,8 @@ perror("Execl:"); } } else if ( strncmp(argv[1], "define", 6) == 0 ) { - if (execl(command, command, define_command, argv[2], NULL) < 0) { + chdir("/etc/libvirt/qemu"); + if (execl(command, command, define_command, name_xml, NULL) < 0) { perror("Execl:"); } } else {
--- a/newvm.py Tue Nov 13 10:36:15 2012 +0900 +++ b/newvm.py Tue Nov 13 11:14:34 2012 +0900 @@ -17,9 +17,9 @@ m=re.match('^students/e(\d\d)/e(\d\d57)\d\d/0[1-4]$',name) if m is not None: if m.group(1)==m.group(2): - return 1 + return 0 else: - return 0 + return 1 elif re.match('^teachers/[-a-z0-9]+/0[1-4]$',name): return 0 else: @@ -37,7 +37,7 @@ def ie_mkdir(name): m=re.match('^(students/e\d\d/e\d\d57\d\d)/0[1-4]$',name) if m is None: - m=re.match('^(teachers/[-a-z0-9]+/0[1-4]$',name) + m=re.match('^(teachers/[-a-z0-9]+)/0[1-4]$',name) if m is not None: dir=m.group(1) ie_mkdir1('/media/fcs/'+dir) @@ -61,7 +61,7 @@ config = ET.parse(options.config) vm_name = options.name if ie_check_name(vm_name): - print "Bad vmname %s. Try students/e11/e115711/01 or teacher/kono/02" % vm_name + print "Bad vmname %s. Try students/e11/e115711/01 or teachers/kono/02" % vm_name sys.exit(1) ie_mkdir(vm_name)