mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
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.
This commit is contained in:
parent
d6defb6bb8
commit
e20851f044
@ -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
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user