cloudstack_client 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/.travis.yml +12 -0
- data/Gemfile.lock +26 -0
- data/README.md +18 -18
- data/cloudstack_client.gemspec +5 -6
- data/lib/cloudstack_client/api.rb +4 -4
- data/lib/cloudstack_client/cli.rb +6 -2
- data/lib/cloudstack_client/connection.rb +6 -13
- data/lib/cloudstack_client/utils.rb +10 -0
- data/lib/cloudstack_client/version.rb +1 -1
- data/test/benchmark.rb +11 -6
- metadata +15 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22cde3225726af7ad083a0e1229787ac49dbdea1
|
4
|
+
data.tar.gz: a5a7875cf042c75c5f7f30b613c5e3f6a373bedf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5816f54df0d72a8d19e003f32f962025abc3d582c2aebdf4fe33b3d39d224d0eca91dc2fea8632b3be3280b6b01f0a1c763b9efb2c821f2acf773f963041cc2
|
7
|
+
data.tar.gz: 3a9f9ed794405204cdd3773d8f63ec20c7b0f5e846f2eb51d595d46f38213a48913df144f84cdfb054e8bce92724b1fb52c7d65dcaec1e4f57eb4ae0e7a14482
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cloudstack_client (1.2.0)
|
5
|
+
multi_json (~> 1.11)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
bond (0.5.1)
|
11
|
+
minitest (5.8.3)
|
12
|
+
multi_json (1.11.2)
|
13
|
+
rake (10.4.2)
|
14
|
+
ripl (0.7.1)
|
15
|
+
bond (~> 0.5.1)
|
16
|
+
thor (0.19.1)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
cloudstack_client!
|
23
|
+
minitest (~> 5.8)
|
24
|
+
rake (~> 10.4)
|
25
|
+
ripl (~> 0.7)
|
26
|
+
thor (~> 0.19)
|
data/README.md
CHANGED
@@ -14,13 +14,13 @@ $ gem install cloudstack_client
|
|
14
14
|
```
|
15
15
|
|
16
16
|
## Features
|
17
|
-
-
|
17
|
+
- Interactive console for playing with the CloudStack API: ```cloudstack_client console```
|
18
|
+
- Dynamically builds API methods based on the listApis function of CloudStack
|
18
19
|
- Command names are converted to match Ruby naming conventions (i.e. ListVirtualMachines becomes list_virtual_machines)
|
19
|
-
- Accepts Ruby
|
20
|
-
-
|
20
|
+
- Accepts Ruby Hash arguments passed to commands as options (i.e. list_all: true becomes listall=true)
|
21
|
+
- Makes sure all required arguments are passed
|
21
22
|
- Removes unsupported arguments and arguments with nil values from commands
|
22
23
|
|
23
|
-
|
24
24
|
## Usage
|
25
25
|
|
26
26
|
### Basic usage
|
@@ -41,7 +41,7 @@ end
|
|
41
41
|
|
42
42
|
### Initialize with options
|
43
43
|
|
44
|
-
Load API definition file from a alternative path and set the version
|
44
|
+
*Load API definition file from a alternative path and set the version:*
|
45
45
|
|
46
46
|
```ruby
|
47
47
|
cs = CloudstackClient::Client.new(
|
@@ -55,7 +55,7 @@ cs = CloudstackClient::Client.new(
|
|
55
55
|
)
|
56
56
|
```
|
57
57
|
|
58
|
-
|
58
|
+
*..or load the API definition directly from a file:*
|
59
59
|
|
60
60
|
```ruby
|
61
61
|
cs = CloudstackClient::Client.new(
|
@@ -66,29 +66,29 @@ cs = CloudstackClient::Client.new(
|
|
66
66
|
)
|
67
67
|
```
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
### Generate/Update API versions
|
69
|
+
### Interactive Console
|
72
70
|
|
73
|
-
|
71
|
+
cloudstack_client comes with an interactive shell to test the client.
|
74
72
|
|
75
73
|
*Example:*
|
76
74
|
|
77
75
|
```bash
|
78
|
-
|
79
|
-
|
80
|
-
$ gzip data/4.5.json
|
76
|
+
$ cloudstack_client console -e prod
|
77
|
+
prod >> list_virtual_machines
|
81
78
|
```
|
82
79
|
|
83
|
-
|
80
|
+
## Development
|
84
81
|
|
85
|
-
|
82
|
+
### Generate/Update API versions
|
83
|
+
|
84
|
+
New API configs can be generated using the list_apis command.
|
86
85
|
|
87
86
|
*Example:*
|
88
87
|
|
89
88
|
```bash
|
90
|
-
|
91
|
-
|
89
|
+
# running against an CloudStack 4.5 API endpoint:
|
90
|
+
$ cloudstack_client list_apis > data/4.5.json
|
91
|
+
$ gzip data/4.5.json
|
92
92
|
```
|
93
93
|
|
94
94
|
## References
|
@@ -104,6 +104,6 @@ prod >> list_virtual_machines
|
|
104
104
|
|
105
105
|
## License
|
106
106
|
|
107
|
-
Copyright (c) 2014-
|
107
|
+
Copyright (c) 2014-2016, Nik Wolfgramm
|
108
108
|
|
109
109
|
Released under the MIT License. See the [LICENSE](https://raw.github.com/niwo/cloudstack_client/master/LICENSE.txt) file for further details.
|
data/cloudstack_client.gemspec
CHANGED
@@ -20,11 +20,10 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.require_paths = ["lib"]
|
21
21
|
gem.rdoc_options = %w[--line-numbers --inline-source]
|
22
22
|
|
23
|
-
gem.add_development_dependency('
|
24
|
-
gem.add_development_dependency('
|
25
|
-
gem.add_development_dependency('
|
26
|
-
gem.add_development_dependency('
|
27
|
-
gem.add_development_dependency('minitest', '~> 5.8.2')
|
23
|
+
gem.add_development_dependency('rake', '~> 10.4')
|
24
|
+
gem.add_development_dependency('thor', '~> 0.19')
|
25
|
+
gem.add_development_dependency('ripl', '~> 0.7')
|
26
|
+
gem.add_development_dependency('minitest', '~> 5.8')
|
28
27
|
|
29
|
-
gem.add_dependency('
|
28
|
+
gem.add_dependency('multi_json', '~> 1.11')
|
30
29
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require "zlib"
|
2
|
-
require "
|
2
|
+
require "multi_json"
|
3
3
|
|
4
4
|
module CloudstackClient
|
5
5
|
class Api
|
@@ -46,8 +46,8 @@ module CloudstackClient
|
|
46
46
|
|
47
47
|
def missing_params_msg(command)
|
48
48
|
"#{command} requires the following parameter" +
|
49
|
-
|
50
|
-
|
49
|
+
"#{ 's' if required_params(command).size > 1 }: " +
|
50
|
+
required_params(command).join(", ")
|
51
51
|
end
|
52
52
|
|
53
53
|
private
|
@@ -87,7 +87,7 @@ module CloudstackClient
|
|
87
87
|
def load_commands
|
88
88
|
@commands = {}
|
89
89
|
Zlib::GzipReader.open(@api_file) do |gz|
|
90
|
-
|
90
|
+
MultiJson.load(gz.read)
|
91
91
|
end.each {|cmd| @commands[cmd["name"]] = cmd }
|
92
92
|
rescue => e
|
93
93
|
raise "Error: Unable to read file '#{@api_file}': #{e.message}"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "cloudstack_client/client"
|
2
2
|
require "yaml"
|
3
|
-
require "
|
3
|
+
require "multi_json"
|
4
4
|
|
5
5
|
begin
|
6
6
|
require "thor"
|
@@ -63,7 +63,7 @@ module CloudstackClient
|
|
63
63
|
when "yaml"
|
64
64
|
apis.to_yaml
|
65
65
|
else
|
66
|
-
options[:pretty_print]
|
66
|
+
MultiJson.dump(apis, pretty: options[:pretty_print])
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -73,6 +73,10 @@ module CloudstackClient
|
|
73
73
|
default: CloudstackClient::Api::DEFAULT_API_VERSION
|
74
74
|
option :api_file,
|
75
75
|
desc: 'specify a custom API definition file'
|
76
|
+
option :pretty_print,
|
77
|
+
desc: 'pretty client output',
|
78
|
+
type: :numeric,
|
79
|
+
default: true
|
76
80
|
def console
|
77
81
|
cs_client = client(options)
|
78
82
|
|
@@ -4,10 +4,11 @@ require "uri"
|
|
4
4
|
require "cgi"
|
5
5
|
require "net/http"
|
6
6
|
require "net/https"
|
7
|
-
require "
|
7
|
+
require "multi_json"
|
8
8
|
|
9
9
|
module CloudstackClient
|
10
10
|
class Connection
|
11
|
+
include Utils
|
11
12
|
|
12
13
|
attr_accessor :api_url, :api_key, :secret_key, :verbose, :debug
|
13
14
|
attr_accessor :async_poll_interval, :async_timeout
|
@@ -36,7 +37,7 @@ module CloudstackClient
|
|
36
37
|
"#{key}=#{value}"
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
+
print_debug_output MultiJson.dump(params, pretty: true) if @debug
|
40
41
|
|
41
42
|
data = params_arr.join('&')
|
42
43
|
signature = OpenSSL::HMAC.digest('sha1', @secret_key, data.downcase)
|
@@ -60,10 +61,10 @@ module CloudstackClient
|
|
60
61
|
end
|
61
62
|
|
62
63
|
begin
|
63
|
-
body =
|
64
|
-
rescue
|
64
|
+
body = MultiJson.load(response.body).values.first
|
65
|
+
rescue MultiJson::ParseError
|
65
66
|
raise ParseError,
|
66
|
-
"Response from server is not readable. Check if the API endpoint (#{@api_url}) is
|
67
|
+
"Response from server is not readable. Check if the API endpoint (#{@api_url}) is valid and accessible."
|
67
68
|
end
|
68
69
|
|
69
70
|
if response.is_a? Net::HTTPOK
|
@@ -122,13 +123,5 @@ module CloudstackClient
|
|
122
123
|
(@async_timeout / @async_poll_interval).round
|
123
124
|
end
|
124
125
|
|
125
|
-
def debug_output(output, seperator = '-' * 80)
|
126
|
-
puts
|
127
|
-
puts seperator
|
128
|
-
puts output
|
129
|
-
puts seperator
|
130
|
-
puts
|
131
|
-
end
|
132
|
-
|
133
126
|
end
|
134
127
|
end
|
@@ -1,10 +1,20 @@
|
|
1
1
|
module CloudstackClient
|
2
2
|
module Utils
|
3
|
+
|
3
4
|
def camel_case_to_underscore(camel_case)
|
4
5
|
camel_case.gsub(/::/, '/').
|
5
6
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
6
7
|
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
7
8
|
tr("-", "_").downcase
|
8
9
|
end
|
10
|
+
|
11
|
+
def print_debug_output(output, seperator = '-' * 80)
|
12
|
+
puts
|
13
|
+
puts seperator
|
14
|
+
puts output
|
15
|
+
puts seperator
|
16
|
+
puts
|
17
|
+
end
|
18
|
+
|
9
19
|
end
|
10
20
|
end
|
data/test/benchmark.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "cloudstack_client/api"
|
4
4
|
require "benchmark"
|
5
|
-
require "
|
5
|
+
require "multi_json"
|
6
6
|
|
7
7
|
GC.disable
|
8
8
|
|
@@ -22,8 +22,13 @@ end
|
|
22
22
|
gc_stat_after = GC.stat
|
23
23
|
memory_after = `ps -o rss= -p #{Process.pid}`.to_i/1024
|
24
24
|
|
25
|
-
puts(
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
puts(
|
26
|
+
MultiJson.dump(
|
27
|
+
{
|
28
|
+
time: time.round(2),
|
29
|
+
gc_count: gc_stat_after[:count] - gc_stat_before[:count],
|
30
|
+
memory: "%dM" % (memory_after - memory_before)
|
31
|
+
},
|
32
|
+
pretty: true
|
33
|
+
)
|
34
|
+
)
|
metadata
CHANGED
@@ -1,99 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudstack_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
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: 2016-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rdoc
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.2.0
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 4.2.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 10.4
|
19
|
+
version: '10.4'
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 10.4
|
26
|
+
version: '10.4'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: thor
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.19
|
33
|
+
version: '0.19'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.19
|
40
|
+
version: '0.19'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: ripl
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.7
|
47
|
+
version: '0.7'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.7
|
54
|
+
version: '0.7'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: minitest
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: 5.8
|
61
|
+
version: '5.8'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: 5.8
|
68
|
+
version: '5.8'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: multi_json
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
75
|
+
version: '1.11'
|
90
76
|
type: :runtime
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.
|
82
|
+
version: '1.11'
|
97
83
|
description: CloudStack API client written in Ruby
|
98
84
|
email:
|
99
85
|
- nik.wolfgramm@gmail.com
|
@@ -105,6 +91,7 @@ files:
|
|
105
91
|
- ".gitignore"
|
106
92
|
- ".travis.yml"
|
107
93
|
- Gemfile
|
94
|
+
- Gemfile.lock
|
108
95
|
- LICENSE.txt
|
109
96
|
- README.md
|
110
97
|
- Rakefile
|
@@ -147,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
134
|
version: '0'
|
148
135
|
requirements: []
|
149
136
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
137
|
+
rubygems_version: 2.4.5.1
|
151
138
|
signing_key:
|
152
139
|
specification_version: 4
|
153
140
|
summary: CloudStack API client written in Ruby
|