<div dir="ltr">Hi,<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 14, 2014 at 3:50 PM, Stephen Nelson-Smith <span dir="ltr"><<a href="mailto:sanelson@gmail.com" target="_blank">sanelson@gmail.com</a>></span> wrote:<br>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra">I'm currently thinking something like (untested, caffeinated):<br>
<div class="gmail_quote"><div>
<br>images = ec2.describe_images(owners: ['self']).images.map(&:to_h)<br>serialised_images = images.to_json<br>MyEc2Struct = Struct.new(images.keys)<br></div><div>canned_images = serialised_images.reduce(MyEc2Struct.new) {|s, kv| s[kv[0]] = kv[1]; s}<span class=""><font color="#888888"><br>
</font></span></div></div></div></div></blockquote><div><br></div><div>OK so:<br><br><br>images = ec2.describe_images(owners: ['self']).images.[1..3]<br>[10] pry(main)> images[0].image_id<br>=> "ami-00ccc374"<br>
[11] pry(main)> images[0].name<br>=> "64-bit Debian 6.0 EBS (1.8) 2013-01-11"<br>File.write('serialised_images.json', images.map(&:to_h).to_json)<br><br></div><div>--- New Session ---<br></div>
<div><br>require 'json'<br>images = JSON.parse(serialised_images)<br>Images = Struct.new(*images[0].keys.map(&:to_sym))<br>Images.members<br>=> [:image_id,<br> :image_location,<br> :state,<br> :owner_id,<br>
:public,<br> :product_codes,<br> :architecture,<br> :image_type,<br> :kernel_id,<br> :ramdisk_id,<br> :platform,<br> :sriov_net_support,<br> :state_reason,<br> :image_owner_alias,<br> :name,<br> :description,<br> :root_device_type,<br>
:root_device_name,<br> :block_device_mappings,<br> :virtualization_type,<br> :tags,<br> :hypervisor]<br><br>original = images.map { |img| img.reduce(Images.new) { |s, kv| s[kv[0]] = kv[1]; s } }<br>[21] pry(main)> original[0].name<br>
=> "64-bit Debian 6.0 EBS (1.8) 2013-01-11"<br>[22] pry(main)> original[0].image_id<br>=> "ami-00ccc374"<br><br></div><div>Not perfect, as there are some nested structs (eg tags) but it's a start!<br>
</div><div><br></div></div></div></div>