Module: Proxmox::RestConnection

Included in:
Base, Base
Defined in:
lib/pve/proxmox.rb

Instance Method Summary collapse

Instance Method Details

#bench(path) ⇒ Object



88
89
90
91
92
93
# File 'lib/pve/proxmox.rb', line 88

def bench path
  #t = Time.now
  r = yield
  #p path => Time.now-t
  r
end

#rest_del(path, &exe) ⇒ Object



105
106
107
# File 'lib/pve/proxmox.rb', line 105

def rest_del path, &exe
  __response__ Proxmox.connection[path].delete( __headers__( :'Content-Type' => 'application/json'))
end

#rest_get(path, **data, &exe) ⇒ Object



95
96
97
98
99
# File 'lib/pve/proxmox.rb', line 95

def rest_get path, **data, &exe
  data = data.delete_if {|k,v|v.nil?}
  path += "#{path.include?( ??) ? ?& : ??}#{data.map{|k,v|"#{CGI.escape k.to_s}=#{CGI.escape v.to_s}"}.join '&'}"  unless data.empty?
  __response__ Proxmox.connection[path].get( __headers__( :'Content-Type' => 'application/json'))
end

#rest_post(path, **data, &exe) ⇒ Object



109
110
111
# File 'lib/pve/proxmox.rb', line 109

def rest_post path, **data, &exe
  __response__ Proxmox.connection[path].post( __data__( data), __headers__( :'Content-Type' => 'application/json'))
end

#rest_put(path, **data, &exe) ⇒ Object



101
102
103
# File 'lib/pve/proxmox.rb', line 101

def rest_put path, **data, &exe
  __response__ Proxmox.connection[path].put( __data__( data), __headers__( :'Content-Type' => 'application/json'))
end