Class: Lumberg::Whm::Server

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

Instance Attribute Summary collapse

Attributes inherited from Base

#server

Instance Method Summary collapse

Methods inherited from Base

#setup_server

Constructor Details

#initialize(options) ⇒ Server

Required

* <tt>:host</tt> - PENDING
* <tt>:hash</tt> - PENDING

Optional

* <tt>:user</tt> - PENDING
* <tt>:ssl</tt> - PENDING
* <tt>:basic_auth</tt>

57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/lumberg/whm/server.rb', line 57

def initialize(options)
  @ssl_verify ||= false
  @ssl        = options.delete(:ssl)
  @host       = options.delete(:host)
  validate_server_host

  @hash       = format_hash(options.delete(:hash))
  @user       = (options.has_key?(:user) ? options.delete(:user) : 'root')
  @basic_auth = options.delete(:basic_auth)
  @timeout    = options.delete(:timeout)
  @whostmgr   = options.delete(:whostmgr)

  @base_url = format_url(options)
end

Instance Attribute Details

#base_urlObject

Base URL to the WHM API


13
14
15
# File 'lib/lumberg/whm/server.rb', line 13

def base_url
  @base_url
end

#basic_authObject

Enable Basic Authentication with API - default false


16
17
18
# File 'lib/lumberg/whm/server.rb', line 16

def basic_auth
  @basic_auth
end

#boolean_paramsObject

Returned params to transfor to booleans


37
38
39
# File 'lib/lumberg/whm/server.rb', line 37

def boolean_params
  @boolean_params
end

#force_response_typeObject

Force response type…ARG!


40
41
42
# File 'lib/lumberg/whm/server.rb', line 40

def force_response_type
  @force_response_type
end

#functionObject (readonly)

WHM API function name


28
29
30
# File 'lib/lumberg/whm/server.rb', line 28

def function
  @function
end

#hashObject

Remote access hash


10
11
12
# File 'lib/lumberg/whm/server.rb', line 10

def hash
  @hash
end

#hostObject

Server


7
8
9
# File 'lib/lumberg/whm/server.rb', line 7

def host
  @host
end

#paramsObject

HTTP Params used for API requests


25
26
27
# File 'lib/lumberg/whm/server.rb', line 25

def params
  @params
end

#responseObject (readonly)

WHM parsed response


22
23
24
# File 'lib/lumberg/whm/server.rb', line 22

def response
  @response
end

#sslObject

Use ssl?


31
32
33
# File 'lib/lumberg/whm/server.rb', line 31

def ssl
  @ssl
end

#ssl_verifyObject

HTTP SSL verify mode


34
35
36
# File 'lib/lumberg/whm/server.rb', line 34

def ssl_verify
  @ssl_verify
end

#timeoutObject

HTTP read/open timeout


43
44
45
# File 'lib/lumberg/whm/server.rb', line 43

def timeout
  @timeout
end

#userObject

API username - default: root


19
20
21
# File 'lib/lumberg/whm/server.rb', line 19

def user
  @user
end

#whostmgrObject

Whostmgr


46
47
48
# File 'lib/lumberg/whm/server.rb', line 46

def whostmgr
  @whostmgr
end

Instance Method Details

#accountObject


219
220
221
# File 'lib/lumberg/whm/server.rb', line 219

def 
  @account ||= Account.new(server: self)
end

#add_ip(options = {}) ⇒ Object


141
142
143
# File 'lib/lumberg/whm/server.rb', line 141

def add_ip(options = {})
  perform_request('addip', options.merge(response_key: 'addip'))
end

#certObject


231
232
233
# File 'lib/lumberg/whm/server.rb', line 231

def cert
  @cert ||= Cert.new(server: self)
end

#delete_ip(options = {}) ⇒ Object


145
146
147
# File 'lib/lumberg/whm/server.rb', line 145

def delete_ip(options = {})
  perform_request('delip', options.merge(response_key: 'delip'))
end

#disk_usageObject


193
194
195
196
197
198
199
200
201
# File 'lib/lumberg/whm/server.rb', line 193

def disk_usage
  request = perform_request('getdiskusage',
                            response_key: 'data',
                            :'api.version' => 1)

  request[:success] = request.has_key?(:params)

  request
end

#dnsObject


223
224
225
# File 'lib/lumberg/whm/server.rb', line 223

def dns
  @dns ||= Dns.new(server: self)
end

#edit_hook(options = {}) ⇒ Object


183
184
185
186
187
188
189
190
191
# File 'lib/lumberg/whm/server.rb', line 183

def edit_hook(options = {})
  request = perform_request('edit_hook',
                            options.merge(:'api.version' => 1,
                                          response_key: 'metadata'))

  request[:success] = request[:params][:reason] == 'OK'

  request
end

#get_hostnameObject


86
87
88
# File 'lib/lumberg/whm/server.rb', line 86

