Class: Fog::Proxmox::Compute::Server
- Inherits:
-
Compute::Server
- Object
- Compute::Server
- Fog::Proxmox::Compute::Server
- Defined in:
- lib/fog/compute/proxmox/models/server.rb
Overview
Server model
Instance Method Summary collapse
- #action(action, options = {}) ⇒ Object
- #attach(disk, options = {}) ⇒ Object
- #backup(options = {}) ⇒ Object
- #backups ⇒ Object
- #clone(newid, options = {}) ⇒ Object
- #connect_vnc(options = {}) ⇒ Object
- #container? ⇒ Boolean
- #create_template(options = {}) ⇒ Object
- #destroy(options = {}) ⇒ Object
- #detach(diskid) ⇒ Object
- #extend(disk, size, options = {}) ⇒ Object
- #images ⇒ Object
-
#initialize(new_attributes = {}) ⇒ Server
constructor
A new instance of Server.
- #list(content) ⇒ Object
- #migrate(target, options = {}) ⇒ Object
- #move(volume, storage, options = {}) ⇒ Object
- #persisted? ⇒ Boolean
- #ready? ⇒ Boolean
-
#request(name, body_params = {}, path_params = {}) ⇒ Object
request with async task.
- #restore(backup, options = {}) ⇒ Object
- #save(new_attributes = {}) ⇒ Object
- #start_console(options = {}) ⇒ Object
- #update(new_attributes = {}) ⇒ Object
Constructor Details
#initialize(new_attributes = {}) ⇒ Server
Returns a new instance of Server.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 63 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 |
Instance Method Details
#action(action, options = {}) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 121 def action(action, = {}) action_known = %w[start stop resume suspend shutdown reset].include? action = "Action #{action} not implemented" raise Fog::Errors::Error, unless action_known request(:action_server, , action: action, vmid: vmid) reload end |
#attach(disk, options = {}) ⇒ Object
179 180 181 182 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 179 def attach(disk, = {}) disk_hash = Fog::Proxmox::DiskHelper.flatten(disk.merge(options: )) update(disk_hash) end |
#backup(options = {}) ⇒ Object
133 134 135 136 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 133 def backup( = {}) request(:create_backup, .merge(vmid: vmid)) reload end |
#backups ⇒ Object
216 217 218 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 216 def backups list 'backup' end |
#clone(newid, options = {}) ⇒ Object
147 148 149 150 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 147 def clone(newid, = {}) request(:clone_server, .merge(newid: newid), vmid: vmid) reload end |
#connect_vnc(options = {}) ⇒ Object
210 211 212 213 214 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 210 def connect_vnc( = {}) path_params = { node: node_id, type: type, vmid: vmid } query_params = { port: ['port'], vncticket: ['ticket'] } service.get_vnc(path_params, query_params) end |
#container? ⇒ Boolean
75 76 77 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 75 def container? type == 'lxc' end |
#create_template(options = {}) ⇒ Object
152 153 154 155 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 152 def create_template( = {}) service.template_server({ node: node_id, type: type, vmid: vmid }, ) reload end |
#destroy(options = {}) ⇒ Object
117 118 119 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 117 def destroy( = {}) request(:delete_server, , vmid: vmid) end |
#detach(diskid) ⇒ Object
184 185 186 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 184 def detach(diskid) update(delete: diskid) end |
#extend(disk, size, options = {}) ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 161 def extend(disk, size, = {}) if container? request(:resize_container, .merge(disk: disk, size: size), vmid: vmid) else service.resize_server({ vmid: vmid, node: node_id }, .merge(disk: disk, size: size)) end reload end |
#images ⇒ Object
220 221 222 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 220 def images list 'images' end |
#list(content) ⇒ Object
224 225 226 227 228 229 |
# 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 = {}) ⇒ Object
157 158 159 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 157 def migrate(target, = {}) request(:migrate_server, .merge(target: target), vmid: vmid) end |
#move(volume, storage, options = {}) ⇒ Object
170 171 172 173 174 175 176 177 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 170 def move(volume, storage, = {}) if container? request(:move_volume, .merge(volume: volume, storage: storage), vmid: vmid) else request(:move_disk, .merge(disk: volume, storage: storage), vmid: vmid) end reload end |
#persisted? ⇒ Boolean
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 79 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? ⇒ Boolean
129 130 131 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 129 def ready? status == 'running' end |
#request(name, body_params = {}, path_params = {}) ⇒ Object
request with async task
92 93 94 95 96 97 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 92 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 = {}) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 138 def restore(backup, = {}) if container? attr_hash = .merge(ostemplate: backup.volid, force: 1, restore: 1) else attr_hash = .merge(archive: backup.volid, force: 1) end save(attr_hash) end |
#save(new_attributes = {}) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 99 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 = {}) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 188 def start_console( = {}) raise ::Fog::Proxmox::Errors::ServiceError, "Unable to start console because server not running." unless ready? if container? type_console = [:console] .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 = 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 = {}) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/fog/compute/proxmox/models/server.rb', line 106 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 |