From 74c9f0800e03f62846d2dd0b42a17cb034d10a0f Mon Sep 17 00:00:00 2001 From: Rodrigo Estebanez Date: Mon, 1 Jul 2013 17:27:12 +0200 Subject: [PATCH] make vm_customization to work --- .../generators/compute/customization.rb | 41 +++++++++++-------- .../models/compute/vm_customization.rb | 20 +++++++-- .../parsers/compute/vm_customization.rb | 2 +- lib/fog/vcloudng/requests/compute/helper.rb | 2 +- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/lib/fog/vcloudng/generators/compute/customization.rb b/lib/fog/vcloudng/generators/compute/customization.rb index 183afd855..7ae95c998 100644 --- a/lib/fog/vcloudng/generators/compute/customization.rb +++ b/lib/fog/vcloudng/generators/compute/customization.rb @@ -57,25 +57,34 @@ module Fog end def header - ' - Specifies Guest OS Customization Settings - ' + '' + end + # the order maters http://communities.vmware.com/thread/448760?start=0&tstart=0 + def body(opts={}) - "#{opts[:enabled]} - #{opts[:change_sid]} - #{opts[:virtual_machine_id]} - #{opts[:join_domain_enabled]} - #{opts[:use_org_settings]} - #{opts[:admin_password_enabled]} - #{opts[:admin_password_auto]} - #{opts[:reset_password_required]} - #{opts[:computer_name]} - #{CGI.escapeHTML(opts[:customization_script])}" + body = <Specifies Guest OS Customization Settings + #{opts[:enabled]} + #{opts[:change_sid]} + #{opts[:virtual_machine_id]} + #{opts[:join_domain_enabled]} + #{opts[:use_org_settings]} + #{opts[:admin_password_enabled]} + #{opts[:admin_password_auto]} + #{opts[:reset_password_required]} + #{CGI.escapeHTML(opts[:customization_script])} + #{opts[:computer_name]} +EOF end def tail diff --git a/lib/fog/vcloudng/models/compute/vm_customization.rb b/lib/fog/vcloudng/models/compute/vm_customization.rb index 762f72cff..089d72758 100644 --- a/lib/fog/vcloudng/models/compute/vm_customization.rb +++ b/lib/fog/vcloudng/models/compute/vm_customization.rb @@ -6,6 +6,7 @@ module Fog class VmCustomization < Fog::Model + identity :id attribute :type @@ -29,10 +30,21 @@ module Fog end def save - response = service.put_vm_customization(id, attributes) - task = response.body - task[:id] = task[:href].split('/').last - attributes[:customization_task] = service.tasks.new(task) + show_exception_body_error { + response = service.put_vm_customization(id, attributes) + task = response.body + task[:id] = task[:href].split('/').last + attributes[:customization_task] = service.tasks.new(task) + } + end + + def show_exception_body_error + yield + rescue => @e + raise @e unless @e.class.to_s =~ /^Excon::Errors/ + puts @e.response.status + puts CGI::unescapeHTML(@e.response.body) + raise @e end diff --git a/lib/fog/vcloudng/parsers/compute/vm_customization.rb b/lib/fog/vcloudng/parsers/compute/vm_customization.rb index a1b2f86f1..66a1e84fb 100644 --- a/lib/fog/vcloudng/parsers/compute/vm_customization.rb +++ b/lib/fog/vcloudng/parsers/compute/vm_customization.rb @@ -43,8 +43,8 @@ module Fog when 'ComputerName' @response[:computer_name] = value when 'CustomizationScript' - @response[:customization_script] = value @response[:has_customization_script] = !value.empty? + @response[:customization_script] = CGI::unescapeHTML(value) if @response[:has_customization_script] end end diff --git a/lib/fog/vcloudng/requests/compute/helper.rb b/lib/fog/vcloudng/requests/compute/helper.rb index 892668595..37f021725 100644 --- a/lib/fog/vcloudng/requests/compute/helper.rb +++ b/lib/fog/vcloudng/requests/compute/helper.rb @@ -1,7 +1,7 @@ module Fog module Compute module Helper - + def catalog_item_end_point(catalog_item_id = nil) end_point + ( catalog_item_id ? "catalogItem/#{catalog_item_id}" : "catalogItem" ) end