class Aeolus::Image::Warehouse::Image

Constants

OS

Public Class Methods

by_environment(environment) click to toggle source
# File lib/aeolus_image/model/warehouse/image.rb, line 128
def by_environment(environment)
  self.where("($environment == \"" + environment + "\")")
end
new(obj) click to toggle source
# File lib/aeolus_image/model/warehouse/image.rb, line 23
def initialize(obj)
  super
  @xml_body = Nokogiri::XML obj.body
end

Public Instance Methods

architecture() click to toggle source
# File lib/aeolus_image/model/warehouse/image.rb, line 123
def architecture
  @architecture || os.arch
end
delete!() click to toggle source

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
description() click to toggle source
# File lib/aeolus_image/model/warehouse/image.rb, line 89
def description
  unless @description
    @description = template_xpath("/template/description")
  end
  @description
end
environment() click to toggle source
# File lib/aeolus_image/model/warehouse/image.rb, line 96
def environment
  @environment
end
image_builds() click to toggle source
# File lib/aeolus_image/model/warehouse/image.rb, line 58
def image_builds
  ImageBuild.where("($image == \"" + @uuid.to_s + "\")")
end
imported?() click to toggle source

No template is created on imported images

# File lib/aeolus_image/model/warehouse/image.rb, line 112
def imported?
  !@template
end
latest_pushed_build() click to toggle source
# File lib/aeolus_image/model/warehouse/image.rb, line 45
def latest_pushed_build
  ImageBuild.find(@latest_build) if @latest_build
end
latest_pushed_or_unpushed_build() click to toggle source
# 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
name() click to toggle source

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
os() click to toggle source
# 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
provider_images() click to toggle source

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
template_xml() click to toggle source

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_xpath(path) click to toggle source

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