cloudstack_client 1.4.0 → 1.4.1

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: bd4cd4b017446c7e94c52e7f8522852bf0dad509
4
- data.tar.gz: 91e77bfe5a99bd81d3fb304afd7c87d90057271b
3
+ metadata.gz: 7fff1252133afca0d217d2dba42a9ef41f9d0124
4
+ data.tar.gz: 8004e1b1557234b62fde004cbd1461f7fc42f4fd
5
5
  SHA512:
6
- metadata.gz: a9a4801541cc3d5c7f63938822a7ceaf19206a19097ed11eabf1e30619d63d791d3f7e7d10d9752d9cf834824d2de834885b8415fefb3d5c9a41421a281e01a8
7
- data.tar.gz: 0c239a5ac06de097b634297d44cc039cd1ad68e461be8beb90d0b77e50cb6701052c38d9bc15e3d562c9b2f0471c92a4287e5067776a6d7f94d93986fc266d8a
6
+ metadata.gz: 0b12dc68ad181f9b03338814820d2951779ff5fe994db00ebc63128bd8bdc22c90a93e562297cc713fbea477458e144f5ff471bcac9f4e55bcad2f43ab6b9546
7
+ data.tar.gz: 0379fd6f4294c0d93cfa500f56fd4133e1b1448046c0ebf20b7c20d85f87e7cae39aa5d407411ad85eec97a5645478d7dabad1e74f79959d96943cdef39f4970
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudstack_client (1.4.0)
4
+ cloudstack_client (1.4.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -31,7 +31,7 @@ require "cloudstack_client"
31
31
  cs = CloudstackClient::Client.new(
32
32
  "https://cloudstack.local/client/api",
33
33
  "API_KEY",
34
- "API_SECRET"
34
+ "SECRET_KEY"
35
35
  )
36
36
 
37
37
  cs.list_virtual_machines(state: "running").each do |server|
@@ -47,7 +47,7 @@ end
47
47
  cs = CloudstackClient::Client.new(
48
48
  "https://cloudstack.local/client/api",
49
49
  "API_KEY",
50
- "API_SECRET",
50
+ "SECRET_KEY",
51
51
  {
52
52
  api_path: "~/cloudstack",
53
53
  api_version: "4.6"
data/Rakefile CHANGED
@@ -6,6 +6,7 @@ Bundler::GemHelper.install_tasks
6
6
  Rake::TestTask.new do |t|
7
7
  t.libs << 'test'
8
8
  t.pattern = "test/*_test.rb"
9
+ t.warning = false
9
10
  end
10
11
 
11
12
  desc "Run Tests"
@@ -34,6 +34,19 @@ module CloudstackClient
34
34
  desc: 'enable debug output',
35
35
  type: :boolean
36
36
 
37
+ # rescue error globally
38
+ def self.start(given_args=ARGV, config={})
39
+ super
40
+ rescue => e
41
+ error_class = e.class.name.split('::')
42
+ if error_class.size == 2 && error_class.first == "CloudstackClient"
43
+ puts "\e[31mERROR\e[0m: #{error_class.last} - #{e.message}"
44
+ puts e.backtrace if ARGV.include? "--debug"
45
+ else
46
+ raise
47
+ end
48
+ end
49
+
37
50
  desc "version", "Print cloudstack_client version number"
38
51
  def version
39
52
  say "cloudstack_client version #{CloudstackClient::VERSION}"
@@ -123,7 +136,7 @@ module CloudstackClient
123
136
  end
124
137
 
125
138
  unless config.key?(:url) && config.key?(:api_key) && config.key?(:secret_key)
126
- say "The environment #{env || '\'-\''} contains no valid data.", :red
139
+ say "The environment #{env || '\'-\''} does not contain all required keys.", :red
127
140
  exit 1
128
141
  end
129
142
  return config, env
@@ -13,15 +13,19 @@ module CloudstackClient
13
13
  attr_accessor :api_url, :api_key, :secret_key, :verbose, :debug
14
14
  attr_accessor :async_poll_interval, :async_timeout
15
15
 
16
+ DEF_POLL_INTERVAL = 2.0
17
+ DEF_ASYNC_TIMEOUT = 400
18
+
16
19
  def initialize(api_url, api_key, secret_key, options = {})
17
20
  @api_url = api_url
18
21
  @api_key = api_key
19
22
  @secret_key = secret_key
20
23
  @verbose = options[:quiet] ? false : true
21
24
  @debug = options[:debug] ? true : false
22
- @async_poll_interval = options[:async_poll_interval] || 2.0
23
- @async_timeout = options[:async_timeout] || 400
25
+ @async_poll_interval = options[:async_poll_interval] || DEF_POLL_INTERVAL
26
+ @async_timeout = options[:async_timeout] || DEF_ASYNC_TIMEOUT
24
27
  @options = options
28
+ validate_input!
25
29
  end
26
30
 
27
31
  ##
@@ -127,12 +131,20 @@ module CloudstackClient
127
131
 
128
132
  private
129
133
 
134
+ def validate_input!
135
+ raise InputError, "API URL not set." if @api_url == nil
136
+ raise InputError, "API KEY not set." if @api_key == nil
137
+ raise InputError, "API SECRET KEY not set." if @secret_key == nil
138
+ raise InputError, "ASYNC POLL INTERVAL must be at least 1." if @async_poll_interval < 1.0
139
+ raise InputError, "ASYNC TIMEOUT must be at least 60." if @async_timeout < 60
140
+ end
141
+
130
142
  def max_tries
131
143
  (@async_timeout / @async_poll_interval).round
132
144
  end
133
145
 
134
146
  def escape(input)
135
- CGI.escape(input.to_s).gsub('+', '%20').gsub(' ','%20')
147
+ CGI.escape(input.to_s).gsub('+', '%20').gsub(' ', '%20')
136
148
  end
137
149
 
138
150
  end
@@ -6,4 +6,5 @@ module CloudstackClient
6
6
  class ApiError < Error; end
7
7
  class JobError < Error; end
8
8
  class TimeoutError < Error; end
9
+ class InputError < Error; end
9
10
  end
@@ -17,11 +17,11 @@ module CloudstackClient
17
17
  end
18
18
  end
19
19
 
20
- def print_debug_output(output, seperator = '-' * 80)
20
+ def print_debug_output(output, separator = '-' * 80)
21
21
  puts
22
- puts seperator
22
+ puts separator
23
23
  puts output
24
- puts seperator
24
+ puts separator
25
25
  puts
26
26
  end
27
27
 
@@ -1,3 +1,3 @@
1
1
  module CloudstackClient
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
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.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nik Wolfgramm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake