class Fog::Proxmox::Compute::Server
Server model
Public Class Methods
new(new_attributes = {})
click to toggle source
Calls superclass method
# File lib/fog/compute/proxmox/models/server.rb, line 62 def initialize(new_attributes = {}) prepare_service_value(new_attributes) Fog::Proxmox::Attributes.set_attr_and_sym('node_id', attributes, new_attributes) Fog::Proxmox::Attributes.set_attr_and_sym('type', attributes, new_attributes) Fog::Proxmox::Attributes.set_attr_and_sym('vmid', attributes, new_attributes) requires :node_id, :type, :vmid initialize_config(new_attributes) initialize_snapshots initialize_tasks super(new_attributes) end
Public Instance Methods
action(action, options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 120 def action(action, options = {}) 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) reload end
attach(disk, options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 179 def attach(disk, options = {}) disk_hash = Fog::Proxmox::DiskHelper.flatten(disk.merge(options: options)) update(disk_hash) end
backup(options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 132 def backup(options = {}) request(:create_backup, options.merge(vmid: vmid)) reload end
backups()
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 216 def backups list 'backup' end
clone(newid, options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 146 def clone(newid, options = {}) request(:clone_server, options.merge(newid: newid), vmid: vmid) reload end
connect_vnc(options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 210 def connect_vnc(options = {}) path_params = { node: node_id, type: type, vmid: vmid } query_params = { port: options['port'], vncticket: options['ticket'] } service.get_vnc(path_params, query_params) end
container?()
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 74 def container? type == 'lxc' end
create_template(options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 151 def create_template(options = {}) service.template_server({ node: node_id, type: type, vmid: vmid }, options) reload end
destroy(options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 116 def destroy(options = {}) request(:delete_server, options, vmid: vmid) end
detach(diskid)
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 184 def detach(diskid) update(delete: diskid) end
extend(disk, size, options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 161 def extend(disk, size, options = {}) if container? request(:resize_container, options.merge(disk: disk, size: size), vmid: vmid) else service.resize_server({ vmid: vmid, node: node_id }, options.merge(disk: disk, size: size)) end reload end
images()
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 220 def images list 'images' end
list(content)
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 224 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, identity) } volumes end
migrate(target, options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 156 def migrate(target, options = {}) request(:migrate_server, options.merge(target: target), vmid: vmid) reload end
move(volume, storage, options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 170 def move(volume, storage, options = {}) if container? request(:move_volume, options.merge(volume: volume, storage: storage), vmid: vmid) else request(:move_disk, options.merge(disk: volume, storage: storage), vmid: vmid) end reload end
persisted?()
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 78 def persisted? service.next_vmid(vmid: vmid) persisted = false persisted rescue Excon::Error::InternalServerError persisted = false persisted rescue Excon::Error::BadRequest persisted = true persisted end
ready?()
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 128 def ready? status == 'running' end
request(name, body_params = {}, path_params = {})
click to toggle source
request with async task
# File lib/fog/compute/proxmox/models/server.rb, line 91 def request(name, body_params = {}, path_params = {}) requires :node_id, :type path = path_params.merge(node: node_id, 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 137 def restore(backup, options = {}) if container? attr_hash = options.merge(ostemplate: backup.volid, force: 1, restore: 1) else attr_hash = options.merge(archive: backup.volid, force: 1) end save(attr_hash) end
save(new_attributes = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 98 def save(new_attributes = {}) body_params = new_attributes.merge(vmid: vmid) body_params = body_params.merge(config.flatten) unless persisted? request(:create_server, body_params) reload end
start_console(options = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 188 def start_console(options = {}) raise ::Fog::Proxmox::Errors::ServiceError, "Unable to start console because server not running." unless ready? if container? type_console = options[:console] options.delete_if { |option| [:console].include? option } raise ::Fog::Proxmox::Errors::ServiceError, "Unable to start console because console container config is not set or unknown." unless type_console else 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 end requires :vmid, :node_id, :type path_params = { node: node_id, 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
update(new_attributes = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 105 def update(new_attributes = {}) if container? path_params = { node: node_id, type: type, vmid: vmid } body_params = new_attributes service.update_server(path_params, body_params) else request(:update_server, new_attributes, vmid: vmid) end reload end
Protected Instance Methods
initialize_config(new_attributes = {})
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 233 def initialize_config(new_attributes = {}) options = { service: service, vmid: vmid } attributes[:config] = Fog::Proxmox::Compute::ServerConfig.new(options.merge(new_attributes)) end
Private Instance Methods
initialize_snapshots()
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 240 def initialize_snapshots attributes[:snapshots] = Fog::Proxmox::Compute::Snapshots.new(service: service, server_id: vmid, server_type: type, node_id: node_id) end
initialize_tasks()
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 244 def initialize_tasks attributes[:tasks] = Fog::Proxmox::Compute::Tasks.new(service: service, node_id: node_id).select { |task| task.id == vmid } end
node()
click to toggle source
# File lib/fog/compute/proxmox/models/server.rb, line 248 def node Fog::Proxmox::Compute::Node.new(service: service, node: node_id) end