Class: CloudstackClient::Connection
- Inherits:
-
Object
- Object
- CloudstackClient::Connection
- Includes:
- RequestHandling, Utils
- Defined in:
- lib/cloudstack_client/connection.rb
Direct Known Subclasses
Constant Summary collapse
- DEF_POLL_INTERVAL =
2.0- DEF_ASYNC_TIMEOUT =
400- DEF_REQ_TIMEOUT =
60- DEF_REQUEST_RETRIES =
1
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#async_poll_interval ⇒ Object
Returns the value of attribute async_poll_interval.
-
#async_timeout ⇒ Object
Returns the value of attribute async_timeout.
-
#ca_file ⇒ Object
Returns the value of attribute ca_file.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#host ⇒ Object
Returns the value of attribute host.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#request_retries ⇒ Object
Returns the value of attribute request_retries.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#symbolize_keys ⇒ Object
Returns the value of attribute symbolize_keys.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
Instance Method Summary collapse
-
#initialize(api_url, api_key, secret_key, options = {}) ⇒ Connection
constructor
A new instance of Connection.
-
#send_async_request(params, opts = {}) ⇒ Object
Sends an asynchronous request and waits for the response.
Methods included from RequestHandling
Methods included from Utils
#camel_case_to_underscore, #print_debug_output, #underscore_to_camel_case
Constructor Details
#initialize(api_url, api_key, secret_key, options = {}) ⇒ Connection
Returns a new instance of Connection.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cloudstack_client/connection.rb', line 24 def initialize(api_url, api_key, secret_key, = {}) @api_url = api_url @api_key = api_key @secret_key = secret_key @verbose = [:quiet] ? false : true @debug = [:debug] ? true : false @symbolize_keys = [:symbolize_keys] ? true : false @host = [:host] @verify_ssl = .fetch(:verify_ssl, true) @ca_file = [:ca_file] @read_timeout = [:read_timeout] || DEF_REQ_TIMEOUT @async_poll_interval = [:async_poll_interval] || DEF_POLL_INTERVAL @async_timeout = [:async_timeout] || DEF_ASYNC_TIMEOUT @request_retries = [:request_retries] || DEF_REQUEST_RETRIES @options = validate_input! end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
14 15 16 |
# File 'lib/cloudstack_client/connection.rb', line 14 def api_key @api_key end |
#api_url ⇒ Object
Returns the value of attribute api_url.
15 16 17 |
# File 'lib/cloudstack_client/connection.rb', line 15 def api_url @api_url end |
#async_poll_interval ⇒ Object
Returns the value of attribute async_poll_interval.
17 18 19 |
# File 'lib/cloudstack_client/connection.rb', line 17 def async_poll_interval @async_poll_interval end |
#async_timeout ⇒ Object
Returns the value of attribute async_timeout.
17 18 19 |
# File 'lib/cloudstack_client/connection.rb', line 17 def async_timeout @async_timeout end |
#ca_file ⇒ Object
Returns the value of attribute ca_file.
16 17 18 |
# File 'lib/cloudstack_client/connection.rb', line 16 def ca_file @ca_file end |
#debug ⇒ Object
Returns the value of attribute debug.
15 16 17 |
# File 'lib/cloudstack_client/connection.rb', line 15 def debug @debug end |
#host ⇒ Object
Returns the value of attribute host.
15 16 17 |
# File 'lib/cloudstack_client/connection.rb', line 15 def host @host end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
15 16 17 |
# File 'lib/cloudstack_client/connection.rb', line 15 def read_timeout @read_timeout end |
#request_retries ⇒ Object
Returns the value of attribute request_retries.
17 18 19 |
# File 'lib/cloudstack_client/connection.rb', line 17 def request_retries @request_retries end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
14 15 16 |
# File 'lib/cloudstack_client/connection.rb', line 14 def secret_key @secret_key end |
#symbolize_keys ⇒ Object
Returns the value of attribute symbolize_keys.
15 16 17 |
# File 'lib/cloudstack_client/connection.rb', line 15 def symbolize_keys @symbolize_keys end |
#verbose ⇒ Object
Returns the value of attribute verbose.
15 16 17 |
# File 'lib/cloudstack_client/connection.rb', line 15 def verbose @verbose end |
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
16 17 18 |
# File 'lib/cloudstack_client/connection.rb', line 16 def verify_ssl @verify_ssl end |
Instance Method Details
#send_async_request(params, opts = {}) ⇒ Object
Sends an asynchronous request and waits for the response.
The contents of the 'jobresult' element are returned upon completion of the command.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cloudstack_client/connection.rb', line 51 def send_async_request(params, opts = {}) request_timeout = opts[:async_timeout] || @async_timeout poll_interval = opts[:async_poll_interval] || @async_poll_interval validate_async_timeouts!(request_timeout, poll_interval) data = send_request(params, opts) params = { 'command' => 'queryAsyncJobResult', 'jobid' => data[k('jobid')] } max_tries(request_timeout, poll_interval).times do data = send_request(params) print "." if @verbose case data[k('jobstatus')] when 1 return data[k('jobresult')] when 2 result = data[k('jobresult')] error_text = result.is_a?(Hash) ? result[k('errortext')] : nil error_text ||= "Unknown error" raise JobError, "Request failed (#{data[k('jobresultcode')]}): #{error_text}." end STDOUT.flush if @verbose sleep poll_interval end raise TimeoutError, "Asynchronous request timed out." end |