Class: ManifestWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2/amitools/manifest_wrapper.rb

Defined Under Namespace

Classes: InvalidManifest

Constant Summary collapse

V3_FIELDS =

All the manifest fields we support.

[
 :name,
 :user,
 :parts,
 :size,
 :bundled_size,
 :user_encrypted_key,
 :ec2_encrypted_key,
 :cipher_algorithm,
 :user_encrypted_iv,
 :ec2_encrypted_iv,
 :digest,
 :digest_algorithm,
 :bundler_name,
 :bundler_version,
 :bundler_release,
]
V20070829_FIELDS =
[
 :arch,
]
V20071010_FIELDS =
[
 :image_type,
 :kernel_id,
 :ramdisk_id,
 :product_codes,
 :ancestor_ami_ids,
 :block_device_mapping,
 :kernel_name,
]
METHODS =

We want to pass some methods through as well.

[
 :authenticate,
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest_xml) ⇒ ManifestWrapper

Returns a new instance of ManifestWrapper.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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

Instance Attribute Details

#manifestObject (readonly)

Should the caller want the underlying manifest for some reason.



72
73
74
# File 'lib/ec2/amitools/manifest_wrapper.rb', line 72

def manifest
  @manifest
end

Instance Method Details

#get_manifest_version(manifest_xml) ⇒ Object



74
75
76
77
78
79
80
81
82
# 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