Class: SolusVM::Server

Inherits:
Base
  • Object
show all
Defined in:
lib/solusvm/server.rb

Overview

SolusVM::Server is the class for working with virtual servers.

Constant Summary

Constants inherited from Base

Base::VALID_SERVER_TYPES

Instance Attribute Summary

Attributes inherited from Base

#returned_parameters

Instance Method Summary collapse

Methods inherited from Base

#api_endpoint, #api_id, #api_key, #api_login, #api_options, #conn, #initialize, #log_messages, #parse_error, #parse_response, #parse_returned_params_as_list, #perform_request, #ssl_option, #statusmsg, #successful?, #validate_server_type

Constructor Details

This class inherits a constructor from SolusVM::Base

Instance Method Details

#add_ip(vid, ip = nil) ⇒ Object

Public: Adds an IP address for a specific server.

vid - The virtual server ID in SolusVM ip - Specific IPv4 address to add (optional)

Returns the IP as a String.



176
177
178
179
# File 'lib/solusvm/server.rb', line 176

def add_ip(vid, ip = nil)
  perform_request(action: 'vserver-addip', vserverid: vid, ipv4addr: ip)
  returned_parameters['ipaddress']
end

#boot(vid) ⇒ Object

Public: Boots a server.

vid - The virtual server ID in SolusVM

Returns true if the server was successfully booted.



47
48
49
# File 'lib/solusvm/server.rb', line 47

def boot(vid)
  perform_request(action: 'vserver-boot', vserverid: vid)
end

#change_bootorder(vid, bootorder) ⇒ Object

Public: Changes server boot order

vid - The virtual server ID in SolusVM bootorder - The boot order, one of the following:

:cd - Hard Disk CDROM
:dc - CDROM Hard Disk
:c  - Hard Disk
:d  - CDROM

Returns true if the boot order was successfully changed.



241
242
243
# File 'lib/solusvm/server.rb', line 241

def change_bootorder(vid, bootorder)
  perform_request(action: 'vserver-bootorder', vserverid: vid, bootorder: bootorder.to_s)
end

#change_hostname(vid, hostname) ⇒ Object

Public: Changes server hostname.

vid - The virtual server ID in SolusVM hostname - The new hostname

Returns true if the server's hostname was successfully changed.



251
252
253
# File 'lib/solusvm/server.rb', line 251

def change_hostname(vid, hostname)
  perform_request(action: 'vserver-hostname', vserverid: vid, hostname: hostname)
end

#change_owner(vid, client_id) ⇒ Object

Public: Changes server owner.

vid - The virtual server ID in SolusVM client_id - The new client ID

Returns true if the server's owner was successfully changed.



207
208
209
# File 'lib/solusvm/server.rb', line 207

def change_owner(vid, client_id)
  perform_request(action: 'vserver-changeowner', vserverid: vid, clientid: client_id)
end

#change_plan(vid, plan) ⇒ Object

Public: Changes server plan.

vid - The virtual server ID in SolusVM plan - The new plan ID

Returns true if the server's plan was successfully changed.



197
198
199
# File 'lib/solusvm/server.rb', line 197

def change_plan(vid, plan)
  perform_request(action: 'vserver-change', vserverid: vid, plan: plan)
end

#change_rootpassword(vid, new_password) ⇒ Object

Public: Changes server root password.

vid - The virtual server ID in SolusVM new_password - The new root password

Returns true if the server's root password was successfully changed.



227
228
229
# File 'lib/solusvm/server.rb', line 227

def change_rootpassword(vid, new_password)
  perform_request(action: 'vserver-rootpassword', vserverid: vid, rootpassword: new_password)
end

#change_vncpass(vid, new_password) ⇒ Object

Public: Changes server VNC password.

vid - The virtual server ID in SolusVM new_password - The new VNC password

Returns true if the server's VNC password was successfully changed.



217
218
219
# File 'lib/solusvm/server.rb', line 217

def change_vncpass(vid, new_password)
  perform_request(action: 'vserver-vncpass', vserverid: vid, vncpassword: new_password)
end

#console(vid, params = {}) ⇒ Object

Public: Retrieves server console information.

vid - The virtual server ID in SolusVM params - A Hash to pass optional parameters to vserver-console call:

