solusvm 1.4.0 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/LICENSE +1 -1
  4. data/README.markdown +159 -116
  5. data/Rakefile +3 -33
  6. data/bin/solusvm +3 -4
  7. data/lib/solusvm.rb +1 -3
  8. data/lib/solusvm/base.rb +101 -46
  9. data/lib/solusvm/cli.rb +8 -8
  10. data/lib/solusvm/cli/base_cli.rb +3 -3
  11. data/lib/solusvm/cli/client_cli.rb +3 -5
  12. data/lib/solusvm/cli/general_cli.rb +3 -5
  13. data/lib/solusvm/cli/node_cli.rb +3 -5
  14. data/lib/solusvm/cli/reseller_cli.rb +3 -5
  15. data/lib/solusvm/cli/server_cli.rb +4 -6
  16. data/lib/solusvm/client.rb +45 -27
  17. data/lib/solusvm/errors.rb +3 -0
  18. data/lib/solusvm/general.rb +11 -12
  19. data/lib/solusvm/hash.rb +1 -11
  20. data/lib/solusvm/node.rb +33 -21
  21. data/lib/solusvm/reseller.rb +53 -49
  22. data/lib/solusvm/server.rb +188 -52
  23. data/lib/solusvm/version.rb +2 -2
  24. data/test/cli/test_base_cli.rb +14 -4
  25. data/test/cli/test_client_cli.rb +13 -13
  26. data/test/cli/test_general_cli.rb +7 -7
  27. data/test/cli/test_node_cli.rb +13 -13
  28. data/test/cli/test_reseller_cli.rb +11 -11
  29. data/test/cli/test_server_cli.rb +61 -61
  30. data/test/sham_rack_stubs/base/parse-response.json +4 -0
  31. data/test/sham_rack_stubs/client/authenticate.json +4 -0
  32. data/test/sham_rack_stubs/client/change-password.json +6 -0
  33. data/test/sham_rack_stubs/client/create.json +9 -0
  34. data/test/sham_rack_stubs/client/delete.json +4 -0
  35. data/test/sham_rack_stubs/client/exists.json +4 -0
  36. data/test/sham_rack_stubs/client/list-empty.json +5 -0
  37. data/test/sham_rack_stubs/client/list.json +30 -0
  38. data/test/sham_rack_stubs/general/isos-empty.json +5 -0
  39. data/test/sham_rack_stubs/general/isos.json +5 -0
  40. data/test/sham_rack_stubs/general/plans-empty.json +5 -0
  41. data/test/sham_rack_stubs/general/plans.json +5 -0
  42. data/test/sham_rack_stubs/general/templates-empty.json +7 -0
  43. data/test/sham_rack_stubs/general/templates.json +7 -0
  44. data/test/sham_rack_stubs/generic/error.json +4 -0
  45. data/test/sham_rack_stubs/node/available-ips-empty.json +6 -0
  46. data/test/sham_rack_stubs/node/available-ips.json +6 -0
  47. data/test/sham_rack_stubs/node/ids.json +5 -0
  48. data/test/sham_rack_stubs/node/list-empty.json +5 -0
  49. data/test/sham_rack_stubs/node/list-groups.json +5 -0
  50. data/test/sham_rack_stubs/node/list.json +5 -0
  51. data/test/sham_rack_stubs/node/statistics.json +21 -0
  52. data/test/sham_rack_stubs/node/virtualservers-empty.json +5 -0
  53. data/test/sham_rack_stubs/node/virtualservers.json +19 -0
  54. data/test/sham_rack_stubs/node/xenresources.json +6 -0
  55. data/test/sham_rack_stubs/reseller/change-resources.json +18 -0
  56. data/test/sham_rack_stubs/reseller/create.json +25 -0
  57. data/test/sham_rack_stubs/reseller/delete.json +4 -0
  58. data/test/sham_rack_stubs/reseller/info.json +24 -0
  59. data/test/sham_rack_stubs/reseller/list-empty.json +5 -0
  60. data/test/sham_rack_stubs/reseller/list.json +5 -0
  61. data/test/sham_rack_stubs/server/add-ip.json +5 -0
  62. data/test/sham_rack_stubs/server/boot.json +4 -0
  63. data/test/sham_rack_stubs/server/change-bootorder.json +4 -0
  64. data/test/sham_rack_stubs/server/change-hostname.json +5 -0
  65. data/test/sham_rack_stubs/server/change-owner.json +4 -0
  66. data/test/sham_rack_stubs/server/change-plan.json +4 -0
  67. data/test/sham_rack_stubs/server/change-rootpassword.json +5 -0
  68. data/test/sham_rack_stubs/server/change-vncpass.json +5 -0
  69. data/test/sham_rack_stubs/server/console.json +13 -0
  70. data/test/sham_rack_stubs/server/create.json +13 -0
  71. data/test/sham_rack_stubs/server/del-ip.json +4 -0
  72. data/test/sham_rack_stubs/server/exists.json +4 -0
  73. data/test/sham_rack_stubs/server/info-all.json +16 -0
  74. data/test/sham_rack_stubs/server/info.json +15 -0
  75. data/test/sham_rack_stubs/server/mountiso.json +4 -0
  76. data/test/sham_rack_stubs/server/network-disable.json +4 -0
  77. data/test/sham_rack_stubs/server/network-enable.json +4 -0
  78. data/test/sham_rack_stubs/server/pae-disable.json +4 -0
  79. data/test/sham_rack_stubs/server/pae-enable.json +4 -0
  80. data/test/sham_rack_stubs/server/reboot.json +4 -0
  81. data/test/sham_rack_stubs/server/rebuild.json +4 -0
  82. data/test/sham_rack_stubs/server/resume.json +4 -0
  83. data/test/sham_rack_stubs/server/shutdown.json +4 -0
  84. data/test/sham_rack_stubs/server/status.json +4 -0
  85. data/test/sham_rack_stubs/server/suspend.json +4 -0
  86. data/test/sham_rack_stubs/server/terminate.json +4 -0
  87. data/test/sham_rack_stubs/server/tun-disable.json +4 -0
  88. data/test/sham_rack_stubs/server/tun-enable.json +4 -0
  89. data/test/sham_rack_stubs/server/unmountiso.json +4 -0
  90. data/test/sham_rack_stubs/server/vnc.json +8 -0
  91. data/test/solusvm/test_base.rb +34 -56
  92. data/test/solusvm/test_cli.rb +3 -3
  93. data/test/solusvm/test_client.rb +56 -66
  94. data/test/solusvm/test_general.rb +34 -19
  95. data/test/solusvm/test_hash.rb +0 -9
  96. data/test/solusvm/test_node.rb +66 -72
  97. data/test/solusvm/test_reseller.rb +47 -58
  98. data/test/solusvm/test_server.rb +149 -164
  99. data/test/test_helper.rb +43 -31
  100. metadata +173 -189
  101. data/.document +0 -5
  102. data/.gitignore +0 -25
  103. data/.travis.yml +0 -12
  104. data/solusvm.gemspec +0 -33
  105. data/test/vcr_cassettes/base/invalid_key.yml +0 -19
  106. data/test/vcr_cassettes/base/invalid_status.yml +0 -19
  107. data/test/vcr_cassettes/base/nonexistent_node.yml +0 -19
  108. data/test/vcr_cassettes/base/parse_response.yml +0 -28
  109. data/test/vcr_cassettes/base/statusmsg.yml +0 -28
  110. data/test/vcr_cassettes/base/successful.yml +0 -68
  111. data/test/vcr_cassettes/base/successful_instance_config.yml +0 -28
  112. data/test/vcr_cassettes/base/unauthorized_ip.yml +0 -19
  113. data/test/vcr_cassettes/client/authenticate.yml +0 -37
  114. data/test/vcr_cassettes/client/change_password.yml +0 -39
  115. data/test/vcr_cassettes/client/create.yml +0 -42
  116. data/test/vcr_cassettes/client/delete.yml +0 -37
  117. data/test/vcr_cassettes/client/exists.yml +0 -20
  118. data/test/vcr_cassettes/client/list.yml +0 -66
  119. data/test/vcr_cassettes/general/isos.yml +0 -38
  120. data/test/vcr_cassettes/general/plans.yml +0 -38
  121. data/test/vcr_cassettes/general/templates.yml +0 -38
  122. data/test/vcr_cassettes/node/available_ips.yml +0 -41
  123. data/test/vcr_cassettes/node/ids.yml +0 -21
  124. data/test/vcr_cassettes/node/list.yml +0 -38
  125. data/test/vcr_cassettes/node/list_groups.yml +0 -20
  126. data/test/vcr_cassettes/node/statistics.yml +0 -32
  127. data/test/vcr_cassettes/node/virtualservers.yml +0 -67
  128. data/test/vcr_cassettes/node/xenresources.yml +0 -22
  129. data/test/vcr_cassettes/reseller/change_resources.yml +0 -27
  130. data/test/vcr_cassettes/reseller/create.yml +0 -27
  131. data/test/vcr_cassettes/reseller/delete.yml +0 -15
  132. data/test/vcr_cassettes/reseller/info.yml +0 -27
  133. data/test/vcr_cassettes/reseller/list.yml +0 -27
  134. data/test/vcr_cassettes/server/.yml +0 -1017
  135. data/test/vcr_cassettes/server/add_ip.yml +0 -15
  136. data/test/vcr_cassettes/server/boot.yml +0 -15
  137. data/test/vcr_cassettes/server/change_bootorder.yml +0 -15
  138. data/test/vcr_cassettes/server/change_consolepass.yml +0 -16
  139. data/test/vcr_cassettes/server/change_hostname.yml +0 -15
  140. data/test/vcr_cassettes/server/change_owner.yml +0 -15
  141. data/test/vcr_cassettes/server/change_plan.yml +0 -15
  142. data/test/vcr_cassettes/server/change_rootpassword.yml +0 -15
  143. data/test/vcr_cassettes/server/change_vncpass.yml +0 -15
  144. data/test/vcr_cassettes/server/console.yml +0 -28
  145. data/test/vcr_cassettes/server/create.yml +0 -27
  146. data/test/vcr_cassettes/server/del_ip.yml +0 -15
  147. data/test/vcr_cassettes/server/exists.yml +0 -15
  148. data/test/vcr_cassettes/server/info.yml +0 -27
  149. data/test/vcr_cassettes/server/info_all.yml +0 -15
  150. data/test/vcr_cassettes/server/mountiso.yml +0 -15
  151. data/test/vcr_cassettes/server/network_disable.yml +0 -15
  152. data/test/vcr_cassettes/server/network_enable.yml +0 -15
  153. data/test/vcr_cassettes/server/pae_disable.yml +0 -15
  154. data/test/vcr_cassettes/server/pae_enable.yml +0 -15
  155. data/test/vcr_cassettes/server/reboot.yml +0 -15
  156. data/test/vcr_cassettes/server/rebuild.yml +0 -15
  157. data/test/vcr_cassettes/server/resume.yml +0 -15
  158. data/test/vcr_cassettes/server/shutdown.yml +0 -15
  159. data/test/vcr_cassettes/server/status.yml +0 -15
  160. data/test/vcr_cassettes/server/suspend.yml +0 -15
  161. data/test/vcr_cassettes/server/terminate.yml +0 -27
  162. data/test/vcr_cassettes/server/tun_disable.yml +0 -15
  163. data/test/vcr_cassettes/server/tun_enable.yml +0 -15
  164. data/test/vcr_cassettes/server/unmountiso.yml +0 -15
  165. data/test/vcr_cassettes/server/vnc.yml +0 -15
