changeset 49:b8887c40f8b8

vncdisplay
author mir3636
date Mon, 12 Dec 2016 16:55:28 +0900
parents 03a2140b2b76
children 7a02dee972c4
files Makefile ie-virsh-template.xml ie-virsh.c libvirtd.sh newvm.py
diffstat 5 files changed, 28 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Dec 07 17:59:41 2016 +0900
+++ b/Makefile	Mon Dec 12 16:55:28 2016 +0900
@@ -11,11 +11,13 @@
 	sudo chown root $(TARGET)
 	sudo chmod 4711 $(TARGET)
 
-install: $(TARGET) $(TARGET2) newvm.py
+install: $(TARGET) newvm.py
 	install ie-virsh $(INSTALL_DIR)
 	install newvm.py $(INSTALL_DIR)
+	install ie-virsh-template.xml /etc/libvirt/qemu 
 	chmod 4711 $(INSTALL_DIR)/ie-virsh
 	chmod 755 $(INSTALL_DIR)/newvm.py
+	chmod 644 /etc/libvirt/qemu/ie-virsh-template.xml
 
 clean:
-	rm -f $(TARGET) $(TARGET2) *.o
+	rm -f $(TARGET) *.o
--- a/ie-virsh-template.xml	Wed Dec 07 17:59:41 2016 +0900
+++ b/ie-virsh-template.xml	Mon Dec 12 16:55:28 2016 +0900
@@ -80,5 +80,6 @@
     <memballoon model='virtio'>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
     </memballoon>
+    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
   </devices>
 </domain>
--- a/ie-virsh.c	Wed Dec 07 17:59:41 2016 +0900
+++ b/ie-virsh.c	Mon Dec 12 16:55:28 2016 +0900
@@ -144,7 +144,7 @@
 void
 usage()
 {
-    printf("Usage: COMMAND [define|define-gdb|list|start|destroy|dumpxml|undefine|console] [vm-name]\n");
+    printf("Usage: COMMAND [define|define-gdb|list|start|destroy|dumpxml|vncdisplay|undefine|console] [vm-name]\n");
     printf("   vm-name should be 01 - 04\n");
 }
 
@@ -354,6 +354,12 @@
         if (execl(command, command, dumpxml_command, vm_name, NULL) < 0) {
             perror("Execl:");
         }
+    } else if ( strncmp(argv[1], "vncdisplay", 10) == 0 ) {
+        if (argc<3) {usage(); exit(1);}
+        check_vmlist_name(vmlist, argv[2]);
+        if (execl(command, command, "vncdisplay", vm_name, NULL) < 0) {
+            perror("Execl:");
+        }
     } else if ( strncmp(argv[1], console_command, 8) == 0 ) {
         if (argc<3) {usage(); exit(1);}
         check_vmlist_name(vmlist, argv[2]);
--- a/libvirtd.sh	Wed Dec 07 17:59:41 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-#! /bin/sh
-### BEGIN INIT INFO
-# Provides:          atd
-# Required-Start:    $syslog $time $remote_fs
-# Required-Stop:     $syslog $time $remote_fs
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: Deferred execution scheduler
-# Description:       Debian init script for the atd deferred executions
-#                    scheduler
-### END INIT INFO
-#
-# Author:	TaikiTAIRA	
-#
-
-PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin
-DAEMON=/usr/local/sbin/libvirtd
-PIDFILE=/usr/local/var/run/libvirtd.pid
-
-test -x $DAEMON || exit 0
-
-. /lib/lsb/init-functions
-
-case "$1" in
-  start)
-	log_daemon_msg "Starting libvirt daemon." "libvirt"
-	start_daemon -p $PIDFILE $DAEMON -d
-	log_end_msg $?
-    ;;
-  stop)
-	log_daemon_msg "Stopping stop libvirt daemon" "libvirt"
-	killproc -p $PIDFILE $DAEMON
-	log_end_msg $?
-    ;;
-  force-reload|restart)
-    $0 stop
-    $0 start
-    ;;
-  status)
-    status_of_proc -p $PIDFILE $DAEMON libvirtd && exit 0 || exit $?
-    ;;
-  *)
-    echo "Usage: /etc/init.d/libvirtd {start|stop|restart|force-reload|status}"
-    exit 1
-    ;;
-esac
-
-exit 0
--- a/newvm.py	Wed Dec 07 17:59:41 2016 +0900
+++ b/newvm.py	Mon Dec 12 16:55:28 2016 +0900
@@ -4,6 +4,7 @@
 import sys,os,string,re
 from optparse import OptionParser
 from virtinst.util import *
+import string
 
 if sys.version_info < (2,5):
     import lxml.etree as ET
@@ -69,6 +70,7 @@
 
 # virtinst.utils.randomMac is omitted from RHEL 7.
 import random
+from random import choice 
 def randomMAC():
     mac = [ 0x52, 0x54, 0x00,
             random.randint(0x00, 0xff),
@@ -76,6 +78,16 @@
             random.randint(0x00, 0xff) ]
     return ':'.join(map(lambda x: "%02x" % x, mac))
 
+def genPassword():
+    chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+    echars = "!@#$%^&*-,./"
+    passwd = ""
+    p = random.randint(0,7)
+    passwd += "".join(choice(chars) for _ in range (p))
+    passwd += "".join(choice(echars) for _ in range (1))
+    passwd += "".join(choice(chars) for _ in range (7-p))
+    return passwd
+
 parser = OptionParser();
 parser.add_option("-n", "--name", dest="name",
         help="VM name");
@@ -115,6 +127,10 @@
 disk_ext = os.path.splitext(disk_old)[1]
 disk_image = disk_path + '/' + vm_name + disk_ext
 disk.attrib['file'] = disk_image
+vnc = config.find('devices/graphics')
+vnc.attrib['passwd'] = genPassword()
+print "vnc password : %s" % vnc.attrib['passwd']
+
 if (options.debug):
     # http://wiki.libvirt.org/page/QEMUSwitchToLibvirt
     domain                      = config.getroot()