:access - A String that can be 'enable' or 'disable'
:time   - An Integer that can be 1|2|3|4|5|6|7|8

returns a Hash



283
284
285
286
# File 'lib/solusvm/server.rb', line 283

def console(vid, params = {})
  perform_request(action: 'vserver-console', vserverid: vid, access: params[:access], time: params[:time])
  returned_parameters
end

#create(hostname, password, options = {}) ⇒ Object

Public: Creates a new virtual server.

hostname - The server hostname password - The server password options - A Hash of options

:type            - openvz|xen|xen hvm|kvm
:node            - name of node
:nodegroup       - name of nodegroup
:username        - client username
:plan            - plan name
:template        - template or iso name
:ips             - amount of ips
:hvmt            - 0|1 Default is 0. This allows to define
                   templates & isos for Xen HVM
:custommemory    - overide plan memory with this amount
:customdiskspace - overide plan diskspace with this amount
:custombandwidth - overide plan bandwidth with this amount
:customcpu       - overide plan cpu cores with this amount
:customextraip   - add this amount of extra ips
:issuelicense    - 1|2 1 = cPanel monthly, 2 = cPanel yearly

Returns a Hash with the new server info, or false if the server was not created successfully.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/solusvm/server.rb', line 28

def create(hostname, password, options = {})
  options.reverse_merge!(
    type:         'xen',
    username:     nil,
    ips:          1,
    node:         nil,
    plan:         nil,
    template:     nil,
    password:     password,
    hostname:     hostname
  ).merge!(action: 'vserver-create')
  perform_request(options) && returned_parameters
end

#del_ip(vid, ip_address) ⇒ Object

Public: Deletes an IP address for a specific server.

vid - The virtual server ID in SolusVM ip_address - The IP address to remove

Returns true if the IP was successfully deleted.



187
188
189
# File 'lib/solusvm/server.rb', line 187

def del_ip(vid, ip_address)
  perform_request(action: 'vserver-delip', vserverid: vid, ipaddr: ip_address)
end

#exists?(vid) ⇒ Boolean

Public: Checks if a specific server exists.

vid - The virtual server ID in SolusVM

Returns true if the server exists.

Returns:

  • (Boolean)


155
156
157
158
# File 'lib/solusvm/server.rb', line 155

def exists?(vid)
  perform_request(action: 'vserver-checkexists', vserverid: vid)
  !!statusmsg.match(/Virtual server exists/i)
end

#info(vid, reboot = false) ⇒ Object

Public: Retrieves server information.

vid - The virtual server ID in SolusVM

Returns a Hash.



260
261
262
263
# File 'lib/solusvm/server.rb', line 260

def info(vid, reboot = false)
  perform_request(action: 'vserver-info', vserverid: vid, reboot: reboot)
  returned_parameters
end

#info_all(vid) ⇒ Object

Public: Retrieves all available server information.

vid - The virtual server ID in SolusVM

Returns a Hash.



293
294
295
296
# File 'lib/solusvm/server.rb', line 293

def info_all(vid)
  perform_request(action: 'vserver-infoall', vserverid: vid)
  returned_parameters
end

#mountiso(vid, iso) ⇒ Object

Public: Mounts a given ISO image.

vid - The virtual server ID in SolusVM iso - The ISO image to mount

Returns true if the ISO was mounted successfully.



314
315
316
# File 'lib/solusvm/server.rb', line 314

def mountiso(vid, iso)
  perform_request(action: 'vserver-mountiso', vserverid: vid, iso: iso)
end

#network_disable(vid) ⇒ Object

Public: Disables Network Mode.

vid - The virtual server ID in SolusVM

Returns true if Network Mode was successfully disabled.



119
120
121
# File 'lib/solusvm/server.rb', line 119

def network_disable(vid)
  perform_request(action: 'vserver-network-disable', vserverid: vid)
end

#network_enable(vid) ⇒ Object

Public: Enable Network Mode.

vid - The virtual server ID in SolusVM

Returns true if Network Mode was successfully enabled.



110
111
112
# File 'lib/solusvm/server.rb', line 110

def network_enable(vid)
  perform_request(action: 'vserver-network-enable', vserverid: vid)
end

#pae_disable(vid) ⇒ Object

Public: Disables PAE.

vid - The virtual server ID in SolusVM

Returns true if PAE was successfully disabled.



