solusvm 0.10.1 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/README.markdown +75 -25
  2. data/bin/solusvm +3 -153
  3. data/lib/solusvm/base.rb +17 -10
  4. data/lib/solusvm/cli/base_cli.rb +47 -0
  5. data/lib/solusvm/cli/client_cli.rb +49 -0
  6. data/lib/solusvm/cli/general_cli.rb +28 -0
  7. data/lib/solusvm/cli/node_cli.rb +43 -0
  8. data/lib/solusvm/cli/reseller_cli.rb +73 -0
  9. data/lib/solusvm/cli/server_cli.rb +168 -0
  10. data/lib/solusvm/cli.rb +22 -0
  11. data/lib/solusvm/client.rb +26 -12
  12. data/lib/solusvm/general.rb +25 -17
  13. data/lib/solusvm/node.rb +60 -0
  14. data/lib/solusvm/reseller.rb +72 -0
  15. data/lib/solusvm/server.rb +116 -2
  16. data/lib/solusvm/version.rb +1 -1
  17. data/lib/solusvm.rb +8 -8
  18. data/solusvm.gemspec +3 -0
  19. data/test/cli/test_client_cli.rb +80 -0
  20. data/test/cli/test_general_cli.rb +35 -0
  21. data/test/cli/test_node_cli.rb +64 -0
  22. data/test/cli/test_reseller_cli.rb +139 -0
  23. data/test/cli/test_server_cli.rb +267 -0
  24. data/test/fixtures/client_delete_success.txt +2 -0
  25. data/test/fixtures/client_list_success.txt +14 -0
  26. data/test/fixtures/client_list_success_empty.txt +2 -0
  27. data/test/fixtures/general_isos_success.txt +3 -0
  28. data/test/fixtures/general_node_virtualservers_success.txt +15 -0
  29. data/test/fixtures/general_node_virtualservers_success_empty.txt +2 -0
  30. data/test/fixtures/general_node_xenresources_success.txt +4 -0
  31. data/test/fixtures/general_nodes_ids_success.txt +3 -0
  32. data/test/fixtures/general_plans_success.txt +3 -0
  33. data/test/fixtures/reseller_change_resources_success.txt +16 -0
  34. data/test/fixtures/reseller_create_success.txt +23 -0
  35. data/test/fixtures/reseller_delete_success.txt +2 -0
  36. data/test/fixtures/reseller_info_success.txt +23 -0
  37. data/test/fixtures/reseller_list_success.txt +3 -0
  38. data/test/fixtures/server_bootorder_success.txt +2 -0
  39. data/test/fixtures/server_change_consolepass_success.txt +3 -0
  40. data/test/fixtures/server_change_owner_success.txt +2 -0
  41. data/test/fixtures/server_change_vncpass_success.txt +3 -0
  42. data/test/fixtures/server_console_success.txt +7 -0
  43. data/test/fixtures/server_hostname_success.txt +3 -0
  44. data/test/fixtures/server_mountiso_success.txt +2 -0
  45. data/test/fixtures/server_network_disable_success.txt +2 -0
  46. data/test/fixtures/server_network_enable_success.txt +2 -0
  47. data/test/fixtures/server_pae_success.txt +2 -0
  48. data/test/fixtures/server_rootpassword_success.txt +3 -0
  49. data/test/fixtures/server_status_success.txt +2 -0
  50. data/test/fixtures/server_tun_disable_success.txt +2 -0
  51. data/test/fixtures/server_tun_enable_success.txt +2 -0
  52. data/test/fixtures/server_unmountiso_success.txt +2 -0
  53. data/test/fixtures/server_vnc_success.txt +6 -0
  54. data/test/helper.rb +6 -0
  55. data/test/test_cli.rb +17 -0
  56. data/test/test_client.rb +50 -6
  57. data/test/test_general.rb +24 -48
  58. data/test/test_node.rb +107 -0
  59. data/test/test_reseller.rb +75 -0
  60. data/test/test_server.rb +95 -1
  61. metadata +132 -17
