Project

General

Profile

Download (1.19 KB) Statistics
| Branch: | Tag: | Revision:
dd42df0a Ohad Levy
class Image < ActiveRecord::Base
acfbc458 Marek Hulan
include Authorizable
229d7436 Joseph Magen
audited :allow_mass_assignment => true

dd42df0a Ohad Levy
belongs_to :operatingsystem
belongs_to :compute_resource
belongs_to :architecture
f2c78d4a Joseph Magen
e0d618ef Joseph Magen
has_many_hosts :dependent => :nullify
3034e8e2 Ori Rabin
validates_lengths_from_database
f2c78d4a Joseph Magen
validates :username, :name, :operatingsystem_id, :compute_resource_id, :architecture_id, :presence => true
validates :uuid, :presence => true, :uniqueness => {:scope => :compute_resource_id}
4cbb4a26 Tom Caspy
validate :uuid_exists?
dd42df0a Ohad Levy
scoped_search :on => [:name, :username], :complete_value => true
scoped_search :in => :compute_resources, :on => :name, :complete_value => :true, :rename => "compute_resource"
1b784c5b Tomer Brisker
scoped_search :in => :architecture, :on => :id, :rename => "architecture", :complete_enabled => false, :only_explicit => true
scoped_search :in => :operatingsystem, :on => :id, :rename => "operatingsystem", :complete_enabled => false, :only_explicit => true
fba2bf5f Greg Sutcliffe
scoped_search :on => :user_data, :complete_value => {:true => true, :false => false}
dd42df0a Ohad Levy
4cbb4a26 Tom Caspy
private

def uuid_exists?
return true if compute_resource.blank?
errors.add(:uuid, _("could not be found in %s") % compute_resource.name) unless compute_resource.image_exists?(uuid)
end
dd42df0a Ohad Levy
end