[Et-mgmt-commits-list] [SCM] koan branch, master now at v0.2.9-32-gf6bb8c9

Michael DeHaan mdehaan at redhat.com
Fri Jul 13 22:55:07 UTC 2007


Hello,

This is an automated email from the git hooks/update script, it was
generated because a ref change was pushed to the repository.

Updating branch, master,
       via  f6bb8c92a2a8cdbda5269dee2a799cf443294b01 (commit)
      from  9660caf2349731f314dd577827fb579e8d3bbab6 (commit)

- Log -----------------------------------------------------------------
commit f6bb8c92a2a8cdbda5269dee2a799cf443294b01
Author: Michael DeHaan <mdehaan at mdehaan.rdu.redhat.com>
Date:   Fri Jul 13 18:56:56 2007 -0400

    Simplify handling of VNC for koan and qemu.
-----------------------------------------------------------------------

Diffstat:
 koan.pod          |    6 +++++-
 koan/app.py       |   49 +++++++++++++++++++++++++++++--------------------
 koan/qcreate.py   |   46 ++++++++++++++++++++++++++++++++++++----------
 koan/xencreate.py |    4 ++--
 4 files changed, 72 insertions(+), 33 deletions(-)

diff --git a/koan.pod b/koan.pod
index 359aaa2..371b2b0 100644
--- a/koan.pod
+++ b/koan.pod
@@ -6,7 +6,7 @@ koan stands for "kickstart-over-a-network" and allows for both network provision
 
 koan --server=<host> [--list-profiles|--list-systems]
 
-koan --server=<host> [--virt|--replace-self|--display] [--profile=<name>|--system=<name>] [--virt-name=<name>] [--virt-path=<path>] [--virt-type=<type>]
+koan --server=<host> [--virt|--replace-self|--display] [--profile=<name>|--system=<name>] [--virt-name=<name>] [--virt-path=<path>] [--virt-type=<type>] [--virt-graphics]
 
 =head1 DESCRIPTION
 
@@ -100,6 +100,10 @@ will provide reasonable defaults.
 
 (optional) Koan can install virtual guests for Xen (paravirtualized), or QEMU/KVM (paravirtualized or fully virtualized based on hardware support).  Use --virt-type="kvm" or --virt-type="xenpv" to override the values already defined in cobbler.  Since this parameter can be set in the cobbler profile, it's best to just set it there.  See the cobbler manpage for more documentation.
 
+=item --virt-graphics
+
+(optional) This enables VNC graphics for virtual installs.  
+
 =back
 
 Example:  koan --server=cobbler.example.org --virt --profile=rhel5-x86_64 --virt-type="qemu" --virt-path="/home/username/qemu/" --virt-name="test_setup"
diff --git a/koan/app.py b/koan/app.py
index 8072bcd..5069559 100755
--- a/koan/app.py
+++ b/koan/app.py
@@ -97,7 +97,10 @@ def main():
     p.add_option("-T", "--virt-type",
                  dest="virt_type",
                  help="virtualization install type (xenpv,qemu)")
- 
+    p.add_option("-g", "--virt-graphics",
+                 action="store_true",
+                 dest="virt_graphics",
+                 help="enable virt graphics (varies with --virt-type)")
     (options, args) = p.parse_args()
 
     if not os.getuid() == 0:
@@ -117,6 +120,7 @@ def main():
         k.live_cd           = options.live_cd
         k.virt_path         = options.virt_path
         k.virt_type         = options.virt_type
+        k.virt_graphics     = options.virt_graphics
         if options.virt_name is not None:
             k.virt_name          = options.virt_name
         if options.port is not None:
@@ -166,6 +170,7 @@ class Koan:
         self.virt_name         = None
         self.virt_type         = None
         self.virt_path         = None 
+        self.virt_graphics     = None
 
     #---------------------------------------------------
 
@@ -321,7 +326,7 @@ class Koan:
             # to download the kernel/initrd
             if self.virt_type is None:
                 self.virt_type = self.safe_load(profile_data,'virt_type',default=None)
-            if self.virt_type is None:
+            if self.virt_type is None or self.virt_type == "":
                 self.virt_type = 'xenpv'
 
             if self.virt_type == "xenpv":
@@ -699,17 +704,18 @@ class Koan:
             raise InfoException, "Unspecified virt type: %s" % self.virt_type
 
         results = creator(
-                name         =  name,
-                ram          =  self.calc_virt_ram(pd),
-                disk         =  self.calc_virt_filesize(pd),
-                mac          =  mac,
-                uuid         =  uuid,
-                kernel       =  self.safe_load(pd,'kernel_local'),
-                initrd       =  self.safe_load(pd,'initrd_local'),
-                extra        =  kextra,
-                vcpus        =  self.calc_virt_cpus(pd),
-                path         =  self.set_virt_path(pd, name, mac),
-                nameoverride =  self.virt_name
+                name          =  name,
+                ram           =  self.calc_virt_ram(pd),
+                disk          =  self.calc_virt_filesize(pd),
+                mac           =  mac,
+                uuid          =  uuid,
+                kernel        =  self.safe_load(pd,'kernel_local'),
+                initrd        =  self.safe_load(pd,'initrd_local'),
+                extra         =  kextra,
+                vcpus         =  self.calc_virt_cpus(pd),
+                path          =  self.set_virt_path(pd, name, mac),
+                nameoverride  =  self.virt_name,
+                virt_graphics =  self.virt_graphics
         )
 
         print results