data/README.markdown CHANGED
@@ -41,31 +41,81 @@ Server creation
41
41
  Command Line Usage
42
42
  ------------------
43
43
 
44
- USAGE: solusvm <command> [options]
45
- -I, --api-login [id] API ID
46
- -K, --api-key [key] API KEY
47
- -N, --node [node] Node to provision on
48
- -U, --api-url [URL] URL to the API
49
- -u, --username [username] The client to put the VPS under
50
- -k, --kind [kind] Type of VPS (openvz,xen,xen hvm)
51
- -t, --template [template] VPS template to boot from
52
- -p, --plan [plan] Plan to use
53
- -i, --ips [number] Number of ips to add to the VPS
54
- -h, --help Show help documentation
55
- Commands:
56
- node-available-ips <nodeid>
57
- server-check-exists <vserverid>
58
- server-shutdown <vserverid>
59
- server-terminate <vserverid>
60
- server-changeplan <vserverid> <newplan>
61
- server-resume <vserverid>
62
- server-reboot <vserverid>
63
- server-rebuild <vserverid> -t myimage
64
- server-status <vserverid>
65
- server-boot <vserverid>
66
- server-create <hostname> <password> -t myimage -k xen -p myplan -i 1
67
- server-suspend <vserverid>
68
- server-addip <vserverid>
44
+ Tasks:
45
+ solusvm client <command> # Client commands
46
+ solusvm general <command> # General commands
47
+ solusvm help [TASK] # Describe available tasks or one specific task
48
+ solusvm node <command> # Node commands
49
+ solusvm reseller <command> # Reseller commands
50
+ solusvm server <command> # Server commands
51
+ solusvm version # Outputs the current program version
52
+
53
+ solusvm client authenticate USERNAME NEWPASSWORD # Verify a clients login. Returns true when the specified login is correct
54
+ solusvm client change-password USERNAME NEWPASSWORD # Changes the password of an existing client
55
+ solusvm client check-exists USERNAME # Checks if a client exists
56
+ solusvm client create # Creates a new client
57
+ solusvm client delete USERNAME # Deletes an existing client
58
+ solusvm client help [COMMAND] # Describe subcommands or one specific subcommand
59
+ solusvm client list # Lists existing clients
60
+
61
+ solusvm general help [COMMAND] # Describe subcommands or one specific subcommand
62
+ solusvm general isos TYPE # Lists existing isos for a given type [openvz|xen|xen hvm|kvm]
63
+ solusvm general plans TYPE # Lists existing plans for a given type [openvz|xen|xen hvm|kvm]
64
+ solusvm general templates TYPE # Lists existing templates for a given type [openvz|xen|xen hvm|kvm]
65
+
66
+ solusvm node available-ips VSERVERID # Lists the available ips for a given node
67
+ solusvm node help [COMMAND] # Describe subcommands or one specific subcommand
68
+ solusvm node list TYPE # Lists existing nodes for a given type [openvz|xen|xen hvm|kvm]
69
+ solusvm node list-ids TYPE # Lists existing nodes ids for a given type [openvz|xen|xen hvm|kvm]
70
+ solusvm node stats VSERVERID # Lists statistics for a given node
71
+ solusvm node virtualservers VSERVERID # Lists the virtual servers for a given node
72
+ solusvm node xenresources VSERVERID # Lists xen resources for a given node
73
+
74
+ solusvm reseller change # Changes the available resources of a reseller
75
+ solusvm reseller create # Creates a new reseller
76
+ solusvm reseller delete USERNAME # Deletes an existing reseller
77
+ solusvm reseller help [COMMAND] # Describe subcommands or one specific subcommand
78
+ solusvm reseller info USERNAME # Retrieves information from an existing reseller
79
+ solusvm reseller list # Lists existing resellers
80
+
81
+ solusvm server addip VSERVERID # Adds an ip to the server
82
+ solusvm server boot VSERVERID # Boots up a server
83
+ solusvm server change-bootorder VSERVERID BOOTORDER # Changes the boot order of a server [cd(Hard Disk CDROM)|dc(CDROM Hard Disk)|c(Hard Di...
84
+ solusvm server change-consolepass VSERVERID NEWPASSWORD # Changes the console password of a server
85
+ solusvm server change-hostname VSERVERID HOSTNAME # Changes the hostname of a server
86
+ solusvm server change-owner VSERVERID CLIENTID # Changes the owner of a server
87
+ solusvm server change-plan VSERVERID NEWPLAN # Changes the plan of a server
88
+ solusvm server change-rootpass VSERVERID NEWPASSWORD # Changes the root password of a server
89
+ solusvm server change-vncpass VSERVERID NEWPASSWORD # Changes the vnc password of a server
90
+ solusvm server check-exists VSERVERID # Checks if a server exists
91
+ solusvm server console VSERVERID # Retrieves console information from a server
92
+ solusvm server create HOSTNAME PASSWORD # Creates a new server
93
+ solusvm server help [COMMAND] # Describe subcommands or one specific subcommand
94
+ solusvm server info VSERVERID # Retrieves information from a server
95
+ solusvm server info-all VSERVERID # Retrieves all availavle information from a server
96
+ solusvm server mountiso VSERVERID ISO # Mounts an iso
97
+ solusvm server network-switcher VSERVERID SWITCH(on|off) # Enable/Disable Network mode
98
+ solusvm server pae-switcher VSERVERID SWITCH(on|off) # Enable/Disable PAE
99
+ solusvm server reboot VSERVERID # Reboots a server
100
+ solusvm server rebuild VSERVERID # Rebuilds a server
101
+ solusvm server resume VSERVERID # Resumes a server
102
+ solusvm server shutdown VSERVERID # Shuts down a server
103
+ solusvm server status VSERVERID # Checks the status of a server
104
+ solusvm server suspend VSERVERID # Suspends a server
105
+ solusvm server terminate VSERVERID # Terminates a server
106
+ solusvm server tun-switcher VSERVERID SWITCH(on|off) # Enable/Disable TUN/TAP
107
+ solusvm server unmountiso VSERVERID # Unmounts an iso
108
+ solusvm server vnc VSERVERID # Retrieves vnc information from a server
109
+
110
+ Options:
111
+ -I, --api-login, [--api-login=API_LOGIN] # API ID. Required.
112
+ -K, --api-key, [--api-key=API_KEY] # API KEY. Required.
113
+ -U, --api-url, [--api-url=API_URL] # API URL. Required.
114
+
115
+
116
+ To check the available options for a given action, you can execute the following command:
117
+
118
+ solusvm server help create
69
119
 
