solusvm 1.4.0 → 2.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c51edb4b2a1565f254f3764f713865e60c9f0b7
4
- data.tar.gz: d0940f9709bd079e7e68d7d95675e7a3c629a4c2
3
+ metadata.gz: db4b3b950573ce517e0c15de049ba58816bdab54
4
+ data.tar.gz: 31c21622c214c66e4f4f60c6af9560fa5e530f17
5
5
  SHA512:
6
- metadata.gz: 9ea7f18ed0eea58289cd486fe03d81b754d5a474bd75250d2fc8e8363ccd0b4d83909c41e5d497a9c2a5f93d550ef38512340b68e720bd4ad466a2df92a1c8e4
7
- data.tar.gz: dbb3c21df6def9db1cabee02f789978c3fa245b7d9f25782c84cacd79f085e407c494484fca18e66372f5225a5a71d1b6de620d7d7eb9122e8d40ba6e6aae7c8
6
+ metadata.gz: 6c1adec97375ad830ca77c3849c8840ccf1f293e353bd77678f500cf3eca001a9a33ee8c79b8c631a10b33fd66bc3478a204f77d9d18e119a9b4ed6063c6a345
7
+ data.tar.gz: 3e5701afdfa513977a781723997622070b5f44a6a02e69c3a8bcf19115297ad868480cad7360deb5f3553e8bcae029fff6c919721ae0deb3a648ee7ebfb750c6
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in lol.gemspec
4
3
  gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012 Site5.com <http://www.site5.com/>
1
+ Copyright (c) 2010-2014 Site5.com <http://www.site5.com/>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -4,167 +4,210 @@ SolusVM [![SolusVM Build Status][Build Icon]][Build Status]
4
4
  SolusVM allows for easy interaction with the [SolusVM Admin::API][].
5
5
  This library was first created for internal use at [Site5 LLC][].
6
6
 
7
- SolusVM has been tested on MRI 1.9.2, MRI 1.9.3 and 1.9-compatible JRuby.
7
+ SolusVM has been tested on MRI versions 1.9.2, 1.9.3, 2.0.0 and 1.9-compatible
8
+ JRuby.
9
+
10
+ Documentation is available in [TomDoc][] format.
8
11
 
9
12
  [Site5 LLC]: http://www.site5.com
10
- [SolusVM Admin::API]: http://wiki.solusvm.com/index.php/API:Admin
13
+ [SolusVM Admin::API]: http://docs.solusvm.com/v2/Default.htm#Developer/Admin-Api/Admin-Api.htm
11
14
  [Build Status]: http://travis-ci.org/site5/solusvm
12
15
  [Build Icon]: https://secure.travis-ci.org/site5/solusvm.png?branch=master
16
+ [TomDoc]: http://site5.github.io/solusvm/
13
17
 
14
18
  Basic Examples
15
19
  --------------
16
20
 
17
- server = Solusvm::Server.new(api_key: 'key', api_id: 'id', url: 'url')
21
+ ```ruby
22
+ server = SolusVM::Server.new(api_key: 'key', api_id: 'id', url: 'url')
18
23
 
19
- # 200 is the id of the virtual server
20
- server.shutdown(200) # => true
21
- server.boot(200) # => true
22
- server.reboot(200) # => true
23
- server.suspend(200) # => true
24
- server.resume(200) # => true
24
+ # 200 is the id of the virtual server
25
+ server.shutdown(200) # => true
26
+ server.boot(200) # => true
27
+ server.reboot(200) # => true
28
+ server.suspend(200) # => true
29
+ server.resume(200) # => true
30
+ ```
25
31
 
26
32
  Server creation
27
33
  ---------------
28
34
 
