Class: Fog::Proxmox::Compute::Servers

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/proxmox/compute/models/servers.rb

Overview

Servers Collection

Instance Method Summary collapse

Instance Method Details

#all(options = {}) ⇒ Object



67
68
69
70
# File 'lib/fog/proxmox/compute/models/servers.rb', line 67

def all(options = {})
  body_params = options.merge(node: node_id, type: type)
  load service.list_servers(body_params)
end

#containers?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/fog/proxmox/compute/models/servers.rb', line 46

def containers?
  type == 'lxc'
end

#create(new_attributes = {}) ⇒ Object



72
73
74
75
76
# File 'lib/fog/proxmox/compute/models/servers.rb', line 72

def create(new_attributes = {})
  object = new(new_attributes.select { |key, _value| %i[node_id vmid type].include? key.to_sym })
  object.save(new_attributes.reject { |key, _value| %i[node_id vmid type].include? key.to_sym })
  object
end

#get(id) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fog/proxmox/compute/models/servers.rb', line 50

def get(id)
  path_params = { node: node_id, type: type, vmid: id }
  begin
    status_data = service.get_server_status path_params
    config_data = service.get_server_config path_params
  rescue StandardError => e
    if e.respond_to?('response') && e.response.respond_to?('data') && e.response.data.has_key?(:reason_phrase) && e.response.data[:reason_phrase].end_with?('does not exist')
      raise(Fog::Errors::NotFound)
    end

    raise(e)
  else
    data = status_data.merge(config_data).merge(node: node_id, vmid: id)
    new(data)
  end
end

#id_valid?(vmid) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/fog/proxmox/compute/models/servers.rb', line 39

def id_valid?(vmid)
  service.next_vmid(vmid: vmid)
  true
rescue Excon::Errors::BadRequest
  false
end

#new(new_attributes = {}) ⇒ Object



31
32
33
# File 'lib/fog/proxmox/compute/models/servers.rb', line 31

def new(new_attributes = {})
  super({ node_id: node_id, type: type }.merge(new_attributes))
end

#next_idObject



35
36
37
# File 'lib/fog/proxmox/compute/models/servers.rb', line 35

def next_id
  service.next_vmid
end