solusvm_client 0.0.1 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +117 -3
- data/lib/solusvm_client.rb +10 -3
- data/lib/solusvm_client/server.rb +79 -0
- data/lib/solusvm_client/version.rb +1 -1
- data/solusvm_client.gemspec +2 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 170aaff3a23f687e5960809d760c5cfbc529da3d
|
4
|
+
data.tar.gz: 5ad30db5ad52b508d9720db816c3474b81f02cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7996e4fbdf47f5779f09c89a5534b08e4d33fbea6a986d826c4752c9ed146135e8e88522691a2c4aeb48943b9e5e527c10aa028118ceae91a9f5e1df088eac0
|
7
|
+
data.tar.gz: 5d96204a840caf99b25c59a263bbb0c86e4b883bee4e46ab23e582d4401d77afb5cc1f2b7b132dbaddce6f6a71e604316c885504ec2b242df87d98c7af8fc5b4
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# SolusVMClient
|
2
2
|
|
3
|
-
|
3
|
+
This Gem is a simple implementation of the SolusVM Client API (http://docs.solusvm.com/client_api)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,121 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
### Initializing
|
22
|
+
|
23
|
+
Initialize the API URL. For Rails put this into `config/initializers/solusvm_client.rb`
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
|
27
|
+
# require 'solusvm_client' # include gem if you are not inside rails
|
28
|
+
|
29
|
+
SolusVMClient.setup do |config|
|
30
|
+
config.api_url = "https://myserver.com:5656/api/client/command.php"
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
### Instantiating a Server Object
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
|
38
|
+
server = SolusVMClient::Server.new("MY API KEY", "MY API HASH")
|
39
|
+
```
|
40
|
+
|
41
|
+
### API Functions
|
42
|
+
|
43
|
+
* reboot
|
44
|
+
* boot
|
45
|
+
* shutdown
|
46
|
+
* status
|
47
|
+
* info
|
48
|
+
|
49
|
+
#### Examples
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
|
53
|
+
result = server.reboot
|
54
|
+
|
55
|
+
# result => {
|
56
|
+
# :status => "success",
|
57
|
+
# :statusmsg => "rebooted",
|
58
|
+
# :hostname => "myhostname.com",
|
59
|
+
# :ipaddress => "123.123.123.123",
|
60
|
+
# :vmstat => nil
|
61
|
+
# }
|
62
|
+
|
63
|
+
result = server.shutdown
|
64
|
+
|
65
|
+
# result => {
|
66
|
+
# :status => "success",
|
67
|
+
# :statusmsg => "shutdown",
|
68
|
+
# :hostname => "myhostname.com",
|
69
|
+
# :ipaddress => "123.123.123.123",
|
70
|
+
# :vmstat => nil
|
71
|
+
# }
|
72
|
+
|
73
|
+
result = server.boot
|
74
|
+
|
75
|
+
# result => {
|
76
|
+
# :status => "success",
|
77
|
+
# :statusmsg => "booted",
|
78
|
+
# :hostname => "myhostname.com",
|
79
|
+
# :ipaddress => "123.123.123.123",
|
80
|
+
# :vmstat => nil
|
81
|
+
# }
|
82
|
+
|
83
|
+
result = server.status
|
84
|
+
|
85
|
+
# result => {
|
86
|
+
# :status => "success",
|
87
|
+
# :statusmsg => "online",
|
88
|
+
# :vmstat => "online",
|
89
|
+
# :hostname => "myhostname.com",
|
90
|
+
# :ipaddress => "123.123.123.123"
|
91
|
+
# }
|
92
|
+
|
93
|
+
result = server.info
|
94
|
+
|
95
|
+
# result => {
|
96
|
+
# :status => "success",
|
97
|
+
# :statusmsg => nil,
|
98
|
+
# :hostname => "myhostname.com",
|
99
|
+
# :ipaddress => "123.123.123.123",
|
100
|
+
# :vmstat => nil
|
101
|
+
# }
|
102
|
+
|
103
|
+
result = server.info({ ipaddr: true, hdd: true, mem: true, bw: true })
|
104
|
+
|
105
|
+
# result => {
|
106
|
+
# :ipaddr => [
|
107
|
+
# [0] "123.123.123.123",
|
108
|
+
# [1] "0:0:0:0:0:ffff:7b7b:7b7b"
|
109
|
+
# ],
|
110
|
+
# :hdd => {
|
111
|
+
# :total => 10737418240,
|
112
|
+
# :used => 775327744,
|
113
|
+
# :free => 9962090496,
|
114
|
+
# :percentage => 7
|
115
|
+
# },
|
116
|
+
# :bw => {
|
117
|
+
# :total => 107374182400,
|
118
|
+
# :used => 256204956,
|
119
|
+
# :free => 107117977444,
|
120
|
+
# :percentage => 0
|
121
|
+
# },
|
122
|
+
# :mem => {
|
123
|
+
# :total => 134217728,
|
124
|
+
# :used => 25272320,
|
125
|
+
# :free => 108945408,
|
126
|
+
# :percentage => 19
|
127
|
+
# },
|
128
|
+
# :status => "success",
|
129
|
+
# :statusmsg => nil,
|
130
|
+
# :hostname => "myhostname.com",
|
131
|
+
# :ipaddress => "123.123.123.123",
|
132
|
+
# :vmstat => nil
|
133
|
+
# }
|
134
|
+
```
|
135
|
+
|
22
136
|
|
23
137
|
## Contributing
|
24
138
|
|
data/lib/solusvm_client.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
require 'solusvm_client/server'
|
1
3
|
require "solusvm_client/version"
|
2
4
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
5
|
+
module SolusVMClient
|
6
|
+
mattr_accessor :api_url
|
7
|
+
@@api_url = nil
|
8
|
+
|
9
|
+
def self.setup
|
10
|
+
yield self if block_given?
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module SolusVMClient
|
7
|
+
class Server
|
8
|
+
attr_accessor :api_key, :api_hash
|
9
|
+
|
10
|
+
@@actions = [
|
11
|
+
:reboot,
|
12
|
+
:boot,
|
13
|
+
:shutdown,
|
14
|
+
:status
|
15
|
+
]
|
16
|
+
|
17
|
+
def initialize(api_key, api_hash)
|
18
|
+
self.api_key = api_key
|
19
|
+
self.api_hash = api_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(m, *args, &block)
|
23
|
+
if @@actions.include?(m)
|
24
|
+
request(m)
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def info(options = {})
|
31
|
+
result = request("info", options)
|
32
|
+
if options.include?(:ipaddr)
|
33
|
+
result[:ipaddr] = result[:ipaddr].split(",")
|
34
|
+
end
|
35
|
+
|
36
|
+
[:hdd, :mem, :bw].each do |k|
|
37
|
+
if options.include?(k)
|
38
|
+
usage = result[k].split(",")
|
39
|
+
result[k] = {
|
40
|
+
total: usage[0].to_i,
|
41
|
+
used: usage[1].to_i,
|
42
|
+
free: usage[2].to_i,
|
43
|
+
percentage: usage[3].to_i
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
def request(action, options = {})
|
52
|
+
uri = URI.parse(SolusVMClient.api_url)
|
53
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
54
|
+
https.use_ssl = true
|
55
|
+
|
56
|
+
params = {
|
57
|
+
key: self.api_key,
|
58
|
+
hash: self.api_hash,
|
59
|
+
action: action
|
60
|
+
}.merge(options)
|
61
|
+
|
62
|
+
request = Net::HTTP::Post.new(uri)
|
63
|
+
request.set_form_data(params)
|
64
|
+
|
65
|
+
response = https.request(request)
|
66
|
+
|
67
|
+
result = {}
|
68
|
+
hash = Hash.from_xml("<root>#{response.body}</root>")["root"]
|
69
|
+
|
70
|
+
hash.each do |k,v|
|
71
|
+
result[k.to_sym] = v
|
72
|
+
end
|
73
|
+
|
74
|
+
raise result[:statusmsg] if result[:status] != "success"
|
75
|
+
|
76
|
+
result
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/solusvm_client.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = SolusvmClient::VERSION
|
9
9
|
spec.authors = ["bontscho"]
|
10
10
|
spec.email = ["software@bontscho.de"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{SolusVM Client API Implementation}
|
12
|
+
spec.description = %q{This Gem implements the SolusVM Client API (http://docs.solusvm.com/client_api) to easily manage your Virtual Private Servers}
|
13
13
|
spec.homepage = "https://github.com/bontscho/solusvm_client-ruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solusvm_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bontscho
|
@@ -52,7 +52,8 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10'
|
55
|
-
description:
|
55
|
+
description: This Gem implements the SolusVM Client API (http://docs.solusvm.com/client_api)
|
56
|
+
to easily manage your Virtual Private Servers
|
56
57
|
email:
|
57
58
|
- software@bontscho.de
|
58
59
|
executables: []
|
@@ -65,6 +66,7 @@ files:
|
|
65
66
|
- README.md
|
66
67
|
- Rakefile
|
67
68
|
- lib/solusvm_client.rb
|
69
|
+
- lib/solusvm_client/server.rb
|
68
70
|
- lib/solusvm_client/version.rb
|
69
71
|
- solusvm_client.gemspec
|
70
72
|
homepage: https://github.com/bontscho/solusvm_client-ruby
|
@@ -90,5 +92,5 @@ rubyforge_project:
|
|
90
92
|
rubygems_version: 2.2.1
|
91
93
|
signing_key:
|
92
94
|
specification_version: 4
|
93
|
-
summary:
|
95
|
+
summary: SolusVM Client API Implementation
|
94
96
|
test_files: []
|