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

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

Overview

Servers Collection

Direct Known Subclasses

Containers

Instance Attribute Summary

Attributes inherited from Proxmox::Collection

#response

Instance Method Summary collapse

Methods inherited from Proxmox::Collection

#clear_ignored_attributes, #create, #destroy, #find_by_id, #load_response, #not_implemented, #read, #summary

Constructor Details

#initialize(attributes = {}) ⇒ Servers

Returns a new instance of Servers


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

def initialize(attributes = {})
  super(attributes)
end

Instance Method Details

#all(options = {}) ⇒ Object


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

def all(options = {})
  body_params = options.merge(node: node, type: type)
  load_response(service.list_servers(body_params), 'servers')
end

#get(vmid) ⇒ Object


56
57
58
59
60
61
62
63
# File 'lib/fog/compute/proxmox/models/servers.rb', line 56

def get(vmid)
  requires :node
  path_params = { node: node, type: type, vmid: vmid }
  server_data = service.get_server_status path_params
  config_data = service.get_server_config path_params
  data = server_data.merge(config_data).merge(node: node, vmid: vmid)
  new(data)
end

#id_valid?(vmid) ⇒ Boolean

Returns:

  • (Boolean)

49
50
51
52
53
54
# File 'lib/fog/compute/proxmox/models/servers.rb', line 49

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

#new(attributes = {}) ⇒ Object


38
39
40
# File 'lib/fog/compute/proxmox/models/servers.rb', line 38

def new(attributes = {})
  super({ node: node, type: type }.merge(attributes))
end

#next_idObject


42
43
44
45
46
47
# File 'lib/fog/compute/proxmox/models/servers.rb', line 42

def next_id
  response = service.next_vmid
  body = JSON.decode(response.body)
  data = body['data']
  Integer(data)
end

#typeObject


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

def type
  'qemu'
end