Mohammed Morsi
2008-Sep-02 09:35 UTC
[Ovirt-devel] [PATCH] added ability to reprovision vm via edit vm form
--- wui/src/app/controllers/vm_controller.rb | 29 +++++++++++++++++------------ wui/src/app/views/vm/_form.rhtml | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/wui/src/app/controllers/vm_controller.rb b/wui/src/app/controllers/vm_controller.rb index e55ec28..6d32427 100644 --- a/wui/src/app/controllers/vm_controller.rb +++ b/wui/src/app/controllers/vm_controller.rb @@ -193,6 +193,21 @@ class VmController < ApplicationController end protected + def _setup_provisioning + @provisioning_options = [[Vm::PXE_OPTION_LABEL, Vm::PXE_OPTION_VALUE], + [Vm::HD_OPTION_LABEL, Vm::HD_OPTION_VALUE]] + # FIXME add cobbler images too + begin + @provisioning_options += Cobbler::Profile.find.collect do |profile| + [profile.name + Vm::COBBLER_PROFILE_SUFFIX, + Vm::COBBLER_PREFIX + Vm::PROVISIONING_DELIMITER + + Vm::PROFILE_PREFIX + Vm::PROVISIONING_DELIMITER + profile.name] + end + rescue + #if cobbler doesn't respond/is misconfigured/etc just don't add profiles + end + end + def pre_new # if no vm_resource_pool is passed in, find (or auto-create) it based on hardware_pool_id unless params[:vm_resource_pool_id] @@ -229,18 +244,7 @@ class VmController < ApplicationController @perm_obj = @vm.vm_resource_pool @redir_controller = 'resources' @current_pool_id=@perm_obj.id - @provisioning_options = [[Vm::PXE_OPTION_LABEL, Vm::PXE_OPTION_VALUE], - [Vm::HD_OPTION_LABEL, Vm::HD_OPTION_VALUE]] - # FIXME add cobbler images too - begin - @provisioning_options += Cobbler::Profile.find.collect do |profile| - [profile.name + Vm::COBBLER_PROFILE_SUFFIX, - Vm::COBBLER_PREFIX + Vm::PROVISIONING_DELIMITER + - Vm::PROFILE_PREFIX + Vm::PROVISIONING_DELIMITER + profile.name] - end - rescue - #if cobbler doesn't respond/is misconfigured/etc just don't add profiles - end + _setup_provisioning end def pre_create params[:vm][:state] = Vm::STATE_PENDING @@ -267,6 +271,7 @@ class VmController < ApplicationController @perm_obj = @vm.vm_resource_pool @redir_obj = @vm @current_pool_id=@perm_obj.id + _setup_provisioning end def pre_vm_action pre_edit diff --git a/wui/src/app/views/vm/_form.rhtml b/wui/src/app/views/vm/_form.rhtml index 60ed003..0dfe940 100644 --- a/wui/src/app/views/vm/_form.rhtml +++ b/wui/src/app/views/vm/_form.rhtml @@ -8,7 +8,7 @@ <%= hidden_field_tag 'hardware_pool_id', @hardware_pool.id if @hardware_pool %> <%= text_field_with_label "Name:", "vm", "description", {:style=>"width:250px;"} %> - <%= select_with_label "Operating System:", 'vm', 'provisioning_and_boot_settings', @provisioning_options, :style=>"width:250px;" if create %> + <%= select_with_label "Operating System:", 'vm', 'provisioning_and_boot_settings', @provisioning_options, :style=>"width:250px;" %> <div class="clear_row" style="height:15px;"></div> <div class="form_heading">Resources</div> -- 1.5.4.1
Scott Seago
2008-Sep-02 13:39 UTC
[Ovirt-devel] [PATCH] added ability to reprovision vm via edit vm form
Mohammed Morsi wrote:> --- > wui/src/app/controllers/vm_controller.rb | 29 +++++++++++++++++------------ > wui/src/app/views/vm/_form.rhtml | 2 +- > 2 files changed, 18 insertions(+), 13 deletions(-) > > diff --git a/wui/src/app/controllers/vm_controller.rb b/wui/src/app/controllers/vm_controller.rb > index e55ec28..6d32427 100644 > --- a/wui/src/app/controllers/vm_controller.rb > +++ b/wui/src/app/controllers/vm_controller.rb > @@ -267,6 +271,7 @@ class VmController < ApplicationController > @perm_obj = @vm.vm_resource_pool > @redir_obj = @vm > @current_pool_id=@perm_obj.id > + _setup_provisioning > end > def pre_vm_action > pre_edit > diff --git a/wui/src/app/views/vm/_form.rhtml b/wui/src/app/views/vm/_form.rhtml > index 60ed003..0dfe940 100644 > --- a/wui/src/app/views/vm/_form.rhtml > +++ b/wui/src/app/views/vm/_form.rhtml > @@ -8,7 +8,7 @@ > <%= hidden_field_tag 'hardware_pool_id', @hardware_pool.id if @hardware_pool %> > > <%= text_field_with_label "Name:", "vm", "description", {:style=>"width:250px;"} %> > - <%= select_with_label "Operating System:", 'vm', 'provisioning_and_boot_settings', @provisioning_options, :style=>"width:250px;" if create %> > + <%= select_with_label "Operating System:", 'vm', 'provisioning_and_boot_settings', @provisioning_options, :style=>"width:250px;" %> > <div class="clear_row" style="height:15px;"></div> > > <div class="form_heading">Resources</div> >The UI needs to make it clear that changing the provisioning bits on a running VM will potentially wipe the contents of the current VM and reprovision from scratch. In addition, if the VM is currently running, should we provide the user an easy way to force an immediate reboot (so the provisioning can take effect). Currently we have a 'start VM now' button for creating VMs -- maybe for edit, we should provide the option to start/restart VM now. Also, we need to be careful in how we handle the boot device and cobbler profile fields. Currently cobbler profile is only set on create -- so the above won't actually register a new cobbler system (and what of the old cobbler system -- do we need to un-register it? There's also the automatic update of the boot device on successful boot -- I don't think the above will cause any problems with that though. Scott
Mohammed Morsi
2008-Sep-04 11:15 UTC
[Ovirt-devel] [PATCH] added ability to reprovision vm via edit vm form
--- wui/src/app/controllers/vm_controller.rb | 73 +++++++++++++++++++++++++----- wui/src/app/views/vm/_form.rhtml | 6 ++- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/wui/src/app/controllers/vm_controller.rb b/wui/src/app/controllers/vm_controller.rb index e55ec28..82d8952 100644 --- a/wui/src/app/controllers/vm_controller.rb +++ b/wui/src/app/controllers/vm_controller.rb @@ -96,6 +96,28 @@ class VmController < ApplicationController end params[:vm][:needs_restart] = 1 if needs_restart @vm.update_attributes!(params[:vm]) + _setup_vm_provision(params) + + if (params[:start_now] and @vm.get_action_list.include?(VmTask::ACTION_START_VM) ) + @task = VmTask.new({ :user => @user, + :vm_id => @vm.id, + :action => VmTask::ACTION_START_VM, + :state => Task::STATE_QUEUED}) + @task.save! + elsif ( params[:restart_now] and @vm.get_action_list.include?(VmTask::ACTION_SHUTDOWN_VM) ) + @task = VmTask.new({ :user => @user, + :vm_id => @vm.id, + :action => VmTask::ACTION_SHUTDOWN_VM, + :state => Task::STATE_QUEUED}) + @task.save! + @task = VmTask.new({ :user => @user, + :vm_id => @vm.id, + :action => VmTask::ACTION_START_VM, + :state => Task::STATE_QUEUED}) + @task.save! + end + + render :json => { :object => "vm", :success => true, :alert => 'Vm was successfully updated.' } rescue @@ -193,6 +215,43 @@ class VmController < ApplicationController end protected + def _setup_provisioning_options + @provisioning_options = [[Vm::PXE_OPTION_LABEL, Vm::PXE_OPTION_VALUE], + [Vm::HD_OPTION_LABEL, Vm::HD_OPTION_VALUE]] + # FIXME add cobbler images too + begin + @provisioning_options += Cobbler::Profile.find.collect do |profile| + [profile.name + Vm::COBBLER_PROFILE_SUFFIX, profile.name] + + end + rescue + #if cobbler doesn't respond/is misconfigured/etc just don't add profiles + end + end + + def _setup_vm_provision(params) + # spaces are invalid in the cobbler name + name = params[:vm][:description].gsub(" ", "-") + provision = params[:vm][:provisioning_and_boot_settings] + unless provision == Vm::PXE_OPTION_VALUE or + provision == Vm::HD_OPTION_VALUE + found = false + Cobbler::System.find.each{ |system| + if system.name == name + system.profile = provision + system.save + found = true + end + } + unless found + system = Cobbler::System.create("name" => name, + "profile" => provision) + # do we need to set any of the other system attributes? + system.save + end + end + end + def pre_new # if no vm_resource_pool is passed in, find (or auto-create) it based on hardware_pool_id unless params[:vm_resource_pool_id] @@ -229,18 +288,7 @@ class VmController < ApplicationController @perm_obj = @vm.vm_resource_pool @redir_controller = 'resources' @current_pool_id=@perm_obj.id - @provisioning_options = [[Vm::PXE_OPTION_LABEL, Vm::PXE_OPTION_VALUE], - [Vm::HD_OPTION_LABEL, Vm::HD_OPTION_VALUE]] - # FIXME add cobbler images too - begin - @provisioning_options += Cobbler::Profile.find.collect do |profile| - [profile.name + Vm::COBBLER_PROFILE_SUFFIX, - Vm::COBBLER_PREFIX + Vm::PROVISIONING_DELIMITER + - Vm::PROFILE_PREFIX + Vm::PROVISIONING_DELIMITER + profile.name] - end - rescue - #if cobbler doesn't respond/is misconfigured/etc just don't add profiles - end + _setup_provisioning_options end def pre_create params[:vm][:state] = Vm::STATE_PENDING @@ -267,6 +315,7 @@ class VmController < ApplicationController @perm_obj = @vm.vm_resource_pool @redir_obj = @vm @current_pool_id=@perm_obj.id + _setup_provisioning_options end def pre_vm_action pre_edit diff --git a/wui/src/app/views/vm/_form.rhtml b/wui/src/app/views/vm/_form.rhtml index 60ed003..3d4cd79 100644 --- a/wui/src/app/views/vm/_form.rhtml +++ b/wui/src/app/views/vm/_form.rhtml @@ -8,7 +8,8 @@ <%= hidden_field_tag 'hardware_pool_id', @hardware_pool.id if @hardware_pool %> <%= text_field_with_label "Name:", "vm", "description", {:style=>"width:250px;"} %> - <%= select_with_label "Operating System:", 'vm', 'provisioning_and_boot_settings', @provisioning_options, :style=>"width:250px;" if create %> + <%= select_with_label "Operating System:", 'vm', 'provisioning_and_boot_settings', @provisioning_options, :style=>"width:250px;" %> + <% if controller.action_name == "edit" %><b style="color: #FF0000">*Warning* Editing provision could overwrite vm</b><% end %> <div class="clear_row" style="height:15px;"></div> <div class="form_heading">Resources</div> @@ -50,7 +51,8 @@ <div class="clear_row"></div> <div class="clear_row"></div> - <%= check_box_tag_with_label "Start VM Now? (pending current resource availability)", "start_now", nil if create%> + <%= check_box_tag_with_label "Start VM Now? (pending current resource availability)", "start_now", nil if create or @vm.state == Vm::STATE_STOPPED %> + <%= check_box_tag_with_label "Restart VM Now? (pending current resource availability)", "restart_now", nil if @vm.state == Vm::STATE_RUNNING %> <!--[eoform:vm]--> <script type="text/javascript"> -- 1.5.4.1