cloudstack_client 1.5.0 → 1.5.1
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/Gemfile.lock +3 -3
- data/README.md +37 -4
- data/cloudstack_client.gemspec +1 -1
- data/lib/cloudstack_client/cli.rb +8 -10
- data/lib/cloudstack_client/configuration.rb +24 -11
- data/lib/cloudstack_client/error.rb +1 -0
- data/lib/cloudstack_client/version.rb +1 -1
- data/test/configuration_test.rb +2 -2
- data/test/data/{cloudstack-cli-1.yml → cloudstack-1.yml} +0 -0
- data/test/data/{cloudstack-cli-2.yml → cloudstack-2.yml} +0 -0
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 689edb1f1411766d7a826b67539d9d68a4f05602
|
|
4
|
+
data.tar.gz: 581a43d3b56a7ae35c9cce4bf5fa1d341dc4fe4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44f316e9813d7aac565bcad2984dafb11e8a34d8b6b8218fd1b6dd3ebf94c0f2d6a5fb8abab13e300ea99792c2bab6ac90517f37ece64460754b4379b9b96d7a
|
|
7
|
+
data.tar.gz: 50ade51230f8f45bdca2c4257c1c0e70e14ec5cda55a078f49c387a66b55079dddbb899ba60a582544b0c9ad45893ef5bc7566e947a2562d8b8b4c595de5cd4a
|
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
cloudstack_client (1.5.
|
|
4
|
+
cloudstack_client (1.5.1)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
9
|
bond (0.5.1)
|
|
10
|
-
minitest (5.10.
|
|
10
|
+
minitest (5.10.2)
|
|
11
11
|
rake (12.0.0)
|
|
12
12
|
ripl (0.7.1)
|
|
13
13
|
bond (~> 0.5.1)
|
|
@@ -18,7 +18,7 @@ PLATFORMS
|
|
|
18
18
|
|
|
19
19
|
DEPENDENCIES
|
|
20
20
|
cloudstack_client!
|
|
21
|
-
minitest (~> 5.
|
|
21
|
+
minitest (~> 5.10)
|
|
22
22
|
rake (~> 12.0)
|
|
23
23
|
ripl (~> 0.7)
|
|
24
24
|
thor (~> 0.19)
|
data/README.md
CHANGED
|
@@ -34,12 +34,12 @@ cs = CloudstackClient::Client.new(
|
|
|
34
34
|
"SECRET_KEY"
|
|
35
35
|
)
|
|
36
36
|
|
|
37
|
-
cs.list_virtual_machines(state: "running").each do |
|
|
38
|
-
puts
|
|
37
|
+
cs.list_virtual_machines(state: "running").each do |vm|
|
|
38
|
+
puts vm["name"]
|
|
39
39
|
end
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
###
|
|
42
|
+
### Advanced Options
|
|
43
43
|
|
|
44
44
|
*Load API definition file from a alternative path and set the version:*
|
|
45
45
|
|
|
@@ -50,7 +50,7 @@ cs = CloudstackClient::Client.new(
|
|
|
50
50
|
"SECRET_KEY",
|
|
51
51
|
{
|
|
52
52
|
api_path: "~/cloudstack",
|
|
53
|
-
api_version: "4.
|
|
53
|
+
api_version: "4.9"
|
|
54
54
|
}
|
|
55
55
|
)
|
|
56
56
|
```
|
|
@@ -66,6 +66,39 @@ cs = CloudstackClient::Client.new(
|
|
|
66
66
|
)
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
### Using the configuration module
|
|
70
|
+
|
|
71
|
+
The Configuration module of CloudstackClient make it easy to load CloudStack API settings from configuration files.
|
|
72
|
+
Use it like this:
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
require "cloudstack_client"
|
|
76
|
+
require "cloudstack_client/configuration"
|
|
77
|
+
|
|
78
|
+
# looks for ~/.cloudstack.yml per default
|
|
79
|
+
config = CloudstackClient::Configuration.load
|
|
80
|
+
cs = CloudstackClient::Client.new(config[:url], config[:api_key], config[:secret_key])
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
A configuration file supports multiple environments and looks like this:
|
|
84
|
+
|
|
85
|
+
```yaml
|
|
86
|
+
# default environment
|
|
87
|
+
:default: production
|
|
88
|
+
|
|
89
|
+
# production environment
|
|
90
|
+
production:
|
|
91
|
+
:url: "https://my-cloudstack-server/client/api/"
|
|
92
|
+
:api_key: "cloudstack-api-key"
|
|
93
|
+
:secret_key: "cloudstack-api-secret"
|
|
94
|
+
|
|
95
|
+
# test environment
|
|
96
|
+
test:
|
|
97
|
+
:url: "http://my-cloudstack-testserver/client/api/"
|
|
98
|
+
:api_key: "cloudstack-api-key"
|
|
99
|
+
:secret_key: "cloudstack-api-secret"
|
|
100
|
+
```
|
|
101
|
+
|
|
69
102
|
### Interactive Console
|
|
70
103
|
|
|
71
104
|
cloudstack_client comes with an interactive shell to test the client.
|
data/cloudstack_client.gemspec
CHANGED
|
@@ -23,5 +23,5 @@ Gem::Specification.new do |gem|
|
|
|
23
23
|
gem.add_development_dependency('rake', '~> 12.0')
|
|
24
24
|
gem.add_development_dependency('thor', '~> 0.19')
|
|
25
25
|
gem.add_development_dependency('ripl', '~> 0.7')
|
|
26
|
-
gem.add_development_dependency('minitest', '~> 5.
|
|
26
|
+
gem.add_development_dependency('minitest', '~> 5.10')
|
|
27
27
|
end
|
|
@@ -7,15 +7,13 @@ begin
|
|
|
7
7
|
require "thor"
|
|
8
8
|
require "ripl"
|
|
9
9
|
rescue LoadError => e
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
raise
|
|
10
|
+
%w(thor ripl).each do |gem|
|
|
11
|
+
if e.message =~ /#{gem}/
|
|
12
|
+
puts "Please install the #{gem} gem first ('gem install #{gem}')."
|
|
13
|
+
exit 1
|
|
14
|
+
end
|
|
16
15
|
end
|
|
17
|
-
|
|
18
|
-
exit 1
|
|
16
|
+
raise e.message
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
module CloudstackClient
|
|
@@ -23,7 +21,7 @@ module CloudstackClient
|
|
|
23
21
|
include Thor::Actions
|
|
24
22
|
|
|
25
23
|
class_option :config_file,
|
|
26
|
-
default:
|
|
24
|
+
default: Configuration.locate_config_file,
|
|
27
25
|
aliases: '-c',
|
|
28
26
|
desc: 'location of your cloudstack-cli configuration file'
|
|
29
27
|
|
|
@@ -89,7 +87,7 @@ module CloudstackClient
|
|
|
89
87
|
desc: 'specify a custom API definition file'
|
|
90
88
|
option :pretty_print,
|
|
91
89
|
desc: 'pretty client output',
|
|
92
|
-
type: :
|
|
90
|
+
type: :boolean,
|
|
93
91
|
default: true
|
|
94
92
|
def console
|
|
95
93
|
cs_client = client(options)
|
|
@@ -2,32 +2,45 @@ module CloudstackClient
|
|
|
2
2
|
require "yaml"
|
|
3
3
|
|
|
4
4
|
module Configuration
|
|
5
|
+
|
|
5
6
|
def self.load(configuration)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
raise
|
|
7
|
+
file = configuration[:config_file] || Configuration.locate_config_file
|
|
8
|
+
unless File.exists?(file)
|
|
9
|
+
raise ConfigurationError, "Configuration file '#{file}' not found."
|
|
9
10
|
end
|
|
11
|
+
|
|
10
12
|
begin
|
|
11
|
-
config = YAML::load(IO.read
|
|
13
|
+
config = YAML::load(IO.read file)
|
|
12
14
|
rescue => e
|
|
13
|
-
message = "Can't load configuration from file '#{
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
message = "Can't load configuration from file '#{file}'."
|
|
16
|
+
if configuration[:debug]
|
|
17
|
+
message += "\nMessage: #{e.message}"
|
|
18
|
+
message += "\nBacktrace:\n\t#{e.backtrace.join("\n\t")}"
|
|
19
|
+
end
|
|
16
20
|
raise message
|
|
17
21
|
end
|
|
18
22
|
|
|
19
|
-
env ||= config[:default]
|
|
20
|
-
if env
|
|
23
|
+
if env ||= config[:default]
|
|
21
24
|
unless config = config[env]
|
|
22
|
-
raise "Can't find environment #{env}."
|
|
25
|
+
raise ConfigurationError, "Can't find environment #{env}."
|
|
23
26
|
end
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
unless config.key?(:url) && config.key?(:api_key) && config.key?(:secret_key)
|
|
27
30
|
message = "The environment #{env || '\'-\''} does not contain all required keys."
|
|
28
|
-
raise message
|
|
31
|
+
raise ConfigurationError, message
|
|
29
32
|
end
|
|
33
|
+
|
|
30
34
|
config.merge(environment: env)
|
|
31
35
|
end
|
|
36
|
+
|
|
37
|
+
def self.locate_config_file
|
|
38
|
+
%w(.cloudstack .cloudstack-cli).each do |file|
|
|
39
|
+
file = File.join(Dir.home, "#{file}.yml")
|
|
40
|
+
return file if File.exists?(file)
|
|
41
|
+
end
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
|
|
32
45
|
end
|
|
33
46
|
end
|
data/test/configuration_test.rb
CHANGED
|
@@ -5,11 +5,11 @@ describe CloudstackClient::Configuration do
|
|
|
5
5
|
|
|
6
6
|
before do
|
|
7
7
|
@config1 = CloudstackClient::Configuration.load({
|
|
8
|
-
config_file: "#{File.expand_path File.dirname(__FILE__)}/data/cloudstack-
|
|
8
|
+
config_file: "#{File.expand_path File.dirname(__FILE__)}/data/cloudstack-1.yml",
|
|
9
9
|
debug: true
|
|
10
10
|
})
|
|
11
11
|
@config2 = CloudstackClient::Configuration.load({
|
|
12
|
-
config_file: "#{File.expand_path File.dirname(__FILE__)}/data/cloudstack-
|
|
12
|
+
config_file: "#{File.expand_path File.dirname(__FILE__)}/data/cloudstack-2.yml",
|
|
13
13
|
debug: true
|
|
14
14
|
})
|
|
15
15
|
end
|
|
File without changes
|
|
File without changes
|
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.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: 2017-
|
|
11
|
+
date: 2017-07-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '5.
|
|
61
|
+
version: '5.10'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '5.
|
|
68
|
+
version: '5.10'
|
|
69
69
|
description: CloudStack API client written in Ruby
|
|
70
70
|
email:
|
|
71
71
|
- nik.wolfgramm@gmail.com
|
|
@@ -99,8 +99,8 @@ files:
|
|
|
99
99
|
- test/configuration_test.rb
|
|
100
100
|
- test/data/0.42.json
|
|
101
101
|
- test/data/0.42.json.gz
|
|
102
|
-
- test/data/cloudstack-
|
|
103
|
-
- test/data/cloudstack-
|
|
102
|
+
- test/data/cloudstack-1.yml
|
|
103
|
+
- test/data/cloudstack-2.yml
|
|
104
104
|
- test/test_helper.rb
|
|
105
105
|
homepage: https://github.com/niwo/cloudstack_client
|
|
106
106
|
licenses:
|
|
@@ -135,6 +135,6 @@ test_files:
|
|
|
135
135
|
- test/configuration_test.rb
|
|
136
136
|
- test/data/0.42.json
|
|
137
137
|
- test/data/0.42.json.gz
|
|
138
|
-
- test/data/cloudstack-
|
|
139
|
-
- test/data/cloudstack-
|
|
138
|
+
- test/data/cloudstack-1.yml
|
|
139
|
+
- test/data/cloudstack-2.yml
|
|
140
140
|
- test/test_helper.rb
|