>From dd6f4c3d9e1a2bef7dfc882f2e572a8735b75419 Mon Sep 17 00:00:00 2001
From: Nicolas Ochem <[email protected]>
Date: Tue, 2 Mar 2010 15:39:19 +0100
Subject: [PATCH] introduce option to always PXE boot a VM

Previously a VM booting from PXE would always revert to HD upon reboot.
We introduce 2 boot methods : PXE boot(once) and PXE boot (always)
Copyright 2010 Alcatel-Lucent

Signed-off-by: Nicolas Ochem <[email protected]>
---
 src/app/controllers/vm_controller.rb |    1 +
 src/app/models/vm.rb                 |   28 ++++++++++++++++++----------
 src/app/views/vm/_form.rhtml         |    2 +-
 src/task-omatic/taskomatic.rb        |   12 ++++++++++--
 4 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/src/app/controllers/vm_controller.rb 
b/src/app/controllers/vm_controller.rb
index 9860843..299356d 100644
--- a/src/app/controllers/vm_controller.rb
+++ b/src/app/controllers/vm_controller.rb
@@ -149,6 +149,7 @@ class VmController < ApplicationController
   protected
   def _setup_provisioning_options
     @provisioning_options = [[Vm::PXE_OPTION_LABEL, Vm::PXE_OPTION_VALUE],
+                             [Vm::PXE_ALWAYS_OPTION_LABEL, 
Vm::PXE_ALWAYS_OPTION_VALUE],
                              [Vm::HD_OPTION_LABEL, Vm::HD_OPTION_VALUE]]
 
     begin
diff --git a/src/app/models/vm.rb b/src/app/models/vm.rb
index 88e0aef..044f61d 100644
--- a/src/app/models/vm.rb
+++ b/src/app/models/vm.rb
@@ -99,10 +99,11 @@ class Vm < ActiveRecord::Base
                  :terms => [ [ :search_users, 'U', "search_users" ] ],
                  :eager_load => :smart_pools
 
-  BOOT_DEV_HD            = "hd"
-  BOOT_DEV_NETWORK       = "network"
-  BOOT_DEV_CDROM         = "cdrom"
-  BOOT_DEV_FIELDS        = [ BOOT_DEV_HD, BOOT_DEV_NETWORK, BOOT_DEV_CDROM ]
+  BOOT_DEV_HD              = "hd"
+  BOOT_DEV_NETWORK         = "network"
+  BOOT_DEV_NETWORK_ALWAYS  = "network_always"
+  BOOT_DEV_CDROM           = "cdrom"
+  BOOT_DEV_FIELDS          = [ BOOT_DEV_HD, BOOT_DEV_NETWORK , 
BOOT_DEV_NETWORK_ALWAYS , BOOT_DEV_CDROM ]
 
   PROVISIONING_DELIMITER = ":"
   COBBLER_PREFIX         = "cobbler"
@@ -111,10 +112,12 @@ class Vm < ActiveRecord::Base
   COBBLER_PROFILE_SUFFIX = " (Cobbler Profile)"
   COBBLER_IMAGE_SUFFIX   = " (Cobbler Image)"
 
