How to Create Image (EBS AMI) from customised server

387 views
Skip to first unread message

Eliot Sykes

unread,
Jul 9, 2011, 10:37:05 AM7/9/11
to ruby-fog
Hi all,

Happily using fog to create and customise a server instance on AWS.

I'd now like to use fog to automate the "Create Image (EBS AMI)"
command I can perform on this custom server when using the AWS web
interface.

I've tried out server.save but with no success.

Does anyone know how to use fog to create an image on EBS for this
running server?

Kind regards,

Eliot

geemus (Wesley Beary)

unread,
Jul 11, 2011, 12:54:29 PM7/11/11
to ruby...@googlegroups.com
Unfortunately this doesn't currently have anything available in the
nicer abstracted interfaces at the moment, but it is still quite
doable. Here is a quick example:

compute = Fog::Compute.new ...

server = compute.servers.create ...
# customization of server goes here

image_name = 'my_new_image'
image_description = 'updated to latest foo'
data = compute.create_image(server.identity, image_name, image_description)
image_id = data.body['imageId']

server.destroy

I think that should cover what you are after and perhaps it should be
added to the model abstraction somewhere, but it is kind of an odd fit
so I haven't figured out exactly where I would want to put it. If you
want to see the specifics of the call in question you can also look
here: https://github.com/geemus/fog/blob/master/lib/fog/compute/requests/aws/create_image.rb

Hope that sorts it out, let me know if I can clarify anything for you.

Thanks!
wes

am4

unread,
Apr 22, 2012, 9:57:23 PM4/22/12
to ruby...@googlegroups.com
Hi Wes, 

The code you provided seems to work (I can see that the AMI creation is initiated), but it fails (possibly due to the server.destroy being called too soon?).
Is there (now) a better way to do this? (Or maybe query AWS to see if AMI creation has completed so that we can destroy the instance).

Thx
Akshay


On Monday, July 11, 2011 9:54:29 AM UTC-7, geemus wrote:
Unfortunately this doesn't currently have anything available in the
nicer abstracted interfaces at the moment, but it is still quite
doable.  Here is a quick example:

    compute = Fog::Compute.new ...

    server = compute.servers.create ...
    # customization of server goes here

    image_name = 'my_new_image'
    image_description = 'updated to latest foo'
    data = compute.create_image(server.identity, image_name, image_description)
    image_id = data.body['imageId']

    server.destroy

I think that should cover what you are after and perhaps it should be
added to the model abstraction somewhere, but it is kind of an odd fit
so I haven't figured out exactly where I would want to put it.  If you
want to see the specifics of the call in question you can also look
here: https://github.com/geemus/fog/blob/master/lib/fog/compute/requests/aws/create_image.rb

Hope that sorts it out, let me know if I can clarify anything for you.

Thanks!
wes

geemus (Wesley Beary)

unread,
Apr 24, 2012, 12:15:38 PM4/24/12
to ruby...@googlegroups.com
Ah, yeah. Sorry I skipped over that part. I think you should be able
to add something like this just before the destroy so that it will
wait correctly:

Fog.wait_for do
compute.describe_images('ImageId' =>
image_id).body['ImagesSet'].first['ImageState'] == ?
end

I left it as ? because I don't know off hand what the "complete" or
"ready" state value actually is, but you should be able to figure it
out with a little trial and error. Hopefully that gets you what you
need, but if not just let me know and I'll try to fill in the
remaining gaps.

Thanks!
wes

Reply all
Reply to author
Forward
0 new messages