@@ -849,19 +855,22 @@ class Koan:
             return "%s/%s" % (prefix, usename)
 
         if location.find(':') == -1:
-            # No colon syntax, assume disk image
+            # this is a disk location
             # FIXME: can we be smarter here, eliminate this syntax, and
             # figure out what the device is by asking it?
-            if location.endswith("/"):
-                return "%s/%s%s" % (prefix,location,usename)
+            if os.path.isdir(location):
+                # existing directory
+                return "%s/%s" % (location, usename)
+            elif not os.path.exists(location) and os.path.isdir(os.path.dirname(location)):
+                # non-existing file in existing directory
+                return location
             else:
-                if os.path.isdir("%s/%s" % (prefix,location)):
-                    return "%s/%s/" % (prefix,location)
-                return "%s/%s" % (prefix,location)
-
+                raise InfoException, "invalid location: %s" % location                
         else:
             # command line indicates partition or volume group
             # FIXME: pathname may legally include ':'
+            # FIXME: not well tested at this point
+            print "warning: experimental --virt-path usage"
 
             count = location.count(':')
             if count == 1:
diff --git a/koan/qcreate.py b/koan/qcreate.py
index a7aee3e..d2163ce 100755
--- a/koan/qcreate.py
+++ b/koan/qcreate.py
@@ -18,39 +18,65 @@ import exceptions
 import errno
 import re
 
+def randomMAC():
+    """
+    from xend/server/netif.py
+    Generate a random MAC address.
+    Uses OUI 00-16-3E, allocated to
+    Xensource, Inc.  Last 3 fields are random.
+    return: MAC address string
+    """
+    mac = [ 0x00, 0x16, 0x3e,
+            random.randint(0x00, 0x7f),
+            random.randint(0x00, 0xff),
+            random.randint(0x00, 0xff) ]
+    return ':'.join(map(lambda x: "%02x" % x, mac))
+
+
 class VirtCreateException(exceptions.Exception):
     pass
 
 def start_install(name=None, ram=None, disk=None, mac=None,
-                           uuid=None, kernel=None, initrd=None, 
-                           extra=None, nameoverride=None, path=None,
-                           vcpus=None):
+                  uuid=None, kernel=None, initrd=None, 
+                  extra=None, nameoverride=None, path=None,
+                  vcpus=None, virt_graphics=None):
 
     usename = name
     if nameoverride is not None:
        usename = nameoverride
 
+    if mac is None:
+       mac = randomMAC()
+    print "using MAC: %s" % mac
+
 
     if os.path.isdir(path):
        path = os.path.join(path, usename)
      
     if os.path.exists(path):
-       # FIXME: EVIL!
-       os.remove(path)
-       # return "ERROR: path (%s) exists" % path
+       msg = "ERROR: disk path (%s) exists. " % path
+       msg = msg + "You can delete it, try a "
+       msg = msg + "different --virt-path, or specify a different --virt-name."
+       msg = msg + "However, koan will not overwrite an existing file."
+       return msg
 
     cmd = "qemu-img create -f qcow2 %s %sG" % (path, disk)
     rc = os.system(cmd)
 
     if rc != 0:
        return "image creation failed"
-    
-    #cmd2 = "qemu-kvm -m %s -hda %s" % (ram,path)
+
+    if not virt_graphics:
+        print "- access your installation with vnc :0"
+
     cmd2 = "qemu -m %s -hda %s" % (ram,path)
     cmd2 = cmd2  + " -kernel %s" % (kernel)
     cmd2 = cmd2  + " -initrd %s" % (initrd)
-    #cmd2 = cmd2 + " -append \"%s\"  -net nic -net tap" % (extra) 
-    cmd2 = cmd2  + " -append \"%s\"  " % (extra) 
+    cmd2 = cmd2  + " -net nic,macaddr=%s -vnc :0" % (mac)
+    cmd2 = cmd2  + " -daemonize -append \"%s\"" % (extra)
+
+    if virt_graphics:
+        cmd2 = cmd2  + " -vnc :0 -serial vc -monitor vc"
 
     print cmd2
 
diff --git a/koan/xencreate.py b/koan/xencreate.py
index cbf984b..e3c27c3 100755
--- a/koan/xencreate.py
+++ b/koan/xencreate.py
@@ -76,7 +76,7 @@ def get_mac(mac):
 def start_paravirt_install(name=None, ram=None, disk=None, mac=None,
                            uuid=None, kernel=None, initrd=None, 
                            extra=None, nameoverride=None, path=None,
-                           vcpus=None):
+                           vcpus=None, virt_graphics=False):
 
 
     if mac == None:
@@ -97,7 +97,7 @@ def start_paravirt_install(name=None, ram=None, disk=None, mac=None,
     if vcpus is None:
         vcpus = 1
     guest.set_vcpus(vcpus)
-    guest.set_graphics(False) # FIXME!
+    guest.set_graphics(virt_graphics)
     if uuid is not None:
         guest.set_uuid(uuid)
 

hooks/update
---
Git Source Code Management System
hooks/update refs/heads/master \
  9660caf2349731f314dd577827fb579e8d3bbab6 \
  f6bb8c92a2a8cdbda5269dee2a799cf443294b01




More information about the Et-mgmt-commits-list mailing list