cloudmonkey 1.0.0 → 1.0.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.
- data/lib/cm.rb +37 -3
- metadata +2 -2
data/lib/cm.rb
CHANGED
@@ -3,13 +3,26 @@ require 'ostruct'
|
|
3
3
|
require 'open3'
|
4
4
|
|
5
5
|
module CloudMonkey
|
6
|
+
# A CloudMonkey client. Requires the cloudmonkey command to be
|
7
|
+
# installed on the system. The client must be synced outside of this
|
8
|
+
# module, or by using the provided sync method, to cache the API
|
9
|
+
# commands available. Once synced, cloudmonkey commands can be
|
10
|
+
# called like Ruby methods using symbolized parameter names in a
|
11
|
+
# hash for the parameters and values.
|
6
12
|
class CMClient
|
7
13
|
def initialize(params)
|
8
14
|
@host = params[:host] || 'localhost'
|
9
15
|
@port = params[:port] || 8080
|
10
16
|
@apikey = params[:apikey]
|
11
17
|
@secretkey = params[:secretkey]
|
12
|
-
|
18
|
+
|
19
|
+
@conf_dir = params[:conf_dir] || File.join("#{Dir.home}", ".cloudmonkey-cmrb")
|
20
|
+
Dir.mkdir(@conf_dir) if not Dir.exists?(@conf_dir)
|
21
|
+
|
22
|
+
@config = params[:config] || File.join(@conf_dir, "config")
|
23
|
+
@cache = File.join(@conf_dir, "cache")
|
24
|
+
@log = File.join(@conf_dir, "log")
|
25
|
+
@history = File.join(@conf_dir, "history")
|
13
26
|
@debug = params[:debug] || false
|
14
27
|
configure
|
15
28
|
end
|
@@ -21,15 +34,36 @@ module CloudMonkey
|
|
21
34
|
|
22
35
|
# Configure the cloudmonkey client for use with the library.
|
23
36
|
def configure
|
37
|
+
# Connection info
|
24
38
|
set('host', "#{@host}")
|
25
39
|
set('port', "#{@port}")
|
26
40
|
set('apikey', "#{@apikey}")
|
27
41
|
set('secretkey', "#{@secretkey}")
|
42
|
+
|
43
|
+
# Local Storage Info
|
44
|
+
set('cache_file', @cache)
|
45
|
+
set('log_file', @log)
|
46
|
+
set('history_file', @history)
|
47
|
+
|
48
|
+
# Display options needed to make parsing of responses simple.
|
28
49
|
set('display', 'json')
|
29
50
|
set('asyncblock', 'false')
|
30
51
|
set('color', 'false')
|
31
52
|
end
|
32
53
|
|
54
|
+
# Synchronize the API list for cloudmonkey and return true or
|
55
|
+
# false depending on success.
|
56
|
+
def sync
|
57
|
+
execute('sync').has_key?(:message)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Retrieve the cloudmonkey version as a string.
|
61
|
+
def version
|
62
|
+
ver = run_cmd('-v')[:message]
|
63
|
+
# x.y.Z versioning scheme, e.g. 5.1.0
|
64
|
+
/\d+\.\d+\.\d+/.match(ver).to_s
|
65
|
+
end
|
66
|
+
|
33
67
|
# Execute a command with cloudmonkey. The command can be
|
34
68
|
# multi-word, e.g. "list users". Params, if provided, must be a
|
35
69
|
# hash (e.g. :account => "admin"), or a string value (.e.g "help"
|
@@ -51,7 +85,7 @@ module CloudMonkey
|
|
51
85
|
execute cmd, args[0]
|
52
86
|
end
|
53
87
|
|
54
|
-
private
|
88
|
+
private
|
55
89
|
# Run a cloudmonkey command.
|
56
90
|
def run_cmd(input, params = nil)
|
57
91
|
input += ' '
|
@@ -113,7 +147,7 @@ module CloudMonkey
|
|
113
147
|
|
114
148
|
# Handle non-json output. This happens when Cloudmonkey returns an
|
115
149
|
# error or if it's just a generic message. Errors are raised as a
|
116
|
-
# runtime exception, while generic
|
150
|
+
# runtime exception, while generic messages are put into a hash
|
117
151
|
# with a :message property.
|
118
152
|
def handle_non_json_output(message)
|
119
153
|
# handle various error messages, otherwise simply return a hash
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudmonkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -20,7 +20,7 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- lib/cm.rb
|
23
|
-
homepage:
|
23
|
+
homepage: https://github.com/greenqloud/cloudmonkey-ruby
|
24
24
|
licenses:
|
25
25
|
- Apache
|
26
26
|
post_install_message:
|