cloudstack_helper 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -1
- data/bin/cloudstack_rb +22 -2
- data/cloudstack_helper.gemspec +2 -1
- data/lib/cloudstack_helper.rb +1 -1
- metadata +22 -6
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# cloudstack_helper
|
2
2
|
cloudstack_helper is a simple ruby library that helps making request to CloudStack API easier. With cloudstack_helper, you only have to specify the command and the parameters for the request, and it will handle everything for you.
|
3
3
|
|
4
|
+
## Installation
|
5
|
+
It's hosted on rubygems.org
|
6
|
+
|
7
|
+
sudo gem install cloudstack_helper
|
8
|
+
|
9
|
+
|
4
10
|
## Library Usage
|
5
11
|
|
6
12
|
```ruby
|
@@ -30,7 +36,8 @@ cloudstack_helper is a simple ruby library that helps making request to CloudSta
|
|
30
36
|
```
|
31
37
|
Usage: cloudstack_rb -c conf -x command param1=value1 param2=value2
|
32
38
|
-x, --execute COMMAND command to execute. See CloudStack API for list of commands.
|
33
|
-
-c, --conf FILE YAML config file that stores api and secret key
|
39
|
+
-c, --conf FILE YAML config file that stores api and secret key.
|
40
|
+
-p, --pretty Pretty print the response of the API call.
|
34
41
|
-h, --help Show this message.
|
35
42
|
|
36
43
|
```
|
@@ -39,6 +46,7 @@ cloudstack_helper is a simple ruby library that helps making request to CloudSta
|
|
39
46
|
```
|
40
47
|
cloudstack_rb -x listUsers domainid=1
|
41
48
|
cloudstack_rb -x listUsers domainid=1 response=json
|
49
|
+
cloudstack_rb -x listUsers domainid=1 response=json -p
|
42
50
|
cloudstack_rb -x deployVirtualMachine serviceofferingid=12 templateid=4 zoneid=1 displayname=ohyea
|
43
51
|
```
|
44
52
|
|
data/bin/cloudstack_rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'optparse'
|
3
3
|
require 'yaml'
|
4
|
+
require 'json'
|
5
|
+
require 'rexml/document'
|
4
6
|
|
5
7
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
8
|
require 'cloudstack_helper'
|
@@ -8,14 +10,20 @@ require 'cloudstack_helper'
|
|
8
10
|
options = []
|
9
11
|
command = nil
|
10
12
|
conf_file = "cloudstack.yml"
|
13
|
+
pretty_print = false
|
14
|
+
json_output = false
|
15
|
+
|
11
16
|
opts = OptionParser.new(nil, 24, ' ')
|
12
17
|
opts.banner = 'Usage: cloudstack_rb -c conf -x command param1=value1 param2=value2'
|
13
18
|
opts.on('-x', '--execute COMMAND', 'command to execute. See CloudStack API for list of commands.') do |opt|
|
14
19
|
command = opt
|
15
20
|
end
|
16
|
-
opts.on('-c', '--conf FILE', 'YAML config file that stores api and secret key') do |opt|
|
21
|
+
opts.on('-c', '--conf FILE', 'YAML config file that stores api and secret key.') do |opt|
|
17
22
|
conf_file = opt
|
18
23
|
end
|
24
|
+
opts.on('-p', '--pretty', 'Pretty print the response of the API call.') do |opt|
|
25
|
+
pretty_print = true
|
26
|
+
end
|
19
27
|
opts.on_tail('-h', '--help', 'Show this message.') do
|
20
28
|
puts opts
|
21
29
|
exit
|
@@ -43,4 +51,16 @@ params.each do |param|
|
|
43
51
|
params_hash[tokens[0]] = tokens[1]
|
44
52
|
end
|
45
53
|
|
46
|
-
|
54
|
+
json_output = true if params_hash.key? "response" and params_hash["response"] == "json"
|
55
|
+
if pretty_print
|
56
|
+
if json_output
|
57
|
+
puts JSON.pretty_generate(JSON.parse(cs_helper.get(params_hash).body))
|
58
|
+
else
|
59
|
+
xml_document = REXML::Document.new(cs_helper.get(params_hash).body)
|
60
|
+
xml_formatter = REXML::Formatters::Pretty.new(2)
|
61
|
+
xml_formatter.compact = true
|
62
|
+
xml_formatter.write(xml_document, $stdout)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
puts cs_helper.get(params_hash).body
|
66
|
+
end
|
data/cloudstack_helper.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "cloudstack_helper"
|
7
|
-
s.version = "0.
|
7
|
+
s.version = "0.5"
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Darren Dao"]
|
10
10
|
s.email = ["darrendao@gmail.com"]
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{cloudstack_helper is a simple ruby library that helps making request to CloudStack API easier. With cloudstack_helper, you only have to specify the command the parameters for the request and it will handle everything for you.}
|
14
14
|
|
15
15
|
s.add_runtime_dependency 'rest-client', '~> 1.6.7'
|
16
|
+
s.add_runtime_dependency 'json', '~> 1.6.5'
|
16
17
|
s.add_development_dependency 'yard', '~> 0.7'
|
17
18
|
|
18
19
|
s.files = `git ls-files`.split("\n")
|
data/lib/cloudstack_helper.rb
CHANGED
@@ -33,7 +33,7 @@ class CloudStackHelper
|
|
33
33
|
data = parameterize(sorted_params, false)
|
34
34
|
|
35
35
|
hash = OpenSSL::HMAC.digest('sha1', @secret_key, data)
|
36
|
-
signature = Base64.
|
36
|
+
signature = Base64.encode64(hash).chomp
|
37
37
|
end
|
38
38
|
|
39
39
|
def parameterize(params, escape=true)
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudstack_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 5
|
9
|
+
version: "0.5"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Darren Dao
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-03-12 00:00:00 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: rest-client
|
@@ -33,9 +33,25 @@ dependencies:
|
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: json
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 5
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 6
|
47
|
+
- 5
|
48
|
+
version: 1.6.5
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: yard
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
55
|
none: false
|
40
56
|
requirements:
|
41
57
|
- - ~>
|
@@ -46,7 +62,7 @@ dependencies:
|
|
46
62
|
- 7
|
47
63
|
version: "0.7"
|
48
64
|
type: :development
|
49
|
-
version_requirements: *
|
65
|
+
version_requirements: *id003
|
50
66
|
description: cloudstack_helper is a simple ruby library that helps making request to CloudStack API easier. With cloudstack_helper, you only have to specify the command the parameters for the request and it will handle everything for you.
|
51
67
|
email:
|
52
68
|
- darrendao@gmail.com
|