PATCH: koan: --no-cobbler --virt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




This patch enables --no-cobbler --virt installs. Please consider including this patch.

                                                 -gavin...

This patch enables para-virt installs to be done with --no_cobbler (full virt 
will also be possible once koan and virtinst support non-ISO based full virt 
installs).

The strategy here has been to take the install location from the kickstart 
file, allow virtinst to find the kernel and initrd from that install location,
and add options to koan to provide the virt_cpus, virt_ram, and 
virt_file_size parameters, rely on the existing virt_path option, and allow
virtinst to choose default virt-bridge.

The changes in this patch were written in such a way that if koan doesn't
receive values for kernel/initrd or virt-bridge from Cobbler, then koan
will allow virtinst to use appropriate defaults.  Right now this can never
happen (unless one uses --no-cobbler) because Cobbler won't allow one to
create distros without an explicit kernal/initrd, or profiles without choosing
a default virt-bridge, but if Cobbler wanted to allow this, Koan will handle
it.

* Tue Mar 11 2008 Gavin Romig-Koch <gavin@xxxxxxxxxx>

Changes to enable --no-cobbler --virt

- koan.pod: manpage changes for --no-cobbler --virt
- koan/app.py: 
    * three new koan options: --virt-ram, --virt-cpus, --virt-file-size 
      which exactly mirror and override (if any) the Cobbler provided values
    * allow --no-cobbler --virt
    * the existing code for grabbing a kernel and initrd from the install_tree
      is only appropriate for --replace-self, so move it to replace()
    * allow for no specified kernel and/or initrd
- koan/xencreate.py: 
    * if no kernel or initrd is specified, send the location of the 
      install_tree to virtinst Guest.
    * if no virt_bridge is specified, either in the profile or in the
      interface, allow the virtinst Guest to choose the default.


diff --git a/koan.pod b/koan.pod
index d351a09..ef5d033 100644
--- a/koan.pod
+++ b/koan.pod
@@ -6,7 +6,12 @@ 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>] [--autonet] [--virt-name=<name>] [--virt-path=<path>] [--virt-type=<type>] [--virt-graphics]
+koan --server=<host> [--virt|--replace-self|--display] [--profile=<name>|--system=<name>] [--autonet] VIRT-OPTIONS
+
+koan --no-cobbler=<kickstart_file> [--virt|--replace-self|--display] [--autonet] VIRT-OPTIONS
+
+VIRT-OPTIONS = [--virt-name=<name>] [--virt-type=<type>] [--virt-path=<path>] [--virt-file-size=<GB>] [--virt-ram=<MB>] [--virt-cpus=<count>] [--virt-graphics]
+
 
 =head1 DESCRIPTION
 
@@ -16,17 +21,33 @@ When invoked, koan requests install information from a remote cobbler boot serve
 
 =over 
 
+Either --server or --no-cobbler must be specified for all koan commands.
+
 =item --server
 
 Indicates the hostname of the Cobbler boot server to be contacted.  Successful
 communication requires that no firewalls are blocking the cobbler XMLRPC port,
 which is usually 25151, and that "cobblerd" is running on the cobbler server.
 
-This argument must be specified for all koan commands.
+Specifying "DISCOVER" for the server in all caps will request automatic 
+discovery of a nearby cobbler server using Avahi.  The avahi-tools package
+must be installed to use this functionality.
+
+
+=item --no-cobbler
 
-Specifying "DISCOVER" for the server in all caps will request automatic discovery
-of a nearby cobbler server using Avahi.  The avahi-tools package must be installed
-to use this functionality.
+The value given to the --no-cobbler option is a kickstart file.  If this
+option is given, no Cobbler server will be contacted.
+
+For --no-cobbler --replace-self, the kickstart can be a file on the local 
+file system (either with or without the explicit "file://" specified), or
+it can be an http://, ftp://, or nfs:// URL. 
+ 
+For --no-cobbler --virt, the kickstart file must _not_ be on the local
+file system, it must be an http, ftp, or nfs URL.
+
+See "REINSTALLATION WITHOUT A COBBLER SERVER" below for an explanation of
+useage.
 
 =back
 
@@ -98,6 +119,12 @@ Optional advanced-configuration parameters for --virt:
 other virtual machines running on the same system.   If not specified, cobbler
 will provide reasonable defaults.
 
