Class: Squall::VirtualMachine

Inherits:
Base
  • Object
show all
Defined in:
lib/squall/virtual_machine.rb

Overview

OnApp VirtualMachine

Instance Attribute Summary

Attributes inherited from Base

#result, #success

Instance Method Summary (collapse)

Methods inherited from Base

#check_config, #default_params, #key_for_class, #request

Instance Method Details

- (Object) build(id, options = {})

Build a virtual machine.

Parameters:

  • id

    ID of the virtual machine

  • options (defaults to: {})

    Params for creating the virtual machine

Options Hash (options):

  • :required_startup (Object)

    Set to '1' to startup virtual machine after building

  • :template_id (Object)

    ID of the template to be used to build the virtual machine

Returns:

  • a Hash.



98
99
100
101
# File 'lib/squall/virtual_machine.rb', line 98

def build(id, options = {})
  response = request(:post, "/virtual_machines/#{id}/build.json", default_params(options))
  response.first[1]
end

- (Object) change_owner(id, user_id)

Change the owner of a virtual machine.

Parameters:

  • id

    ID of the virtual machine

  • user_id

    ID of the target User

Returns:

  • a Hash.



120
121
122
123
# File 'lib/squall/virtual_machine.rb', line 120

def change_owner(id, user_id)
  response = request(:post, "/virtual_machines/#{id}/change_owner.json", query: { user_id: user_id })
  response['virtual_machine']
end

- (Object) change_password(id, password)

Change the password.

Parameters:

  • id

    ID of the virtual machine

  • password

    New password

Returns:

  • a Hash.



131
132
133
134
# File 'lib/squall/virtual_machine.rb', line 131

def change_password(id, password)
  response = request(:post, "/virtual_machines/#{id}/reset_password.json", query: { new_password: password })
  response['virtual_machine']
end

- (Object) console(id)

Open a console for a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



275
276
277
278
# File 'lib/squall/virtual_machine.rb', line 275

def console(id)
  response = request(:post, "/virtual_machines/#{id}/console.json")
  response['virtual_machine']
end

- (Object) create(options = {})

Create a new virtual machine.

Examples:

create(
  label:             'testmachine',
  hypervisor_id:     5,
  hostname:          'testmachine',
  memory:            512,
  cpus:              1,
  cpu_shares:        10,
  primary_disk_size: 10,
  template_id:       1
)

Parameters:

  • options (defaults to: {})

    Params for creating the virtual machine: admin_note - Comment that can only be set by admin of virtual machine allowed_hot_migrate - Set to '1' to allow hot migration cpu_shares - CPU priority for this virtual machine cpus - Number of CPUs assigned to the virtual machine hostname - Hostname for the virtual machine hypervisor_group_id - the ID of the hypervisor zone in which the VM will be created. Optional: if no hypervisor zone is set, the VM will be built in any available hypervisor zone. hypervisor_id - ID for a hypervisor where virtual machine will be built. If not provided the virtual machine will be assigned to the first available hypervisor initial_root_password - Root password for the virtual machine. 6-31 characters consisting of letters, numbers, '-' and '_' label - Label for the virtual machine memory - Amount of RAM assigned to this virtual machine note - Comment that can be set by the user of the virtual machine primary_disk_size - Disk space for this virtual machine primary_network_id - ID of the primary network rate_limit - Max port speed required_automatic_backup - Set to '1' if automatic backups are required required_ip_address_assignment - Set to '1' if you wish to assign an IP address automatically required_virtual_machine_build - Set to '1' to build virtual machine automatically swap_disk_size - Swap space (does not apply to Windows virtual machines) template_id - ID for a template from which the virtual machine will be built

Returns:

  • a Hash.



83
84
85
86
# File 'lib/squall/virtual_machine.rb', line 83

def create(options = {})
  response = request(:post, '/virtual_machines.json', default_params(options))
  response['virtual_machine']
end

- (Object) delete(id)

Delete a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



176
177
178
# File 'lib/squall/virtual_machine.rb', line 176

def delete(id)
  request(:delete, "/virtual_machines/#{id}.json")
end

- (Object) edit(id, options = {})

Edit a virtual machine.

Parameters:

  • id

    ID of the virtual machine

  • options (defaults to: {})

    Params for creating the virtual machine, see `#create`

Returns:

  • a Hash.



109
110
111
112
# File 'lib/squall/virtual_machine.rb', line 109

def edit(id, options = {})
  response = request(:put, "/virtual_machines/#{id}.json", default_params(options))
  response['virtual_machine']
end

- (Object) list

List all virtual machines.

Returns:

  • an Array.



7
8
9
10
# File 'lib/squall/virtual_machine.rb', line 7

def list
  response = request(:get, '/virtual_machines.json')
  response.collect { |v| v['virtual_machine'] }
end

- (Object) migrate(id, options = {})

Migrate a virtual machine to a new hypervisor.

