Skip to content

Commit

Permalink
set private server memory size
Browse files Browse the repository at this point in the history
  • Loading branch information
jerodsanto committed May 3, 2009
1 parent 98f303a commit 4183b79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/dreamy/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,17 @@ def ps_set(name,setting,value)
true
end

def ps_sizes(name)
def ps_size_history(name)
doc = request("dreamhost_ps-list_size_history", {"ps" => name})
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
(doc/:data).inject([]) { |sizes, size| sizes << PrivateServer.size_from_xml(size); sizes }
end

def ps_size_set(name,size)
doc = request("dreamhost_ps-set_size", {"ps" => name, "size" => size })
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
true
end

private

Expand Down
11 changes: 8 additions & 3 deletions lib/dreamy/commands/ps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ def set
end

def size
if args.length == 1
sizes = @account.ps_sizes(args[0])
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]"
display "Usage: dh ps:size [ps name] [new size (optional)]"
end
end

Expand Down
7 changes: 6 additions & 1 deletion test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,16 @@ class DreamyBaseTest < Test::Unit::TestCase
context "Size" do

should "return an array of size history hashes" do
sizes = @@base.ps_sizes(@ps)
sizes = @@base.ps_size_history(@ps)
assert_kind_of Array, sizes
assert_kind_of Hash, sizes.first
end

should "set new size" do
@@base.ps_size_set(@ps,"200")
assert_equal 200, @@base.ps_size_history(@ps).last["memory_mb"]
end

end

end
Expand Down

0 comments on commit 4183b79

Please sign in to comment.