From 97854e31d4733aed149b616c252e7447ad7cdbc4 Mon Sep 17 00:00:00 2001 From: Lee Huffman Date: Wed, 7 Sep 2011 12:43:12 -0700 Subject: [PATCH] [bluebox|compute] Create and destroy images --- lib/fog/bluebox/compute.rb | 2 ++ lib/fog/bluebox/models/compute/image.rb | 19 +++++++++++-- .../requests/compute/create_template.rb | 27 +++++++++++++++++++ .../requests/compute/destroy_template.rb | 26 ++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 lib/fog/bluebox/requests/compute/create_template.rb create mode 100644 lib/fog/bluebox/requests/compute/destroy_template.rb diff --git a/lib/fog/bluebox/compute.rb b/lib/fog/bluebox/compute.rb index 51f039baa..fb08687e4 100644 --- a/lib/fog/bluebox/compute.rb +++ b/lib/fog/bluebox/compute.rb @@ -25,6 +25,8 @@ module Fog request :get_products request :get_template request :get_templates + request :create_template + request :destroy_template request :reboot_block class Mock diff --git a/lib/fog/bluebox/models/compute/image.rb b/lib/fog/bluebox/models/compute/image.rb index 93fb1725e..f3af4709e 100644 --- a/lib/fog/bluebox/models/compute/image.rb +++ b/lib/fog/bluebox/models/compute/image.rb @@ -7,11 +7,26 @@ module Fog class Image < Fog::Model identity :id - + + attribute :block_id attribute :description attribute :public attribute :created_at, :aliases => 'created' - + + def save + requires :block_id + + data = connection.create_template(block_id, attributes) + true + end + + def destroy + requires :id + + data = connection.destroy_template(id) + true + end + end end diff --git a/lib/fog/bluebox/requests/compute/create_template.rb b/lib/fog/bluebox/requests/compute/create_template.rb new file mode 100644 index 000000000..fcc9e0dba --- /dev/null +++ b/lib/fog/bluebox/requests/compute/create_template.rb @@ -0,0 +1,27 @@ +module Fog + module Compute + class Bluebox + class Real + + # Create a template from block + # + # ==== Parameters + # * block_id<~Integer> - Id of block to create template from + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Array>: + # TODO + def create_template(block_id, options={}) + request( + :expects => 200, + :method => 'POST', + :path => "api/block_templates.json", + :query => {'id' => block_id}.merge!(options) + ) + end + + end + end + end +end diff --git a/lib/fog/bluebox/requests/compute/destroy_template.rb b/lib/fog/bluebox/requests/compute/destroy_template.rb new file mode 100644 index 000000000..b788e3bd6 --- /dev/null +++ b/lib/fog/bluebox/requests/compute/destroy_template.rb @@ -0,0 +1,26 @@ +module Fog + module Compute + class Bluebox + class Real + + # Create a template from block + # + # ==== Parameters + # * id<~Integer> - Id of image to destroy + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Array>: + # TODO + def destroy_template(id) + request( + :expects => 200, + :method => 'DELETE', + :path => "api/block_templates/#{id}.json" + ) + end + + end + end + end +end