@@ -6,17 +6,17 @@ require 'solusvm/cli/general_cli'
6
6
  require 'solusvm/cli/reseller_cli'
7
7
  require 'solusvm/cli/client_cli'
8
8
 
9
- module Solusvm
10
- class Cli < Thor
11
- register(ServerCli, 'server', 'server <command>', 'Server commands')
12
- register(NodeCli, 'node', 'node <command>', 'Node commands')
13
- register(GeneralCli, 'general', 'general <command>', 'General commands')
14
- register(ResellerCli, 'reseller', 'reseller <command>', 'Reseller commands')
15
- register(ClientCli, 'client', 'client <command>', 'Client commands')
9
+ module SolusVM
10
+ class CLI < Thor
11
+ register(ServerCLI, 'server', 'server <command>', 'Server commands')
12
+ register(NodeCLI, 'node', 'node <command>', 'Node commands')
13
+ register(GeneralCLI, 'general', 'general <command>', 'General commands')
14
+ register(ResellerCLI, 'reseller', 'reseller <command>', 'Reseller commands')
15
+ register(ClientCLI, 'client', 'client <command>', 'Client commands')
16
16
 
17
17
  desc "version", "Outputs the current program version"
18
18
  def version
19
- say Solusvm::VERSION
19
+ say SolusVM::VERSION
20
20
  end
21
21
  end
22
22
  end
@@ -3,8 +3,8 @@ require 'thor'
3
3
  require 'thor/group'
4
4
  require 'solusvm/version'
5
5
 
6
- module Solusvm
7
- class BaseCli < Thor
6
+ module SolusVM
7
+ class BaseCLI < Thor
8
8
  include Thor::Actions
9
9
 
10
10
  class << self
@@ -72,7 +72,7 @@ module Solusvm
72
72
  end
73
73
 
74
74
  def present_or_exit(options_key, default_option_key, message)
75
- options[options_key] || BaseCli.default_option(default_option_key) || (say(message) && raise(SystemExit))
75
+ options[options_key] || BaseCLI.default_option(default_option_key) || (say(message) && raise(SystemExit))
76
76
  end
77
77
  end
78
78
  end
@@ -1,5 +1,5 @@
1
- module Solusvm
2
- class ClientCli < BaseCli
1
+ module SolusVM
2
+ class ClientCLI < BaseCLI
3
3
 
4
4
  desc "create", "Creates a new h"
5
5
  method_option :username, type: :string, desc: "Username", aliases: ["-u", "--username"]
@@ -40,9 +40,7 @@ module Solusvm
40
40
  private
41
41
 
42
42
  def api
43
- @client ||= begin
44
- Solusvm::Client.new(api_params())
45
- end
43
+ @client ||= SolusVM::Client.new(api_params())
46
44
  end
