Class: Lumberg::Cpanel::MysqlDb

Inherits:
Base show all
Defined in:
lib/lumberg/cpanel/mysql_db.rb

Overview

Public: Allows you to manage MySQL Databases, users and other related settings.

Instance Attribute Summary

Attributes inherited from Base

#api_username

Attributes inherited from Whm::Base

#server

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #perform_request

Methods inherited from Whm::Base

#initialize, #setup_server

Constructor Details

This class inherits a constructor from Lumberg::Cpanel::Base

Class Method Details

.api_moduleObject



5
# File 'lib/lumberg/cpanel/mysql_db.rb', line 5

def self.api_module; "Mysql"; end

Instance Method Details

#add_db(options = {}) ⇒ Object

Public: Add a new MySQL database to a cPanel account.

options - Hash options for API call params (default: {}).

:dbname - String name of the MySQL database to add.

Returns Hash API response.



13
14
15
16
17
18
# File 'lib/lumberg/cpanel/mysql_db.rb', line 13

def add_db(options = {})
  perform_request({
    api_function: 'adddb',
    'arg-0' => options.delete(:dbname)
  }.merge(default_options(options)))
end

#add_host(options = {}) ⇒ Object

Public: Authorize a remote host to access a cPanel account's MySQL users.

options - Hash options for API call params (default: {})

:hostname - String IP address or hostname that should be provided access.

Returns Hash API response.



163
164
165
166
167
168
# File 'lib/lumberg/cpanel/mysql_db.rb', line 163

def add_host(options = {})
  perform_request({
   api_function: 'addhost',
   'arg-0' => options.delete(:hostname)
  }.merge(default_options(options)))
end

#add_user(options = {}) ⇒ Object

Public: Create a new MySQL user.

options - Hash options for API call params (default: {}).

:username - String MySQL user to create.
:password - String password for the new MySQL user.

Returns Hash API respone.



27
28
29
30
31
32
33
# File 'lib/lumberg/cpanel/mysql_db.rb', line 27

def add_user(options = {})
  perform_request({
    api_function: 'adduser',
    'arg-0' => options.delete(:username),
    'arg-1' => options.delete(:password)
  }.merge(default_options(options)))
end

#add_user_db(options = {}) ⇒ Object

Public: Grant a user permission to access a cPanel account's database.

options - Hash options for API call params (default: {})

:dbname - String name of the database to allow the user to access.
:dbuser - String MySQL user who should be given access to the database.
:perms_list - A space-separated String containing a list of permissions
              to grant to the user
              (e.g. "all" or "alter drop create delete insert update lock" )

Returns Hash API respone.



45
46
47
48
49
50
51
52
# File 'lib/lumberg/cpanel/mysql_db.rb', line 45

def add_user_db(options = {})
  perform_request({
    api_function: 'adduserdb',
    'arg-0' => options.delete(:dbname),
    'arg-1' => options.delete(:dbuser),
    'arg-2' => options.delete(:perms_list)
  }.merge(default_options(options)))
end

#check_db(options = {}) ⇒ Object

Public: Run a MySQL database check.

options - Hash options for API call params (default: {}).

:dbname - String name of the MySQL database to check.

Returns Hash API response.



69
70
71
72
73
74
# File 'lib/lumberg/cpanel/mysql_db.rb', line 69

def check_db(options = {})
  perform_request({
    api_function: 'checkdb',
    'arg-0' => options.delete(:dbname)
  }.merge(default_options(options)))
end

#del_db(options = {}) ⇒ Object

Public: Remove a database from MySQL.

options - Hash options for API call params (default: {}).

:dbname - String name of the MySQL database to remove.
         This value must be prefixed with the cPanel username
         (e.g., cpuser_dbname).

Returns Hash API response.



150
151
152
153
154
155
# File 'lib/lumberg/cpanel/mysql_db.rb', line 150

def del_db(options = {})
  perform_request({
    api_function: 'deldb',
    'arg-0' => options.delete(:dbname)
  }.merge(default_options(options)))
end

#del_host(options = {}) ⇒ Object

Public: Remove host access permissions from MySQL.

options - Hash options for API call params (default: {})

:host - String IP address or hostname that should be provided access.

Returns Hash API response.



176
177
178
179
180
181
# File 'lib/lumberg/cpanel/mysql_db.rb', line 176

def del_host(options = {})
  perform_request({
    api_function: 'delhost',
    'arg-0' => options.delete(:host)
  }.merge(default_options(options)))
end

#del_user(options = {}) ⇒ Object

Public: Remove a user from MySQL.

options - Hash options for API call params (default: {})

:dbuser - String name of the MySQL user to remove.
          This value must be prefixed with the cPanel username.
          (e.g. cpuser_dbuser)

Returns Hash API response.



135
136
137
138
139
140
# File 'lib/lumberg/cpanel/mysql_db.rb', line 135

def del_user(options = {})
  perform_request({
    api_function: 'deluser',
    'arg-0' => options.delete(:dbuser)
  }.merge(default_options(options)))
end

#del_user_db(options = {}) ⇒ Object

Public: Disallow a MySQL user from accessing a database.

options - Hash options for API call params (default: {})

:dbname - String MySQL database from which to remove the user's permissions.
:dbuser - String name of the MySQL user to remove.

Returns Hash API response.



119
120
121
122
123
124
125
# File 'lib/lumberg/cpanel/mysql_db.rb', line 119

def del_user_db(options = {})
  perform_request({
    api_function: 'deluserdb',
    'arg-0' => options.delete(:dbname),
    'arg-1' => options.delete(:dbuser)
  }.merge(default_options(options)))
end

#init_cache(options = {}) ⇒ Object

Public: Refresh the cache of MySQL information. This includes users,

databases, routines and other related information.

options - Hash options for API call params (default: {})

Returns Hash API response.



106
107
108
109
110
# File 'lib/lumberg/cpanel/mysql_db.rb', line 106

def init_cache(options = {})
  perform_request({
    api_function: 'initcache'
  }.merge(default_options(options)))
end

#number_of_dbs(options = {}) ⇒ Object

Public: Retrieve the number of database users an account has created.

Returns Hash API response.



57
58
59
60
61
# File 'lib/lumberg/cpanel/mysql_db.rb', line 57

def number_of_dbs(options = {})
  perform_request({
    api_function: 'number_of_dbs'
  }.merge(default_options(options)))
end

#repair_db(options = {}) ⇒ Object

Public: Run a MySQL database repair.

options - Hash options for API call params (default: {}).

:dbname - String name of the MySQL database to repair.

Returns Hash API response.



82
83
84
85
86
87
# File 'lib/lumberg/cpanel/mysql_db.rb', line 82

def repair_db(options = {})
  perform_request({
    api_function: 'repairdb',
    'arg-0' => options.delete(:dbname)
  }.merge(default_options(options)))
end

#update_privs(options = {}) ⇒ Object

Public: Force an update of MySQL privileges and passwords.

options - Hash options for API call params (default: {})

Returns Hash API response.



94
95
96
97
98
# File 'lib/lumberg/cpanel/mysql_db.rb', line 94

def update_privs(options = {})
  perform_request({
    api_function: 'updateprivs'
  }.merge(default_options(options)))
end