solusvm_client 0.0.1 → 0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ab6d5b713ffed3f881959070f5bb2d7bf76a18c
4
- data.tar.gz: c9d42df1091573b3f47b5e0255c5797d223f4a81
3
+ metadata.gz: 170aaff3a23f687e5960809d760c5cfbc529da3d
4
+ data.tar.gz: 5ad30db5ad52b508d9720db816c3474b81f02cfd
5
5
  SHA512:
6
- metadata.gz: f4776b1ef98e1b32c20b43082232c720cfd568844189fa4f4559a699e56ba0f41b936c5ff5d07e2ba8b575855e0e859d68e25ceae3b4f1713d6c9b6479e6e34d
7
- data.tar.gz: a48944f1131b0afb12e1a590d0875fee033cdac4cb3ec628c9a471f3c4ec40c3d1e41c86ed77a8c67e6127d34af45ffeb869eb8fc7badd45d2c8b144c6ea17d5
6
+ metadata.gz: b7996e4fbdf47f5779f09c89a5534b08e4d33fbea6a986d826c4752c9ed146135e8e88522691a2c4aeb48943b9e5e527c10aa028118ceae91a9f5e1df088eac0
7
+ data.tar.gz: 5d96204a840caf99b25c59a263bbb0c86e4b883bee4e46ab23e582d4401d77afb5cc1f2b7b132dbaddce6f6a71e604316c885504ec2b242df87d98c7af8fc5b4
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
+ .idea
1
2
  *.gem
3
+ test.rb
2
4
  *.rbc
3
5
  .bundle
4
6
  .config
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # SolusvmClient
1
+ # SolusVMClient
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
 
@@ -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 SolusvmClient
4
- # Your code goes here...
5
- end
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
@@ -1,3 +1,3 @@
1
1
  module SolusvmClient
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1"
3
3
  end
@@ -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{Hello World}
12
- spec.description = %q{Hello World Description}
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.0.1
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: Hello World 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: Hello World
95
+ summary: SolusVM Client API Implementation
94
96
  test_files: []