Skip to content

Commit

Permalink
Add option to provide specific ip for add_ip
Browse files Browse the repository at this point in the history
  • Loading branch information
mzahir committed Apr 14, 2014
1 parent e498676 commit 4f48743
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/solusvm/cli/server_cli.rb
Expand Up @@ -56,9 +56,9 @@ def change_hostname(vserverid, newhostname)
output api.change_hostname(vserverid, newhostname)
end

desc "addip VSERVERID", "Adds an ip to the server"
def addip(vserverid)
output api.add_ip(vserverid)
desc "addip VSERVERID [ip]", "Adds an ip to the server"
def addip(vserverid, ip = nil)
output api.add_ip(vserverid, ip)
end

desc "boot VSERVERID", "Boots up a server"
Expand Down
5 changes: 3 additions & 2 deletions lib/solusvm/server.rb
Expand Up @@ -170,10 +170,11 @@ def status(vid)
# Public: Adds an IP address for a specific server.
#
# vid - The virtual server ID in SolusVM
# ip - Specific IPv4 address to add (optional)
#
# Returns the IP as a String.
def add_ip(vid)
perform_request(action: 'vserver-addip', vserverid: vid)
def add_ip(vid, ip = nil)
perform_request(action: 'vserver-addip', vserverid: vid, ipv4addr: ip)
returned_parameters['ipaddress']
end

Expand Down
4 changes: 2 additions & 2 deletions test/cli/test_server_cli.rb
Expand Up @@ -97,11 +97,11 @@ def test_should_delegate_server_change_hostname_to_server
def test_should_delegate_server_add_ip_to_server
SolusVM::Server.stubs(:new).with(@solusvm_params).returns(mock do
expects(:successful?).returns(true)
expects(:add_ip).with("thevserverid").returns("theresult")
expects(:add_ip).with("thevserverid", "ipv4addr").returns("theresult")
end)

out = capture_stdout do
SolusVM::CLI.start(cli_expand_base_arguments(["server", "addip", "thevserverid"]))
SolusVM::CLI.start(cli_expand_base_arguments(["server", "addip", "thevserverid", "ipv4addr"]))
end
assert_match "theresult", out.string
end
Expand Down
7 changes: 7 additions & 0 deletions test/solusvm/test_server.rb
Expand Up @@ -146,6 +146,13 @@ def test_add_ip
assert @server.successful?
end

def test_add_specific_ip
stub_response 'server/add-ip'

assert_equal '123.123.123.123', @server.add_ip(1, '123.123.123.123')
assert @server.successful?
end

def test_del_ip
stub_response 'server/del-ip'

Expand Down

0 comments on commit 4f48743

Please sign in to comment.