47
45
  end
48
46
  end
@@ -1,5 +1,5 @@
1
- module Solusvm
2
- class GeneralCli < BaseCli
1
+ module SolusVM
2
+ class GeneralCLI < BaseCLI
3
3
 
4
4
  desc "templates TYPE", "Lists existing templates for a given type [openvz|xen|xen hvm|kvm]"
5
5
  def templates(type)
@@ -19,9 +19,7 @@ module Solusvm
19
19
  private
20
20
 
21
21
  def api
22
- @general ||= begin
23
- Solusvm::General.new(api_params)
24
- end
22
+ @general ||= SolusVM::General.new(api_params)
25
23
  end
26
24
  end
27
25
  end
@@ -1,5 +1,5 @@
1
- module Solusvm
2
- class NodeCli < BaseCli
1
+ module SolusVM
2
+ class NodeCLI < BaseCLI
3
3
 
4
4
  desc "list TYPE", "Lists existing nodes for a given type [openvz|xen|xen hvm|kvm]"
5
5
  def list(type)
@@ -34,9 +34,7 @@ module Solusvm
34
34
  private
35
35
 
36
36
  def api
37
- @node ||= begin
38
- Solusvm::Node.new(api_params)
39
- end
37
+ @node ||= SolusVM::Node.new(api_params)
40
38
  end
41
39
  end
42
40
  end
@@ -1,5 +1,5 @@
1
- module Solusvm
2
- class ResellerCli < BaseCli
1
+ module SolusVM
2
+ class ResellerCLI < BaseCLI
3
3
 
4
4
  desc "create", "Creates a new reseller"
5
5
  method_option :username, type: :string, desc: "Username", aliases: ["-u", "--username"]
@@ -64,9 +64,7 @@ module Solusvm
64
64
  private
65
65
 
66
66
  def api
67
- @reseller ||= begin
68
- Solusvm::Reseller.new(api_params)
69
- end
67
+ @reseller ||= SolusVM::Reseller.new(api_params)
70
68
  end
71
69
  end
72
70
  end
@@ -1,5 +1,5 @@
1
- module Solusvm
2
- class ServerCli < BaseCli
1
+ module SolusVM
2
+ class ServerCLI < BaseCLI
3
3
 
4
4
  desc "status VSERVERID", "Checks the status of a server"
5
5
  def status(vserverid)
@@ -135,7 +135,7 @@ module Solusvm
135
135
  desc "create HOSTNAME PASSWORD", "Creates a new server"
136
136
  method_option :plan, type: :string, desc: "Plan to use", aliases: ["-p", "--plan"]