29
- options = {:type => 'xen', :username => 'bob', :node => 'node1', :plan => 'plan1', :template => 'mytpl', :ips => 1}
30
- result = sever.create('server.hostname.com', 'password', options}
31
- p server.successful?
32
- => true
35
+ ```ruby
36
+ options = {
37
+ type: 'xen',
38
+ username: 'bob',
39
+ node: 'node1',
40
+ plan: 'plan1',
41
+ template: 'mytpl',
42
+ ips: 1
43
+ }
44
+
45
+ result = sever.create('server.hostname.com', 'password', options}
46
+
47
+ p server.successful? #=> true
33
48
 
34
- p result
35
- => {"mainipaddress"=>"127.0.0.1", "consoleuser"=>"console-user", "vserverid"=>"10",
36
- "statusmsg"=>"Virtual server created", "virtid"=>"vm10", "consolepassword"=>"myPassisL33t",
37
- "extraipaddress"=>{}, "hostname"=>"server.hostname", "rootpassword"=>"password", "status"=>"success"}
49
+ p result
50
+ => {"mainipaddress"=>"127.0.0.1", "consoleuser"=>"console-user", "vserverid"=>"10",
51
+ "statusmsg"=>"Virtual server created", "virtid"=>"vm10", "consolepassword"=>"myPassisL33t",
52
+ "extraipaddress"=>{}, "hostname"=>"server.hostname", "rootpassword"=>"password", "status"=>"success"}
53
+ ```
38
54
 
39
55
  Command Line Usage
40
56
  ------------------
41
57
 
