# File lib/aeolus_image/model/warehouse/image.rb, line 128 def by_environment(environment) self.where("($environment == \"" + environment + "\")") end
# File lib/aeolus_image/model/warehouse/image.rb, line 23 def initialize(obj) super @xml_body = Nokogiri::XML obj.body end
# File lib/aeolus_image/model/warehouse/image.rb, line 123 def architecture @architecture || os.arch end
Delete this image and all child objects
# File lib/aeolus_image/model/warehouse/image.rb, line 101 def delete! begin image_builds.each do |build| build.delete! end rescue NoMethodError end Image.delete(@uuid) end
# File lib/aeolus_image/model/warehouse/image.rb, line 89 def description unless @description @description = template_xpath("/template/description") end @description end
# File lib/aeolus_image/model/warehouse/image.rb, line 96 def environment @environment end
# File lib/aeolus_image/model/warehouse/image.rb, line 58 def image_builds ImageBuild.where("($image == \"" + @uuid.to_s + "\")") end
No template is created on imported images
# File lib/aeolus_image/model/warehouse/image.rb, line 112 def imported? !@template end
# File lib/aeolus_image/model/warehouse/image.rb, line 45 def latest_pushed_build ImageBuild.find(@latest_build) if @latest_build end
# File lib/aeolus_image/model/warehouse/image.rb, line 49 def latest_pushed_or_unpushed_build build = @latest_build ? ImageBuild.find(@latest_build) : nil push = @latest_unpushed ? ImageBuild.find(@latest_unpushed) : nil if build and push return push.timestamp > build.timestamp ? push : build end return build || push || nil end
TODO: We should get the image fields from the object body once we have it defined.
# File lib/aeolus_image/model/warehouse/image.rb, line 72 def name unless @name @name = @xml_body.xpath("/image/name").text if @name.empty? @name = template_xml.xpath("/template/name").text end end @name end
# File lib/aeolus_image/model/warehouse/image.rb, line 82 def os unless @os @os = OS.new(template_xpath("/template/os/name"), template_xpath("/template/os/version"), template_xpath("/template/os/arch")) end @os end
Return all Provider Images associated with this Image
# File lib/aeolus_image/model/warehouse/image.rb, line 63 def provider_images provider_images = [] image_builds.each do |b| provider_images = provider_images + b.provider_images end provider_images end
This can now return nil
# File lib/aeolus_image/model/warehouse/image.rb, line 29 def template_xml unless @template_xml begin # if an image is directly associated with template, use this if @template @template_xml = Template.find(@template).xml_body else @template_xml = Nokogiri::XML image_builds.first.target_images.first.target_template.body end rescue @template_xml = nil end end @template_xml end
template_xml.xpath(PATH).text => #template_xpath(PATH) Rescues exceptions and returns an empty string if necessary
# File lib/aeolus_image/model/warehouse/image.rb, line 118 def template_xpath(path) xml = template_xml xml.present? ? xml.xpath(path).text : "" end