Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional parameters to server#console #48

Merged
merged 1 commit into from
Aug 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/solusvm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def perform_request(options = {}, force_array = false)
ca_path = File.join(File.dirname(__FILE__), "..", "cacert.pem")
ssl = {verify: true, ca_file: File.expand_path(ca_path)}

options.reject! {|_,v| v.nil? }

response = Faraday.new(url: api_endpoint, ssl: ssl) do |c|
c.params = options.merge(api_login)
c.adapter :net_http
Expand Down
12 changes: 9 additions & 3 deletions lib/solusvm/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,17 @@ def vnc(vid)
end

# Retrieves server console information.
def console(vid)
perform_request(action: 'vserver-console', vserverid: vid)
#
# params - A Hash to pass optional parameters to vserver-console call:
# :access - A String that can be 'enable' or 'disable'
# :time - A Integer that can be 1|2|3|4|5|6|7|8
#
# returns a Hash
def console(vid, params = {})
perform_request(action: 'vserver-console', vserverid: vid, access: params[:access], time: params[:time])
returned_parameters
end

# Retrieves all available server information.
def info_all(vid)
perform_request(action: 'vserver-infoall', vserverid: vid)
Expand Down
7 changes: 7 additions & 0 deletions test/solusvm/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ def test_console
assert_equal 'theconsoleport', info['consoleport']
assert_equal 'theconsolepassword', info['consolepassword']
assert_equal 'theconsoleusername', info['consoleusername']

# with the optional parameters
VCR.use_cassette "server/console" do
@server.console(1, access: "admin", time: 1)
end
# a check to see if it returned a expected parameter even with the optional parameter
assert_equal 'thetype', @server.returned_parameters['type']
end

def test_info_all
Expand Down
13 changes: 13 additions & 0 deletions test/vcr_cassettes/server/console.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/vcr_cassettes/server/create.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.