Parameters:

  • id

    ID of the virtual machine

  • options (defaults to: {})

    A Hash of options:

Options Hash (options):

  • :destination (Object)

    ID of a hypervisor to which to migrate the virtual machine

  • :cold_migrate_on_rollback (Object)

    Set to '1' to switch to cold migration if migration fails

Returns:

  • a Hash.



157
158
159
# File 'lib/squall/virtual_machine.rb', line 157

def migrate(id, options = {})
  request(:post, "/virtual_machines/#{id}/migrate.json", query: { virtual_machine: options } )
end

- (Object) reboot(id, recovery = false)

Reboot a virtual machine

Parameters:

  • id

    ID of the virtual machine

  • recovery (defaults to: false)

    Set to true to reboot in recovery, defaults to false

Returns:

  • a Hash.



253
254
255
256
# File 'lib/squall/virtual_machine.rb', line 253

def reboot(id, recovery=false)
  response = request(:post, "/virtual_machines/#{id}/reboot.json", { query: recovery ? { mode: :recovery } : nil })
  response['virtual_machine']
end

- (Object) resize(id, options = {})

Resize a virtual machine's memory.

Parameters:

  • id

    ID of the virtual machine

  • options (defaults to: {})

    Options for resizing:

Options Hash (options):

  • :memory (Object)

    Amount of RAM assigned to this virtual machine

  • :cpus (Object)

    Number of CPUs assigned to the virtual machine

  • :cpu_shares (Object)

    CPU priority for this virtual machine

  • :allow_cold_resize (Object)

    Set to '1' to allow cold resize

Returns:

  • a Hash.



192
193
194
195
# File 'lib/squall/virtual_machine.rb', line 192

def resize(id, options = {})
  response = request(:post, "/virtual_machines/#{id}/resize.json", default_params(options))
  response['virtual_machine']
end

- (Object) segregate(id, target_vm_id)

Segregate a virtual machine from another virtual machine.

Parameters:

  • id

    ID of the virtual machine

  • target_vm_id

    ID of another virtual machine from which it should be segregated

Returns:

  • a Hash.



265
266
267
268
# File 'lib/squall/virtual_machine.rb', line 265

def segregate(id, target_vm_id)
  response = request(:post, "/virtual_machines/#{id}/strict_vm.json", default_params(strict_virtual_machine_id: target_vm_id))
  response['virtual_machine']
end

- (Object) set_ssh_keys(id)

Assigns SSH keys of all administrators and a owner to a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



142
143
144
145
# File 'lib/squall/virtual_machine.rb', line 142

def set_ssh_keys(id)
  response = request(:post, "/virtual_machines/#{id}/set_ssh_keys.json")
  response['virtual_machine']
end

- (Object) set_vip(id)

Toggle the VIP status of the virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



166
167
168
169
# File 'lib/squall/virtual_machine.rb', line 166

def set_vip(id)
  response = request(:post, "/virtual_machines/#{id}/set_vip.json")
  response['virtual_machine']
end

- (Object) show(id)

Get info for a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



17
18
19
20
# File 'lib/squall/virtual_machine.rb', line 17

def show(id)
  response = request(:get, "/virtual_machines/#{id}.json")
  response.first[1]
end

- (Object) shutdown(id)

Shutdown a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



232
233
234
235
# File 'lib/squall/virtual_machine.rb', line 232

def shutdown(id)
  response = request(:post, "/virtual_machines/#{id}/shutdown.json")
  response['virtual_machine']
end

- (Object) startup(id)

Boot a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



222
223
224
225
# File 'lib/squall/virtual_machine.rb', line 222

def startup(id)
  response = request(:post, "/virtual_machines/#{id}/startup.json")
  response['virtual_machine']
end

- (Object) stats(id)

Get billing statistics for a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



285
286
287
288
# File 'lib/squall/virtual_machine.rb', line 285

def stats(id)
  response = request(:post, "/virtual_machines/#{id}/vm_stats.json")
  response['virtual_machine']
end

- (Object) stop(id)

Stop a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



242
243
244
245
# File 'lib/squall/virtual_machine.rb', line 242

def stop(id)
  response = request(:post, "/virtual_machines/#{id}/stop.json")
  response['virtual_machine']
end

- (Object) suspend(id)

Suspend/Unsuspend a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



202
203
204
205
# File 'lib/squall/virtual_machine.rb', line 202

def suspend(id)
  response = request(:post, "/virtual_machines/#{id}/suspend.json")
  response['virtual_machine']
end

- (Object) unlock(id)

Unlock a virtual machine.

Parameters:

  • id

    ID of the virtual machine

Returns:

  • a Hash.



212
213
214
215
# File 'lib/squall/virtual_machine.rb', line 212

def unlock(id)
  response = request(:post, "/virtual_machines/#{id}/unlock.json")
  response['virtual_machine']
end