42
- Tasks:
43
- solusvm client <command> # Client commands
44
- solusvm general <command> # General commands
45
- solusvm help [TASK] # Describe available tasks or one specific task
46
- solusvm node <command> # Node commands
47
- solusvm reseller <command> # Reseller commands
48
- solusvm server <command> # Server commands
49
- solusvm version # Outputs the current program version
50
-
51
- solusvm client authenticate USERNAME NEWPASSWORD # Verify a clients login. Returns true when the specified login is correct
52
- solusvm client change-password USERNAME NEWPASSWORD # Changes the password of an existing client
53
- solusvm client check-exists USERNAME # Checks if a client exists
54
- solusvm client create # Creates a new client
55
- solusvm client delete USERNAME # Deletes an existing client
56
- solusvm client help [COMMAND] # Describe subcommands or one specific subcommand
57
- solusvm client list # Lists existing clients
58
-
59
- solusvm general help [COMMAND] # Describe subcommands or one specific subcommand
60
- solusvm general isos TYPE # Lists existing isos for a given type [openvz|xen|xen hvm|kvm]
61
- solusvm general plans TYPE # Lists existing plans for a given type [openvz|xen|xen hvm|kvm]
62
- solusvm general templates TYPE # Lists existing templates for a given type [openvz|xen|xen hvm|kvm]
63
-
64
- solusvm node available-ips VSERVERID # Lists the available ips for a given node
65
- solusvm node help [COMMAND] # Describe subcommands or one specific subcommand
66
- solusvm node list TYPE # Lists existing nodes for a given type [openvz|xen|xen hvm|kvm]
67
- solusvm node list-ids TYPE # Lists existing nodes ids for a given type [openvz|xen|xen hvm|kvm]
68
- solusvm node stats VSERVERID # Lists statistics for a given node
69
- solusvm node virtualservers VSERVERID # Lists the virtual servers for a given node
70
- solusvm node xenresources VSERVERID # Lists xen resources for a given node
71
-
72
- solusvm reseller change # Changes the available resources of a reseller
73
- solusvm reseller create # Creates a new reseller
74
- solusvm reseller delete USERNAME # Deletes an existing reseller
75
- solusvm reseller help [COMMAND] # Describe subcommands or one specific subcommand
76
- solusvm reseller info USERNAME # Retrieves information from an existing reseller
77
- solusvm reseller list # Lists existing resellers
78
-
79
- solusvm server addip VSERVERID # Adds an ip to the server
80
- solusvm server boot VSERVERID # Boots up a server
81
- solusvm server change-bootorder VSERVERID BOOTORDER # Changes the boot order of a server [cd(Hard Disk CDROM)|dc(CDROM Hard Disk)|c(Hard Di...
82
- solusvm server change-consolepass VSERVERID NEWPASSWORD # Changes the console password of a server
83
- solusvm server change-hostname VSERVERID HOSTNAME # Changes the hostname of a server
84
- solusvm server change-owner VSERVERID CLIENTID # Changes the owner of a server
85
- solusvm server change-plan VSERVERID NEWPLAN # Changes the plan of a server
86
- solusvm server change-rootpass VSERVERID NEWPASSWORD # Changes the root password of a server
87
- solusvm server change-vncpass VSERVERID NEWPASSWORD # Changes the vnc password of a server
88
- solusvm server check-exists VSERVERID # Checks if a server exists
89
- solusvm server console VSERVERID # Retrieves console information from a server
90
- solusvm server create HOSTNAME PASSWORD # Creates a new server
91
- solusvm server help [COMMAND] # Describe subcommands or one specific subcommand
92
- solusvm server info VSERVERID # Retrieves information from a server
93
- solusvm server info-all VSERVERID # Retrieves all availavle information from a server
94
- solusvm server mountiso VSERVERID ISO # Mounts an iso
95
- solusvm server network-switcher VSERVERID SWITCH(on|off) # Enable/Disable Network mode
96
- solusvm server pae-switcher VSERVERID SWITCH(on|off) # Enable/Disable PAE
97
- solusvm server reboot VSERVERID # Reboots a server
98
- solusvm server rebuild VSERVERID # Rebuilds a server
99
- solusvm server resume VSERVERID # Resumes a server
100
- solusvm server shutdown VSERVERID # Shuts down a server
101
- solusvm server status VSERVERID # Checks the status of a server
102
- solusvm server suspend VSERVERID # Suspends a server
103
- solusvm server terminate VSERVERID # Terminates a server
104
- solusvm server tun-switcher VSERVERID SWITCH(on|off) # Enable/Disable TUN/TAP
105
- solusvm server unmountiso VSERVERID # Unmounts an iso
106
- solusvm server vnc VSERVERID # Retrieves vnc information from a server
107
-
108
- Options:
109
- -I, --api-login, [--api-login=API_LOGIN] # API ID. Required.
110
- -K, --api-key, [--api-key=API_KEY] # API KEY. Required.
111
- -U, --api-url, [--api-url=API_URL] # API URL. Required.
112
-
113
-
114
- To check the available options for a given action, you can execute the following command:
115
-
116
- solusvm server help create
58
+ ```
59
+ Tasks:
60
+ solusvm client <command> # Client commands
61
+ solusvm general <command> # General commands
62
+ solusvm help [TASK] # Describe available tasks or one specific task
63
+ solusvm node <command> # Node commands
64
+ solusvm reseller <command> # Reseller commands
65
+ solusvm server <command> # Server commands
66
+ solusvm version # Outputs the current program version
67
+
68
+ solusvm client authenticate USERNAME NEWPASSWORD # Verify a clients login. Returns true when the specified login is correct
69
+ solusvm client change-password USERNAME NEWPASSWORD # Changes the password of an existing client
70
+ solusvm client check-exists USERNAME # Checks if a client exists
71
+ solusvm client create # Creates a new client
72
+ solusvm client delete USERNAME # Deletes an existing client
73
+ solusvm client help [COMMAND] # Describe subcommands or one specific subcommand
74
+ solusvm client list # Lists existing clients
75
+
76
+ solusvm general help [COMMAND] # Describe subcommands or one specific subcommand
77
+ solusvm general isos TYPE # Lists existing isos for a given type [openvz|xen|xen hvm|kvm]
78
+ solusvm general plans TYPE # Lists existing plans for a given type [openvz|xen|xen hvm|kvm]
79
+ solusvm general templates TYPE # Lists existing templates for a given type [openvz|xen|xen hvm|kvm]
80
+
81
+ solusvm node available-ips VSERVERID # Lists the available ips for a given node
82
+ solusvm node help [COMMAND] # Describe subcommands or one specific subcommand
83
+ solusvm node list TYPE # Lists existing nodes for a given type [openvz|xen|xen hvm|kvm]
84
+ solusvm node list-ids TYPE # Lists existing nodes ids for a given type [openvz|xen|xen hvm|kvm]
85
+ solusvm node stats VSERVERID # Lists statistics for a given node
86
+ solusvm node virtualservers VSERVERID # Lists the virtual servers for a given node
87
+ solusvm node xenresources VSERVERID # Lists xen resources for a given node
88
+
89
+ solusvm reseller change # Changes the available resources of a reseller
90
+ solusvm reseller create # Creates a new reseller
91
+ solusvm reseller delete USERNAME # Deletes an existing reseller
92
+ solusvm reseller help [COMMAND] # Describe subcommands or one specific subcommand
93
+ solusvm reseller info USERNAME # Retrieves information from an existing reseller
94
+ solusvm reseller list # Lists existing resellers
95
+
96
+ solusvm server addip VSERVERID # Adds an ip to the server
97
+ solusvm server boot VSERVERID # Boots up a server
98
+ solusvm server change-bootorder VSERVERID BOOTORDER # Changes the boot order of a server [cd(Hard Disk CDROM)|dc(CDROM Hard Disk)|c(Hard Di...
99
+ solusvm server change-consolepass VSERVERID NEWPASSWORD # Changes the console password of a server
100
+ solusvm server change-hostname VSERVERID HOSTNAME # Changes the hostname of a server
101
+ solusvm server change-owner VSERVERID CLIENTID # Changes the owner of a server
102
+ solusvm server change-plan VSERVERID NEWPLAN # Changes the plan of a server
103
+ solusvm server change-rootpass VSERVERID NEWPASSWORD # Changes the root password of a server
104
+ solusvm server change-vncpass VSERVERID NEWPASSWORD # Changes the vnc password of a server
105
+ solusvm server check-exists VSERVERID # Checks if a server exists
106
+ solusvm server console VSERVERID # Retrieves console information from a server
107
+ solusvm server create HOSTNAME PASSWORD # Creates a new server
108
+ solusvm server help [COMMAND] # Describe subcommands or one specific subcommand
109
+ solusvm server info VSERVERID # Retrieves information from a server
110
+ solusvm server info-all VSERVERID # Retrieves all availavle information from a server
111
+ solusvm server mountiso VSERVERID ISO # Mounts an iso
112
+ solusvm server network-switcher VSERVERID SWITCH(on|off) # Enable/Disable Network mode
113
+ solusvm server pae-switcher VSERVERID SWITCH(on|off) # Enable/Disable PAE
114
+ solusvm server reboot VSERVERID # Reboots a server
115
+ solusvm server rebuild VSERVERID # Rebuilds a server
116
+ solusvm server resume VSERVERID # Resumes a server
117
+ solusvm server shutdown VSERVERID # Shuts down a server
118
+ solusvm server status VSERVERID # Checks the status of a server
119
+ solusvm server suspend VSERVERID # Suspends a server
120
+ solusvm server terminate VSERVERID # Terminates a server
121
+ solusvm server tun-switcher VSERVERID SWITCH(on|off) # Enable/Disable TUN/TAP
122
+ solusvm server unmountiso VSERVERID # Unmounts an iso
123
+ solusvm server vnc VSERVERID # Retrieves vnc information from a server
124
+
125
+ Options:
126
+ -I, --api-login, [--api-login=API_LOGIN] # API ID. Required.
127
+ -K, --api-key, [--api-key=API_KEY] # API KEY. Required.
128
+ -U, --api-url, [--api-url=API_URL] # API URL. Required.
129
+
130
+
131
+ To check the available options for a given action, you can execute the following command:
132
+
133
+ solusvm server help create
134
+ ```
117
135
 