-  PXE_OPTION_LABEL       = "PXE Boot"
-  PXE_OPTION_VALUE       = "pxe"
-  HD_OPTION_LABEL        = "Boot from HD"
-  HD_OPTION_VALUE        = "hd"
+  PXE_OPTION_LABEL        = "PXE Boot (once)"
+  PXE_OPTION_VALUE        = "pxe"
+  PXE_ALWAYS_OPTION_LABEL = "PXE Boot (always)"
+  PXE_ALWAYS_OPTION_VALUE = "pxe_always"
+  HD_OPTION_LABEL         = "Boot from HD"
+  HD_OPTION_VALUE         = "hd"
 
   NEEDS_RESTART_FIELDS = [:uuid,
                           :num_vcpus_allocated,
@@ -254,6 +257,9 @@ class Vm < ActiveRecord::Base
     elsif settings==PXE_OPTION_VALUE
       self[:boot_device]= BOOT_DEV_NETWORK
       self[:provisioning]= nil
+    elsif settings==PXE_ALWAYS_OPTION_VALUE
+      self[:boot_device]= BOOT_DEV_NETWORK_ALWAYS
+      self[:provisioning]= nil
     elsif settings==HD_OPTION_VALUE
       self[:boot_device]= BOOT_DEV_HD
       self[:provisioning]= nil
@@ -264,7 +270,9 @@ class Vm < ActiveRecord::Base
   end
   def provisioning_and_boot_settings
     if provisioning == nil
-      if boot_device==BOOT_DEV_NETWORK
+      if boot_device==BOOT_DEV_NETWORK_ALWAYS
+        PXE_ALWAYS_OPTION_VALUE
+      elsif boot_device==BOOT_DEV_NETWORK
         PXE_OPTION_VALUE
       elsif boot_device==BOOT_DEV_HD
         HD_OPTION_VALUE
@@ -464,7 +472,7 @@ class Vm < ActiveRecord::Base
       self.storage_volum...@storage_volumes_pending
       @storage_volumes_pending = []
     end
-    errors.add("nics", "must specify at least one network if pxe booting off a 
network") unless boot_device != BOOT_DEV_NETWORK || nics.size > 0
+    errors.add("nics", "must specify at least one network if pxe booting off a 
network") unless boot_device != BOOT_DEV_NETWORK  || boot_device != 
BOOT_DEV_NETWORK_ALWAYS || nics.size > 0
 
   end
 
diff --git a/src/app/views/vm/_form.rhtml b/src/app/views/vm/_form.rhtml
index adb75d2..492b15d 100644
--- a/src/app/views/vm/_form.rhtml
+++ b/src/app/views/vm/_form.rhtml
@@ -330,7 +330,7 @@ ${htmlList(pools, id)}
          // only set value if we have a network to set it to and we've
          // selected a provision type requiring a net
          if(nics.length > 0 &&
-           (e.target.value == "<%= Vm::PXE_OPTION_VALUE %>" ||
+           (e.target.value == "<%= Vm::PXE_OPTION_VALUE %>" || e.target.value 
== "<%= Vm::PXE_ALWAYS_OPTION_VALUE %>" ||
             e.target.value.indexOf("<%= Vm::PROFILE_PREFIX %>@<%= 
Vm::COBBLER_PREFIX %>") == 0)){
               
$('#vm_network_config_select_0').val(nics[0].network_id).trigger('change');
          }
diff --git a/src/task-omatic/taskomatic.rb b/src/task-omatic/taskomatic.rb
index 7de725d..844adc1 100755
--- a/src/task-omatic/taskomatic.rb
+++ b/src/task-omatic/taskomatic.rb
@@ -395,9 +395,16 @@ class TaskOmatic
        end
        net_interfaces.push({ :mac => nic.mac, :interface => net_device })
     }
+    # network_always indicates that the boot device is "network" and will not 
change
+    # upon reboot.
+    if db_vm.boot_device == "network_always"
+       boot_device = "network"
+    else
+       boot_device = db_vm.boot_device
+    end
 
     xml = create_vm_xml(db_vm.description, db_vm.uuid, db_vm.memory_allocated,
-              db_vm.memory_used, db_vm.num_vcpus_allocated, db_vm.boot_device,
+              db_vm.memory_used, db_vm.num_vcpus_allocated, boot_device,
               net_interfaces, storagedevs)
 
     @logger.debug("XML Domain definition: #{xml}")
@@ -423,7 +430,8 @@ class TaskOmatic
 
     # This information is not available via the libvirt interface.
     db_vm.memory_used = db_vm.memory_allocated
-    db_vm.boot_device = Vm::BOOT_DEV_HD
+    # Revert to HD booting unless we have selected to always boot from the 
network.
+    db_vm.boot_device = Vm::BOOT_DEV_HD unless db_vm.boot_device == 
Vm::BOOT_DEV_NETWORK_ALWAYS
     db_vm.host_id = db_host.id
     db_vm.save!
 
-- 
1.6.2.5

_______________________________________________
Ovirt-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/ovirt-devel

Reply via email to