lib/proxmox.rb in proxmox-0.0.2 vs lib/proxmox.rb in proxmox-0.0.3
- old
+ new
@@ -1,6 +1,6 @@
-require "proxmox/version"
+require 'proxmox/version'
require 'rest_client'
require 'json'
# This module encapsulates ability to manage Proxmox server
module Proxmox
@@ -24,11 +24,11 @@
@pve_cluster = pve_cluster
@node = node
@username = username
@password = password
@realm = realm
- @connection_status = "error"
+ @connection_status = 'error'
@site = RestClient::Resource.new(@pve_cluster)
@auth_params = create_ticket
end
# Get task status
@@ -86,11 +86,11 @@
# }
# }
#
def templates
data = http_action_get "nodes/#{@node}/storage/local/content"
- template_list = Hash.new
+ template_list = {}
data.each do |ve|
name = ve['volid'].gsub(/^local:vztmpl\/(.*).tar.gz$/, '\1')
template_list[name] = ve
end
template_list
@@ -133,11 +133,11 @@
# },
# [...]
# }
def openvz_get
data = http_action_get "nodes/#{@node}/openvz"
- ve_list = Hash.new
+ ve_list = {}
data.each do |ve|
ve_list[ve['vmid']] = ve
end
ve_list
end
@@ -294,21 +294,26 @@
#
def openvz_config(vmid)
http_action_get "nodes/#{@node}/openvz/#{vmid}/config"
end
+ def openvz_config_set(vmid, data)
+ http_action_put("nodes/#{@node}/openvz/#{vmid}/config", data)
+ end
+
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|
- if response.code == 200
- extract_ticket response
- else
- @connection_status = "error"
- end
+ post_param = { :username => @username, :realm => @realm, :password => @password }
+ @site['access/ticket'].post post_param do |response, request, result, &block|
+ if response.code == 200
+ extract_ticket response
+ else
+ @connection_status = "error"
end
+ end
end
# Method create ticket
def extract_ticket(response)
data = JSON.parse(response.body)
@@ -334,9 +339,15 @@
end
# Methods manage http dialogs
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|
check_response response
end
end
def http_action_get(url)