Class: Dreamy::Command::Ps
- Inherits:
-
Base
- Object
- Base
- Dreamy::Command::Ps
show all
- Defined in:
- lib/dreamy/commands/ps.rb
Instance Method Summary
collapse
Methods inherited from Base
#announce_add, #announce_list, #announce_lists, #announce_post, #announce_remove, #dns, #dns_add, #dns_remove, #domains, #initialize, #mail_add_filter, #mail_list_filters, #mail_remove_filter, #mysql_dbs, #mysql_hosts, #mysql_users, #ps, #ps_add, #ps_pending, #ps_reboot!, #ps_reboot_history, #ps_remove, #ps_set, #ps_settings, #ps_size_history, #ps_size_set, #ps_usage, #users
Constructor Details
This class inherits a constructor from Dreamy::Base
Instance Method Details
#add ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/dreamy/commands/ps.rb', line 99
def add
case args.length
when 1
if args[0] == "web"
display "you must specify 'yes' or 'no' for whether or not to move data to new server"
else
@account.ps_add(args[0])
display "Successfully requested new private mysql server"
end
when 2
type, move = args[0], args[1]
@account.ps_add(type,move)
display "Successfully requested new private server"
else
display "Usage: dh ps:add <web|mysql> <yes|no>"
end
end
|
#list ⇒ Object
Also known as:
index
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/dreamy/commands/ps.rb', line 4
def list
servers = @account.ps
if servers.empty?
display "No private servers for this account"
else
servers_table = table do |t|
t.headings = 'Name', 'Type', 'Memory (MB)', 'Start Date'
servers.each { |ps| t << [ps.name,ps.type,ps.memory,ps.start_date] }
end
display servers_table
end
end
|
#pending ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/dreamy/commands/ps.rb', line 122
def pending
pendings = @account.ps_pending
if pendings.empty?
display "You have no pending server creations"
else
pending_table = table do |t|
t.headings = 'Account', 'IP Address', 'Type', 'Time'
pendings.each { |p| t << [p["account_id"],p["ip"],p["type"],p["stamp"]]}
end
display pending_table
end
end
|
#reboot ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/dreamy/commands/ps.rb', line 73
def reboot
if args.length == 2
if args[1] == "now!"
@account.ps_reboot!(args[0])
display "Successfully sent reboot command for #{args[0]}"
else
display "Are you sure?? If yes, finish the command with 'now!'"
end
else
display "Usage: dh ps:reboot [ps name] now! (WARNING: this will reboot your server)"
end
end
|
#reboots ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/dreamy/commands/ps.rb', line 60
def reboots
if args.length == 1
reboots = @account.ps_reboot_history(args[0])
reboots_table = table do |t|
t.headings = 'Count', 'Reboot Time'
reboots.each_with_index { |r,i| t << [i + 1,r] }
end
display reboots_table
else
display "Usage: dh ps:reboots [ps name]"
end
end
|
#remove ⇒ Object
117
118
119
120
|
# File 'lib/dreamy/commands/ps.rb', line 117
def remove
@account.ps_remove
display "Successfully removed all pending private server requests"
end
|
#set ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/dreamy/commands/ps.rb', line 32
def set
if args.length == 3
name, setting, value = args[0], args[1], args[2]
@account.ps_set(name,setting,value)
display "Successfully set #{setting} to #{value} for #{name}"
else
display "Usage: dh ps:set [ps name] [setting] [value]"
end
end
|
#settings ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/dreamy/commands/ps.rb', line 19
def settings
if args.length == 1
settings = @account.ps_settings(args[0])
settings_table = table do |t|
t.headings = 'Setting', 'Value'
settings.each { |k,v| t << [k,v] }
end
display settings_table
else
display "Usage: dh ps:settings [ps name]"
end
end
|
#size ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/dreamy/commands/ps.rb', line 42
def size
case args.length
when 1
sizes = @account.ps_size_history(args[0])
sizes_table = table do |t|
t.headings = 'Time', 'Memory (MB)', 'Duration (Seconds)', 'Cost (Period)', 'Cost (Monthly)'
sizes.each { |s| t << [s["stamp"],s["memory_mb"],s["period_seconds"],s["period_cost"],s["monthy_cost"]] }
end
display sizes_table
when 2
name, new_size = args[0], args[1]
@account.ps_size_set(name,new_size)
display "Successfully set memory size to #{new_size} for #{name}"
else
display "Usage: dh ps:size [ps name] [new size (optional)]"
end
end
|
#usage ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/dreamy/commands/ps.rb', line 86
def usage
if args.length == 1
usages = @account.ps_usage(args[0])
usage_table = table do |t|
t.headings = 'Time', 'Memory (MB)', 'CPU Load'
usages.each { |u| t << [u["stamp"], u["memory_mb"],u["load"]] }
end
display usage_table
else
display "Usage: dh ps:usage [ps name]"
end
end
|