lib/proxmox.rb in proxmox-0.0.4 vs lib/proxmox.rb in proxmox-0.0.5
- old
+ new
@@ -32,10 +32,26 @@
@connection_status = 'error'
@site = RestClient::Resource.new(@pve_cluster, @ssl_options)
@auth_params = create_ticket
end
+ def get(path, args = {})
+ http_action_get(path, args)
+ end
+
+ def post(path, args = {})
+ http_action_post(path, args)
+ end
+
+ def put(path, args = {})
+ http_action_put(path, args)
+ end
+
+ def delete(path)
+ http_action_delete(path)
+ end
+
# Get task status
#
# :call-seq:
# task_status(task-id) -> String
#
@@ -49,11 +65,11 @@
# Examples return:
# - running
# - stopped:OK
#
def task_status(upid)
- data = http_action_get "nodes/#{@node}/tasks/#{URI::encode upid}/status"
+ data = http_action_get "nodes/#{@node}/tasks/#{URI.encode upid}/status"
status = data['status']
exitstatus = data['exitstatus']
if exitstatus
"#{status}:#{exitstatus}"
else
@@ -91,11 +107,11 @@
#
def templates
data = http_action_get "nodes/#{@node}/storage/local/content"
template_list = {}
data.each do |ve|
- name = ve['volid'].gsub(/^local:vztmpl\/(.*).tar.gz$/, '\1')
+ name = ve['volid'].gsub(%r{local:vztmpl\/(.*).tar.gz}, '\1')
template_list[name] = ve
end
template_list
end
@@ -321,11 +337,11 @@
private
# Methods manages auth
def create_ticket
post_param = { username: @username, realm: @realm, password: @password }
- @site['access/ticket'].post post_param do |response, request, result, &block|
+ @site['access/ticket'].post post_param do |response, _request, _result, &_block|
if response.code == 200
extract_ticket response
else
@connection_status = 'error'
end
@@ -355,29 +371,29 @@
'NOK: error code = ' + response.code.to_s
end
end
# Methods manage http dialogs
- def http_action_post(url, data = '')
- @site[url].post data, @auth_params do |response, request, result, &block|
+ def http_action_post(url, data = {})
+ @site[url].post data, @auth_params do |response, _request, _result, &_block|
check_response response
end
end
- def http_action_put(url, data = '')
- @site[url].put data, @auth_params do |response, request, result, &block|
+ def http_action_put(url, data = {})
+ @site[url].put data, @auth_params do |response, _request, _result, &_block|
check_response response
end
end
- def http_action_get(url)
- @site[url].get @auth_params do |response, request, result, &block|
+ def http_action_get(url, data = {})
+ @site[url].get @auth_params.merge(data) do |response, _request, _result, &_block|
check_response response
end
end
def http_action_delete(url)
- @site[url].delete @auth_params do |response, request, result, &block|
+ @site[url].delete @auth_params do |response, _request, _result, &_block|
check_response response
end
end
end
end