From e20851f044ba1edf9d5a292b595039851523ecfb Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 6 Oct 2011 14:43:48 +0200 Subject: [PATCH] Feature #789: Small improvements to OZonesClient and cli helpers The client's default template attribute to put_resource() and post_resource() is now a JSON string. post/put_resource_str() converts a ONE template into json (method to_body) and then calls put/post_resource() post_resource_file() reads the ONE template from file, then calls post_resource_str() cli helpers have been accordingly updated. FORCE attribute handling has been remove from delhost action. --- src/ozones/Client/bin/onevdc | 2 +- src/ozones/Client/lib/OZonesClient.rb | 22 ++++++++++++------- src/ozones/Client/lib/cli/ozones_helper.rb | 2 +- .../lib/cli/ozones_helper/vdc_helper.rb | 8 ++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/ozones/Client/bin/onevdc b/src/ozones/Client/bin/onevdc index 0ad2e6c85b..246487f312 100755 --- a/src/ozones/Client/bin/onevdc +++ b/src/ozones/Client/bin/onevdc @@ -64,7 +64,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do end command :delhost, 'Deletes the set of hosts from the VDC', - :vdcid, :range, :options=>[FORCE] do + :vdcid, :range do helper.delhost(args[0], args[1], options) end end diff --git a/src/ozones/Client/lib/OZonesClient.rb b/src/ozones/Client/lib/OZonesClient.rb index bb015b6f63..f139b0a3ad 100644 --- a/src/ozones/Client/lib/OZonesClient.rb +++ b/src/ozones/Client/lib/OZonesClient.rb @@ -89,18 +89,21 @@ EOT # Post a new Resource to the relevant OZones Pool # :zonetemplate ###################################################################### - def post_resource(kind, template) + def post_resource_file(kind, template) tmpl_str = File.read(template) post_resource_str(kind, tmpl_str) end def post_resource_str(kind, tmpl_str) - body_str = OZonesClient::to_body(kind, tmpl_str) - + tmpl_json = OZonesClient::tobody(tmpl_str) + post_resource(kind, tmpl_json) + end + + def post_resource(kind, tmpl_json) url = URI.parse("#{@endpoint}/#{kind}") req = Net::HTTP::Post.new(url.path) - req.body=body_str + req.body=tmpl_json req.basic_auth @ozonesauth[0], @ozonesauth[1] @@ -111,13 +114,16 @@ EOT return OZonesClient::parse_error(res, kind) end - def put_resource(kind, id, tmpl_str) - body_str = OZonesClient::to_body(kind, tmpl_str) - + def put_resource_str(kind, id, tmpl_str) + tmpl_json = OZonesClient::to_body(kind, tmpl_str) + put_resource(kind, id, tmpl_json) + end + + def put_resource(kind, id, tmpl_json) url = URI.parse("#{@endpoint}/#{kind}/#{id}") req = Net::HTTP::Put.new(url.path) - req.body=body_str + req.body=tmpl_json req.basic_auth @ozonesauth[0], @ozonesauth[1] diff --git a/src/ozones/Client/lib/cli/ozones_helper.rb b/src/ozones/Client/lib/cli/ozones_helper.rb index 6363e1f7fb..70115f8832 100644 --- a/src/ozones/Client/lib/cli/ozones_helper.rb +++ b/src/ozones/Client/lib/cli/ozones_helper.rb @@ -29,7 +29,7 @@ module OZonesHelper end def create_resource(kind, template) - rc = @client.post_resource(kind, template) + rc = @client.post_resource_file(kind, template) if OZonesClient::is_error?(rc) [-1, rc.message] diff --git a/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb b/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb index b3d56bdd2c..6ddb48e412 100644 --- a/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb +++ b/src/ozones/Client/lib/cli/ozones_helper/vdc_helper.rb @@ -72,7 +72,7 @@ class VDCHelper < OZonesHelper::OZHelper template << "FORCE=YES\n" end - rc = @client.put_resource(@vdc_str, id, template) + rc = @client.put_resource_str(@vdc_str, id, template) if OZonesClient::is_error?(rc) return [-1, rc.message] @@ -95,11 +95,7 @@ class VDCHelper < OZonesHelper::OZHelper new_host = (hosts - host_array).join(',') template = "ID=#{id}\nHOSTS=#{new_host}\n" - if options[:force] - template << "FORCE=YES\n" - end - - rc = @client.put_resource(@vdc_str, id, template) + rc = @client.put_resource_str(@vdc_str, id, template) if OZonesClient::is_error?(rc) return [-1, rc.message]