Class: Proxmox::HA

Inherits:
Base
  • Object
show all
Defined in:
lib/pve/proxmox.rb

Instance Attribute Summary

Attributes inherited from Base

#sid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

__new__, fetch, #method_missing, #respond_to?

Methods included from RestConnection

#bench, #rest_del, #rest_get, #rest_post, #rest_put

Constructor Details

#initializeHA

Returns a new instance of HA.



589
590
591
# File 'lib/pve/proxmox.rb', line 589

def initialize
  rest_prefix
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Proxmox::Base

Class Method Details

.create(host, **options) ⇒ Object



599
600
601
# File 'lib/pve/proxmox.rb', line 599

def create host, **options
  find( host).create **options
end

.find(host) ⇒ Object



594
595
596
597
# File 'lib/pve/proxmox.rb', line 594

def find host
  ha = HA.send :__new__, digest: nil, state: nil, virt: host
  ha.refresh!
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


653
# File 'lib/pve/proxmox.rb', line 653

def active?() ! ! digest end

#create(group: nil, comment: nil, max_relocate: nil, max_restart: nil, state: nil) ⇒ Object



612
613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/pve/proxmox.rb', line 612

def create group: nil, comment: nil, max_relocate: nil, max_restart: nil, state: nil
  options = {
    sid: virt.sid,
    group: group,
    comment: comment,
    max_relocate: max_relocate,
    max_restart: max_restart,
    state: state
  }
  options.delete_if {|k,v| v.nil? }
  rest_post "/cluster/ha/resources", **options
  refresh!
end

#deleteObject



626
627
628
# File 'lib/pve/proxmox.rb', line 626

def delete
  rest_del "#{@rest_prefix}"
end

#disabled!Object



645
646
647
648
# File 'lib/pve/proxmox.rb', line 645

def disabled!
  self.state = :disabled
  self
end

#error?Boolean

Returns:

  • (Boolean)


652
# File 'lib/pve/proxmox.rb', line 652

def error?() 'error' == self.state end

#refresh!Object



604
605
606
607
608
609
610
# File 'lib/pve/proxmox.rb', line 604

def refresh!
  virt = @virt
  __update__( {state: nil}.merge( rest_get( "/cluster/ha/resources/#{virt.sid}")).merge( virt: virt))
  self
rescue RestClient::InternalServerError
  __update__ digest: nil, state: nil, virt: virt
end

#rest_prefixObject



585
586
587
# File 'lib/pve/proxmox.rb', line 585

def rest_prefix
  @rest_prefix ||= "/cluster/ha/resources/#{virt.sid}"
end

#started!Object



635
636
637
638
# File 'lib/pve/proxmox.rb', line 635

def started!
  self.state = :started
  self
end

#started?Boolean

Returns:

  • (Boolean)


650
# File 'lib/pve/proxmox.rb', line 650

def started?() 'started' == self.state end

#state=(state) ⇒ Object



630
631
632
633
# File 'lib/pve/proxmox.rb', line 630

def state= state
  rest_put "#{@rest_prefix}", state: state.to_s
  refresh!
end

#stopped!Object



640
641
642
643
# File 'lib/pve/proxmox.rb', line 640

def stopped!
  self.state = :stopped
  self
end

#stopped?Boolean

Returns:

  • (Boolean)


651
# File 'lib/pve/proxmox.rb', line 651

def stopped?() 'stopped' == self.state end