[Ovirt-devel] [PATCH] Adding the ability to select a Host to start a VM
Arthur Clément
aclement at linagora.com
Wed Sep 1 13:06:04 UTC 2010
ACK and pushed
On jeudi 26 août 2010 11:17:23 Simon COURTOIS wrote:
> Signed-off-by: Simon COURTOIS <scourtois at linagora.com>
> ---
> src/app/controllers/vm_controller.rb | 5 ++
> src/app/models/vm_task.rb | 4 +-
> src/app/views/vm/start.rhtml | 77
> ++++++++++++++++++++++++++++++++++ src/task-omatic/taskomatic.rb |
> 7 +++-
> 4 files changed, 91 insertions(+), 2 deletions(-)
> create mode 100644 src/app/views/vm/start.rhtml
>
> diff --git a/src/app/controllers/vm_controller.rb
> b/src/app/controllers/vm_controller.rb index f4a90b9..1b77db0 100644
> --- a/src/app/controllers/vm_controller.rb
> +++ b/src/app/controllers/vm_controller.rb
> @@ -130,6 +130,11 @@ class VmController < ApplicationController
> render :json => { :object => "vm", :success => true, :alert => alert
> } end
>
> + def start
> + @vm = Vm.find(params[:id])
> + render :layout => 'popup'
> + end
> +
> def migrate
> svc_get_for_migrate(params[:id])
> render :layout => 'popup'
> diff --git a/src/app/models/vm_task.rb b/src/app/models/vm_task.rb
> index 649001d..b8da529 100644
> --- a/src/app/models/vm_task.rb
> +++ b/src/app/models/vm_task.rb
> @@ -56,7 +56,9 @@ class VmTask < Task
>
> :success => Vm::STATE_RUNNING,
> :failure => Vm::STATE_STOPPED,
> :privilege =>
> :[Privilege::VM_CONTROL,
>
> -
> PRIV_OBJECT_VM_POOL]}, +
> PRIV_OBJECT_VM_POOL], +
> :popup_action => 'start'},
> +
> ACTION_SHUTDOWN_VM => { :label => "Shutdown",
>
> :icon => "icon_stop_11px.png",
> :start => Vm::STATE_RUNNING,
>
> diff --git a/src/app/views/vm/start.rhtml b/src/app/views/vm/start.rhtml
> new file mode 100644
> index 0000000..bed1d2d
> --- /dev/null
> +++ b/src/app/views/vm/start.rhtml
> @@ -0,0 +1,77 @@
> +<%- content_for :title do -%>
> + Start Virtual Machine
> +<%- end -%>
> +<%- content_for :description do -%>
> + Please choose a Host to start the Virtual Machine. Leave the selection
> blank to allow oVirt to choose the most appropriate starting host. +<%-
> end -%>
> +<div class="panel_header"></div>
> +
> +<form method="POST" id="start_vm_form" action="<%= url_for :action =>
> 'vm_action' %>"> + <div class="dialog_form">
> + <%= error_messages_for 'start_vm' %>
> +
> + <%= render :partial => '/host/grid', :locals => {
> + :table_id => 'start_vm_grid',
> + :hwpool => @vm.get_hardware_pool,
> + :exclude_pool => nil,
> + :exclude_host => nil,
> + :is_popup => true,
> + :checkboxes => false,
> + :on_select => 'start_vm_select',
> + :on_deselect => 'start_vm_deselect',
> + :on_hover => 'load_widget_hover',
> + :on_unhover => 'load_widget_unhover'
> + } %>
> +
> + <% form_tag do %>
> + <!--[form:start_vm]-->
> + <%= hidden_field_tag 'id', @vm.id %>
> + <%= hidden_field_tag 'vm_action', VmTask::ACTION_START_VM %>
> + Selected Migration Target:
> + <div id='selected_starting_host'>
> + <div class="selection_left">
> + <div>No starting host selected.</div>
> + </div>
> + </div>
> + <%= hidden_field_tag 'vm_action_data', "" %>
> + <% end %>
> + </div>
> + <%= popup_footer("$('#start_vm_form').submit()", "Start Virtual
> Machine") %> +</form>
> +<script type="text/javascript">
> + $(function() {
> +
> + $('#start_vm_form').ajaxForm({
> + dataType: 'json',
> + success: afterVm
> + });
> +
> + });
> +
> + function start_vm_select(selected_rows) {
> + var selected_ids = new Array();
> + for (i=0; i<selected_rows.length; i++) {
> + load_widget_select(selected_rows[i]);
> + selected_ids[i] = selected_rows[i].id;
> + }
> + if (selected_ids.length == 1) {
> + $('#selected_starting_host')
> + .load('<%= url_for :controller => "host", :action =>
> "quick_summary" %>', + { id:
> parseInt(selected_ids[0].substring(3)) });
> + $('#vm_action_data').val(selected_ids[0].substring(3));
> + }
> + }
> +
> + function start_vm_deselect(selected_rows) {
> + var selected_ids = new Array()
> + for (i=0; i<selected_rows.length; i++) {
> + load_widget_deselect(selected_rows[i]);
> + selected_ids[i] = selected_rows[i].id;
> + }
> + refresh_summary_static('selected_starting_host',
> + '<div class="selection_left"> \
> + <div>No starting host selected.</div> \
> + </div>');
> + $('#vm_action_data').val('');
> + }
> +</script>
> diff --git a/src/task-omatic/taskomatic.rb b/src/task-omatic/taskomatic.rb
> index 31c38e3..8e80115 100755
> --- a/src/task-omatic/taskomatic.rb
> +++ b/src/task-omatic/taskomatic.rb
> @@ -354,7 +354,12 @@ class TaskOmatic
> raise "Virtual machine is currently paused, cannot start, must
> resume." end
> end
> - db_host = find_capable_host(db_vm)
> +
> + if task.args
> + db_host =
> db_vm.vm_resource_pool.get_hardware_pool.hosts.find(task.args) + else
> + db_host = find_capable_host(db_vm)
> + end
>
> node = @qmfc.object(:class => "node", 'hostname' => db_host.hostname)
--
Arthur CLEMENT
Linagora Paris
More information about the ovirt-devel
mailing list