137
138
139
# File 'lib/solusvm/server.rb', line 137

def pae_disable(vid)
  perform_request(action: 'vserver-pae', vserverid: vid, pae: "off")
end

#pae_enable(vid) ⇒ Object

Public: Enable PAE.

vid - The virtual server ID in SolusVM

Returns true if PAE was successfully enabled.



128
129
130
# File 'lib/solusvm/server.rb', line 128

def pae_enable(vid)
  perform_request(action: 'vserver-pae', vserverid: vid, pae: "on")
end

#reboot(vid) ⇒ Object

Public: Reboots a server.

vid - The virtual server ID in SolusVM

Returns true if the server was successfully rebooted.



56
57
58
# File 'lib/solusvm/server.rb', line 56

def reboot(vid)
  perform_request(action: 'vserver-reboot', vserverid: vid)
end

#rebuild(vid, template) ⇒ Object

Public: Rebuilds a server using a given template.

vid - The virtual server ID in SolusVM template - The template to use

Returns true if the server was successfully rebuilt.



304
305
306
# File 'lib/solusvm/server.rb', line 304

def rebuild(vid, template)
  perform_request(action: 'vserver-rebuild', vserverid: vid, template: template)
end

#resume(vid) ⇒ Object

Public: Resumes a server.

vid - The virtual server ID in SolusVM

Returns true if the server was successfully resumed.



74
75
76
# File 'lib/solusvm/server.rb', line 74

def resume(vid)
  perform_request(action: 'vserver-unsuspend', vserverid: vid)
end

#shutdown(vid) ⇒ Object

Public: Shuts down a server.

vid - The virtual server ID in SolusVM

Returns true if the server was successfully shutdown.



83
84
85
# File 'lib/solusvm/server.rb', line 83

def shutdown(vid)
  perform_request(action: 'vserver-shutdown', vserverid: vid)
end

#status(vid) ⇒ Object

Public: Checks the status of specific server (disabled|online|offline).

vid - The virtual server ID in SolusVM

Returns the server's status.



165
166
167
168
# File 'lib/solusvm/server.rb', line 165

def status(vid)
  perform_request(action: 'vserver-status', vserverid: vid)
  statusmsg
end

#suspend(vid) ⇒ Object

Public: Suspends a server.

vid - The virtual server ID in SolusVM

Returns true if the server was successfully suspended.



65
66
67
# File 'lib/solusvm/server.rb', line 65

def suspend(vid)
  perform_request(action: 'vserver-suspend', vserverid: vid)
end

#terminate(vid, deleteclient = false) ⇒ Object

Public: Terminates a server.

vid - The virtual server ID in SolusVM

Returns true if the server was successfully terminated.



146
147
148
# File 'lib/solusvm/server.rb', line 146

def terminate(vid, deleteclient = false)
  perform_request(action: 'vserver-terminate', vserverid: vid, deleteclient: deleteclient)
end

#tun_disable(vid) ⇒ Object

Public: Disable TUN/TAP.

vid - The virtual server ID in SolusVM

Returns true if TUN/TAP was successfully disabled.



101
102
103
# File 'lib/solusvm/server.rb', line 101

def tun_disable(vid)
  perform_request(action: 'vserver-tun-disable', vserverid: vid)
end

#tun_enable(vid) ⇒ Object

Public: Enable TUN/TAP.

vid - The virtual server ID in SolusVM

Returns true if TUN/TAP was successfully enabled.



92
93
94
# File 'lib/solusvm/server.rb', line 92

def tun_enable(vid)
  perform_request(action: 'vserver-tun-enable', vserverid: vid)
end

#unmountiso(vid) ⇒ Object

Public: Unmounts a given ISO image.

vid - The virtual server ID in SolusVM

Returns true if the ISO was unmounted successfully.



323
324
325
# File 'lib/solusvm/server.rb', line 323

def unmountiso(vid)
  perform_request(action: 'vserver-unmountiso', vserverid: vid)
end

#vnc(vid) ⇒ Object

Public: Retrieves server vnc information.

vid - The virtual server ID in SolusVM

Returns a Hash.



270
271
272
273
# File 'lib/solusvm/server.rb', line 270

def vnc(vid)
  perform_request(action: 'vserver-vnc', vserverid: vid)
  returned_parameters
end