From 297d2be06cac97b237fc52b4936e1539cb1febab Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 21 May 2013 21:11:06 +0800 Subject: [PATCH] [stormondemand|compute] Add all template APIs --- lib/fog/storm_on_demand/compute.rb | 2 ++ .../storm_on_demand/models/compute/template.rb | 8 +++++++- .../storm_on_demand/models/compute/templates.rb | 9 +++++++-- .../requests/compute/get_template_details.rb | 16 ++++++++++++++++ .../requests/compute/list_templates.rb | 4 ++-- .../requests/compute/restore_template.rb | 16 ++++++++++++++++ 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 lib/fog/storm_on_demand/requests/compute/get_template_details.rb create mode 100644 lib/fog/storm_on_demand/requests/compute/restore_template.rb diff --git a/lib/fog/storm_on_demand/compute.rb b/lib/fog/storm_on_demand/compute.rb index edbadd4b7..63312a4c3 100644 --- a/lib/fog/storm_on_demand/compute.rb +++ b/lib/fog/storm_on_demand/compute.rb @@ -58,6 +58,8 @@ module Fog request :get_config_details request :list_templates + request :get_template_details + request :restore_template request :list_images request :create_image diff --git a/lib/fog/storm_on_demand/models/compute/template.rb b/lib/fog/storm_on_demand/models/compute/template.rb index 12a4491a6..98a58cb3b 100644 --- a/lib/fog/storm_on_demand/models/compute/template.rb +++ b/lib/fog/storm_on_demand/models/compute/template.rb @@ -7,16 +7,22 @@ module Fog class Template < Fog::Model identity :id attribute :name + attribute :deprecated attribute :description attribute :manage_level attribute :os - attribute :price + attribute :zone_availability end def initialize(attributes={}) super end + def restore(options) + requires :identity + service.restore_template({:id => identity}.merge!(options)) + end + end end end diff --git a/lib/fog/storm_on_demand/models/compute/templates.rb b/lib/fog/storm_on_demand/models/compute/templates.rb index 50b471259..9953135a1 100644 --- a/lib/fog/storm_on_demand/models/compute/templates.rb +++ b/lib/fog/storm_on_demand/models/compute/templates.rb @@ -9,11 +9,16 @@ module Fog model Fog::Compute::StormOnDemand::Template - def all - data = service.list_templates.body['items'] + def all(options={}) + data = service.list_templates(options).body['items'] load(data) end + def get(template_id) + tpl = service.get_template_details(:id => template_id).body + new(tpl) + end + end end diff --git a/lib/fog/storm_on_demand/requests/compute/get_template_details.rb b/lib/fog/storm_on_demand/requests/compute/get_template_details.rb new file mode 100644 index 000000000..6580a4994 --- /dev/null +++ b/lib/fog/storm_on_demand/requests/compute/get_template_details.rb @@ -0,0 +1,16 @@ +module Fog + module Compute + class StormOnDemand + class Real + + def get_template_details(options={}) + request( + :path => '/Storm/Template/details', + :body => Fog::JSON.encode(:params => options) + ) + end + + end + end + end +end diff --git a/lib/fog/storm_on_demand/requests/compute/list_templates.rb b/lib/fog/storm_on_demand/requests/compute/list_templates.rb index 0d56975da..99a638837 100644 --- a/lib/fog/storm_on_demand/requests/compute/list_templates.rb +++ b/lib/fog/storm_on_demand/requests/compute/list_templates.rb @@ -5,8 +5,8 @@ module Fog def list_templates(options = {}) request( - :path => "/server/template/list", - :body => Fog::JSON.encode(options) + :path => "/Storm/Template/list", + :body => Fog::JSON.encode(:params => options) ) end diff --git a/lib/fog/storm_on_demand/requests/compute/restore_template.rb b/lib/fog/storm_on_demand/requests/compute/restore_template.rb new file mode 100644 index 000000000..38a2016f6 --- /dev/null +++ b/lib/fog/storm_on_demand/requests/compute/restore_template.rb @@ -0,0 +1,16 @@ +module Fog + module Compute + class StormOnDemand + class Real + + def restore_template(options={}) + request( + :path => '/Storm/Template/restore', + :body => Fog::JSON.encode(:params => options) + ) + end + + end + end + end +end