118
136
  Default Config for Command Line
119
137
  --------------------------------
120
138
 
121
- The command line utility, solusvm, will look for a .solusvm.yml file in ~/. You can specify some defaults.
139
+ The command line utility, `solusvm`, will look for a config file in
140
+ `~/.solusvm.yml`. You can specify some defaults.
122
141
 
123
- ~/.solusvm.yml
124
- id: api_id
125
- key: api_key
126
- # URL to the API endpoint
127
- url: https://portal.yoursite.com/api/admin/command.php
128
- # Default client to put servers under
129
- username: bob
142
+ ```
143
+ ~/.solusvm.yml
144
+ id: api_id
145
+ key: api_key
146
+ # URL to the API endpoint
147
+ url: https://portal.yoursite.com/api/admin/command.php
148
+ # Default client to put servers under
149
+ username: bob
150
+ ```
130
151
 
131
- Requirements
152
+ Installation
132
153
  ------------
133
154
 
134
- * xml-simple
155
+ To install SolusVM using [Bundler](http://gembundler.com):
135
156
 
136
- Documentation
137
- -------------
157
+ ```
158
+ echo "gem 'solusvm'" >> Gemfile
159
+ bundle install
160
+ ```
138
161
 
139
- * http://solusvm.rubyforge.org/solusvm/
162
+ To install SolusVM globally using RubyGems:
140
163
 
141
- Installation
142
- ------------
164
+ ```
165
+ gem install solusvm
166
+ ```
143
167
 
144
- gem install solusvm
168
+ Upgrading to SolusVM 2
169
+ ----------------------
170
+
171
+ Version 2 of the SolusVM gem uses the JSON API that was introduced in the
172
+ SolusVM Admin API in version v1.14. If you are using SolusVM software older
173
+ than v1.14, you will need to stick to an older version of this gem (i.e.
174
+ [v1.4.0](https://github.com/site5/solusvm/tree/v1.4.0)).
175
+
176
+ Version 2 also changes the name of the gem's top-level module -- it is now
177
+ `SolusVM` instead of the old `Solusvm`. Upgrading will require changing this
178
+ in your code.
145
179
 
146
180
  Contributors
147
181
  ------------
148
182
 
149
- * [Justin Mazzi](http://github.com/jmazzi)
150
- * [Maran H.](http://github.com/maran)
151
- * [Joshua Priddle](http://github.com/itspriddle)
152
- * [Vince Stratful](http://github.com/Vincepbell)
153
- * [Rubem Nakamura](http://github.com/rubemz)
183
+ SolusVM was originally written by [jmazzi](https://github.com/site5/jmazzi)
184
+ for internal use at Site5.com. Additional contributors are [listed on
185
+ GitHub](https://github.com/site5/solusvm/graphs/contributors).
186
+
187
+ Tests
188
+ -----
189
+
190
+ SolusVM uses test-unit for tests. To run:
191
+
192
+ ```
193
+ bundle exec rake # Runs all tests
194
+ bundle exec ruby -I"lib:test" test/path/test_file.rb
195
+ ```
154
196
 
155
197
  Note on Patches/Pull Requests
156
198
  -----------------------------
157
-
199
+
158
200
  * Fork the project.
159
201
  * Add yourself to the Contributors list
160
202
  * Make your feature addition or bug fix.
161
203
  * Add tests for it. This is important so I don't break it in a
162
204
  future version unintentionally.
163
205
  * Commit, do not mess with rakefile, version, or history.
164
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
206
+ (if you want to have your own version, that is fine but bump version in a
207
+ commit by itself I can ignore when I pull)
165
208
  * Send me a pull request. Bonus points for topic branches.
166
209
 
167
210
  Copyright
168
211
  ---------
169
212
 
170
- Copyright (c) 2010-2013 Site5.com. See LICENSE for details.
213
+ Copyright (c) 2010-2014 Site5.com. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
- require 'rubygems'
2
1
  require 'rake'
3
2
  require 'bundler/gem_tasks'
4
-
5
3
  require 'rake/testtask'
4
+ require 'rake-tomdoc'
6
5
 
7
6
  Rake::TestTask.new(:test) do |test|
8
7
  test.libs << 'lib' << 'test'
@@ -10,34 +9,5 @@ Rake::TestTask.new(:test) do |test|
10
9
  test.verbose = true
11
10
  end
12
11
 
13
- begin
14
- require 'rcov/rcovtask'
15
- Rcov::RcovTask.new do |test|
16
- test.libs << 'test'
17
- test.pattern = 'test/**/test_*.rb'
18
- test.verbose = true
19
- end
20
- rescue LoadError
21
- task :rcov do
22
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
23
- end
24
- end
25
-
26
- begin
27
- require 'rdoc/task'
28
- Rake::RDocTask.new do |rdoc|
29
- version = Solusvm::VERSION
30
-
31
- rdoc.rdoc_dir = 'rdoc'
32
- rdoc.title = "solusvm #{version}"
33
- rdoc.rdoc_files.include('README*')
34
- rdoc.rdoc_files.include('lib/**/*.rb')
35
- end
36
- rescue LoadError
37
- task :rdoc do
38
- abort "rdoc is not available. In order to run rdoc, you must: sudo gem install rdoc"
39
- end
40
- end
41
-
42
- task :default => :test
43
- task :spec => :test
12
+ task default: :test
13
+ task spec: :test
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
4
-
5
- require "thor"
3
+ # Setup bundler if this script is called directly
4
+ require "bundler/setup" if $0 == __FILE__
6
5
  require "solusvm/cli"
7
6
 
8
- Solusvm::Cli.start
7
+ SolusVM::CLI.start
@@ -1,9 +1,7 @@
1
- require 'cgi'
2
- require 'rubygems'
3
- require 'xmlsimple'
4
1
  require 'faraday'
5
2
 
6
3
  require 'solusvm/hash'
4
+ require 'solusvm/errors'
7
5
  require 'solusvm/base'
8
6
  require 'solusvm/general'
9
7
  require 'solusvm/client'
@@ -1,5 +1,5 @@
1
- module Solusvm
2
- # Solusvm::Base is the main class for mapping API resources as subclasses.
1
+ module SolusVM
2
+ # SolusVM::Base is the main class for mapping API resources as subclasses.
3
3
  class Base
4
4
  VALID_SERVER_TYPES = ["openvz", "xen", "xen hvm"]
5
5
 
@@ -9,63 +9,94 @@ module Solusvm
9
9
  @config = config
10
10
  end
11
11
 
12
- # Prepares and sends the API request to the URL specificed in Solusvm.config
12
+ # Public: Prepares and sends the API request to the URL specified in
13
+ # `@config`.
13
14
  #
14
- # class MyClass < Base
15
- # def create_server(name)
16
- # perform_request(:action => "name", :id => 1)
17
- # end
18
- # end
15
+ # options - A Hash of options. Any options not listed below are converted
16
+ # to HTTP query arguments and are passed along to the API.
17
+ # :action - Specifies which API method to execute
19
18
  #
20
- # Options:
21
- # * <tt>:action</tt> - Specifies which API method to execute
22
- # All other options passed in are converted to http query arguments and are passed along to the API
19
+ # Example
23
20
  #
24
- # <tt>force_array</tt> - see parse_response
25
- def perform_request(options = {}, force_array = false)
26
- ca_path = File.join(File.dirname(__FILE__), "..", "cacert.pem")
27
- ssl = {verify: true, ca_file: File.expand_path(ca_path)}
21
+ # class MyClass < Base
22
+ # def create_server(name)
23
+ # perform_request(:action => "name", :id => 1)
24
+ # end
25
+ # end
26
+ #
27
+ # Returns true if the request was successful.
28
+ def perform_request(options = {})
29
+ options.reject! { |_, v| v.nil? }
28
30
 
29
- options.reject! {|_,v| v.nil? }
31
+ # Force JSON responses
32
+ options[:rdtype] = "json"
30
33
 
31
- response = Faraday.new(url: api_endpoint, ssl: ssl) do |c|
32
- c.params = options.merge(api_login)
33
- c.adapter :net_http
34
- end.get
34
+ response = conn.get api_endpoint, options.merge(api_login)
35
35
 
36
- @returned_parameters = parse_response(response.status, response.body, force_array)
36
+ @returned_parameters = parse_response(response.status, response.body)
37
37
  log_messages(options)
38
38
  successful?
39
39
  end
40
40
 
41
- # Converts the XML response to a Hash
41
+ # Public: Creates a Faraday connection.
42
42
  #
43
- # <tt>force_array</tt> - Parses the xml element as an array; can be a string with the element name
44
- # or an array with element names
45
- def parse_response(status, body, force_array = false)
46
- parse_error(status, body) || begin
47
- force_array = Array(force_array) if force_array
48
- body = "<solusrequest>#{body}</solusrequest>"
49
- XmlSimple.xml_in(body, "ForceArray" => force_array)
43
+ # Returns a Faraday::Connection.
44
+ def conn
45
+ @conn ||= Faraday.new(ssl: ssl_option) do |c|
46
+ c.request :retry if @config.fetch(:retry_request, false)
47
+ c.adapter :net_http
50
48
  end
51
49
  end
52
50
 
53
- # Parses a returned_parameters value as a list, if present.
51
+ # Public: SSL options used when creating a Faraday connection.
52
+ #
53
+ # Returns a Hash.
54
+ def ssl_option
55
+ {
56
+ verify: true,
57
+ ca_file: File.expand_path("../../cacert.pem", __FILE__)
58
+ }
59
+ end
60
+
61
+ # Public: Converts the XML response to a Hash.
62
+ #
63
+ # status - Faraday::Response#status
64
+ # body - Faraday::Response#body
65
+ #
66
+ # Returns a Hash.
67
+ def parse_response(status, body)
68
+ parse_error(status, body) || JSON.parse(body)
69
+ end
70
+
71
+ # Public: Parses a returned_parameters value as a list, if present.
72
+ #
73
+ # attribute - The attribute to check
74
+ #
75
+ # Returns an Array or nil.
54
76
  def parse_returned_params_as_list(attribute)
55
77
  if returned_parameters[attribute] && !returned_parameters[attribute].empty?
56
78
  returned_parameters[attribute].to_s.split(",")
57
79
  end
58
80
  end
59
81
 
60
- # Parses error responses.
82
+ # Public: Parses error responses.
83
+ #
84
+ # status - HTTP status code
85
+ # body - Raw body
86
+ #
87
+ # Raises SolusVM::AuthenticationError if there is an error authenticating
88
+ # with the API. This can happen if the request IP is not authorized, or if
89
+ # an invalid API key/id was provided.
90
+ #
91
+ # Returns a Hash or nil.
61
92
  def parse_error(status, body)
62
93
  if (200..299).include?(status)
63
94
  # Checks for application errors
64
95
  case body.downcase
65
96
  when /invalid ipaddress/i
66
- { "status" => "error", "statusmsg" => "This IP is not authorized to use the API" }
97
+ raise AuthenticationError, "This IP is not authorized to use the API"
67
98
  when /Invalid id or key/i
68
- { "status" => "error", "statusmsg" => "Invalid ID or key" }
99
+ raise AuthenticationError, "Invalid ID or key"
69
100
  when /Node not found/i
70
101
  { "status" => "error", "statusmsg" => "Node does not exist" }
71
102
  end
@@ -74,24 +105,26 @@ module Solusvm
74
105
  end
75
106
  end
76
107
 
77
- # Returns true when a request has been successful
108
+ # Public: Check if the request was successful.
109
+ #
110
+ # my_class = MyClass.new
111
+ # my_class.create_server("example.com")
112
+ # my_class.successful? # => true
78
113
  #
79
- # my_class = MyClass.new
80
- # my_class.create_server("example.com")
81
- # my_class.successful? # => true
114
+ # Returns true if the request was successful.
82
115
  def successful?
83
116
  returned_parameters["status"].nil? || returned_parameters["status"] == "success"
84
117
  end
85
118
 
86
- # Returns the API endpoint set in the instance configuration. Otherwise,
87
- # it returns the default configuration.
119
+ # Public: Returns the API endpoint set in the instance configuration.
120
+ # Otherwise, it returns the default configuration.
88
121
  #
89
122
  # Returns a String
90
123
  def api_endpoint
91
124
  @config.fetch(:url)
92
125
  end
93
126
 
94
- # Returns the API id set in the instance configuration. Otherwise,
127
+ # Public: Returns the API id set in the instance configuration. Otherwise,
95
128
  # it returns the default configuration.
96
129
  #
97
130
  # Returns a String
@@ -99,24 +132,38 @@ module Solusvm
99
132
  @config.fetch(:api_id)
100
133
  end
101
134
 
102
- # Returns the API key set in the instance configuration. Otherwise,
103
- # it returns the default configuration.
135
+ # Public: Returns the API key set in the instance configuration.
136
+ # Otherwise, it returns the default configuration.
104
137
  #
105
- # Returns a String
138
+ # Returns a String.
106
139
  def api_key
107
140
  @config.fetch(:api_key)
108
141
  end
109
142
 
143
+ # Public: API options
144
+ #
145
+ # option - Key to fetch
146
+ #
147
+ # Returns the given option.
110
148
  def api_options(option)
111
149
  if options = @config[:options]
112
150
  options[option.to_sym]
113
151
  end
114
152
  end
115
153
 
154
+ # Public: API login information.
155
+ #
156
+ # Returns a Hash.
116
157
  def api_login
117
- {id: api_id, key: api_key}
158
+ { id: api_id, key: api_key }
118
159
  end
119
160
 
161
+ # Public: Logs API actions to the configured logger.
162
+ #
163
+ # options - A Hash of options
164
+ # :action - the API action
165
+ #
166
+ # Returns nothing.
120
167
  def log_messages(options)
121
168
  logger, logger_method = api_options(:logger), api_options(:logger_method)
122
169
 
@@ -129,12 +176,20 @@ module Solusvm
129
176
  end
130
177
  end
131
178
 
132
- # API response message
179
+ # Public: API response message
180
+ #
181
+ # Returns a String.
133
182
  def statusmsg
134
183
  returned_parameters["statusmsg"]
135
184
  end
136
185
 
137
- # Validates the server type.
186
+ # Public: Validates the server type.
187
+ #
188
+ # type - The server type to check
189
+ #
190
+ # Yields a required block if given server type is valid.
191
+ #
192
+ # Returns the result of the block, or false if the server type is invalid.
138
193
  def validate_server_type(type, &block)
139
194
  type = type.strip
140
195