137
137
  method_option :ips, type: :string, desc: "Number of ips to add to the vps", aliases: ["-i", "--ips"]
138
- method_option :kind, type: :string, desc: "Type of VPS (#{Solusvm::Server::VALID_SERVER_TYPES.join(',')})", aliases: ["-k", "--kind"]
138
+ method_option :kind, type: :string, desc: "Type of VPS (#{SolusVM::Server::VALID_SERVER_TYPES.join(',')})", aliases: ["-k", "--kind"]
139
139
  method_option :username, type: :string, desc: "The client to put the VPS under", aliases: ["-u", "--username"]
140
140
  method_option :template, type: :string, desc: "VPS template to boot from", aliases: ["-t", "--template"]
141
141
  method_option :node, type: :string, desc: "Node to provision on", aliases: ["-n", "--node"]
@@ -149,9 +149,7 @@ module Solusvm
149
149
  private
150
150
 
151
151
  def api
152
- @server ||= begin
153
- Solusvm::Server.new(api_params)
154
- end
152
+ @server ||= SolusVM::Server.new(api_params)
155
153
  end
156
154
 
157
155
  def switch(vserverid, switch_value, on_method, off_method)
@@ -1,49 +1,67 @@
1
- module Solusvm
2
- # Solusvm::Client is the class for working with clients.
1
+ module SolusVM
2
+ # SolusVM::Client is the class for working with clients.
3
3
  class Client < Base
4
- # Creates a client.
4
+ # Public: Creates a client.
5
5
  #
6
- # Options:
6
+ # options - A Hash of options:
7
+ # :username
8
+ # :password
9
+ # :email
10
+ # :firstname
11
+ # :lastname
12
+ # :company
7
13
  #
8
- # * <tt>:username</tt>
9
- # * <tt>:password</tt>
10
- # * <tt>:email</tt>
11
- # * <tt>:firstname</tt>
12
- # * <tt>:lastname</tt>
13
- # * <tt>:company</tt>
14
- def create(options ={})
14
+ # Returns a Hash with the new client info, or false if the client was not
15
+ # created successfully.
16
+ def create(options = {})
15
17
  perform_request(options.merge(action: 'client-create')) && returned_parameters
16
18
  end
17
19
 
18
- # Change client password for the solus admin.
20
+ # Public: Change client password for the Solus admin.
21
+ #
22
+ # username - The client's username
23
+ # new_password - The new password
24
+ #
25
+ # Returns true if the client's password was successfully changed.
19
26
  def change_password(username, new_password)
20
- perform_request({action: "client-updatepassword", username: username, password: new_password})
27
+ perform_request(action: "client-updatepassword", username: username, password: new_password)
21
28
  end
22
29
 
23
- # Checks wether a specific client exists.
30
+ # Public: Checks if a specific client exists.
31
+ #
32
+ # username - The client's username
33
+ #
34
+ # Returns true if the client exists.
24
35
  def exists?(username)
25
- perform_request({action: 'client-checkexists', username: username})
36
+ perform_request(action: 'client-checkexists', username: username)
37
+ !!statusmsg.match(/Client exists/i)
26
38
  end
27
39
 
28
- # Verify a clients login. Returns true when the specified login is correct.
40
+ # Public: Verify a client's login.
41
+ #
42
+ # username - The client's username
43
+ # password - The client's password
44
+ #
45
+ # Returns true if the given credentials are correct.
29
46
  def authenticate(username, password)
30
- perform_request({action: 'client-authenticate', username: username, password: password})
47
+ perform_request(action: 'client-authenticate', username: username, password: password)
31
48
  end
32
49
 
33
- # Deletes an existing client.
50
+ # Public: Deletes an existing client.
51
+ #
52
+ # username - The client's username
53
+ #
54
+ # Returns true if the client was successfully deleted.
34
55
  def delete(username)
35
- perform_request({action: "client-delete", username: username})
56
+ perform_request(action: "client-delete", username: username)
36
57
  end
37
58
 
38
- # Lists existing clients.
59
+ # Public: Lists existing clients.
60
+ #
61
+ # Returns an Array if clients were found, otherwise nil.
39
62
  def list