70
120
  Default Config for Command Line
71
121
  --------------------------------
data/bin/solusvm CHANGED
@@ -1,158 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "optparse"
4
- require "pp"
5
- require "yaml"
6
-
7
3
  $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
8
- require "solusvm"
9
-
10
- opts = {}
11
- $shell_methods = {}
12
- $shell_methods['server-create'] = "<hostname> <password> -t myimage -k xen -p myplan -i 1"
13
- $shell_methods['server-boot'] = "<vserverid>"
14
- $shell_methods['server-reboot'] = "<vserverid>"
15
- $shell_methods['server-shutdown'] = "<vserverid>"
16
- $shell_methods['server-suspend'] = "<vserverid>"
17
- $shell_methods['server-resume'] = "<vserverid>"
18
- $shell_methods['server-status'] = "<vserverid>"
19
- $shell_methods['server-addip'] = "<vserverid>"
20
- $shell_methods['server-changeplan'] = "<vserverid> <newplan>"
21
- $shell_methods['server-check-exists'] = "<vserverid>"
22
- $shell_methods['server-terminate'] = "<vserverid>"
23
- $shell_methods['node-stats'] = "<nodeid>"
24
- $shell_methods['node-available-ips'] = "<nodeid>"
25
- $shell_methods['server-rebuild'] = "<vserverid> -t myimage"
26
-
27
- def list_commands
28
- puts "Commands:"
29
- puts $shell_methods.collect { |k,v| " #{k} #{v}"}.join("\n")
30
- exit
31
- end
32
-
33
- op = OptionParser.new do |o|
34
- o.banner = "USAGE: #{File.basename($0)} <command> [options]"
35
- o.on("-I", "--api-login [id]", "API ID") do |opt|
36
- opts[:api_id] = opt
37
- end
38
-
39
- o.on("-K", "--api-key [key]", "API KEY") do |opt|
40
- opts[:api_key] = opt
41
- end
42
-
43
- o.on("-N", "--node [node]", "Node to provision on") do |opt|
44
- opts[:node] = opt
45
- end
46
-
47
- o.on("-U", "--api-url [URL]", "URL to the API") do |opt|
48
- opts[:api_url] = opt
49
- end
50
-
51
- o.on("-u", "--username [username]", "The client to put the VPS under") do |opt|
52
- opts[:username] = opt
53
- end
54
-
55
- o.on("-k", "--kind [kind]", "Type of VPS (#{Solusvm::Server::VALID_SERVER_TYPES.join(',')})") do |opt|
56
- opts[:kind] = opt
57
- end
58
-
59
- o.on("-t", "--template [template]", "VPS template to boot from") do |opt|
60
- opts[:template] = opt
61
- end
62
-
63
- o.on("-p", "--plan [plan]", "Plan to use") do |opt|
64
- opts[:plan] = opt
65
- end
66
-
67
- o.on("-i", "--ips [number]", "Number of ips to add to the VPS") do |opt|
68
- opts[:ips] = opt.to_i
69
- end
70
-
71
- o.on("-h", "--help", "Show help documentation") do |h|
72
- puts o
73
- list_commands
74
- end
75
- end
76
-
77
- optparse = op
78
- op.parse!
79
4
 
