From 24adf4b7ffe663e5de8400b69c1b7d1502ebfdda Mon Sep 17 00:00:00 2001 From: geemus Date: Sun, 25 Apr 2010 11:11:43 -0700 Subject: [PATCH] redo marios fixes that accidently got lost in rebase --- .../shared/instantiate_vapp_template.rb | 138 +++++++----------- 1 file changed, 49 insertions(+), 89 deletions(-) diff --git a/lib/fog/terremark/requests/shared/instantiate_vapp_template.rb b/lib/fog/terremark/requests/shared/instantiate_vapp_template.rb index 763f3d4a0..f861056bb 100644 --- a/lib/fog/terremark/requests/shared/instantiate_vapp_template.rb +++ b/lib/fog/terremark/requests/shared/instantiate_vapp_template.rb @@ -1,113 +1,73 @@ module Fog module Terremark module Shared - module Real + class Real # Instatiate a vapp template # # ==== Parameters - # * vdc_id<~Integer> - Id of vdc to instantiate template in + # * name<~String>: Name of the resulting vapp .. must start with letter, up to 15 chars alphanumeric. # * options<~Hash>: - # * cpus<~Integer>: Number of cpus in [1, 2, 4, 8], defaults to 1 - # * memory<~Integer>: Amount of memory either 512 or a multiple of 1024, defaults to 512 + # * cpus<~Integer>: Number of cpus in [1, 2, 4, 8], defaults to 1 + # * memory<~Integer>: Amount of memory either 512 or a multiple of 1024, defaults to 512 + # * vapp_template<~String>: id of the vapp template to be instantiated # ==== Returns # * response<~Excon::Response>: - # * body<~Hash>: - - # FIXME - - # * 'CatalogItems'<~Array> - # * 'href'<~String> - linke to item - # * 'name'<~String> - name of item - # * 'type'<~String> - type of item - # * 'description'<~String> - Description of catalog - # * 'name'<~String> - Name of catalog - def instantiate_vapp_template(name, options = {}) + # * body<~Hash>: + # * 'Links;<~Array> (e.g. up to vdc) + # * 'href'<~String> Link to the resulting vapp + # * 'name'<~String> - name of item + # * 'type'<~String> - type of item + # * 'status'<~String> - 0(pending) --> 2(off) -->4(on) + def instantiate_vapp_template(name, vapp_template, options = {}) + unless name.length < 15 + raise ArgumentError.new('Name must be fewer than 15 characters') + end options['cpus'] ||= 1 options['memory'] ||= 512 - - # FIXME: much cheating to commence - vdc_id = default_vdc_id - network_id = default_network_id - catalog_item = 12 # Ubuntu JeOS 9.10 (64-bit) - - # case UNRESOLVED: - # return "0"; - # case RESOLVED: - # return "1"; - # case OFF: - # return "2"; - # case SUSPENDED: - # return "3"; - # case ON: - # return "4"; - # default: - # - # /** - # * The vApp is unresolved (one or more file references are unavailable in the cloud) - # */ - # UNRESOLVED, - # /** - # * The vApp is resolved (all file references are available in the cloud) but not deployed - # */ - # RESOLVED, - # /** - # * The vApp is deployed and powered off - # */ - # OFF, - # /** - # * The vApp is deployed and suspended - # */ - # SUSPENDED, - # /** - # * The vApp is deployed and powered on - # */ - # ON; + options['network_id'] ||= default_network_id + options['vdc_id'] ||= default_vdc_id data = <<-DATA - - - - - - - - 1 - 3 - #{options['cpus']} - - - 2 - 4 - #{options['memory']} - - - - - - allowInOut - true - - - - - - - DATA + + + + + + + + 1 + 3 + #{options['cpus']} + + + 2 + 4 + #{options['memory']} + + + + + + + + + +DATA request( - :body => data, - :expects => 200, - :headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml' }, - :method => 'POST', - :parser => Fog::Parsers::Terremark::Shared::InstantiateVappTemplate.new, - :path => "vdc/#{vdc_id}/action/instantiatevAppTemplate" + :body => data, + :expects => 200, + :headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml' }, + :method => 'POST', + :parser => Fog::Parsers::Terremark::InstantiateVappTemplate.new, + :path => "vdc/#{options['vdc_id']}/action/instantiatevAppTemplate" ) end end - module Mock + class Mock def instatiate_vapp_template(vapp_template_id) raise MockNotImplemented.new("Contributions welcome!")