class Fog::Compute::Proxmox::Server

Server model

Public Class Methods

new(attributes = {}) click to toggle source
Calls superclass method
# File lib/fog/compute/proxmox/models/server.rb, line 56
def initialize(attributes = {})
  prepare_service_value(attributes)
  set_config(attributes)
  super
end

Public Instance Methods

action(action, options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 87
def action(action, options = {})
  requires :vmid
  action_known = %w[start stop resume suspend shutdown reset].include? action
  message = "Action #{action} not implemented"
  raise Fog::Errors::Error, message unless action_known
  request(:action_server, options, action: action, vmid: vmid)
end
attach(disk, options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 141
def attach(disk, options = {})
  config = Fog::Proxmox::DiskHelper.flatten(disk.merge(options: options))
  update(config)
end
backup(options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 105
def backup(options = {})
  requires :vmid
  request(:create_backup, options.merge(vmid: vmid))
end
backups() click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 167
def backups
  list 'backup'
end
clone(newid, options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 116
def clone(newid, options = {})
  requires :vmid
  request(:clone_server, options.merge(newid: newid), vmid: vmid)
end
config() click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 154
def config
  path_params = { node: node, type: type, vmid: vmid }
  set_config(service.get_server_config(path_params)) if uptime
  @config
end
connect_vnc(options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 202
def connect_vnc(options = {})
  requires :vmid, :node, :type
  path_params = { node: node, type: type, vmid: vmid }
  query_params = { port: options['port'], vncticket: options['ticket'] }
  service.get_vnc(path_params, query_params)
end
create(config = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 73
def create(config = {})
  request(:create_server, config.merge(vmid: vmid))
end
destroy(options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 82
def destroy(options = {})
  requires :vmid
  request(:delete_server, options, vmid: vmid)
end
detach(diskid) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 146
def detach(diskid)
  update(delete: diskid)
end
extend(disk, size, options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 131
def extend(disk, size, options = {})
  requires :vmid, :node
  service.resize_server({ node: node, vmid: vmid }, options.merge(disk: disk, size: size))
end
images() click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 171
def images
  list 'images'
end
list(content) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 175
def list(content)
  storages = node.storages.list_by_content_type content
  volumes = []
  storages.each { |storage| volumes += storage.volumes.list_by_content_type_and_by_server(content, vmid) }
  volumes
end
migrate(target, options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 126
def migrate(target, options = {})
  requires :vmid
  request(:migrate_server, options.merge(target: target), vmid: vmid)
end
move(disk, storage, options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 136
def move(disk, storage, options = {})
  requires :vmid
  request(:move_disk, options.merge(disk: disk, storage: storage), vmid: vmid)
end
ready?() click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 95
def ready?
  status == 'running'
end
reload() click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 99
def reload
  requires :vmid
  object = collection.get(vmid)
  merge_attributes(object.attributes)
end
request(name, body_params = {}, path_params = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 66
def request(name, body_params = {}, path_params = {})
  requires :node, :type
  path = path_params.merge(node: node, type: type)
  task_upid = service.send(name, path, body_params)
  tasks.wait_for(task_upid)
end
restore(backup, options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 110
def restore(backup, options = {})
  requires :vmid
  config = options.merge(archive: backup.volid, force: 1)
  create(config)
end
set_config(attributes = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 150
def set_config(attributes = {})
  @config = Fog::Compute::Proxmox::ServerConfig.new({ service: service, vmid: vmid }.merge(attributes))
end
snapshots() click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 160
def snapshots
  @snapshots ||= begin
    Fog::Compute::Proxmox::Snapshots.new(service: service,
                                         server: self)
  end
end
start_console(options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 186
def start_console(options = {})
  raise ::Fog::Proxmox::Errors::ServiceError, "Unable to start console because server not running." unless ready?
  type_console = config.type_console
  raise ::Fog::Proxmox::Errors::ServiceError, "Unable to start console because VGA display server config is not set or unknown." unless type_console
  requires :vmid, :node, :type
  path_params = { node: node, type: type, vmid: vmid }
  body_params = options
  data = service.send(('create_' + type_console).to_sym, path_params, body_params)
  task_upid = data['upid']
  if task_upid
    task = tasks.get(task_upid)
    task.wait_for { running? }
  end
  data
end
tasks() click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 182
def tasks
  node.tasks.search(vmid: vmid)
end
template(options = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 121
def template(options = {})
  requires :vmid, :node
  service.template_server({ node: node, type: type, vmid: vmid }, options)
end
type() click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 62
def type
  attributes[:type]
end
update(config = {}) click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 77
def update(config = {})
  requires :vmid
  request(:update_server, config, vmid: vmid)
end