+=item --virt-type
+
+(optional) Koan can install virtual guests for Xen (paravirtualized), or QEMU/KVM (paravirtualized or fully virtualized based on hardware support).  Use --virt-type="qemu" 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.
+
+qemu installs will select kvm, kqemu, or qemu, based on available hardware support.  
+
 =item --virt-path
 
 (optional) Specifies the storage for the virtual image, as a forced override over a storage location that might be set on the cobbler server.  This path must be an absolute path of an existing directory in which to store the image, with an optional filename component.  
@@ -106,11 +133,23 @@ Advanced usage: There is also support for specifying partitions such as "/dev/sd
 
 If you want to specify the location for more than one disk image, seperate the values with commas, such as "/opt/foo/a,/opt/foo/b".  
 
-=item --virt-type
+=item --virt-file-size
 
-(optional) Koan can install virtual guests for Xen (paravirtualized), or QEMU/KVM (paravirtualized or fully virtualized based on hardware support).  Use --virt-type="qemu" 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.
+(optional) How large the disk image should be in Gigabytes. This can be 
+a comma seperated list (ex: "5,6,7") to allow for multiple disks of 
+different sizes depending on what is given to --virt-path.
 
-qemu installs will select kvm, kqemu, or qemu, based on available hardware support.  
+This overrides any value from the Cobbler server.  
+
+=item --virt-ram
+
+(optional) How many megabytes of RAM to consume.  This overrides any 
+value from the Cobbler server.  
+
+=item --virt-cpus
+
+(optional) How many virtual CPUs should koan give the virtual
+machine?
 
 =item --nogfx
 
@@ -130,14 +169,24 @@ Example:  koan --server=cobbler.example.org --replace-self
 
 =head1 REINSTALLATION WITHOUT A COBBLER SERVER
 
-While it is expected that most folks will want to use a cobbler server, the functionality of --replace-self
-can still be used in koan without contacting a cobbler server.  This may be useful if you want
-to use koan with some existing infrastructure and can't yet upgrade that infrastructure to use cobbler.
+While it is expected that most folks will want to use a cobbler server, 
+the functionality of koan can still be used without contacting a cobbler 
+server.  This may be useful in a testing environment where the profile
+of an installation changes with each re-install.  This may also be useful
+if you want to use koan with some existing  infrastructure and can't 
+yet upgrade that infrastructure to use cobbler.
 
 Example:  koan --no-cobbler=http://somewebserver/ks.cfg --replace-self
 
-The --no-cobbler option does not work for virtualized installs.  In addition --display, --list-profiles, and
---list-systems are also not available with --no-cobbler.
+The kernel and initrd used are the ones found in the install location
+specified in the kickstart file.
+
+The --no-cobbler option can also be used for virtualized installs, though you
+will have to specify values for --virt-path, --virt-file-size, --virt-ram, and
+--virt-cpus, as no defaults are provided by Cobbler.  
+
+The --list-profiles, and --list-systems are also not available with 
+--no-cobbler.
 
 =head1 NOTES FOR USERS OF COBBLER TEMPLATING
 
diff --git a/koan/app.py b/koan/app.py
index 9cbbf3f..bbf7913 100755
--- a/koan/app.py
+++ b/koan/app.py
@@ -53,7 +53,7 @@ DISPLAY_PARAMS = [
    "install_tree","kernel","initrd",
    "kernel_options",
    "repos",
-   "virt_ram","virt_disk","virt_type", "virt_path"
+   "virt_type","virt_cpus","virt_ram","virt_path","virt_file_size"
 ]
 
 def setupLogging(appname, debug=False):
@@ -157,6 +157,15 @@ def main():
     p.add_option("-P", "--virt-path",
                  dest="virt_path",
                  help="virtual install location (see manpage)")  
+    p.add_option("", "--virt-file-size",
+                 dest="virt_file_size",
+                 help="(Virt-only) Gigabytes of disk space to allocate at virt-path")
+    p.add_option("", "--virt-ram",
+                 dest="virt_ram",
+                 help="(Virt-only) Megabytes of RAM to give the VM.")  
+    p.add_option("", "--virt-cpus",
+                 dest="virt_cpus",
+                 help="(Virt-only) CPUs to give the VM.")
     p.add_option("-T", "--virt-type",
                  dest="virt_type",
                  help="virtualization install type (xenpv,xenfv,qemu,vmware)")
@@ -190,6 +199,9 @@ def main():
         k.autonet           = options.autonet
         k.live_cd           = options.live_cd
         k.virt_path         = options.virt_path
+        k.virt_file_size    = options.virt_file_size
+        k.virt_ram          = options.virt_ram
+        k.virt_cpus         = options.virt_cpus
         k.virt_type         = options.virt_type
         k.no_gfx            = options.no_gfx
         k.no_cobbler         = options.no_cobbler