def get_hostname
  perform_request('gethostname', {response_key: 'hostname'})
end

#get_nv_var(options = {}) ⇒ Object


165
166
167
# File 'lib/lumberg/whm/server.rb', line 165

def get_nv_var(options = {})
  perform_request('nvget', options.merge(response_key: 'nvget'))
end

#get_tweaksetting(options = {}) ⇒ Object


117
118
119
120
121
122
123
124
125
126
127
# File 'lib/lumberg/whm/server.rb', line 117

def get_tweaksetting(options = {})
  request = perform_request('get_tweaksetting',
    options.merge(
      response_key:     'data',
      :'api.version' => 1
    )
  )

  request[:success] = !request[:params].empty?
  request
end

#languagesObject


105
106
107
# File 'lib/lumberg/whm/server.rb', line 105

def languages
  perform_request('getlanglist', {response_key: 'lang'})
end

#list_hooksObject


173
174
175
176
177
178
179
180
181
# File 'lib/lumberg/whm/server.rb', line 173

def list_hooks
  request = perform_request('list_hooks',
                            response_key: 'data',
                            :'api.version' => 1)

  request[:success] = request.has_key?(:params)

  request
end

#list_ipsObject


113
114
115
# File 'lib/lumberg/whm/server.rb', line 113

def list_ips
  perform_request('listips', {response_key: 'result'})
end

#load_averageObject


94
95
96
97
98
99
# File 'lib/lumberg/whm/server.rb', line 94

def load_average
  @force_response_type = :query
  result = perform_request('loadavg')
  result[:success] = result[:params].has_key?(:one)
  result
end

#lookup_nameserver_ip(options = {}) ⇒ Object

Public: Gets IP address for a given hostname.

options - Hash of options (default: {})

:host - String host name

Returns a Hash API Response


209
210
211
212
213
214
215
216
217
# File 'lib/lumberg/whm/server.rb', line 209

def lookup_nameserver_ip(options = {})
  request = perform_request('lookupnsip',
                            options.merge(:'api.version' => 1,
                                          response_key: 'data'))

  request[:success] = request[:params].has_key?(:ip)

  request
end

#perform_request(function, options = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:


72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/lumberg/whm/server.rb', line 72

def perform_request(function, options = {})
  # WHM sometime uses different keys for the result hash
  @response_key = options.delete(:response_key) || 'result'

  @whostmgr = options.delete(:whostmgr)
  @base_url = format_url(options) if @whostmgr
  @function = function
  @params   = format_query(options)

  yield self if block_given?

  do_request(@base_url, function, @params)
end

#rebootObject


169
170
171
# File 'lib/lumberg/whm/server.rb', line 169

def reboot
  perform_request('reboot', {response_key: "reboot"})
end

#resellerObject


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

def reseller
  @reseller ||= Reseller.new(server: self)
end

#set_hostname(options = {}) ⇒ Object


149
150
151
# File 'lib/lumberg/whm/server.rb', line 149

def set_hostname(options = {})
  perform_request('sethostname', options.merge(response_key: 'sethostname'))
end

#set_nv_var(options = {}) ⇒ Object


161
162
163
# File 'lib/lumberg/whm/server.rb', line 161

def set_nv_var(options = {})
  perform_request('nvset', options.merge(response_key: 'nvset'))
end

#set_resolvers(options = {}) ⇒ Object


153
154
155
# File 'lib/lumberg/whm/server.rb', line 153

def set_resolvers(options = {})
  perform_request('setresolvers', options.merge(response_key: 'setresolvers'))
end

#set_tweaksetting(options = {}) ⇒ Object


129
130
131
132
133
134
135
136
137
138
139
# File 'lib/lumberg/whm/server.rb', line 129

def set_tweaksetting(options = {})
  request = perform_request('set_tweaksetting',
    options.merge(
      response_key:     'metadata',
      :'api.version' => 1
    )
  )

  request[:success] = (request[:params][:reason] == 'OK')
  request
end

#show_bandwidth(options = {}) ⇒ Object


157
158
159
# File 'lib/lumberg/whm/server.rb', line 157

def show_bandwidth(options = {})
  perform_request('showbw', options.merge(response_key: 'bandwidth'))
end

#system_load_average(options = {}) ⇒ Object


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

def system_load_average(options = {})
  perform_request('systemloadavg', options.merge(response_key: 'data'))
end

#themesObject


109
110
111
# File 'lib/lumberg/whm/server.rb', line 109

def themes
  perform_request('getlanglist', {response_key: 'themes'})
end

#transfer_toolObject


235
236
237
# File 'lib/lumberg/whm/server.rb', line 235

def transfer_tool
  @transfer_tool ||= TransferTool.new(server: self)
end

#versionObject


90
91
92
# File 'lib/lumberg/whm/server.rb', line 90

def version
  perform_request('version', {response_key: 'version'})
end