cloudstack_client 1.5.10 → 1.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/Gemfile.lock +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +18 -1
- data/lib/cloudstack_client/client.rb +3 -2
- data/lib/cloudstack_client/connection.rb +18 -8
- data/lib/cloudstack_client/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 58ccc2b4e84e160367f416922cc1489c7344c4e64c5fd5b047d91a5c6cedebb3
|
|
4
|
+
data.tar.gz: e55008e191421c0cbf993e7c51d25d9a1638c39322f97db97eb583e4925aef0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 718ddbe8ed71342f2a2067497c71863c0407722bed849aed2e1061978ecbd6440bacedc4c3f20fcd5f0c395e969ab664f4d8d63afbebd381fe51eb5d5d3d38c9
|
|
7
|
+
data.tar.gz: 2f67eab635a6a61bae7df757bde727d2d4ccaa03f3b2a654dccea02e7fab0069913f7faef5924be50bc4a0037164119e4c36aedb9854c63d8db327df2c255d29
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
cloudstack_client (1.5.
|
|
4
|
+
cloudstack_client (1.5.11)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
9
|
bond (0.5.1)
|
|
10
|
-
minitest (5.
|
|
11
|
-
rake (13.
|
|
10
|
+
minitest (5.27.0)
|
|
11
|
+
rake (13.3.1)
|
|
12
12
|
ripl (0.7.1)
|
|
13
13
|
bond (~> 0.5.1)
|
|
14
|
-
thor (1.
|
|
14
|
+
thor (1.5.0)
|
|
15
15
|
|
|
16
16
|
PLATFORMS
|
|
17
17
|
x86_64-linux
|
|
@@ -24,4 +24,4 @@ DEPENDENCIES
|
|
|
24
24
|
thor (~> 1.1)
|
|
25
25
|
|
|
26
26
|
BUNDLED WITH
|
|
27
|
-
2.
|
|
27
|
+
2.6.9
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -68,6 +68,21 @@ cs = CloudstackClient::Client.new(
|
|
|
68
68
|
)
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
### Pagination and Response Options
|
|
72
|
+
|
|
73
|
+
When working with paginated responses, you can include the total count in the API response:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
# Get paginated results with count information
|
|
77
|
+
vms = cs.list_virtual_machines({ page: 1, pagesize: 10 }, { include_count: true })
|
|
78
|
+
total_count = vms[:count]
|
|
79
|
+
items = vms[:virtualmachine]
|
|
80
|
+
|
|
81
|
+
# Default behavior (without count)
|
|
82
|
+
vms = cs.list_virtual_machines(page: 1, pagesize: 10)
|
|
83
|
+
# Returns just the items array
|
|
84
|
+
```
|
|
85
|
+
|
|
71
86
|
### Using the configuration module
|
|
72
87
|
|
|
73
88
|
The configuration module of CloudstackClient makes it easy to load CloudStack API settings from configuration files.
|
|
@@ -105,13 +120,15 @@ test:
|
|
|
105
120
|
```
|
|
106
121
|
|
|
107
122
|
### Configuration options
|
|
123
|
+
|
|
108
124
|
You can pass `options` as 4th argument in `CloudstackClient::Client.new`. All its keys are optional.
|
|
109
125
|
|
|
110
126
|
```ruby
|
|
111
127
|
options = {
|
|
112
128
|
symbolize_keys: true, # pass symbolize_names: true in JSON#parse for Cloudstack responses, default: false
|
|
113
129
|
host: 'localhost', # custom host header to be used in Net::Http. May be useful when Cloudstack is set up locally via docker (i.e. Cloudstack-simulator), default: parsed from config[:url] via Net::Http
|
|
114
|
-
read_timeout: 10 # timeout in seconds of a connection to the Cloudstack, default: 60
|
|
130
|
+
read_timeout: 10, # timeout in seconds of a connection to the Cloudstack, default: 60
|
|
131
|
+
request_retries: 3 # number of attempts for HTTP requests before raising a ConnectionError, default: 1 (no retries). Uses incremental back-off between attempts.
|
|
115
132
|
}
|
|
116
133
|
cs = CloudstackClient::Client.new(config[:url], config[:api_key], config[:secret_key], options)
|
|
117
134
|
```
|
|
@@ -34,10 +34,11 @@ module CloudstackClient
|
|
|
34
34
|
raise ParameterError, @api.missing_params_msg(command["name"])
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
|
|
37
38
|
if command["isasync"] == false || options[:sync]
|
|
38
|
-
send_request(params)
|
|
39
|
+
send_request(params, options)
|
|
39
40
|
else
|
|
40
|
-
send_async_request(params)
|
|
41
|
+
send_async_request(params, options)
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
end
|
|
@@ -10,11 +10,12 @@ module CloudstackClient
|
|
|
10
10
|
include Utils
|
|
11
11
|
|
|
12
12
|
attr_accessor :api_url, :api_key, :secret_key, :verbose, :debug, :symbolize_keys, :host, :read_timeout
|
|
13
|
-
attr_accessor :async_poll_interval, :async_timeout
|
|
13
|
+
attr_accessor :async_poll_interval, :async_timeout, :request_retries
|
|
14
14
|
|
|
15
15
|
DEF_POLL_INTERVAL = 2.0
|
|
16
16
|
DEF_ASYNC_TIMEOUT = 400
|
|
17
17
|
DEF_REQ_TIMEOUT = 60
|
|
18
|
+
DEF_REQUEST_RETRIES = 1
|
|
18
19
|
|
|
19
20
|
def initialize(api_url, api_key, secret_key, options = {})
|
|
20
21
|
@api_url = api_url
|
|
@@ -27,6 +28,7 @@ module CloudstackClient
|
|
|
27
28
|
@read_timeout = options[:read_timeout] || DEF_REQ_TIMEOUT
|
|
28
29
|
@async_poll_interval = options[:async_poll_interval] || DEF_POLL_INTERVAL
|
|
29
30
|
@async_timeout = options[:async_timeout] || DEF_ASYNC_TIMEOUT
|
|
31
|
+
@request_retries = options[:request_retries] || DEF_REQUEST_RETRIES
|
|
30
32
|
@options = options
|
|
31
33
|
validate_input!
|
|
32
34
|
end
|
|
@@ -35,7 +37,7 @@ module CloudstackClient
|
|
|
35
37
|
# Sends a synchronous request to the CloudStack API and returns the response as a Hash.
|
|
36
38
|
#
|
|
37
39
|
|
|
38
|
-
def send_request(params)
|
|
40
|
+
def send_request(params, opts = {})
|
|
39
41
|
params['response'] = 'json'
|
|
40
42
|
params['apiKey'] = @api_key
|
|
41
43
|
print_debug_output JSON.pretty_generate(params) if @debug
|
|
@@ -50,12 +52,19 @@ module CloudstackClient
|
|
|
50
52
|
end
|
|
51
53
|
http.read_timeout = @read_timeout
|
|
52
54
|
|
|
55
|
+
retries = 0
|
|
53
56
|
begin
|
|
54
57
|
req = Net::HTTP::Get.new(uri.request_uri)
|
|
55
58
|
req['Host'] = host if host.present?
|
|
56
59
|
response = http.request(req)
|
|
57
|
-
rescue
|
|
58
|
-
|
|
60
|
+
rescue => e
|
|
61
|
+
retries += 1
|
|
62
|
+
if retries < @request_retries
|
|
63
|
+
sleep(retries) # incremental back-off
|
|
64
|
+
print "." if @verbose
|
|
65
|
+
retry
|
|
66
|
+
end
|
|
67
|
+
raise ConnectionError, "API URL \'#{@api_url}\' is not reachable (after #{retries} attempt#{'s' if retries > 1}): #{e.message}"
|
|
59
68
|
end
|
|
60
69
|
|
|
61
70
|
begin
|
|
@@ -68,12 +77,12 @@ module CloudstackClient
|
|
|
68
77
|
if response.is_a?(Net::HTTPOK)
|
|
69
78
|
return body unless body.respond_to?(:keys)
|
|
70
79
|
if body.size == 2 && body.key?(k('count'))
|
|
71
|
-
return body.reject { |key, _| key == k('count') }.values.first
|
|
80
|
+
return opts[:include_count] ? body : body.reject { |key, _| key == k('count') }.values.first
|
|
72
81
|
elsif body.size == 1 && body.values.first.respond_to?(:keys)
|
|
73
82
|
item = body.values.first
|
|
74
83
|
return (item.is_a?(Array) || item.is_a?(Hash)) ? item : []
|
|
75
84
|
else
|
|
76
|
-
body.reject! { |key, _| key == k('count') } if body.key?(k('count'))
|
|
85
|
+
body.reject! { |key, _| key == k('count') } if body.key?(k('count')) && !opts[:include_count]
|
|
77
86
|
body.size == 0 ? [] : body
|
|
78
87
|
end
|
|
79
88
|
else
|
|
@@ -87,8 +96,8 @@ module CloudstackClient
|
|
|
87
96
|
#
|
|
88
97
|
# The contents of the 'jobresult' element are returned upon completion of the command.
|
|
89
98
|
|
|
90
|
-
def send_async_request(params)
|
|
91
|
-
data = send_request(params)
|
|
99
|
+
def send_async_request(params, opts = {})
|
|
100
|
+
data = send_request(params, opts)
|
|
92
101
|
|
|
93
102
|
params = {
|
|
94
103
|
'command' => 'queryAsyncJobResult',
|
|
@@ -121,6 +130,7 @@ module CloudstackClient
|
|
|
121
130
|
raise InputError, "API SECRET KEY not set." if @secret_key == nil
|
|
122
131
|
raise InputError, "ASYNC POLL INTERVAL must be at least 1." if @async_poll_interval < 1.0
|
|
123
132
|
raise InputError, "ASYNC TIMEOUT must be at least 60." if @async_timeout < 60
|
|
133
|
+
raise InputError, "REQUEST RETRIES must be at least 1." if @request_retries < 1
|
|
124
134
|
end
|
|
125
135
|
|
|
126
136
|
def params_to_data(params)
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cloudstack_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.5.
|
|
4
|
+
version: 1.5.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nik Wolfgramm
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rake
|
|
@@ -106,7 +105,6 @@ homepage: https://github.com/niwo/cloudstack_client
|
|
|
106
105
|
licenses:
|
|
107
106
|
- MIT
|
|
108
107
|
metadata: {}
|
|
109
|
-
post_install_message:
|
|
110
108
|
rdoc_options:
|
|
111
109
|
- "--line-numbers"
|
|
112
110
|
- "--inline-source"
|
|
@@ -123,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
121
|
- !ruby/object:Gem::Version
|
|
124
122
|
version: '0'
|
|
125
123
|
requirements: []
|
|
126
|
-
rubygems_version: 3.
|
|
127
|
-
signing_key:
|
|
124
|
+
rubygems_version: 3.6.9
|
|
128
125
|
specification_version: 4
|
|
129
126
|
summary: CloudStack API client written in Ruby
|
|
130
127
|
test_files:
|