class Squall::VirtualMachine

OnApp VirtualMachine

Public Instance Methods

build(id, options = {}) click to toggle source

Public: Build a virtual machine.

id - ID of the virtual machine options - Params for creating the virtual machine

:required_startup - Set to '1' to startup virtual machine after
                    building
:template_id      - ID of the template to be used to build the
                    virtual machine

Returns a Hash.

# 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
change_owner(id, user_id) click to toggle source

Public: Change the owner of a virtual machine.

id - ID of the virtual machine user_id - ID of the target User

Returns a Hash.

# 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
change_password(id, password) click to toggle source

Public: Change the password.

id - ID of the virtual machine password - New password

Returns a Hash.

# 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
console(id) click to toggle source

Public: Open a console for a virtual machine.

id - ID of the virtual machine

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 275
def console(id)
  response = request(:post, "/virtual_machines/#{id}/console.json")
  response['virtual_machine']
end
create(options = {}) click to toggle source

Public: Create a new virtual machine.

options - 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

Example

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

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 83
def create(options = {})
  response = request(:post, '/virtual_machines.json', default_params(options))
  response['virtual_machine']
end
delete(id) click to toggle source

Public: Delete a virtual machine.

id - ID of the virtual machine

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 176
def delete(id)
  request(:delete, "/virtual_machines/#{id}.json")
end
edit(id, options = {}) click to toggle source

Public: Edit a virtual machine.

id - ID of the virtual machine options - Params for creating the virtual machine, see `#create`

Returns a Hash.

# 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
list() click to toggle source

Public: List all virtual machines.

Returns an Array.

# File lib/squall/virtual_machine.rb, line 7
def list
  response = request(:get, '/virtual_machines.json')
  response.collect { |v| v['virtual_machine'] }
end
migrate(id, options = {}) click to toggle source

Public: Migrate a virtual machine to a new hypervisor.

id - ID of the virtual machine options - A Hash of options:

:destination              - ID of a hypervisor to which to
                            migrate the virtual machine
:cold_migrate_on_rollback - Set to '1' to switch to cold
                            migration if migration fails

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 157
def migrate(id, options = {})
  request(:post, "/virtual_machines/#{id}/migrate.json", query: { virtual_machine: options } )
end
reboot(id, recovery=false) click to toggle source

Public: Reboot a virtual machine

id - ID of the virtual machine recovery - Set to true to reboot in recovery, defaults to false

Returns a Hash.

# 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
resize(id, options = {}) click to toggle source

Public: Resize a virtual machine's memory.

id - ID of the virtual machine options - Options for resizing:

:memory            - Amount of RAM assigned to this virtual
                     machine
:cpus              - Number of CPUs assigned to the virtual
                     machine
:cpu_shares        - CPU priority for this virtual machine
:allow_cold_resize - Set to '1' to allow cold resize

Returns a Hash.

# 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
segregate(id, target_vm_id) click to toggle source

Public: Segregate a virtual machine from another virtual machine.

id - ID of the virtual machine target_vm_id - ID of another virtual machine from which it should be

segregated

Returns a Hash.

# 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
set_ssh_keys(id) click to toggle source

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

id - ID of the virtual machine

Returns a Hash.

# 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
set_vip(id) click to toggle source

Public: Toggle the VIP status of the virtual machine.

id - ID of the virtual machine

Returns a Hash.

# 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
show(id) click to toggle source

Public: Get info for a virtual machine.

id - ID of the virtual machine

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 17
def show(id)
  response = request(:get, "/virtual_machines/#{id}.json")
  response.first[1]
end
shutdown(id) click to toggle source

Public: Shutdown a virtual machine.

id - ID of the virtual machine

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 232
def shutdown(id)
  response = request(:post, "/virtual_machines/#{id}/shutdown.json")
  response['virtual_machine']
end
startup(id) click to toggle source

Public: Boot a virtual machine.

id - ID of the virtual machine

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 222
def startup(id)
  response = request(:post, "/virtual_machines/#{id}/startup.json")
  response['virtual_machine']
end
stats(id) click to toggle source

Public: Get billing statistics for a virtual machine.

id - ID of the virtual machine

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 285
def stats(id)
  response = request(:post, "/virtual_machines/#{id}/vm_stats.json")
  response['virtual_machine']
end
stop(id) click to toggle source

Public: Stop a virtual machine.

id - ID of the virtual machine

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 242
def stop(id)
  response = request(:post, "/virtual_machines/#{id}/stop.json")
  response['virtual_machine']
end
suspend(id) click to toggle source

Public: Suspend/Unsuspend a virtual machine.

id - ID of the virtual machine

Returns a Hash.

# File lib/squall/virtual_machine.rb, line 202
def suspend(id)
  response = request(:post, "/virtual_machines/#{id}/suspend.json")
  response['virtual_machine']
end
unlock(id) click to toggle source

Public: Unlock a virtual machine.

id - ID of the virtual machine

Returns a Hash.

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