@@ -248,6 +260,9 @@ class Koan:
         self.virt_name         = None
         self.virt_type         = None
         self.virt_path         = None 
+        self.virt_ram          = None 
+        self.virt_cpus         = None 
+        self.virt_file_size    = None
 
     #---------------------------------------------------
 
@@ -273,11 +288,6 @@ class Koan:
                 raise InfoException, "missing argument: --replace-self ?"
  
 
-        # for now, kickstart only works with --replace-self
-        if self.no_cobbler and self.is_virt:
-            raise InfoException, "--no-cobbler does not work with --virt"
-
-
         # This set of options are only valid with --server
         if not self.server:
             if self.list_profiles:
@@ -573,16 +583,6 @@ class Koan:
             # find_kickstart source tree in the kickstart file
             self.get_install_tree_from_kickstart(profile_data)
 
-            # if we found an install_tree, and we don't have a kernel or initrd
-            # use the ones in the install_tree
-            if self.safe_load(profile_data,"install_tree"):
-                if not self.safe_load(profile_data,"kernel"):
-                    profile_data["kernel"] = profile_data["install_tree"] + "/images/pxeboot/vmlinuz"
-
-                if not self.safe_load(profile_data,"initrd"):
-                    profile_data["initrd"] = profile_data["install_tree"] + "/images/pxeboot/initrd.img"
-
-
         # find the correct file download location 
         if not self.is_virt:
             if self.live_cd:
@@ -782,6 +782,15 @@ class Koan:
             if err != errno.EEXIST:
                 raise
 
+        # if we found an install_tree, and we don't have a kernel or initrd
+        # use the ones in the install_tree
+        if self.safe_load(profile_data,"install_tree"):
+            if not self.safe_load(profile_data,"kernel"):
+                profile_data["kernel"] = profile_data["install_tree"] + "/images/pxeboot/vmlinuz"
+
+            if not self.safe_load(profile_data,"initrd"):
+                profile_data["initrd"] = profile_data["install_tree"] + "/images/pxeboot/initrd.img"
+
         def after_download(self, profile_data):
             if not os.path.exists("/sbin/grubby"):
                 raise InfoException, "grubby is not installed"
@@ -1222,29 +1231,37 @@ class Koan:
         distro = self.safe_load(profile_data,'distro')
         kernel = self.safe_load(profile_data,'kernel')
         initrd = self.safe_load(profile_data,'initrd')
-        kernel_short = os.path.basename(kernel)
-        initrd_short = os.path.basename(initrd)
-        kernel_save = "%s/%s" % (download_root, kernel_short)
-        initrd_save = "%s/%s" % (download_root, initrd_short)
+        if kernel:
+            kernel_short = os.path.basename(kernel)
+            kernel_save = "%s/%s" % (download_root, kernel_short)
+            if self.server:
+                if kernel.startswith("/"):
+                    kernel = "http://%s/cobbler/images/%s/%s"; % (self.server, distro, kernel_short)
+            try:
+                print "downloading kernel %s to %s" % (kernel_short, kernel_save)
+                print "url=%s" % kernel
+                self.urlgrab(kernel,kernel_save)
+            except:
+                raise InfoException, "error downloading files"
+            profile_data['kernel_local'] = kernel_save
 
-        if self.server:
-            if kernel.startswith("/"):
-                kernel = "http://%s/cobbler/images/%s/%s"; % (self.server, distro, kernel_short)
-            if initrd.startswith("/"):
-                initrd = "http://%s/cobbler/images/%s/%s"; % (self.server, distro, initrd_short)
+        if initrd:
+            initrd_short = os.path.basename(initrd)
+            initrd_save = "%s/%s" % (download_root, initrd_short)
+            if self.server:
+                if initrd.startswith("/"):
+                    initrd = "http://%s/cobbler/images/%s/%s"; % (self.server, distro, initrd_short)
+
+            try:
+                print "downloading initrd %s to %s" % (initrd_short, initrd_save)
+                print "url=%s" % initrd
+                self.urlgrab(initrd,initrd_save)
+
+            except:
+                raise InfoException, "error downloading files"
+            profile_data['initrd_local'] = initrd_save
 
-        try:
-            print "downloading initrd %s to %s" % (initrd_short, initrd_save)
-            print "url=%s" % initrd
-            self.urlgrab(initrd,initrd_save)
-            print "downloading kernel %s to %s" % (kernel_short, kernel_save)
 
