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.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/LICENSE +1 -1
- data/README.markdown +159 -116
- data/Rakefile +3 -33
- data/bin/solusvm +3 -4
- data/lib/solusvm.rb +1 -3
- data/lib/solusvm/base.rb +101 -46
- data/lib/solusvm/cli.rb +8 -8
- data/lib/solusvm/cli/base_cli.rb +3 -3
- data/lib/solusvm/cli/client_cli.rb +3 -5
- data/lib/solusvm/cli/general_cli.rb +3 -5
- data/lib/solusvm/cli/node_cli.rb +3 -5
- data/lib/solusvm/cli/reseller_cli.rb +3 -5
- data/lib/solusvm/cli/server_cli.rb +4 -6
- data/lib/solusvm/client.rb +45 -27
- data/lib/solusvm/errors.rb +3 -0
- data/lib/solusvm/general.rb +11 -12
- data/lib/solusvm/hash.rb +1 -11
- data/lib/solusvm/node.rb +33 -21
- data/lib/solusvm/reseller.rb +53 -49
- data/lib/solusvm/server.rb +188 -52
- data/lib/solusvm/version.rb +2 -2
- data/test/cli/test_base_cli.rb +14 -4
- data/test/cli/test_client_cli.rb +13 -13
- data/test/cli/test_general_cli.rb +7 -7
- data/test/cli/test_node_cli.rb +13 -13
- data/test/cli/test_reseller_cli.rb +11 -11
- data/test/cli/test_server_cli.rb +61 -61
- data/test/sham_rack_stubs/base/parse-response.json +4 -0
- data/test/sham_rack_stubs/client/authenticate.json +4 -0
- data/test/sham_rack_stubs/client/change-password.json +6 -0
- data/test/sham_rack_stubs/client/create.json +9 -0
- data/test/sham_rack_stubs/client/delete.json +4 -0
- data/test/sham_rack_stubs/client/exists.json +4 -0
- data/test/sham_rack_stubs/client/list-empty.json +5 -0
- data/test/sham_rack_stubs/client/list.json +30 -0
- data/test/sham_rack_stubs/general/isos-empty.json +5 -0
- data/test/sham_rack_stubs/general/isos.json +5 -0
- data/test/sham_rack_stubs/general/plans-empty.json +5 -0
- data/test/sham_rack_stubs/general/plans.json +5 -0
- data/test/sham_rack_stubs/general/templates-empty.json +7 -0
- data/test/sham_rack_stubs/general/templates.json +7 -0
- data/test/sham_rack_stubs/generic/error.json +4 -0
- data/test/sham_rack_stubs/node/available-ips-empty.json +6 -0
- data/test/sham_rack_stubs/node/available-ips.json +6 -0
- data/test/sham_rack_stubs/node/ids.json +5 -0
- data/test/sham_rack_stubs/node/list-empty.json +5 -0
- data/test/sham_rack_stubs/node/list-groups.json +5 -0
- data/test/sham_rack_stubs/node/list.json +5 -0
- data/test/sham_rack_stubs/node/statistics.json +21 -0
- data/test/sham_rack_stubs/node/virtualservers-empty.json +5 -0
- data/test/sham_rack_stubs/node/virtualservers.json +19 -0
- data/test/sham_rack_stubs/node/xenresources.json +6 -0
- data/test/sham_rack_stubs/reseller/change-resources.json +18 -0
- data/test/sham_rack_stubs/reseller/create.json +25 -0
- data/test/sham_rack_stubs/reseller/delete.json +4 -0
- data/test/sham_rack_stubs/reseller/info.json +24 -0
- data/test/sham_rack_stubs/reseller/list-empty.json +5 -0
- data/test/sham_rack_stubs/reseller/list.json +5 -0
- data/test/sham_rack_stubs/server/add-ip.json +5 -0
- data/test/sham_rack_stubs/server/boot.json +4 -0
- data/test/sham_rack_stubs/server/change-bootorder.json +4 -0
- data/test/sham_rack_stubs/server/change-hostname.json +5 -0
- data/test/sham_rack_stubs/server/change-owner.json +4 -0
- data/test/sham_rack_stubs/server/change-plan.json +4 -0
- data/test/sham_rack_stubs/server/change-rootpassword.json +5 -0
- data/test/sham_rack_stubs/server/change-vncpass.json +5 -0
- data/test/sham_rack_stubs/server/console.json +13 -0
- data/test/sham_rack_stubs/server/create.json +13 -0
- data/test/sham_rack_stubs/server/del-ip.json +4 -0
- data/test/sham_rack_stubs/server/exists.json +4 -0
- data/test/sham_rack_stubs/server/info-all.json +16 -0
- data/test/sham_rack_stubs/server/info.json +15 -0
- data/test/sham_rack_stubs/server/mountiso.json +4 -0
- data/test/sham_rack_stubs/server/network-disable.json +4 -0
- data/test/sham_rack_stubs/server/network-enable.json +4 -0
- data/test/sham_rack_stubs/server/pae-disable.json +4 -0
- data/test/sham_rack_stubs/server/pae-enable.json +4 -0
- data/test/sham_rack_stubs/server/reboot.json +4 -0
- data/test/sham_rack_stubs/server/rebuild.json +4 -0
- data/test/sham_rack_stubs/server/resume.json +4 -0
- data/test/sham_rack_stubs/server/shutdown.json +4 -0
- data/test/sham_rack_stubs/server/status.json +4 -0
- data/test/sham_rack_stubs/server/suspend.json +4 -0
- data/test/sham_rack_stubs/server/terminate.json +4 -0
- data/test/sham_rack_stubs/server/tun-disable.json +4 -0
- data/test/sham_rack_stubs/server/tun-enable.json +4 -0
- data/test/sham_rack_stubs/server/unmountiso.json +4 -0
- data/test/sham_rack_stubs/server/vnc.json +8 -0
- data/test/solusvm/test_base.rb +34 -56
- data/test/solusvm/test_cli.rb +3 -3
- data/test/solusvm/test_client.rb +56 -66
- data/test/solusvm/test_general.rb +34 -19
- data/test/solusvm/test_hash.rb +0 -9
- data/test/solusvm/test_node.rb +66 -72
- data/test/solusvm/test_reseller.rb +47 -58
- data/test/solusvm/test_server.rb +149 -164
- data/test/test_helper.rb +43 -31
- metadata +173 -189
- data/.document +0 -5
- data/.gitignore +0 -25
- data/.travis.yml +0 -12
- data/solusvm.gemspec +0 -33
- data/test/vcr_cassettes/base/invalid_key.yml +0 -19
- data/test/vcr_cassettes/base/invalid_status.yml +0 -19
- data/test/vcr_cassettes/base/nonexistent_node.yml +0 -19
- data/test/vcr_cassettes/base/parse_response.yml +0 -28
- data/test/vcr_cassettes/base/statusmsg.yml +0 -28
- data/test/vcr_cassettes/base/successful.yml +0 -68
- data/test/vcr_cassettes/base/successful_instance_config.yml +0 -28
- data/test/vcr_cassettes/base/unauthorized_ip.yml +0 -19
- data/test/vcr_cassettes/client/authenticate.yml +0 -37
- data/test/vcr_cassettes/client/change_password.yml +0 -39
- data/test/vcr_cassettes/client/create.yml +0 -42
- data/test/vcr_cassettes/client/delete.yml +0 -37
- data/test/vcr_cassettes/client/exists.yml +0 -20
- data/test/vcr_cassettes/client/list.yml +0 -66
- data/test/vcr_cassettes/general/isos.yml +0 -38
- data/test/vcr_cassettes/general/plans.yml +0 -38
- data/test/vcr_cassettes/general/templates.yml +0 -38
- data/test/vcr_cassettes/node/available_ips.yml +0 -41
- data/test/vcr_cassettes/node/ids.yml +0 -21
- data/test/vcr_cassettes/node/list.yml +0 -38
- data/test/vcr_cassettes/node/list_groups.yml +0 -20
- data/test/vcr_cassettes/node/statistics.yml +0 -32
- data/test/vcr_cassettes/node/virtualservers.yml +0 -67
- data/test/vcr_cassettes/node/xenresources.yml +0 -22
- data/test/vcr_cassettes/reseller/change_resources.yml +0 -27
- data/test/vcr_cassettes/reseller/create.yml +0 -27
- data/test/vcr_cassettes/reseller/delete.yml +0 -15
- data/test/vcr_cassettes/reseller/info.yml +0 -27
- data/test/vcr_cassettes/reseller/list.yml +0 -27
- data/test/vcr_cassettes/server/.yml +0 -1017
- data/test/vcr_cassettes/server/add_ip.yml +0 -15
- data/test/vcr_cassettes/server/boot.yml +0 -15
- data/test/vcr_cassettes/server/change_bootorder.yml +0 -15
- data/test/vcr_cassettes/server/change_consolepass.yml +0 -16
- data/test/vcr_cassettes/server/change_hostname.yml +0 -15
- data/test/vcr_cassettes/server/change_owner.yml +0 -15
- data/test/vcr_cassettes/server/change_plan.yml +0 -15
- data/test/vcr_cassettes/server/change_rootpassword.yml +0 -15
- data/test/vcr_cassettes/server/change_vncpass.yml +0 -15
- data/test/vcr_cassettes/server/console.yml +0 -28
- data/test/vcr_cassettes/server/create.yml +0 -27
- data/test/vcr_cassettes/server/del_ip.yml +0 -15
- data/test/vcr_cassettes/server/exists.yml +0 -15
- data/test/vcr_cassettes/server/info.yml +0 -27
- data/test/vcr_cassettes/server/info_all.yml +0 -15
- data/test/vcr_cassettes/server/mountiso.yml +0 -15
- data/test/vcr_cassettes/server/network_disable.yml +0 -15
- data/test/vcr_cassettes/server/network_enable.yml +0 -15
- data/test/vcr_cassettes/server/pae_disable.yml +0 -15
- data/test/vcr_cassettes/server/pae_enable.yml +0 -15
- data/test/vcr_cassettes/server/reboot.yml +0 -15
- data/test/vcr_cassettes/server/rebuild.yml +0 -15
- data/test/vcr_cassettes/server/resume.yml +0 -15
- data/test/vcr_cassettes/server/shutdown.yml +0 -15
- data/test/vcr_cassettes/server/status.yml +0 -15
- data/test/vcr_cassettes/server/suspend.yml +0 -15
- data/test/vcr_cassettes/server/terminate.yml +0 -27
- data/test/vcr_cassettes/server/tun_disable.yml +0 -15
- data/test/vcr_cassettes/server/tun_enable.yml +0 -15
- data/test/vcr_cassettes/server/unmountiso.yml +0 -15
- data/test/vcr_cassettes/server/vnc.yml +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db4b3b950573ce517e0c15de049ba58816bdab54
|
4
|
+
data.tar.gz: 31c21622c214c66e4f4f60c6af9560fa5e530f17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c1adec97375ad830ca77c3849c8840ccf1f293e353bd77678f500cf3eca001a9a33ee8c79b8c631a10b33fd66bc3478a204f77d9d18e119a9b4ed6063c6a345
|
7
|
+
data.tar.gz: 3e5701afdfa513977a781723997622070b5f44a6a02e69c3a8bcf19115297ad868480cad7360deb5f3553e8bcae029fff6c919721ae0deb3a648ee7ebfb750c6
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -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,
|
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://
|
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
|
-
|
21
|
+
```ruby
|
22
|
+
server = SolusVM::Server.new(api_key: 'key', api_id: 'id', url: 'url')
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
139
|
+
The command line utility, `solusvm`, will look for a config file in
|
140
|
+
`~/.solusvm.yml`. You can specify some defaults.
|
122
141
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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
|
-
|
152
|
+
Installation
|
132
153
|
------------
|
133
154
|
|
134
|
-
|
155
|
+
To install SolusVM using [Bundler](http://gembundler.com):
|
135
156
|
|
136
|
-
|
137
|
-
|
157
|
+
```
|
158
|
+
echo "gem 'solusvm'" >> Gemfile
|
159
|
+
bundle install
|
160
|
+
```
|
138
161
|
|
139
|
-
|
162
|
+
To install SolusVM globally using RubyGems:
|
140
163
|
|
141
|
-
|
142
|
-
|
164
|
+
```
|
165
|
+
gem install solusvm
|
166
|
+
```
|
143
167
|
|
144
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
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-
|
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
|
-
|
14
|
-
|
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
|
data/bin/solusvm
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
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
|
-
|
7
|
+
SolusVM::CLI.start
|
data/lib/solusvm.rb
CHANGED
data/lib/solusvm/base.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
#
|
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
|
12
|
+
# Public: Prepares and sends the API request to the URL specified in
|
13
|
+
# `@config`.
|
13
14
|
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
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
|
-
#
|
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
|
-
# <
|
25
|
-
def
|
26
|
-
|
27
|
-
|
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
|
-
|
31
|
+
# Force JSON responses
|
32
|
+
options[:rdtype] = "json"
|
30
33
|
|
31
|
-
response =
|
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
|
36
|
+
@returned_parameters = parse_response(response.status, response.body)
|
37
37
|
log_messages(options)
|
38
38
|
successful?
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
41
|
+
# Public: Creates a Faraday connection.
|
42
42
|
#
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
#
|
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
|
-
|
97
|
+
raise AuthenticationError, "This IP is not authorized to use the API"
|
67
98
|
when /Invalid id or key/i
|
68
|
-
|
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
|
-
#
|
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
|
-
#
|
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.
|
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.
|
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
|
|