sant0sk1-dreamy 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -9
- data/VERSION.yml +2 -2
- data/lib/dreamy.rb +1 -0
- data/lib/dreamy/base.rb +72 -5
- data/lib/dreamy/commands/help.rb +20 -9
- data/lib/dreamy/commands/ps.rb +136 -0
- data/lib/dreamy/private_server.rb +53 -0
- data/test/base_test.rb +78 -4
- data/test/private_server_test.rb +147 -0
- data/test/user_test.rb +1 -1
- metadata +6 -2
data/README.md
CHANGED
@@ -68,6 +68,19 @@ You can interact with DNS by adding and removing records
|
|
68
68
|
# remove the A record just created
|
69
69
|
account.dns_remove(subdomain,"A","123.321.123.321")
|
70
70
|
|
71
|
+
You can interact with your Private Server in many different ways
|
72
|
+
|
73
|
+
# change a private server setting
|
74
|
+
account.ps_set(ps_name,setting,value)
|
75
|
+
|
76
|
+
# set the memory size (MB)
|
77
|
+
account.ps_size_set(ps_name,"200")
|
78
|
+
|
79
|
+
# reboot the server
|
80
|
+
account.ps_reboot!(ps_name)
|
81
|
+
|
82
|
+
Check the base class for all the different API calls.
|
83
|
+
|
71
84
|
More and more functions will be added as time allows. If there's something missing that you want in, please:
|
72
85
|
|
73
86
|
fork -> commit -> pull request
|
@@ -97,21 +110,32 @@ Run this from the command line to print the usage:
|
|
97
110
|
dh help
|
98
111
|
|
99
112
|
=== Commands
|
100
|
-
help # show this usage
|
101
113
|
|
102
|
-
|
103
|
-
|
104
|
-
|
114
|
+
announce # list announce lists
|
115
|
+
announce:list <list> # list all subscribers to <name> list
|
116
|
+
announce:add <list> <email> # add subscriber with <email> to <list>
|
117
|
+
announce:remove <list> <email> # remove subscriber with <email> from <list>
|
105
118
|
|
106
119
|
dns # list DNS records
|
107
120
|
dns <name> # list DNS records for <name>
|
108
121
|
dns:add <record> <type> <value> # add DNS record
|
109
122
|
dns:remove <record> <type> <value> # remove DNS record
|
110
123
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
124
|
+
domains:http # list HTTP domain details
|
125
|
+
domains:mysql # list MySQL domains
|
126
|
+
domains:status # check availability of all domains (pingability)
|
127
|
+
|
128
|
+
ps # list private servers
|
129
|
+
ps:add <web|mysql> <yes|no> # adds a private server of type <web|mysql>. Yes = move data
|
130
|
+
ps:pending # list private servers scheduled to be created
|
131
|
+
ps:reboots <name> # list historical reboots for <name>
|
132
|
+
ps:reboot <name> now! # reboot <name> now! (proceed with caution)
|
133
|
+
ps:remove # removes all pending private servers
|
134
|
+
ps:settings <name> # list settings for private server <name>
|
135
|
+
ps:set <name> <setting> <value> # change <setting> on <name> to <value>
|
136
|
+
ps:size <name> # list historical memory sizes for <name>
|
137
|
+
ps:size <name> <value> # set new memory <value> for <name>
|
138
|
+
ps:usage <name> # list historical memory & CPU usage for <name>
|
115
139
|
|
116
140
|
users # list user accounts: details
|
117
141
|
users:pw # list user accounts: usernames & passwords
|
@@ -122,7 +146,6 @@ That's it for now. New commands should be springing up as Dreamy and the DreamHo
|
|
122
146
|
TODO
|
123
147
|
====
|
124
148
|
|
125
|
-
* add PS commands (once DH creates test account)
|
126
149
|
* add real rdocs
|
127
150
|
|
128
151
|
[1]:http://github.com/sant0sk1/dreamy
|
data/VERSION.yml
CHANGED
data/lib/dreamy.rb
CHANGED
data/lib/dreamy/base.rb
CHANGED
@@ -62,15 +62,81 @@ module Dreamy
|
|
62
62
|
def announce_add(listname,domain,email,name="")
|
63
63
|
doc = request("announcement_list-add_subscriber",
|
64
64
|
{"listname" => listname, "domain" => domain, "email" => email, "name" => name})
|
65
|
-
|
66
|
-
|
65
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
66
|
+
true
|
67
67
|
end
|
68
68
|
|
69
69
|
def announce_remove(listname,domain,email)
|
70
70
|
doc = request("announcement_list-remove_subscriber",
|
71
|
-
{"listname" => listname, "domain" => domain, "email" => email}
|
72
|
-
|
73
|
-
|
71
|
+
{"listname" => listname, "domain" => domain, "email" => email})
|
72
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
def ps
|
77
|
+
doc = request("dreamhost_ps-list_ps")
|
78
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
79
|
+
(doc/:data).inject([]) { |servers, server| servers << PrivateServer.new_from_xml(server); servers }
|
80
|
+
end
|
81
|
+
|
82
|
+
def ps_settings(name)
|
83
|
+
doc = request("dreamhost_ps-list_settings", {"ps" => name})
|
84
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
85
|
+
PrivateServer.settings_from_xml(doc)
|
86
|
+
end
|
87
|
+
|
88
|
+
def ps_set(name,setting,value)
|
89
|
+
doc = request("dreamhost_ps-set_settings", {"ps" => name, setting => value})
|
90
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
91
|
+
true
|
92
|
+
end
|
93
|
+
|
94
|
+
def ps_size_history(name)
|
95
|
+
doc = request("dreamhost_ps-list_size_history", {"ps" => name})
|
96
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
97
|
+
(doc/:data).inject([]) { |sizes, size| sizes << PrivateServer.size_from_xml(size); sizes }
|
98
|
+
end
|
99
|
+
|
100
|
+
def ps_size_set(name,size)
|
101
|
+
doc = request("dreamhost_ps-set_size", {"ps" => name, "size" => size})
|
102
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
def ps_reboot_history(name)
|
107
|
+
doc = request("dreamhost_ps-list_reboot_history", {"ps" => name})
|
108
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
109
|
+
(doc/:data).inject([]) { |reboots,reboot| reboots << reboot.at('stamp').innerHTML; reboots }
|
110
|
+
end
|
111
|
+
|
112
|
+
def ps_reboot!(name)
|
113
|
+
doc = request("dreamhost_ps-reboot", {"ps" => name})
|
114
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
115
|
+
true
|
116
|
+
end
|
117
|
+
|
118
|
+
def ps_usage(name)
|
119
|
+
doc = request("dreamhost_ps-list_usage", {"ps" => name})
|
120
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
121
|
+
(doc/:data).inject([]) { |usages, usage| usages << PrivateServer.usage_from_xml(usage); usages }
|
122
|
+
end
|
123
|
+
|
124
|
+
def ps_add(type,movedata="no")
|
125
|
+
doc = request("dreamhost_ps-add_ps", {"type" => type, "movedata" => movedata})
|
126
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
127
|
+
true
|
128
|
+
end
|
129
|
+
|
130
|
+
def ps_remove
|
131
|
+
doc = request("dreamhost_ps-remove_pending_ps")
|
132
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
133
|
+
true
|
134
|
+
end
|
135
|
+
|
136
|
+
def ps_pending
|
137
|
+
doc = request("dreamhost_ps-list_pending_ps")
|
138
|
+
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
|
139
|
+
(doc/:data).inject([]) { |pends, pend| pends << PrivateServer.pending_from_xml(pend); pends }
|
74
140
|
end
|
75
141
|
|
76
142
|
private
|
@@ -95,6 +161,7 @@ module Dreamy
|
|
95
161
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
96
162
|
|
97
163
|
begin
|
164
|
+
# puts path
|
98
165
|
response = http.get(path)
|
99
166
|
rescue => error
|
100
167
|
raise CantConnect, error.message
|
data/lib/dreamy/commands/help.rb
CHANGED
@@ -8,21 +8,32 @@ module Dreamy::Command
|
|
8
8
|
usage = <<EOTXT
|
9
9
|
|
10
10
|
=== Commands
|
11
|
-
help # show this usage
|
12
|
-
|
13
|
-
domains:http # list HTTP domain details
|
14
|
-
domains:mysql # list MySQL domains
|
15
|
-
domains:status # check availability of all domains (pingability)
|
16
11
|
|
12
|
+
announce # list announce lists
|
13
|
+
announce:list <list> # list all subscribers to <name> list
|
14
|
+
announce:add <list> <email> # add subscriber with <email> to <list>
|
15
|
+
announce:remove <list> <email> # remove subscriber with <email> from <list>
|
16
|
+
|
17
17
|
dns # list DNS records
|
18
18
|
dns <name> # list DNS records for <name>
|
19
19
|
dns:add <record> <type> <value> # add DNS record
|
20
20
|
dns:remove <record> <type> <value> # remove DNS record
|
21
|
+
|
22
|
+
domains:http # list HTTP domain details
|
23
|
+
domains:mysql # list MySQL domains
|
24
|
+
domains:status # check availability of all domains (pingability)
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
ps # list private servers
|
27
|
+
ps:add <web|mysql> <yes|no> # adds a private server of type <web|mysql>. Yes = move data
|
28
|
+
ps:pending # list private servers scheduled to be created
|
29
|
+
ps:reboots <name> # list historical reboots for <name>
|
30
|
+
ps:reboot <name> now! # reboot <name> now! (proceed with caution)
|
31
|
+
ps:remove # removes all pending private servers
|
32
|
+
ps:settings <name> # list settings for private server <name>
|
33
|
+
ps:set <name> <setting> <value> # change <setting> on <name> to <value>
|
34
|
+
ps:size <name> # list historical memory sizes for <name>
|
35
|
+
ps:size <name> <value> # set new memory <value> for <name>
|
36
|
+
ps:usage <name> # list historical memory & CPU usage for <name>
|
26
37
|
|
27
38
|
users # list user accounts: details
|
28
39
|
users:pw # list user accounts: usernames & passwords
|
@@ -0,0 +1,136 @@
|
|
1
|
+
module Dreamy::Command
|
2
|
+
class Ps < Base
|
3
|
+
|
4
|
+
def list
|
5
|
+
servers = @account.ps
|
6
|
+
|
7
|
+
if servers.empty?
|
8
|
+
display "No private servers for this account"
|
9
|
+
else
|
10
|
+
servers_table = table do |t|
|
11
|
+
t.headings = 'Name', 'Type', 'Memory (MB)', 'Start Date'
|
12
|
+
servers.each { |ps| t << [ps.name,ps.type,ps.memory,ps.start_date] }
|
13
|
+
end
|
14
|
+
display servers_table
|
15
|
+
end
|
16
|
+
end
|
17
|
+
alias :index :list
|
18
|
+
|
19
|
+
def settings
|
20
|
+
if args.length == 1
|
21
|
+
settings = @account.ps_settings(args[0])
|
22
|
+
settings_table = table do |t|
|
23
|
+
t.headings = 'Setting', 'Value'
|
24
|
+
settings.each { |k,v| t << [k,v] }
|
25
|
+
end
|
26
|
+
display settings_table
|
27
|
+
else
|
28
|
+
display "Usage: dh ps:settings [ps name]"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def set
|
33
|
+
if args.length == 3
|
34
|
+
name, setting, value = args[0], args[1], args[2]
|
35
|
+
@account.ps_set(name,setting,value)
|
36
|
+
display "Successfully set #{setting} to #{value} for #{name}"
|
37
|
+
else
|
38
|
+
display "Usage: dh ps:set [ps name] [setting] [value]"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def size
|
43
|
+
case args.length
|
44
|
+
when 1
|
45
|
+
sizes = @account.ps_size_history(args[0])
|
46
|
+
sizes_table = table do |t|
|
47
|
+
t.headings = 'Time', 'Memory (MB)', 'Duration (Seconds)', 'Cost (Period)', 'Cost (Monthly)'
|
48
|
+
sizes.each { |s| t << [s["stamp"],s["memory_mb"],s["period_seconds"],s["period_cost"],s["monthy_cost"]] }
|
49
|
+
end
|
50
|
+
display sizes_table
|
51
|
+
when 2
|
52
|
+
name, new_size = args[0], args[1]
|
53
|
+
@account.ps_size_set(name,new_size)
|
54
|
+
display "Successfully set memory size to #{new_size} for #{name}"
|
55
|
+
else
|
56
|
+
display "Usage: dh ps:size [ps name] [new size (optional)]"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def reboots
|
61
|
+
if args.length == 1
|
62
|
+
reboots = @account.ps_reboot_history(args[0])
|
63
|
+
reboots_table = table do |t|
|
64
|
+
t.headings = 'Count', 'Reboot Time'
|
65
|
+
reboots.each_with_index { |r,i| t << [i + 1,r] }
|
66
|
+
end
|
67
|
+
display reboots_table
|
68
|
+
else
|
69
|
+
display "Usage: dh ps:reboots [ps name]"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def reboot
|
74
|
+
if args.length == 2
|
75
|
+
if args[1] == "now!"
|
76
|
+
@account.ps_reboot!(args[0])
|
77
|
+
display "Successfully sent reboot command for #{args[0]}"
|
78
|
+
else
|
79
|
+
display "Are you sure?? If yes, finish the command with 'now!'"
|
80
|
+
end
|
81
|
+
else
|
82
|
+
display "Usage: dh ps:reboot [ps name] now! (WARNING: this will reboot your server)"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def usage
|
87
|
+
if args.length == 1
|
88
|
+
usages = @account.ps_usage(args[0])
|
89
|
+
usage_table = table do |t|
|
90
|
+
t.headings = 'Time', 'Memory (MB)', 'CPU Load'
|
91
|
+
usages.each { |u| t << [u["stamp"], u["memory_mb"],u["load"]] }
|
92
|
+
end
|
93
|
+
display usage_table
|
94
|
+
else
|
95
|
+
display "Usage: dh ps:usage [ps name]"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def add
|
100
|
+
case args.length
|
101
|
+
when 1
|
102
|
+
if args[0] == "web"
|
103
|
+
display "you must specify 'yes' or 'no' for whether or not to move data to new server"
|
104
|
+
else
|
105
|
+
@account.ps_add(args[0])
|
106
|
+
display "Successfully requested new private mysql server"
|
107
|
+
end
|
108
|
+
when 2
|
109
|
+
type, move = args[0], args[1]
|
110
|
+
@account.ps_add(type,move)
|
111
|
+
display "Successfully requested new private server"
|
112
|
+
else
|
113
|
+
display "Usage: dh ps:add <web|mysql> <yes|no>"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def remove
|
118
|
+
@account.ps_remove
|
119
|
+
display "Successfully removed all pending private server requests"
|
120
|
+
end
|
121
|
+
|
122
|
+
def pending
|
123
|
+
pendings = @account.ps_pending
|
124
|
+
if pendings.empty?
|
125
|
+
display "You have no pending server creations"
|
126
|
+
else
|
127
|
+
pending_table = table do |t|
|
128
|
+
t.headings = 'Account', 'IP Address', 'Type', 'Time'
|
129
|
+
pendings.each { |p| t << [p["account_id"],p["ip"],p["type"],p["stamp"]]}
|
130
|
+
end
|
131
|
+
display pending_table
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Dreamy
|
2
|
+
class PrivateServer
|
3
|
+
include EasyClassMaker
|
4
|
+
|
5
|
+
attributes :account_id, :name, :type, :memory, :start_date
|
6
|
+
|
7
|
+
def self.new_from_xml(xml)
|
8
|
+
ps = new
|
9
|
+
ps.account_id = (xml).at('account_id').innerHTML.to_i
|
10
|
+
ps.name = (xml).at('ps').innerHTML
|
11
|
+
ps.type = (xml).at('type').innerHTML
|
12
|
+
ps.memory = (xml).at('memory_mb').innerHTML.to_i
|
13
|
+
ps.start_date = (xml).at('start_date').innerHTML
|
14
|
+
ps
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.settings_from_xml(xml)
|
18
|
+
settings = {}
|
19
|
+
(xml/:data).each do |d|
|
20
|
+
settings[(d).at('setting').innerHTML] = (d).at('value').innerHTML
|
21
|
+
end
|
22
|
+
settings
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.size_from_xml(xml)
|
26
|
+
size = {}
|
27
|
+
size["memory_mb"] = (xml).at('memory_mb').innerHTML.to_i
|
28
|
+
size["monthly_cost"] = (xml).at('monthly_cost').innerHTML.to_f
|
29
|
+
size["period_cost"] = (xml).at('period_cost').innerHTML.to_f
|
30
|
+
size["period_seconds"] = (xml).at('period_seconds').innerHTML.to_i
|
31
|
+
size["stamp"] = (xml).at('stamp').innerHTML
|
32
|
+
size
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.usage_from_xml(xml)
|
36
|
+
usage = {}
|
37
|
+
usage["load"] = (xml).at('load').innerHTML.to_f
|
38
|
+
usage["memory_mb"] = (xml).at('memory_mb').innerHTML.to_i
|
39
|
+
usage["stamp"] = (xml).at('stamp').innerHTML
|
40
|
+
usage
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.pending_from_xml(xml)
|
44
|
+
pending = {}
|
45
|
+
pending["account_id"] = (xml).at('account_id').innerHTML
|
46
|
+
pending["ip"] = (xml).at('ip').innerHTML
|
47
|
+
pending["type"] = (xml).at('type').innerHTML
|
48
|
+
pending["stamp"] = (xml).at('stamp').innerHTML
|
49
|
+
pending
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/test/base_test.rb
CHANGED
@@ -63,21 +63,21 @@ class DreamyBaseTest < Test::Unit::TestCase
|
|
63
63
|
end
|
64
64
|
|
65
65
|
context "removing a record" do
|
66
|
-
setup { @record_count = @@base.dns.size }
|
67
66
|
|
68
67
|
should "require 3 arguments" do
|
69
68
|
assert_raise(ArgumentError) { @@base.dns_remove("first","second") }
|
70
69
|
end
|
71
70
|
|
72
71
|
should "remove record and return true with valid data" do
|
72
|
+
record_count = @@base.dns.size
|
73
73
|
assert @@base.dns_remove("test." + CREDS["domain"],"A","208.97.188.35")
|
74
|
-
|
75
|
-
assert_equal @record_count, @@base.dns.size
|
74
|
+
assert_equal record_count - 1, @@base.dns.size
|
76
75
|
end
|
77
76
|
|
78
77
|
should "not remove record and raise error with invalid data" do
|
78
|
+
record_count = @@base.dns.size
|
79
79
|
assert_raise(Dreamy::ApiError) { @@base.dns_remove("test." + CREDS["domain"],"B","208.97.188.35") }
|
80
|
-
assert_equal
|
80
|
+
assert_equal record_count, @@base.dns.size
|
81
81
|
end
|
82
82
|
|
83
83
|
end
|
@@ -136,4 +136,78 @@ class DreamyBaseTest < Test::Unit::TestCase
|
|
136
136
|
|
137
137
|
end # announcement lists
|
138
138
|
|
139
|
+
context "Private Servers" do
|
140
|
+
setup { @ps = CREDS["ps"] }
|
141
|
+
|
142
|
+
should "return an array of PrivateServer objects" do
|
143
|
+
ps = @@base.ps
|
144
|
+
assert_kind_of Array, ps
|
145
|
+
assert_kind_of Dreamy::PrivateServer, ps.first unless ps.empty?
|
146
|
+
end
|
147
|
+
|
148
|
+
context "settings" do
|
149
|
+
|
150
|
+
should "return a hash of settings" do
|
151
|
+
settings = @@base.ps_settings(@ps)
|
152
|
+
assert_kind_of Hash, settings
|
153
|
+
end
|
154
|
+
|
155
|
+
should "require values for ps, setting, and value when setting value" do
|
156
|
+
assert_raise(ArgumentError) { @@base.ps_set() }
|
157
|
+
end
|
158
|
+
|
159
|
+
should "set specified setting" do
|
160
|
+
@@base.ps_set(@ps,'comment','testps')
|
161
|
+
settings = @@base.ps_settings(@ps)
|
162
|
+
assert_equal 'testps', settings['comment']
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
context "Size" do
|
168
|
+
|
169
|
+
should "return an array of size history hashes" do
|
170
|
+
sizes = @@base.ps_size_history(@ps)
|
171
|
+
assert_kind_of Array, sizes
|
172
|
+
assert_kind_of Hash, sizes.first
|
173
|
+
end
|
174
|
+
|
175
|
+
should "set new size" do
|
176
|
+
@@base.ps_size_set(@ps,"200")
|
177
|
+
assert_equal 200, @@base.ps_size_history(@ps).last["memory_mb"]
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
context "Rebooting" do
|
183
|
+
|
184
|
+
should "return an array of reboot time stamps" do
|
185
|
+
reboots = @@base.ps_reboot_history(@ps)
|
186
|
+
assert_kind_of Array, reboots
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
context "Usage" do
|
192
|
+
|
193
|
+
should "return array of usage hashes" do
|
194
|
+
usage = @@base.ps_usage(@ps)
|
195
|
+
assert_kind_of Array, usage
|
196
|
+
assert_kind_of Hash, usage.first
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
context "Pending requests" do
|
202
|
+
|
203
|
+
should "return array of pending hashes" do
|
204
|
+
pending = @@base.ps_pending
|
205
|
+
assert_kind_of Array, pending
|
206
|
+
assert_kind_of Hash, pending.first unless pending.empty?
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
139
213
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
|
+
|
3
|
+
class DreamyPrivateServerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Creation" do
|
6
|
+
setup do
|
7
|
+
@xml = <<EOF
|
8
|
+
<data>
|
9
|
+
<account_id>8675309</account_id>
|
10
|
+
<ps>ps10034</ps>
|
11
|
+
<type>web</type>
|
12
|
+
<memory_mb>200</memory_mb>
|
13
|
+
<start_date>2008-07-23</start_date>
|
14
|
+
</data>
|
15
|
+
EOF
|
16
|
+
end
|
17
|
+
|
18
|
+
should "create a new PS from xml" do
|
19
|
+
ps = Dreamy::PrivateServer.new_from_xml(Hpricot.XML(@xml))
|
20
|
+
assert_equal 8675309, ps.account_id
|
21
|
+
assert_equal "ps10034", ps.name
|
22
|
+
assert_equal "web", ps.type
|
23
|
+
assert_equal 200, ps.memory
|
24
|
+
assert_equal "2008-07-23", ps.start_date
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "Settings" do
|
29
|
+
setup do
|
30
|
+
@xml = <<EOF
|
31
|
+
<data>
|
32
|
+
<setting>apache2_enabled</setting>
|
33
|
+
<value>1</value>
|
34
|
+
</data>
|
35
|
+
<data>
|
36
|
+
<setting>comment</setting>
|
37
|
+
<value></value>
|
38
|
+
</data>
|
39
|
+
<data>
|
40
|
+
<setting>courier_enabled</setting>
|
41
|
+
<value>0</value>
|
42
|
+
</data>
|
43
|
+
<data>
|
44
|
+
<setting>jabber_transports_enabled</setting>
|
45
|
+
<value>1</value>
|
46
|
+
</data>
|
47
|
+
<data>
|
48
|
+
<setting>lighttpd_enabled</setting>
|
49
|
+
<value>0</value>
|
50
|
+
</data>
|
51
|
+
<data>
|
52
|
+
<setting>machine</setting>
|
53
|
+
<value>ps12345</value>
|
54
|
+
</data>
|
55
|
+
<data>
|
56
|
+
<setting>modphp_4_selected</setting>
|
57
|
+
<value>1</value>
|
58
|
+
</data>
|
59
|
+
<data>
|
60
|
+
<setting>php_cache_xcache</setting>
|
61
|
+
<value>0</value>
|
62
|
+
</data>
|
63
|
+
<data>
|
64
|
+
<setting>proftpd_enabled</setting>
|
65
|
+
<value>1</value>
|
66
|
+
</data>
|
67
|
+
<result>success</result>
|
68
|
+
EOF
|
69
|
+
end
|
70
|
+
|
71
|
+
should "create settings hash from xml" do
|
72
|
+
settings = Dreamy::PrivateServer.settings_from_xml(Hpricot.XML(@xml))
|
73
|
+
assert_equal "1", settings["apache2_enabled"]
|
74
|
+
assert_equal "", settings["comment"]
|
75
|
+
assert_equal "0", settings["courier_enabled"]
|
76
|
+
assert_equal "1", settings["jabber_transports_enabled"]
|
77
|
+
assert_equal "0", settings["lighttpd_enabled"]
|
78
|
+
assert_equal "ps12345", settings["machine"]
|
79
|
+
assert_equal "1", settings["modphp_4_selected"]
|
80
|
+
assert_equal "0", settings["php_cache_xcache"]
|
81
|
+
assert_equal "1", settings["proftpd_enabled"]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "Sizes" do
|
86
|
+
setup do
|
87
|
+
@xml = <<EOF
|
88
|
+
<data>
|
89
|
+
<memory_mb>2300</memory_mb>
|
90
|
+
<monthly_cost>0.00</monthly_cost>
|
91
|
+
<period_cost>0.0000</period_cost>
|
92
|
+
<period_seconds>715</period_seconds>
|
93
|
+
<stamp>2009-04-29 16:28:28</stamp>
|
94
|
+
</data>
|
95
|
+
EOF
|
96
|
+
end
|
97
|
+
|
98
|
+
should "create size hash from xml" do
|
99
|
+
size = Dreamy::PrivateServer.size_from_xml(Hpricot.XML(@xml))
|
100
|
+
assert_equal 2300, size["memory_mb"]
|
101
|
+
assert_equal 0.00, size["monthly_cost"]
|
102
|
+
assert_equal 0.0000, size["period_cost"]
|
103
|
+
assert_equal 715, size["period_seconds"]
|
104
|
+
assert_equal "2009-04-29 16:28:28", size["stamp"]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "Usage" do
|
109
|
+
setup do
|
110
|
+
@xml = <<EOF
|
111
|
+
<data>
|
112
|
+
<load>0.02</load>
|
113
|
+
<memory_mb>146</memory_mb>
|
114
|
+
<stamp>2009-05-02 17:26:44</stamp>
|
115
|
+
</data>
|
116
|
+
EOF
|
117
|
+
end
|
118
|
+
|
119
|
+
should "create usage hash from xml" do
|
120
|
+
usage = Dreamy::PrivateServer.usage_from_xml(Hpricot.XML(@xml))
|
121
|
+
assert_equal 0.02, usage["load"]
|
122
|
+
assert_equal 146, usage["memory_mb"]
|
123
|
+
assert_equal "2009-05-02 17:26:44", usage["stamp"]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "Pending servers" do
|
128
|
+
setup do
|
129
|
+
@xml = <<EOF
|
130
|
+
<data>
|
131
|
+
<account_id>8675309</account_id>
|
132
|
+
<ip>10.5.3.2</ip>
|
133
|
+
<type>web</type>
|
134
|
+
<stamp>2009-03-12 06:43:48</stamp>
|
135
|
+
</data>
|
136
|
+
EOF
|
137
|
+
end
|
138
|
+
|
139
|
+
should "create pending server hash from xml" do
|
140
|
+
pending = Dreamy::PrivateServer.pending_from_xml(Hpricot.XML(@xml))
|
141
|
+
assert_equal "8675309", pending["account_id"]
|
142
|
+
assert_equal "10.5.3.2", pending["ip"]
|
143
|
+
assert_equal "2009-03-12 06:43:48", pending["stamp"]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
data/test/user_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sant0sk1-dreamy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerod Santo
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-02 00:00:00 -07:00
|
13
13
|
default_executable: dh
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -64,17 +64,20 @@ files:
|
|
64
64
|
- lib/dreamy/commands/dns.rb
|
65
65
|
- lib/dreamy/commands/domains.rb
|
66
66
|
- lib/dreamy/commands/help.rb
|
67
|
+
- lib/dreamy/commands/ps.rb
|
67
68
|
- lib/dreamy/commands/users.rb
|
68
69
|
- lib/dreamy/core_extensions.rb
|
69
70
|
- lib/dreamy/dns.rb
|
70
71
|
- lib/dreamy/domain.rb
|
71
72
|
- lib/dreamy/easy_class_maker.rb
|
73
|
+
- lib/dreamy/private_server.rb
|
72
74
|
- lib/dreamy/subscriber.rb
|
73
75
|
- lib/dreamy/user.rb
|
74
76
|
- test/announce_test.rb
|
75
77
|
- test/base_test.rb
|
76
78
|
- test/dns_test.rb
|
77
79
|
- test/domain_test.rb
|
80
|
+
- test/private_server_test.rb
|
78
81
|
- test/subscriber_test.rb
|
79
82
|
- test/test_helper.rb
|
80
83
|
- test/user_test.rb
|
@@ -109,6 +112,7 @@ test_files:
|
|
109
112
|
- test/base_test.rb
|
110
113
|
- test/dns_test.rb
|
111
114
|
- test/domain_test.rb
|
115
|
+
- test/private_server_test.rb
|
112
116
|
- test/subscriber_test.rb
|
113
117
|
- test/test_helper.rb
|
114
118
|
- test/user_test.rb
|