Class: Proxmox::Hosted
- Inherits:
-
Base
- Object
- Base
- Proxmox::Hosted
show all
- Defined in:
- lib/pve/proxmox.rb
Instance Attribute Summary
Attributes inherited from Base
#sid
Instance Method Summary
collapse
Methods inherited from Base
__new__, fetch, #method_missing, #respond_to?
#bench, #rest_del, #rest_get, #rest_post, #rest_put
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Proxmox::Base
Instance Method Details
#===(t) ⇒ Object
294
295
296
|
# File 'lib/pve/proxmox.rb', line 294
def === t
@name =~ t or @vmid.to_s =~ t or @sid =~ t
end
|
#cnfset(**cnf) ⇒ Object
373
374
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/pve/proxmox.rb', line 373
def cnfset **cnf
r = {delete: []}
cnf.each do |k,v|
case v
when true then r[k] = 1
when false then r[k] = 0
when nil then r[:delete].push k
else r[k] = v
end
end
r.delete :delete if r[:delete].empty?
rest_put "#{@rest_prefix}/config", r
end
|
#config ⇒ Object
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
# File 'lib/pve/proxmox.rb', line 345
def config
cnf = rest_get "#{@rest_prefix}/config"
cnf[:network] =
cnf.
keys.
map( &:to_s).
grep( /\Anet\d+\z/).
map do |k|
nc = {card: k}
cnf.delete( k.to_sym).
split( ',').
each do |f|
k, v = f.split( '=', 2)
nc[k.to_sym] = v
end
nc[:ip] &&= IPAddress::IPv4.new nc[:ip]
nc[:gw] &&= IPAddress::IPv4.new nc[:gw]
nc[:mtu] &&= nc[:mtu].to_i
nc[:tag] &&= nc[:tag].to_i
nc[:firewall] &&= 1 == nc[:firewall].to_i
nc
end
cnf[:unprivileged] &&= 1 == cnf[:unprivileged]
cnf[:memory] &&= cnf[:memory].to_i
cnf[:cores] &&= cnf[:cores].to_i
cnf
end
|
#current_status ⇒ Object
319
320
321
|
# File 'lib/pve/proxmox.rb', line 319
def current_status
rest_get "#{@rest_prefix}/status/current"
end
|
#destroy ⇒ Object
315
316
317
|
# File 'lib/pve/proxmox.rb', line 315
def destroy
Task.send :__new__, node: @node, host: self, upid: rest_del( "#{@rest_prefix}")
end
|
#migrate(node) ⇒ Object
298
299
300
301
302
303
304
305
|
# File 'lib/pve/proxmox.rb', line 298
def migrate node
node =
case node
when Node then node
else Node.find!( node.to_s)
end
Task.send :__new__, node: @node, host: self, upid: rest_post( "#{@rest_prefix}/migrate", target: node.node)
end
|
#refresh! ⇒ Object
290
291
292
|
# File 'lib/pve/proxmox.rb', line 290
def refresh!
__update__ rest_get( "#{@rest_prefix}/status/current").merge( node: @node, t: @t)
end
|
#resize(disk, size) ⇒ Object
387
388
389
390
|
# File 'lib/pve/proxmox.rb', line 387
def resize disk, size
upid = rest_put "#{@rest_prefix}/resize", disk: disk, size: size
Task.send :__new__, node: @node, host: self, upid: upid
end
|
#running? ⇒ Boolean
323
324
325
|
# File 'lib/pve/proxmox.rb', line 323
def running?
current_status[:status] == 'running'
end
|
#start ⇒ Object
307
308
309
|
# File 'lib/pve/proxmox.rb', line 307
def start
Task.send :__new__, node: @node, host: self, upid: rest_post( "#{@rest_prefix}/status/start")
end
|
#stop ⇒ Object
311
312
313
|
# File 'lib/pve/proxmox.rb', line 311
def stop
Task.send :__new__, node: @node, host: self, upid: rest_post( "#{@rest_prefix}/status/stop")
end
|
#stopped? ⇒ Boolean
327
328
329
|
# File 'lib/pve/proxmox.rb', line 327
def stopped?
current_status[:status] == 'stopped'
end
|
#wait(forstatus, timeout: nil, secs: nil, lock: nil, &exe) ⇒ Object
331
332
333
334
335
336
337
338
339
340
341
342
343
|
# File 'lib/pve/proxmox.rb', line 331
def wait forstatus, timeout: nil, secs: nil, lock: nil, &exe
forstatus = forstatus.to_s
secs ||= 0.2
b = Time.now + timeout.to_i + secs
loop do
d = current_status
return true if d[:status] == forstatus and (not lock or lock == d[:lock])
exe.call d[:status], d[:lock] if exe
return false if timeout and b <= Time.now
sleep secs
end
nil
end
|