80
- config_file = File.join(File.expand_path(ENV['HOME']), '.solusvm.yml')
81
- server = Solusvm::Server.new
82
- general = Solusvm::General.new
5
+ require "thor"
6
+ require "solusvm/cli"
83
7
 
84
- if ARGV.empty?
85
- # STDERR.puts "USAGE: #{File.basename($0)} [function] [options]"
86
- puts optparse.help
87
- list_commands
88
- else
89
- if File.exists?(config_file)
90
- config = YAML::load(File.open(config_file))
91
- Solusvm.config(config['id'], config['key'], :url => config['url'])
92
- opts[:username] = config['username'] unless opts[:username]
93
- elsif opts[:api_url] && opts[:api_id] && opts[:api_key]
94
- Solusvm.config(opts[:api_id], opts[:api_key], :url => opts[:api_url])
95
- else
96
- puts "Must supply the api id/key and URL"
97
- exit
98
- end
99
- meth = ARGV[0].chomp
100
- if $shell_methods.include?(meth)
101
- ARGV.shift
102
- if ARGV.empty?
103
- p $shell_methods[meth]
104
- exit
105
- else
106
- begin
107
- case meth
108
- when 'server-create'
109
- unless ARGV.size == 2
110
- list_commands
111
- end
112
- p server.create(ARGV[0], ARGV[1], :plan => opts[:plan], :ips => opts[:ips], :type => opts[:kind],
113
- :username => opts[:username], :template => opts[:template], :node => opts[:node])
114
- when 'server-status'
115
- p server.status(ARGV[0])
116
- when 'server-changeplan'
117
- p server.change_plan(ARGV[0], ARGV[1])
118
- when 'server-addip'
119
- p server.add_ip(ARGV[0])
120
- when 'server-boot'
121
- p server.boot(ARGV[0])
122
- when 'server-reboot'
123
- p server.reboot(ARGV[0])
124
- when 'server-shutdown'
125
- p server.shutdown(ARGV[0])
126
- when 'server-suspend'
127
- p server.suspend(ARGV[0])
128
- when 'server-resume'
129
- p server.resume(ARGV[0])
130
- when 'server-check-exists'
131
- p server.exists?(ARGV[0])
132
- when 'server-terminate'
133
- p server.terminate(ARGV[0])
134
- when 'node-available-ips'
135
- ips = general.node_available_ips(ARGV[0])
136
- if ips.any?
137
- puts ips.join("\n")
138
- else
139
- puts ips
140
- end
141
- when 'node-stats'
142
- stats = general.node_statistics(ARGV[0])
143
- stats.each do |k,v|
144
- puts "#{k} => #{v}"
145
- end
146
- when 'server-rebuild'
147
- p server.rebuild(ARGV[0], opts[:template])
148
- end
149
- rescue Exception => e
150
- puts "Error: #{e}\n\n"
151
- puts "Backtrace: \n\n"
152
- puts e.backtrace.join("\n")
153
- end
154
- end
155
- else
156
- puts "#{meth} is not a valid function"
157
- end
158
- end
8
+ Solusvm::Cli.start
data/lib/solusvm/base.rb CHANGED
@@ -6,16 +6,18 @@ module Solusvm
6
6
 