40
- perform_request({action: "client-list"}, "client")
41
-
42
- if returned_parameters["clients"] && returned_parameters["clients"]["client"]
43
- returned_parameters["clients"]["client"]
44
- elsif returned_parameters["clients"]
45
- []
46
- end
63
+ perform_request(action: "client-list")
64
+ returned_parameters["clients"]
47
65
  end
48
66
  end
49
67
  end
@@ -0,0 +1,3 @@
1
+ module SolusVM
2
+ class AuthenticationError < StandardError; end
3
+ end
@@ -1,12 +1,11 @@
1
- module Solusvm
2
- # Solusvm::General is the class for retrieving general information.
1
+ module SolusVM
2
+ # SolusVM::General is the class for retrieving general information.
3
3
  class General < Base
4
-
5
- # Lists available templates.
4
+ # Public: Lists available templates.
6
5
  #
7
- # Parameters:
6
+ # type - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
8
7
  #
9
- # * +type+ - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
8
+ # Returns an Array.
10
9
  def templates(type)
11
10
  validate_server_type(type) do
12
11
  perform_request(action: 'listtemplates', type: type)
@@ -14,11 +13,11 @@ module Solusvm
14
13
  end
15
14
  end
16
15
 
17
- # Lists available plans.
16
+ # Public: Lists available plans.
18
17
  #
19
- # Parameters:
18
+ # type - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
20
19
  #
21
- # * +type+ - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
20
+ # Returns an Array.
22
21
  def plans(type)
23
22
  validate_server_type(type) do
24
23
  perform_request(action: 'listplans', type: type)
@@ -26,11 +25,11 @@ module Solusvm
26
25
  end
27
26
  end
28
27
 
29
- # Lists available isos.
28
+ # Public: Lists available ISOS.
30
29
  #
31
- # Parameters:
30
+ # type - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
32
31
  #
33
- # * +type+ - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
32
+ # Returns an Array.
34
33
  def isos(type)
35
34
  validate_server_type(type) do
36
35
  perform_request(action: 'listiso', type: type)
@@ -1,14 +1,4 @@
1
1
  class Hash
2
- unless method_defined?(:to_query)
3
- def to_query
4
- elements = []
5
- self.each do |key, value|
6
- elements << "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"
7
- end
8
- elements.join('&')
9
- end
10
- end
11
-
12
2
  unless method_defined?(:reverse_merge)
13
3
  def reverse_merge(other_hash)
14
4
  other_hash.merge(self)
@@ -20,4 +10,4 @@ class Hash
20
10
  replace(reverse_merge(other_hash))
21
11
  end
22
12
  end
23
- end
13
+ end
@@ -1,12 +1,11 @@
1
- module Solusvm
2
- # Solusvm::Node is the class for working with nodes.
1
+ module SolusVM
2
+ # SolusVM::Node is the class for working with nodes.
3
3
  class Node < Base
4
-
5
- # Lists existing nodes of a given type.
4
+ # Public: Lists existing nodes of a given type.
6
5
  #
7
- # Parameters:
6
+ # type - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
8
7
  #
9
- # * +type+ - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
8
+ # Returns an Array.
10
9
  def list(type)
11
10
  validate_server_type(type) do
12
11
  perform_request(action: 'listnodes', type: type)
@@ -14,7 +13,9 @@ module Solusvm
14
13
  end
15
14
  end
16
15
 
17
- # Lists existing node groups
16
+ # Public: Lists existing node groups
17
+ #
18
+ # Returns an Array.
18
19
  def list_groups
19
20
  perform_request(action: 'listnodegroups')
20
21
 
@@ -22,11 +23,11 @@ module Solusvm
22
23
  returned_parameters['nodegroups'].to_s.split(',').map {|group| group.split('|')[1]}
23
24
  end
24
25
 
25
- # Lists existing nodes ids of a given type.
26
+ # Public: Lists existing nodes ids of a given type.
26
27
  #
27
- # Parameters:
28
+ # type - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
28
29
  #
29
- # * +type+ - a valid virtualization type; e.g: [openvz|xen|xen hvm|kvm]
30
+ # Returns an Array.
30
31
  def ids(type)
31
32
  validate_server_type(type) do
32
33
  perform_request(action: 'node-idlist', type: type)
@@ -34,19 +35,31 @@ module Solusvm
34
35
  end
35
36
  end
36
37
 
