class ManifestWrapper

Constants

METHODS

We want to pass some methods through as well.

V20070829_FIELDS
V20071010_FIELDS
V3_FIELDS

All the manifest fields we support.

Attributes

manifest[R]

Should the caller want the underlying manifest for some reason.

Public Class Methods

new(manifest_xml) click to toggle source
# File lib/ec2/amitools/manifest_wrapper.rb, line 84
def initialize(manifest_xml)
  version = get_manifest_version(manifest_xml)
  
  if version > 20071010
    raise InvalidManifest.new("Manifest is too new for this tool to handle. Please upgrade.")
  end
  
  if version < 3
    raise InvalidManifest.new("Manifest is too old for this tool to handle.")
  end
  
  # Try figure out what manifest version we have
  @manifest = if ManifestV20071010::version20071010?(manifest_xml)
                ManifestV20071010.new(manifest_xml)
              elsif ManifestV20070829::version20070829?(manifest_xml)
                ManifestV20070829.new(manifest_xml)
              elsif ManifestV3::version3?(manifest_xml)
                ManifestV3.new(manifest_xml)
              else
                raise InvalidManifest.new("Unrecognised manifest version.")
              end
  
  # Now populate the fields. First, stuff that's in all the
  # manifests we deal with.
  V3_FIELDS.each do |field|
    instance_variable_set("@#{field.to_s}", @manifest.send(field))
  end
  
  # Next, the next version up.
  if @manifest.version > 3
    V20070829_FIELDS.each do |field|
      instance_variable_set("@#{field.to_s}", @manifest.send(field))
    end
  else
    # Some mandatory fields we need in later versions:
    @arch = 'i386'
  end
  
  # Next, the next version up.
  if @manifest.version > 20070829
    V20071010_FIELDS.each do |field|
      instance_variable_set("@#{field.to_s}", @manifest.send(field))
    end
  else
    # Some mandatory fields we need in later versions:
    @image_type = 'machine'
  end
end

Public Instance Methods

get_manifest_version(manifest_xml) click to toggle source
# File lib/ec2/amitools/manifest_wrapper.rb, line 74
def get_manifest_version(manifest_xml)
  begin
    version_elem = REXML::XPath.first(REXML::Document.new(manifest_xml), '/manifest/version')
    raise InvalidManifest.new("Invalid manifest.") if version_elem.nil?
    return version_elem.text.to_i
  rescue => e
    raise InvalidManifest.new("Invalid manifest.")
  end
end