cloudstack_client 1.5.8 → 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile.lock +5 -5
- data/README.md +42 -24
- data/lib/cloudstack_client/connection.rb +25 -13
- data/lib/cloudstack_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a0a4ca31c3cfcee330c0f72ca9d0fa9895788cfb5718e3499181abdc7564df1
|
4
|
+
data.tar.gz: 688112d58736d2ada94c993f271eda18a923308fc94bcd93bad2775d193506b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d2e11bbf05fa22573de42450b49015bbeabfdf29dfe2ba49701c815bc3e6f0d6f1b35fadc72dca3f3ca8ff803fbe08b37e9320b961050d1e526e1803e45b307
|
7
|
+
data.tar.gz: bd6003fb8f3f82c4a07f548608d927eed95d17a051a0134c2bee061eea6562d9df94caca8c5549a01e0eeccb55ee6f0ec7076140c8d9744c4a2794e8addb3c1a
|
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.9)
|
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.24.1)
|
11
|
+
rake (13.2.1)
|
12
12
|
ripl (0.7.1)
|
13
13
|
bond (~> 0.5.1)
|
14
|
-
thor (1.1
|
14
|
+
thor (1.3.1)
|
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.3.14
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# cloudstack_client
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/cloudstack_client.png)](http://badge.fury.io/rb/cloudstack_client)
|
4
|
-
[![Build Status](https://travis-ci.
|
4
|
+
[![Build Status](https://travis-ci.com/niwo/cloudstack_client.svg?branch=master)](https://travis-ci.com/niwo/cloudstack_client)
|
5
5
|
|
6
6
|
A CloudStack API client written in Ruby.
|
7
7
|
|
@@ -14,12 +14,14 @@ $ gem install cloudstack_client
|
|
14
14
|
```
|
15
15
|
|
16
16
|
## Features
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
|
18
|
+
- Access to the whole CloudStack-API from Ruby
|
19
|
+
- Interactive console for playing with the CloudStack API: ```cloudstack_client console```
|
20
|
+
- Dynamically builds API methods based on the listApis function of CloudStack
|
21
|
+
- Command names are converted to match Ruby naming conventions (i.e. ListVirtualMachines becomes list_virtual_machines)
|
22
|
+
- Accepts Ruby Hash arguments passed to commands as options (i.e. list_all: true becomes listall=true)
|
23
|
+
- Assure all required arguments are passed
|
24
|
+
- Removes unsupported arguments and arguments with nil values from commands
|
23
25
|
|
24
26
|
## Usage
|
25
27
|
|
@@ -41,7 +43,7 @@ end
|
|
41
43
|
|
42
44
|
### Advanced Options
|
43
45
|
|
44
|
-
|
46
|
+
Load API definition file from an alternative path and set the version:
|
45
47
|
|
46
48
|
```ruby
|
47
49
|
cs = CloudstackClient::Client.new(
|
@@ -50,26 +52,27 @@ cs = CloudstackClient::Client.new(
|
|
50
52
|
"SECRET_KEY",
|
51
53
|
{
|
52
54
|
api_path: "~/cloudstack",
|
53
|
-
api_version: "4.
|
55
|
+
api_version: "4.15"
|
54
56
|
}
|
55
57
|
)
|
56
58
|
```
|
57
59
|
|
58
|
-
|
60
|
+
...or load the API definition directly from a file:
|
59
61
|
|
60
62
|
```ruby
|
61
63
|
cs = CloudstackClient::Client.new(
|
62
64
|
"https://cloudstack.local/client/api",
|
63
65
|
"API_KEY",
|
64
66
|
"API_SECRET",
|
65
|
-
{ api_file: "~/cloudstack/4.
|
67
|
+
{ api_file: "~/cloudstack/4.15.json.gz" }
|
66
68
|
)
|
67
69
|
```
|
68
70
|
|
69
71
|
### Using the configuration module
|
70
72
|
|
71
|
-
The
|
72
|
-
|
73
|
+
The configuration module of CloudstackClient makes it easy to load CloudStack API settings from configuration files.
|
74
|
+
|
75
|
+
#### Example
|
73
76
|
|
74
77
|
```ruby
|
75
78
|
require "cloudstack_client"
|
@@ -80,7 +83,9 @@ config = CloudstackClient::Configuration.load
|
|
80
83
|
cs = CloudstackClient::Client.new(config[:url], config[:api_key], config[:secret_key])
|
81
84
|
```
|
82
85
|
|
83
|
-
|
86
|
+
#### Configuration files
|
87
|
+
|
88
|
+
Configuration files support multiple environments (i.e. `~/.cloudstack.yml`):
|
84
89
|
|
85
90
|
```yaml
|
86
91
|
# default environment
|
@@ -99,11 +104,23 @@ test:
|
|
99
104
|
:secret_key: "cloudstack-api-secret"
|
100
105
|
```
|
101
106
|
|
107
|
+
### Configuration options
|
108
|
+
You can pass `options` as 4th argument in `CloudstackClient::Client.new`. All its keys are optional.
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
options = {
|
112
|
+
symbolize_keys: true, # pass symbolize_names: true in JSON#parse for Cloudstack responses, default: false
|
113
|
+
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
|
115
|
+
}
|
116
|
+
cs = CloudstackClient::Client.new(config[:url], config[:api_key], config[:secret_key], options)
|
117
|
+
```
|
118
|
+
|
102
119
|
### Interactive Console
|
103
120
|
|
104
|
-
cloudstack_client comes with an interactive
|
121
|
+
cloudstack_client comes with an interactive console.
|
105
122
|
|
106
|
-
|
123
|
+
#### Example
|
107
124
|
|
108
125
|
```bash
|
109
126
|
$ cloudstack_client console -e prod
|
@@ -112,20 +129,21 @@ prod >> list_virtual_machines
|
|
112
129
|
|
113
130
|
## Development
|
114
131
|
|
115
|
-
### Generate
|
132
|
+
### Generate or update API definitions
|
116
133
|
|
117
|
-
New API
|
134
|
+
New API definitions can be generated using the `list_apis` command.
|
118
135
|
|
119
|
-
|
136
|
+
#### Example
|
120
137
|
|
121
138
|
```bash
|
122
|
-
# running against
|
123
|
-
$ cloudstack_client list_apis > data/4.
|
124
|
-
$ gzip data/4.
|
139
|
+
# running against a CloudStack 4.15 API endpoint:
|
140
|
+
$ cloudstack_client list_apis > data/4.15.json
|
141
|
+
$ gzip data/4.15.json
|
125
142
|
```
|
126
143
|
|
127
144
|
## References
|
128
|
-
|
145
|
+
|
146
|
+
- [Apache CloudStack API documentation](http://cloudstack.apache.org/api/apidocs-4.15/)
|
129
147
|
|
130
148
|
## Contributing
|
131
149
|
|
@@ -137,6 +155,6 @@ $ gzip data/4.5.json
|
|
137
155
|
|
138
156
|
## License
|
139
157
|
|
140
|
-
Copyright (c) 2014-
|
158
|
+
Copyright (c) 2014-2021, Nik Wolfgramm
|
141
159
|
|
142
160
|
Released under the MIT License. See the [LICENSE](https://raw.github.com/niwo/cloudstack_client/master/LICENSE.txt) file for further details.
|
@@ -9,11 +9,12 @@ module CloudstackClient
|
|
9
9
|
class Connection
|
10
10
|
include Utils
|
11
11
|
|
12
|
-
attr_accessor :api_url, :api_key, :secret_key, :verbose, :debug
|
12
|
+
attr_accessor :api_url, :api_key, :secret_key, :verbose, :debug, :symbolize_keys, :host, :read_timeout
|
13
13
|
attr_accessor :async_poll_interval, :async_timeout
|
14
14
|
|
15
15
|
DEF_POLL_INTERVAL = 2.0
|
16
16
|
DEF_ASYNC_TIMEOUT = 400
|
17
|
+
DEF_REQ_TIMEOUT = 60
|
17
18
|
|
18
19
|
def initialize(api_url, api_key, secret_key, options = {})
|
19
20
|
@api_url = api_url
|
@@ -21,6 +22,9 @@ module CloudstackClient
|
|
21
22
|
@secret_key = secret_key
|
22
23
|
@verbose = options[:quiet] ? false : true
|
23
24
|
@debug = options[:debug] ? true : false
|
25
|
+
@symbolize_keys = options[:symbolize_keys] ? true : false
|
26
|
+
@host = options[:host]
|
27
|
+
@read_timeout = options[:read_timeout] || DEF_REQ_TIMEOUT
|
24
28
|
@async_poll_interval = options[:async_poll_interval] || DEF_POLL_INTERVAL
|
25
29
|
@async_timeout = options[:async_timeout] || DEF_ASYNC_TIMEOUT
|
26
30
|
@options = options
|
@@ -44,33 +48,36 @@ module CloudstackClient
|
|
44
48
|
http.use_ssl = true
|
45
49
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
46
50
|
end
|
51
|
+
http.read_timeout = @read_timeout
|
47
52
|
|
48
53
|
begin
|
49
|
-
|
54
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
55
|
+
req['Host'] = host if host.present?
|
56
|
+
response = http.request(req)
|
50
57
|
rescue
|
51
58
|
raise ConnectionError, "API URL \'#{@api_url}\' is not reachable."
|
52
59
|
end
|
53
60
|
|
54
61
|
begin
|
55
|
-
body = JSON.parse(response.body).values.first
|
62
|
+
body = JSON.parse(response.body, symbolize_names: @symbolize_keys).values.first
|
56
63
|
rescue JSON::ParserError
|
57
64
|
raise ParseError,
|
58
|
-
|
65
|
+
"Response from server is not readable. Check if the API endpoint (#{@api_url}) is valid and accessible."
|
59
66
|
end
|
60
67
|
|
61
68
|
if response.is_a?(Net::HTTPOK)
|
62
69
|
return body unless body.respond_to?(:keys)
|
63
|
-
if body.size == 2 && body.key?('count')
|
64
|
-
return body.reject { |key, _| key == 'count' }.values.first
|
70
|
+
if body.size == 2 && body.key?(k('count'))
|
71
|
+
return body.reject { |key, _| key == k('count') }.values.first
|
65
72
|
elsif body.size == 1 && body.values.first.respond_to?(:keys)
|
66
73
|
item = body.values.first
|
67
74
|
return (item.is_a?(Array) || item.is_a?(Hash)) ? item : []
|
68
75
|
else
|
69
|
-
body.reject! { |key, _| key == 'count' } if body.key?('count')
|
76
|
+
body.reject! { |key, _| key == k('count') } if body.key?(k('count'))
|
70
77
|
body.size == 0 ? [] : body
|
71
78
|
end
|
72
79
|
else
|
73
|
-
message = body['errortext'] rescue body
|
80
|
+
message = body[k('errortext')] rescue body
|
74
81
|
raise ApiError, "Status #{response.code}: #{message}."
|
75
82
|
end
|
76
83
|
end
|
@@ -85,18 +92,18 @@ module CloudstackClient
|
|
85
92
|
|
86
93
|
params = {
|
87
94
|
'command' => 'queryAsyncJobResult',
|
88
|
-
'jobid' => data['jobid']
|
95
|
+
'jobid' => data[k('jobid')]
|
89
96
|
}
|
90
97
|
|
91
98
|
max_tries.times do
|
92
99
|
data = send_request(params)
|
93
100
|
print "." if @verbose
|
94
101
|
|
95
|
-
case data['jobstatus']
|
102
|
+
case data[k('jobstatus')]
|
96
103
|
when 1
|
97
|
-
return data['jobresult']
|
104
|
+
return data[k('jobresult')]
|
98
105
|
when 2
|
99
|
-
raise JobError, "Request failed (#{data['jobresultcode']}): #{data['jobresult']['errortext']}."
|
106
|
+
raise JobError, "Request failed (#{data[k('jobresultcode')]}): #{data[k('jobresult')][k('errortext')]}."
|
100
107
|
end
|
101
108
|
|
102
109
|
STDOUT.flush if @verbose
|
@@ -128,7 +135,7 @@ module CloudstackClient
|
|
128
135
|
when Hash # support for maps values of values (Hash values of Hashes)
|
129
136
|
value.each_with_index.map do |(k, v), i|
|
130
137
|
"#{key}[#{i}].key=#{escape(k)}&" +
|
131
|
-
|
138
|
+
"#{key}[#{i}].value=#{escape(v)}"
|
132
139
|
end.join("&")
|
133
140
|
else
|
134
141
|
"#{key}=#{escape(value)}"
|
@@ -151,5 +158,10 @@ module CloudstackClient
|
|
151
158
|
CGI.escape(input.to_s).gsub('+', '%20').gsub(' ', '%20')
|
152
159
|
end
|
153
160
|
|
161
|
+
def symbolized_key(name)
|
162
|
+
@symbolize_keys ? name.to_sym : name
|
163
|
+
end
|
164
|
+
alias_method :k, :symbolized_key
|
165
|
+
|
154
166
|
end # class
|
155
167
|
end # module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nik Wolfgramm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.3.7
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: CloudStack API client written in Ruby
|