7
7
  # Prepares and sends the API request to the URL specificed in Solusvm.config
8
8
  #
9
- #
10
9
  # class MyClass < Base
11
10
  # def create_server(name)
12
11
  # perform_request(:action => 'name', :id => 1)
13
12
  # end
14
13
  # end
14
+ #
15
15
  # Options:
16
16
  # * <tt>:action</tt> - Specifies which API method to execute
17
17
  # All other options passed in are converted to http query arguments and are passed along to the API
18
- def perform_request(options = {})
18
+ #
19
+ # <tt>force_array</tt> - see parse_response
20
+ def perform_request(options = {}, force_array = false)
19
21
  options.merge!(api_login)
20
22
  http = Net::HTTP.new(api_endpoint.host, api_endpoint.port)
21
23
  if api_endpoint.port == 443
@@ -27,16 +29,20 @@ module Solusvm
27
29
  response = http.request(request)
28
30
 
29
31
  handle_errors(response.body)
30
- @returned_parameters = parse_response(response.body)
32
+ @returned_parameters = parse_response(response.body, force_array)
31
33
  log_messages(options)
32
34
  end
33
35
  successful?
34
36
  end
35
37
 
36
38
  # Converts the XML response to a Hash
37
- def parse_response(body)
39
+ #
40
+ # <tt>force_array</tt> - Parses the xml element as an array; can be a string with the element name
41
+ # or an array with element names
42
+ def parse_response(body, force_array = false)
43
+ force_array = Array(force_array) if force_array
38
44
  body = "<solusrequest>#{body}</solusrequest>"
39
- XmlSimple.xml_in(body, 'ForceArray' => false)
45
+ XmlSimple.xml_in(body, 'ForceArray' => force_array)
40
46
  end
41
47
 
42
48
  # Look for known error messages
@@ -69,14 +75,15 @@ module Solusvm
69
75
  {:id => Solusvm.api_id, :key => Solusvm.api_key}
70
76
  end
71
77
 
72
- # TODO: clean this up
73
78
  def log_messages(options)
74
- if Solusvm.api_options[:logger] && Solusvm.api_options[:logger].respond_to?(Solusvm.api_options[:logger_method])
75
- Solusvm.api_options[:logger].send(Solusvm.api_options[:logger_method], "[Start] => #{options[:action]}")
79
+ logger, logger_method = Solusvm.api_options[:logger], Solusvm.api_options[:logger_method]
80
+
81
+ if logger && logger.respond_to?(logger_method)
82
+ logger.send(logger_method, "[Start] => #{options[:action]}")
76
83
  returned_parameters.each do |k,v|
77
- Solusvm.api_options[:logger].send(Solusvm.api_options[:logger_method], " #{k} => #{v}")
84
+ logger.send(logger_method, " #{k} => #{v}")
78
85
  end
79
- Solusvm.api_options[:logger].send(Solusvm.api_options[:logger_method], "[End] => #{options[:action]}")
86
+ logger.send(logger_method, "[End] => #{options[:action]}")
80
87
  end
81
88
  end
82
89
 