37
- # Retrieves statistics from a specific node.
38
+ # Public: Retrieves statistics from a specific node.
39
+ #
40
+ # nodeid - The node ID
41
+ #
42
+ # Returns a Hash.
38
43
  def statistics(nodeid)
39
44
  perform_request(action: 'node-statistics', nodeid: nodeid)
40
45
  returned_parameters
41
46
  end
42
47
 
43
48
  # Retrieves available xen resources from a specific node.
49
+ #
50
+ # nodeid - The node ID
51
+ #
52
+ # Returns a Hash.
44
53
  def xenresources(nodeid)
45
54
  perform_request(action: 'node-xenresources', nodeid: nodeid)
46
55
  returned_parameters
47
56
  end
48
57
 
49
- # Retrieves a list of available IPs for a specific node.
58
+ # Public: Retrieves a list of available IPs for a specific node.
59
+ #
60
+ # nodeid - The node ID
61
+ #
62
+ # Returns an Array.
50
63
  def available_ips(nodeid)
51
64
  perform_request(action: 'node-iplist', nodeid: nodeid)
52
65
  if statusmsg.match /no available ip/i
@@ -56,15 +69,14 @@ module Solusvm
56
69
  end
57
70
  end
58
71
 
59
- # Lists virtual servers from a specific node.
72
+ # Public: Lists virtual servers from a specific node.
73
+ #
74
+ # nodeid - The node ID
75
+ #
76
+ # Returns an Array if virtual servers were found, otherwise nil.
60
77
  def virtualservers(nodeid)
61
- perform_request({action: "node-virtualservers", nodeid: nodeid}, "virtualserver")
62
-
63
- if returned_parameters["virtualservers"] && returned_parameters["virtualservers"]["virtualserver"]
64
- returned_parameters["virtualservers"]["virtualserver"]
65
- elsif returned_parameters["virtualservers"]
66
- []
67
- end
78
+ perform_request(action: "node-virtualservers", nodeid: nodeid)
79
+ returned_parameters["virtualservers"]
68
80
  end
69
81
  end
70
- end
82
+ end
@@ -1,72 +1,76 @@
1
- module Solusvm
1
+ module SolusVM
2
+ # SolusVM::Server is the class for working with reseller accounts.
2
3
  class Reseller < Base
3
-
4
- # Creates a reseller.
4
+ # Public: Creates a reseller.
5
5
  #
6
- # Options:
6
+ # options - A Hash of options:
7
+ # :username
8
+ # :password
9
+ # :email
10
+ # :firstname
11
+ # :lastname
12
+ # :company - (optional)
13
+ # :usernameprefix - prefix for reseller client usernames (optional)
14
+ # :maxvps - maximum amount of virtual servers (optional)
15
+ # :maxusers - maximum amount of users (optional)
16
+ # :maxmem - maximum amount memory (optional)
17
+ # :maxburst - maximum amount of burst memory or swapspace
18
+ # (optional)
19
+ # :maxdisk - maximum amount of diskspace (optional)
20
+ # :maxbw - maximum amount of bandwidth (optional)
21
+ # :maxipv4 - maximum amount of ipv4 addresses (optional)
22
+ # :maxipv6 - maximum amount of ipv6 addresses (optional)
23
+ # :nodegroups - comma separated list of node groups (optional)
24
+ # :mediagroups - comma separated list of media groups
25
+ # (optional)
26
+ # :openvz - y|n Allow building of openvz virtual servers
27
+ # (optional)
28
+ # :xenpv - y|n Allow building of xen pv virtual servers
29
+ # (optional)
30
+ # :xenhvm - y|n Allow building of xen hvm virtual servers
31
+ # (optional)
32
+ # :kvm - y|n Allow building of kvmvirtual servers
33
+ # (optional)
7
34
  #
