[Ovirt-devel] [PATCH] added hardware_pool and vm_pool to tasks to facilitate pool-level task summaries.

Steve Linabery slinabery at redhat.com
Wed Aug 27 19:16:52 UTC 2008


On Mon, Aug 25, 2008 at 10:06:55AM -0400, Scott Seago wrote:
> 
> Signed-off-by: Scott Seago <sseago at redhat.com>
> ---
>  wui/src/app/models/hardware_pool.rb          |    1 +
>  wui/src/app/models/host_task.rb              |    4 ++
>  wui/src/app/models/storage_task.rb           |    4 ++
>  wui/src/app/models/task.rb                   |    2 +
>  wui/src/app/models/vm_resource_pool.rb       |    1 +
>  wui/src/app/models/vm_task.rb                |    7 +++
>  wui/src/db/migrate/016_add_pools_to_tasks.rb |   58 ++++++++++++++++++++++++++
>  7 files changed, 77 insertions(+), 0 deletions(-)
>  create mode 100644 wui/src/db/migrate/016_add_pools_to_tasks.rb
> 
> diff --git a/wui/src/app/models/hardware_pool.rb b/wui/src/app/models/hardware_pool.rb
> index 276779f..3678420 100644
> --- a/wui/src/app/models/hardware_pool.rb
> +++ b/wui/src/app/models/hardware_pool.rb
> @@ -19,6 +19,7 @@
>  
>  class HardwarePool < Pool
>  
> +  has_many :tasks, :dependent => :nullify, :order => "id ASC"
>    def all_storage_volumes
>      StorageVolume.find(:all, :include => {:storage_pool => :hardware_pool}, :conditions => "pools.id = #{id}")
>    end
> diff --git a/wui/src/app/models/host_task.rb b/wui/src/app/models/host_task.rb
> index 5cce5b9..ae597b0 100644
> --- a/wui/src/app/models/host_task.rb
> +++ b/wui/src/app/models/host_task.rb
> @@ -21,4 +21,8 @@ class HostTask < Task
>    belongs_to :host
>  
>    ACTION_CLEAR_VMS = "clear_vms"
> +
> +  def after_initialize
> +    self.hardware_pool = host.hardware_pool if self.host
> +  end
>  end
> diff --git a/wui/src/app/models/storage_task.rb b/wui/src/app/models/storage_task.rb
> index 5d67b98..e57b6de 100644
> --- a/wui/src/app/models/storage_task.rb
> +++ b/wui/src/app/models/storage_task.rb
> @@ -21,4 +21,8 @@ class StorageTask < Task
>    belongs_to :storage_pool
>  
>    ACTION_REFRESH_POOL = "refresh_pool"
> +
> +  def after_initialize
> +    self.hardware_pool = storage_pool.hardware_pool if self.storage_pool
> +  end
>  end
> diff --git a/wui/src/app/models/task.rb b/wui/src/app/models/task.rb
> index 7960056..a7faaf0 100644
> --- a/wui/src/app/models/task.rb
> +++ b/wui/src/app/models/task.rb
> @@ -18,6 +18,8 @@
>  # also available at http://www.gnu.org/copyleft/gpl.html.
>  
>  class Task < ActiveRecord::Base
> +  belongs_to :hardware_pool
> +  belongs_to :vm_resource_pool
>  
>    STATE_QUEUED       = "queued"
>    STATE_RUNNING      = "running"
> diff --git a/wui/src/app/models/vm_resource_pool.rb b/wui/src/app/models/vm_resource_pool.rb
> index d3f7d43..fff6dac 100644
> --- a/wui/src/app/models/vm_resource_pool.rb
> +++ b/wui/src/app/models/vm_resource_pool.rb
> @@ -19,6 +19,7 @@
>  
>  class VmResourcePool < Pool
>  
> +  has_many :tasks, :dependent => :nullify, :order => "id ASC"
>    def get_type_label
>      "Virtual Machine Pool"
>    end
> diff --git a/wui/src/app/models/vm_task.rb b/wui/src/app/models/vm_task.rb
> index 3f52478..ab96e6f 100644
> --- a/wui/src/app/models/vm_task.rb
> +++ b/wui/src/app/models/vm_task.rb
> @@ -107,6 +107,13 @@ class VmTask < Task
>                                                       PRIV_OBJECT_HW_POOL],
>                                        :popup_action => 'migrate'} }
>  
> +  def after_initialize
> +    if self.vm
> +      self.vm_resource_pool = vm.vm_resource_pool
> +      self.hardware_pool = vm.get_hardware_pool
> +    end
> +  end
> +
>    def self.valid_actions_for_vm_state(state, vm=nil, user=nil)
>      actions = []
>      ACTIONS.each do |action, hash|
> diff --git a/wui/src/db/migrate/016_add_pools_to_tasks.rb b/wui/src/db/migrate/016_add_pools_to_tasks.rb
> new file mode 100644
> index 0000000..58ff83d
> --- /dev/null
> +++ b/wui/src/db/migrate/016_add_pools_to_tasks.rb
> @@ -0,0 +1,58 @@
> +#
> +# Copyright (C) 2008 Red Hat, Inc.
> +# Written by Scott Seago <sseago at redhat.com>
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; version 2 of the License.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> +# MA  02110-1301, USA.  A copy of the GNU General Public License is
> +# also available at http://www.gnu.org/copyleft/gpl.html.
> +
> +class AddPoolsToTasks < ActiveRecord::Migration
> +  def self.up
> +    add_column :tasks, :vm_resource_pool_id, :integer
> +    add_column :tasks, :hardware_pool_id, :integer
> +    execute "alter table tasks add constraint fk_tasks_vm_pools
> +             foreign key (vm_resource_pool_id) references pools(id)"
> +    execute "alter table tasks add constraint fk_tasks_hw_pools
> +             foreign key (hardware_pool_id) references pools(id)"
> +    Task.transaction do
> +      VmTask.find(:all).each do |task|
> +        vm = task.vm
> +        if vm
> +          task.vm_resource_pool = vm.vm_resource_pool
> +          task.hardware_pool = vm.get_hardware_pool
> +          task.save!
> +        end
> +      end
> +      StorageTask.find(:all).each  do |task|
> +        pool = task.storage_pool
> +        if pool
> +          task.hardware_pool = pool.hardware_pool
> +          task.save!
> +        end
> +      end
> +      HostTask.find(:all).each do |task|
> +        host = task.host
> +        if host
> +          task.hardware_pool = host.hardware_pool
> +          task.save!
> +        end
> +      end
> +    end
> +  end
> +
> +  def self.down
> +    remove_column :tasks, :vm_resource_pool_id
> +    remove_column :tasks, :hardware_pool_id
> +  end
> +end
> -- 
> 1.5.5.1
> 
> _______________________________________________
> Ovirt-devel mailing list
> Ovirt-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/ovirt-devel

Works for me. ACK!




More information about the ovirt-devel mailing list