@@ -0,0 +1,47 @@
1
+ require 'yaml'
2
+ require 'thor'
3
+ require 'thor/group'
4
+ require 'solusvm/version'
5
+
6
+ module Solusvm
7
+ class BaseCli < Thor
8
+ include Thor::Actions
9
+
10
+ # Retrieves default options coming from a configuration file, if any.
11
+ def self.default_option(key)
12
+ @@yaml ||= begin
13
+ file = File.join(File.expand_path(ENV['HOME']), '.solusvm.yml')
14
+ if File.exists?(file)
15
+ YAML::load(File.open(file))
16
+ else
17
+ {}
18
+ end
19
+ end
20
+
21
+ @@yaml[key.to_s]
22
+ end
23
+
24
+ # Convenience method to get the namespace from the class name. It's the
25
+ # same as Thor default except that the "_cli" at the end of the class
26
+ # is removed.
27
+ def self.namespace(name=nil)
28
+ return super if name
29
+ @namespace ||= super.sub(/_cli$/, '')
30
+ end
31
+
32
+ class_option :api_login, :type => :string, :desc => "API ID; Required.", :aliases => ["-I", "--api-login"], :default => default_option(:id)
33
+ class_option :api_key, :type => :string, :desc => "API KEY; Required.", :aliases => ["-K", "--api-key"], :default => default_option(:key)
34
+ class_option :api_url, :type => :string, :desc => "API URL; Required.", :aliases => ["-U", "--api-url"], :default => default_option(:url)
35
+
36
+ # Overrides the default banner implementation to output the whole command
37
+ def self.banner(task, namespace = true, subcommand = false)
38
+ "#{self.namespace.split(":").join(" ")} #{task.formatted_usage(self, false, false)}"
39
+ end
40
+
41
+ protected
42
+
43
+ def configure
44
+ Solusvm.config(options[:api_login], options[:api_key], :url => options[:api_url])
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ module Solusvm
2
+ class ClientCli < BaseCli
3
+
4
+ desc "create", "Creates a new client"
5
+ method_option :username, :type => :string, :desc => "Username", :aliases => ["-u", "--username"]
6
+ method_option :password, :type => :string, :desc => "Password", :aliases => ["-p", "--password"]
7
+ method_option :email, :type => :string, :desc => "Email", :aliases => ["-e", "--email"]
8
+ method_option :firstname, :type => :string, :desc => "Firstname", :aliases => ["-f", "--firstname"]
9
+ method_option :lastname, :type => :string, :desc => "Lastname", :aliases => ["-l", "--lastname"]
10
+ method_option :company, :type => :string, :desc => "Company", :aliases => ["-c", "--company"]
11
+ def create
12
+ say client.create(options)
13
+ end
14
+
15
+ desc "change-password USERNAME NEWPASSWORD", "Changes the password of an existing client"
16
+ def change_password(username, password)
17
+ say client.change_password(username, password)
18
+ end
19
+
20
+ desc "authenticate USERNAME NEWPASSWORD", "Verify a clients login. Returns true when the specified login is correct"
21
+ def authenticate(username, password)
22
+ say client.authenticate(username, password)
23
+ end
24
+
25
+ desc "check-exists USERNAME", "Checks if a client exists"
26
+ def check_exists(username)
27
+ say client.exists?(username)
28
+ end
29
+
30
+ desc "delete USERNAME", "Deletes an existing client"
31
+ def delete(username)
32
+ say client.delete(username)
33
+ end
34
+
35
+ desc "list", "Lists existing clients"
36
+ def list
37
+ say client.list
38
+ end
39
+
40
+ private
41
+
42
+ def client
43
+ @client ||= begin
44
+ configure
45
+ Solusvm::Client.new
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ module Solusvm
2
+ class GeneralCli < BaseCli
3
+
4
+ desc "templates TYPE", "Lists existing templates for a given type [openvz|xen|xen hvm|kvm]"
5
+ def templates(type)
6
+ say general.templates(type)
7
+ end
8
+
9
+ desc "plans TYPE", "Lists existing plans for a given type [openvz|xen|xen hvm|kvm]"
10
+ def plans(type)
11
+ say general.plans(type)
12
+ end
13
+
14
+ desc "isos TYPE", "Lists existing isos for a given type [openvz|xen|xen hvm|kvm]"
15
+ def isos(type)
16
+ say general.isos(type)
17
+ end
18
+
19
+ private
20
+
21
+ def general
22
+ @general ||= begin
23
+ configure
24
+ Solusvm::General.new
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,43 @@
1
+ module Solusvm
2
+ class NodeCli < BaseCli
3
+
4
+ desc "list TYPE", "Lists existing nodes for a given type [openvz|xen|xen hvm|kvm]"
5
+ def list(type)
6
+ say node.list(type)
7
+ end
8
+
9
+ desc "list-ids TYPE", "Lists existing nodes ids for a given type [openvz|xen|xen hvm|kvm]"
10
+ def list_ids(type)
11
+ say node.ids(type)
12
+ end
13
+
14
+ desc "available-ips VSERVERID", "Lists the available ips for a given node"
15
+ def available_ips(vserverid)
16
+ say node.available_ips(vserverid).join("\n")
17
+ end
18
+
19
+ desc "stats VSERVERID", "Lists statistics for a given node"
20
+ def stats(vserverid)
21
+ say node.statistics(vserverid).map{|k, v| "#{k} => #{v}" }.join("\n")
22
+ end
23
+
24
+ desc "xenresources VSERVERID", "Lists xen resources for a given node"
25
+ def xenresources(vserverid)
26
+ say node.xenresources(vserverid).map{|k, v| "#{k} => #{v}" }.join("\n")
27
+ end
28
+
29
+ desc "virtualservers VSERVERID", "Lists the virtual servers for a given node"
30
+ def virtualservers(vserverid)
31
+ say node.virtualservers(vserverid)
32
+ end
33
+
34
+ private
35
+
36
+ def node
37
+ @node ||= begin
38
+ configure
39
+ Solusvm::Node.new
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,73 @@
1
+ module Solusvm
2
+ class ResellerCli < BaseCli
3
+
4
+ desc "create", "Creates a new reseller"
5
+ method_option :username, :type => :string, :desc => "Username", :aliases => ["-u", "--username"]
6
+ method_option :password, :type => :string, :desc => "Password", :aliases => ["-p", "--password"]
7
+ method_option :email, :type => :string, :desc => "Email", :aliases => ["-e", "--email"]
8
+ method_option :firstname, :type => :string, :desc => "Firstname", :aliases => ["-f", "--firstname"]
9
+ method_option :lastname, :type => :string, :desc => "Lastname", :aliases => ["-l", "--lastname"]
10
+ method_option :company, :type => :string, :desc => "Company", :aliases => ["-c", "--company"]
11
+ method_option :usernameprefix, :type => :string, :desc => "Prefix for reseller client usernames (optional)", :aliases => ["-up", "--usernameprefix"]
12
+ method_option :maxvps, :type => :string, :desc => "Maximum amount of virtual servers (optional)", :aliases => ["-mvps", "--maxvps"]
13
+ method_option :maxusers, :type => :string, :desc => "Maximum amount of users (optional)", :aliases => ["-mu", "--maxusers"]
14
+ method_option :maxmem, :type => :string, :desc => "Maximum amount of memory (optional)", :aliases => ["-mm", "--maxmem"]
15
+ method_option :maxburst, :type => :string, :desc => "Maximum amount of burst memory or swapspace (optional)", :aliases => ["-mb", "--maxburst"]
16
+ method_option :maxbw, :type => :string, :desc => "Maximum amount of bandwith (optional)", :aliases => ["-mb", "--maxbw"]
17
+ method_option :maxdisk, :type => :string, :desc => "Maximum amount of disk (optional)", :aliases => ["-mb", "--maxdisk"]
18
+ method_option :maxipv4, :type => :string, :desc => "Maximum amount of ipv4 addresses (optional)", :aliases => ["-mipv4", "--maxipv4"]
19
+ method_option :maxipv6, :type => :string, :desc => "Maximum amount of ipv6 addresses (optional)", :aliases => ["-mipv6", "--maxipv6"]
20
+ method_option :nodegroups, :type => :string, :desc => "Comma separated list of node groups (optional)", :aliases => ["-ng", "--nodegroups"]
21
+ method_option :mediagroups, :type => :string, :desc => "Comma separated list of media groups (optional)", :aliases => ["-mg", "--mediagroups"]
22
+ method_option :openvz, :type => :string, :desc => "y|n Allow building of openvz virtual servers (optional)", :aliases => ["-ovz", "--openvz"]
23
+ method_option :xenpv, :type => :string, :desc => "y|n Allow building of xen pv virtual servers (optional)", :aliases => ["-xpv", "--xenpv"]
24
+ method_option :xenhvm, :type => :string, :desc => "y|n Allow building of xen hvm virtual servers (optional)", :aliases => ["-xhvm", "--xenhvm"]
25
+ method_option :kvm, :type => :string, :desc => "y|n Allow building of kvmvirtual servers (optional)", :aliases => ["-kvm"]
26
+ def create
27
+ say reseller.create(options)
28
+ end
29
+
30
+ desc "change", "Changes the available resources of a reseller"
31
+ method_option :maxvps, :type => :string, :desc => "Maximum amount of virtual servers (optional)", :aliases => ["-mvps", "--maxvps"]
32
+ method_option :maxusers, :type => :string, :desc => "Maximum amount of users (optional)", :aliases => ["-mu", "--maxusers"]
33
+ method_option :maxmem, :type => :string, :desc => "Maximum amount of memory (optional)", :aliases => ["-mm", "--maxmem"]
34
+ method_option :maxburst, :type => :string, :desc => "Maximum amount of burst memory or swapspace (optional)", :aliases => ["-mb", "--maxburst"]
35
+ method_option :maxbw, :type => :string, :desc => "Maximum amount of bandwith (optional)", :aliases => ["-mb", "--maxbw"]
36
+ method_option :maxdisk, :type => :string, :desc => "Maximum amount of disk (optional)", :aliases => ["-mb", "--maxdisk"]
37
+ method_option :maxipv4, :type => :string, :desc => "Maximum amount of ipv4 addresses (optional)", :aliases => ["-mipv4", "--maxipv4"]
38
+ method_option :maxipv6, :type => :string, :desc => "Maximum amount of ipv6 addresses (optional)", :aliases => ["-mipv6", "--maxipv6"]
39
+ method_option :nodegroups, :type => :string, :desc => "Comma separated list of node groups (optional)", :aliases => ["-ng", "--nodegroups"]
40
+ method_option :mediagroups, :type => :string, :desc => "Comma separated list of media groups (optional)", :aliases => ["-mg", "--mediagroups"]
41
+ method_option :openvz, :type => :string, :desc => "y|n Allow building of openvz virtual servers (optional)", :aliases => ["-ovz", "--openvz"]
42
+ method_option :xenpv, :type => :string, :desc => "y|n Allow building of xen pv virtual servers (optional)", :aliases => ["-xpv", "--xenpv"]
43
+ method_option :xenhvm, :type => :string, :desc => "y|n Allow building of xen hvm virtual servers (optional)", :aliases => ["-xhvm", "--xenhvm"]
44
+ method_option :kvm, :type => :string, :desc => "y|n Allow building of kvmvirtual servers (optional)", :aliases => ["-kvm"]
45
+ def change_resources
46
+ say reseller.change_resources(options)
47
+ end
48
+
49
+ desc "info USERNAME", "Retrieves information from an existing reseller"
50
+ def info(username)
51
+ say reseller.info(username)
52
+ end
53
+
54
+ desc "delete USERNAME", "Deletes an existing reseller"
55
+ def delete(username)
56
+ say reseller.delete(username)
57
+ end
58
+
59
+ desc "list", "Lists existing resellers"
60
+ def list
61
+ say reseller.list
62
+ end
63
+
64
+ private
65
+
66
+ def reseller
67
+ @reseller ||= begin
68
+ configure
69
+ Solusvm::Reseller.new
70
+ end
71
+ end
72
+ end
73
+ end