8
- # * <tt>:username</tt>
9
- # * <tt>:password</tt>
10
- # * <tt>:email</tt>
11
- # * <tt>:firstname</tt>
12
- # * <tt>:lastname</tt>
13
- # * <tt>:company</tt> - (optional)
14
- # * <tt>:usernameprefix</tt> - prefix for reseller client usernames (optional)
15
- # * <tt>:maxvps</tt> - maximum amount of virtual servers (optional)
16
- # * <tt>:maxusers</tt> - maximum amount of users (optional)
17
- # * <tt>:maxmem</tt> - maximum amount memory - (optional)
18
- # * <tt>:maxburst</tt> - maximum amount of burst memory or swapspace (optional)
19
- # * <tt>:maxdisk</tt> - maximum amount of diskspace (optional)
20
- # * <tt>:maxbw</tt> - maximum amount of bandwidth (optional)
21
- # * <tt>:maxipv4</tt> - maximum amount of ipv4 addresses (optional)
22
- # * <tt>:maxipv6</tt> - maximum amount of ipv6 addresses (optional)
23
- # * <tt>:nodegroups</tt> - comma seperated list of node groups (optional)
24
- # * <tt>:mediagroups</tt> - comma seperated list of media groups (optional)
25
- # * <tt>:openvz</tt> - y|n Allow building of openvz virtual servers (optional)
26
- # * <tt>:xenpv</tt> - y|n Allow building of xen pv virtual servers (optional)
27
- # * <tt>:xenhvm</tt> - y|n Allow building of xen hvm virtual servers (optional)
28
- # * <tt>:kvm</tt> - y|n Allow building of kvmvirtual servers (optional)
29
- def create(options ={})
35
+ # Returns a Hash with the new client info, or false if the client was not
36
+ # created successfully.
37
+ def create(options = {})
30
38
  perform_request(options.merge(action: 'reseller-create')) && returned_parameters
31
39
  end
32
40
 
33
41
  # Changes the available resources for a specific reseller.
34
42
  #
35
- # Options:
43
+ # options - A Hash of options, see `#create` for details
36
44
  #
37
- # * <tt>:maxvps</tt> - maximum amount of virtual servers (optional)
38
- # * <tt>:maxusers</tt> - maximum amount of users (optional)
39
- # * <tt>:maxmem</tt> - maximum amount memory - (optional)
40
- # * <tt>:maxburst</tt> - maximum amount of burst memory or swapspace (optional)
41
- # * <tt>:maxdisk</tt> - maximum amount of diskspace (optional)
42
- # * <tt>:maxbw</tt> - maximum amount of bandwidth (optional)
43
- # * <tt>:maxipv4</tt> - maximum amount of ipv4 addresses (optional)
44
- # * <tt>:maxipv6</tt> - maximum amount of ipv6 addresses (optional)
45
- # * <tt>:nodegroups</tt> - comma seperated list of node groups (optional)
46
- # * <tt>:mediagroups</tt> - comma seperated list of media groups (optional)
47
- # * <tt>:openvz</tt> - y|n Allow building of openvz virtual servers (optional)
48
- # * <tt>:xenpv</tt> - y|n Allow building of xen pv virtual servers (optional)
49
- # * <tt>:xenhvm</tt> - y|n Allow building of xen hvm virtual servers (optional)
50
- # * <tt>:kvm</tt> - y|n Allow building of kvmvirtual servers (optional)
51
- def change_resources(username, options={})
45
+ # Returns a Hash with the new reseller info, or false if the reseller was
46
+ # not created successfully.
47
+ def change_resources(username, options = {})
52
48
  perform_request(options.merge(action: 'reseller-modifyresources', username: username)) && returned_parameters
53
49
  end
54
50
 
55
- # Retrieves information from an existing reseller.
51
+ # Public: Retrieves information from an existing reseller.
52
+ #
53
+ # username - The reseller's username
54
+ #
55
+ # Returns a Hash with the reseller info, or false if the reseller was not
56
+ # found.
56
57
  def info(username)
57
- perform_request({action: 'reseller-info', username: username}) && returned_parameters
58
+ perform_request(action: 'reseller-info', username: username) && returned_parameters
58
59
  end
59
60
 
60
- # Deletes an existing reseller.
61
+ # Public: Deletes an existing reseller.
62
+ #
63
+ # Returns true if the reseller was deleted.
61
64
  def delete(username)
62
- perform_request({action: 'reseller-delete', username: username})
65
+ perform_request(action: 'reseller-delete', username: username)
63
66
  end
64
67
 
65
- # Lists existing resellers.
68
+ # Public: Lists existing resellers.
69
+ #
70
+ # Returns an Array.
66
71
  def list
67
72
  perform_request(action: 'reseller-list')
68
73
  parse_returned_params_as_list('usernames')
69
74
  end
70
-
71
75
  end
72
- end
76
+ end