Class: Fog::Compute::Proxmox::Server

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

Overview

Server model

Direct Known Subclasses

Container

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server


57
58
59
60
61
# File 'lib/fog/compute/proxmox/models/server.rb', line 57

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

Instance Method Details

#action(action, options = {}) ⇒ Object

Raises:

  • (Fog::Errors::Error)

88
89
90
91
92
93
94
# File 'lib/fog/compute/proxmox/models/server.rb', line 88

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 = {}) ⇒ Object


142
143
144
145
# File 'lib/fog/compute/proxmox/models/server.rb', line 142

def attach(disk, options = {})
  config = Fog::Proxmox::DiskHelper.flatten(disk.merge(options: options))
  update(config)
end

#backup(options = {}) ⇒ Object


106
107
108
109
# File 'lib/fog/compute/proxmox/models/server.rb', line 106

def backup(options = {})
  requires :vmid
  request(:create_backup, options.merge(vmid: vmid))
end

#backupsObject


168
169
170
# File 'lib/fog/compute/proxmox/models/server.rb', line 168

def backups
  list 'backup'
end

#clone(newid, options = {}) ⇒ Object


117
118
119
120
# File 'lib/fog/compute/proxmox/models/server.rb', line 117

def clone(newid, options = {})
  requires :vmid
  request(:clone_server, options.merge(newid: newid), vmid: vmid)
end

#configObject


155
156
157
158
159
# File 'lib/fog/compute/proxmox/models/server.rb', line 155

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 = {}) ⇒ Object


203
204
205
206
207
208
# File 'lib/fog/compute/proxmox/models/server.rb', line 203

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 = {}) ⇒ Object


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

def create(config = {})
  request(:create_server, config.merge(vmid: vmid))
end

#destroy(options = {}) ⇒ Object


83
84
85
86
# File 'lib/fog/compute/proxmox/models/server.rb', line 83

def destroy(options = {})
  requires :vmid
  request(:delete_server, options, vmid: vmid)
end

#detach(diskid) ⇒ Object


147
148
149
# File 'lib/fog/compute/proxmox/models/server.rb', line 147

def detach(diskid)
  update(delete: diskid)
end

#extend(disk, size, options = {}) ⇒ Object


132
133
134
135
# File 'lib/fog/compute/proxmox/models/server.rb', line 132

def extend(disk, size, options = {})
  requires :vmid, :node
  service.resize_server({ node: node, vmid: vmid }, options.merge(disk: disk, size: size))
end

#imagesObject


172
173
174
# File 'lib/fog/compute/proxmox/models/server.rb', line 172

def images
  list 'images'
end

#list(content) ⇒ Object


176
177
178
179
180
181
# File 'lib/fog/compute/proxmox/models/server.rb', line 176

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 = {}) ⇒ Object


127
128
129
130
# File 'lib/fog/compute/proxmox/models/server.rb', line 127

def migrate(target, options = {})
  requires :vmid
  request(:migrate_server, options.merge(target: target), vmid: vmid)
end

#move(disk, storage, options = {}) ⇒ Object


137
138
139
140
# File 'lib/fog/compute/proxmox/models/server.rb', line 137

def move(disk, storage, options = {})
  requires :vmid
  request(:move_disk, options.merge(disk: disk, storage: storage), vmid: vmid)
end

#ready?Boolean

Returns:

  • (Boolean)

96
97
98
# File 'lib/fog/compute/proxmox/models/server.rb', line 96

def ready?
  status == 'running'
end

#reloadObject


100
101
102
103
104
# File 'lib/fog/compute/proxmox/models/server.rb', line 100

def reload
  requires :vmid
  object = collection.get(vmid)
  merge_attributes(object.attributes)
end

#request(name, body_params = {}, path_params = {}) ⇒ Object


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

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 = {}) ⇒ Object


111
112
113
114
115
# File 'lib/fog/compute/proxmox/models/server.rb', line 111

def restore(backup, options = {})
  requires :vmid
  config = options.merge(archive: backup.volid, force: 1)
  create(config)
end

#set_config(attributes = {}) ⇒ Object


151
152
153
# File 'lib/fog/compute/proxmox/models/server.rb', line 151

def set_config(attributes = {})
  @config = Fog::Compute::Proxmox::ServerConfig.new({ service: service, vmid: vmid }.merge(attributes))
end

#snapshotsObject


161
162
163
164
165
166
# File 'lib/fog/compute/proxmox/models/server.rb', line 161

def snapshots
  @snapshots ||= begin
    Fog::Compute::Proxmox::Snapshots.new(service: service,
                                         server: self)
  end
end

#start_console(options = {}) ⇒ Object


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/fog/compute/proxmox/models/server.rb', line 187

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

#tasksObject


183
184
185
# File 'lib/fog/compute/proxmox/models/server.rb', line 183

def tasks
  node.tasks.search(vmid: vmid)
end

#template(options = {}) ⇒ Object


122
123
124
125
# File 'lib/fog/compute/proxmox/models/server.rb', line 122

def template(options = {})
  requires :vmid, :node
  service.template_server({ node: node, type: type, vmid: vmid }, options)
end

#typeObject


63
64
65
# File 'lib/fog/compute/proxmox/models/server.rb', line 63

def type
  attributes[:type]
end

#update(config = {}) ⇒ Object


78
79
80
81
# File 'lib/fog/compute/proxmox/models/server.rb', line 78

def update(config = {})
  requires :vmid
  request(:update_server, config, vmid: vmid)
end