-            print "url=%s" % kernel
-            self.urlgrab(kernel,kernel_save)
-        except:
-            raise InfoException, "error downloading files"
-        profile_data['kernel_local'] = kernel_save
-        profile_data['initrd_local'] = initrd_save
 
     #---------------------------------------------------
 
@@ -1380,7 +1397,10 @@ class Koan:
     def calc_virt_filesize(self,data,default_filesize=0):
 
         # MAJOR FIXME: are there overrides?  
-        size = self.safe_load(data,'virt_file_size','xen_file_size',0)
+        if self.virt_file_size:
+            size = self.virt_file_size
+        else:
+            size = self.safe_load(data,'virt_file_size','xen_file_size',0)
 
         tokens = str(size).split(",")
         accum = []
@@ -1413,7 +1433,12 @@ class Koan:
         """
         Assign a virt ram size if none is given in the profile.
         """
-        size = self.safe_load(data,'virt_ram','xen_ram',0)
+
+        if self.virt_ram:
+            size = self.virt_ram
+        else:
+            size = self.safe_load(data,'virt_ram','xen_ram',0)
+
         err = False
         try:
             int(size)
@@ -1432,7 +1457,11 @@ class Koan:
         """
         Assign virtual CPUs if none is given in the profile.
         """
-        size = self.safe_load(data,'virt_cpus',default=default_cpus)
+        if self.virt_cpus:
+            size = self.virt_cpus
+        else:
+            size = self.safe_load(data,'virt_cpus',default=default_cpus)
+
         try:
             isize = int(size)
         except:
diff --git a/koan/xencreate.py b/koan/xencreate.py
index 289c80e..cc46aba 100755
--- a/koan/xencreate.py
+++ b/koan/xencreate.py
@@ -62,7 +62,11 @@ def start_install(name=None, ram=None, disks=None,
         guest = virtinst.ParaVirtGuest()
 
     if not fullvirt:
-        guest.set_boot((profile_data["kernel_local"], profile_data["initrd_local"]))
+        if profile_data.has_key("kernel_local") or profile_data.has_key("initrd_local"):
+            guest.set_boot((profile_data["kernel_local"], profile_data["initrd_local"]))
+        elif profile_data.has_key("install_tree"):
+            guest.set_location(profile_data["install_tree"])
+
         # fullvirt OS's will get this from the PXE config (managed by Cobbler)
         guest.extraargs = extra
 
@@ -84,6 +88,11 @@ def start_install(name=None, ram=None, disks=None,
 
     counter = 0
 
+    if profile_data.has_key("virt_bridge"):
+        profile_bridge = profile_data["virt_bridge"]
+    else:
+        profile_bridge = ""
+
     if profile_data.has_key("interfaces"):
 
         interfaces = profile_data["interfaces"].keys()
@@ -97,31 +106,29 @@ def start_install(name=None, ram=None, disks=None,
             if mac == "":
                 mac = random_mac()
 
-            profile_bridge = profile_data["virt_bridge"]
-
             intf_bridge = intf["virt_bridge"]
             if intf_bridge == "":
-                if profile_bridge == "":
-                    raise koan.InfoException("virt-bridge setting is not defined in cobbler")
-                intf_bridge = profile_bridge
-    
-
-            nic_obj = virtinst.XenNetworkInterface(macaddr=mac, bridge=intf_bridge)
+                if profile_bridge != "":
+                    intf_bridge = profile_bridge
+                    
+            if intf_bridge == "":
+                nic_obj = virtinst.XenNetworkInterface(macaddr=mac)
+            else:
+                nic_obj = virtinst.XenNetworkInterface(macaddr=mac, bridge=intf_bridge)
             guest.nics.append(nic_obj)
             counter = counter + 1
    
     else:
-            # for --profile you just get one NIC, go define a system if you want more.
-            # FIXME: can mac still be sent on command line in this case?
+        # FIXME: can mac still be sent on command line in this case?
+        mac = random_mac()
 
-            profile_bridge = profile_data["virt_bridge"]
-            if profile_bridge == "":
-                raise koan.InfoException("virt-bridge setting is not defined in cobbler")
+        # for --profile you just get one NIC, go define a system if you want more.
+        if profile_bridge == "":
+            nic_obj = virtinst.XenNetworkInterface(macaddr=mac)
+        else:
+            nic_obj = virtinst.XenNetworkInterface(macaddr=mac, bridge=profile_bridge)
 
-            nic_obj = virtinst.XenNetworkInterface(macaddr=random_mac(), bridge=profile_bridge)
-            guest.nics.append(nic_obj)
-            
-        
+        guest.nics.append(nic_obj)
 
 
     guest.start_install()
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux