Nicolas Ochem
2010-Sep-02 14:40 UTC
[Ovirt-devel] [PATCH 1/1] Introduce an option to always pxe-boot a vm.
Previously, a pxe-booted vm would always boot to HD at next startup. Signed-off-by: Nicolas Ochem <nicolas.ochem at alcatel-lucent.com> --- src/app/controllers/vm_controller.rb | 1 + src/app/models/vm.rb | 15 +++++++++++---- src/app/views/vm/_form.rhtml | 2 +- src/task-omatic/taskomatic.rb | 13 +++++++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/app/controllers/vm_controller.rb b/src/app/controllers/vm_controller.rb index 88e13ab..8e99b67 100644 --- a/src/app/controllers/vm_controller.rb +++ b/src/app/controllers/vm_controller.rb @@ -154,6 +154,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..885112e 100644 --- a/src/app/models/vm.rb +++ b/src/app/models/vm.rb @@ -101,8 +101,9 @@ class Vm < ActiveRecord::Base 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_CDROM ] + BOOT_DEV_FIELDS = [ BOOT_DEV_HD, BOOT_DEV_NETWORK, BOOT_DEV_NETWORK_ALWAYS, BOOT_DEV_CDROM ] PROVISIONING_DELIMITER = ":" COBBLER_PREFIX = "cobbler" @@ -111,8 +112,10 @@ class Vm < ActiveRecord::Base COBBLER_PROFILE_SUFFIX = " (Cobbler Profile)" COBBLER_IMAGE_SUFFIX = " (Cobbler Image)" - PXE_OPTION_LABEL = "PXE Boot" + 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" @@ -264,7 +267,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 +469,9 @@ class Vm < ActiveRecord::Base self.storage_volumes=@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 || 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 7a46680..1ab6dda 100644 --- a/src/app/views/vm/_form.rhtml +++ b/src/app/views/vm/_form.rhtml @@ -351,7 +351,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 1dfd74f..6f699d2 100755 --- a/src/task-omatic/taskomatic.rb +++ b/src/task-omatic/taskomatic.rb @@ -415,9 +415,17 @@ class TaskOmatic end net_interfaces.push({ :mac => nic.mac, :interface => net_device, :virtio => nic.virtio }) } + # 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, db_vm.virtio, net_interfaces, storagedevs) @logger.debug("XML Domain definition: #{xml}") @@ -443,7 +451,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.7.2.1
Arthur Clément
2010-Sep-02 16:11 UTC
[Ovirt-devel] [PATCH 1/1] Introduce an option to always pxe-boot a vm.
Tested and ACK On jeudi 02 septembre 2010 16:40:51 Nicolas Ochem wrote:> Previously, a pxe-booted vm would always boot to HD at next startup. > > Signed-off-by: Nicolas Ochem <nicolas.ochem at alcatel-lucent.com> > --- > src/app/controllers/vm_controller.rb | 1 + > src/app/models/vm.rb | 15 +++++++++++---- > src/app/views/vm/_form.rhtml | 2 +- > src/task-omatic/taskomatic.rb | 13 +++++++++++-- > 4 files changed, 24 insertions(+), 7 deletions(-) > > diff --git a/src/app/controllers/vm_controller.rb > b/src/app/controllers/vm_controller.rb index 88e13ab..8e99b67 100644 > --- a/src/app/controllers/vm_controller.rb > +++ b/src/app/controllers/vm_controller.rb > @@ -154,6 +154,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..885112e 100644 > --- a/src/app/models/vm.rb > +++ b/src/app/models/vm.rb > @@ -101,8 +101,9 @@ class Vm < ActiveRecord::Base > > 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_CDROM > ] + BOOT_DEV_FIELDS = [ BOOT_DEV_HD, BOOT_DEV_NETWORK, > BOOT_DEV_NETWORK_ALWAYS, BOOT_DEV_CDROM ] > > PROVISIONING_DELIMITER = ":" > COBBLER_PREFIX = "cobbler" > @@ -111,8 +112,10 @@ class Vm < ActiveRecord::Base > COBBLER_PROFILE_SUFFIX = " (Cobbler Profile)" > COBBLER_IMAGE_SUFFIX = " (Cobbler Image)" > > - PXE_OPTION_LABEL = "PXE Boot" > + 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" > > @@ -264,7 +267,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 +469,9 @@ class Vm < ActiveRecord::Base > self.storage_volumes=@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 || 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 7a46680..1ab6dda 100644 > --- a/src/app/views/vm/_form.rhtml > +++ b/src/app/views/vm/_form.rhtml > @@ -351,7 +351,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 1dfd74f..6f699d2 100755 > --- a/src/task-omatic/taskomatic.rb > +++ b/src/task-omatic/taskomatic.rb > @@ -415,9 +415,17 @@ class TaskOmatic > end > net_interfaces.push({ :mac => nic.mac, :interface => net_device, > :virtio => nic.virtio }) } > + # 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, db_vm.virtio, > net_interfaces, storagedevs) > > @logger.debug("XML Domain definition: #{xml}") > @@ -443,7 +451,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!-- Arthur CLEMENT Linagora Paris