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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1908e792f8375d14f488b04d8cb71135c1a73bc
4
- data.tar.gz: 9988940067c7287d18419bcfba91ca73a7e52e2f
3
+ metadata.gz: 22cde3225726af7ad083a0e1229787ac49dbdea1
4
+ data.tar.gz: a5a7875cf042c75c5f7f30b613c5e3f6a373bedf
5
5
  SHA512:
6
- metadata.gz: 47de7e778de3e3c4eb718603aee7d7177b1ae1dea1fa703953e30d6c18356b4d59c11fc030cbb1963dabefd7f3d02aba8ad084fe3c9c730d6e595a26a277967f
7
- data.tar.gz: c96b9eed861a34eb49c7f13194b0c43b39793a99e69625547f36be9b7f777b5f72d706e17bd63328b7aaf83e4ffd5e97e5822ff363b9f8c86ae4afcf4d6a256d
6
+ metadata.gz: b5816f54df0d72a8d19e003f32f962025abc3d582c2aebdf4fe33b3d39d224d0eca91dc2fea8632b3be3280b6b01f0a1c763b9efb2c821f2acf773f963041cc2
7
+ data.tar.gz: 3a9f9ed794405204cdd3773d8f63ec20c7b0f5e846f2eb51d595d46f38213a48913df144f84cdfb054e8bce92724b1fb52c7d65dcaec1e4f57eb4ae0e7a14482
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
- Gemfile.lock
2
1
  .bundle/*
3
2
  .bundle
3
+ vendor
4
+ vendor/*
4
5
  pkg/*
5
- pkg
6
+ pkg
data/.travis.yml CHANGED
@@ -1 +1,13 @@
1
1
  language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.2.0
7
+ - 2.3.0
8
+ before_install:
9
+ - gem update --system
10
+ - gem update bundler
11
+ install:
12
+ - bundle install --deployment --path vendor/bundle
13
+ cache: bundler
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
- - Dynamically builds API methods based on the lisApis function of CloudStack
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 style args passed to commands (i.e. list_all: true becomes listall=true)
20
- - makes sure all required arguments are passed
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
- ..or load the API definition directly from a file:
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
- ## Development
70
-
71
- ### Generate/Update API versions
69
+ ### Interactive Console
72
70
 
73
- New API configs can be generated using the list_apis command.
71
+ cloudstack_client comes with an interactive shell to test the client.
74
72
 
75
73
  *Example:*
76
74
 
77
75
  ```bash
78
- # running against an CloudStack 4.5 API endpoint:
79
- $ cloudstack_client list_apis > data/4.5.json
80
- $ gzip data/4.5.json
76
+ $ cloudstack_client console -e prod
77
+ prod >> list_virtual_machines
81
78
  ```
82
79
 
83
- ### Interactive Console
80
+ ## Development
84
81
 
85
- cloudstack_client comes with an interactive shell to test the client.
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
- $ cloudstack_client console -e prod
91
- prod >> list_virtual_machines
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-2015, Nik Wolfgramm
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.
@@ -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('rdoc', '~> 4.2.0')
24
- gem.add_development_dependency('rake', '~> 10.4.2')
25
- gem.add_development_dependency('thor', '~> 0.19.1')
26
- gem.add_development_dependency('ripl', '~> 0.7.0')
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('json_pure', '~> 1.8.3')
28
+ gem.add_dependency('multi_json', '~> 1.11')
30
29
  end
@@ -1,5 +1,5 @@
1
1
  require "zlib"
2
- require "json"
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
- "#{ 's' if required_params(command).size > 1 }: " +
50
- required_params(command).join(", ")
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
- JSON.parse(gz.read)
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 "json"
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] ? JSON.pretty_generate(apis) : apis.to_json
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 "json"
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
- debug_output JSON.pretty_generate(params) if @debug
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 = JSON.parse(response.body).values.first
64
- rescue JSON::ParserError
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 correct and accessible."
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
@@ -1,3 +1,3 @@
1
1
  module CloudstackClient
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
data/test/benchmark.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "cloudstack_client/api"
4
4
  require "benchmark"
5
- require "json"
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
- time: time.round(2),
27
- gc_count: gc_stat_after[:count] - gc_stat_before[:count],
28
- memory: "%dM" % (memory_after - memory_before)
29
- }.to_json)
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.1.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: 2015-12-04 00:00:00.000000000 Z
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.2
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.2
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.1
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.1
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.0
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.0
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.2
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.2
68
+ version: '5.8'
83
69
  - !ruby/object:Gem::Dependency
84
- name: json_pure
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.8.3
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.8.3
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.2.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