cloudmonkey 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cm.rb +19 -12
  3. metadata +7 -8
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e31c8c37b9e6a32f225f6142d0a7f413967ead9
4
+ data.tar.gz: c51471ea36165d660a4f4cb76f59882596e08233
5
+ SHA512:
6
+ metadata.gz: fded3968fb7d8d3d9c2a567944c3b659ddda1a7679921d1f3abed0fe78119fbabe12fde03eda50f2b5b0ef8528f20e26468d500f0d61a32bed6efd634a5fa16f
7
+ data.tar.gz: 5737d919a6b3b52fc614d1ba49986e042e82ef4de37095821ab523783926e08620a7132d5788759d32076c73a6aafbc5eb0e1f8e964bb6222723f7764dc21d82
data/lib/cm.rb CHANGED
@@ -18,7 +18,7 @@ module CloudMonkey
18
18
 
19
19
  @conf_dir = params[:conf_dir] || File.join("#{Dir.home}", ".cloudmonkey-cmrb")
20
20
  Dir.mkdir(@conf_dir) if not Dir.exists?(@conf_dir)
21
-
21
+
22
22
  @config = params[:config] || File.join(@conf_dir, "config")
23
23
  @cache = File.join(@conf_dir, "cache")
24
24
  @log = File.join(@conf_dir, "log")
@@ -83,18 +83,18 @@ module CloudMonkey
83
83
  def method_missing(name, *args)
84
84
  cmd = name.to_s.split('_').join(' ').strip
85
85
  execute cmd, args[0]
86
- end
86
+ end
87
87
 
88
- private
88
+ private
89
89
  # Run a cloudmonkey command.
90
90
  def run_cmd(input, params = nil)
91
91
  input += ' '
92
-
92
+
93
93
  # We recognize hash parameters and straight-up string
94
94
  # parameters, but nothing else
95
95
  unless params.nil?
96
96
  if params.is_a?(Hash)
97
- params.each { |key, value|
97
+ params.each { |key, value|
98
98
  value = "\"#{value}\"" if value.is_a?(String)
99
99
  input += "#{key.downcase}=#{value} "
100
100
  }
@@ -105,13 +105,20 @@ module CloudMonkey
105
105
  raise 'We do not know how to handle these parameters'
106
106
  end
107
107
  end
108
-
108
+
109
109
  cmd = "cloudmonkey -c #{@config} '#{input}'"
110
110
  output = nil
111
+ error = nil
111
112
 
112
113
  puts "running #{cmd}" if @debug
113
114
  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
114
115
  output = stdout.read
116
+ error = stderr.read.strip
117
+ end
118
+
119
+ # did stderr return some problem?
120
+ if !error.nil? && !error.empty?
121
+ return handle_non_json_output(error)
115
122
  end
116
123
 
117
124
  # usually the output is json, but not if it is an error or just
@@ -122,7 +129,7 @@ module CloudMonkey
122
129
  # whatever you are making and the jobid (2 keys)
123
130
  if json.has_key?(:jobid) and json.length <= 2
124
131
  handle_async_job(json[:jobid])
125
- else
132
+ else
126
133
  # it is a query result.
127
134
  return json
128
135
  end
@@ -141,7 +148,7 @@ module CloudMonkey
141
148
  sleep(3)
142
149
  result = run_cmd('query asyncjobresult', :jobid => jobid)
143
150
  end
144
-
151
+
145
152
  # if there is a job result, we are interested only in
146
153
  # that. otherwise just return the whole response because we
147
154
  # don't really know what's in it.
@@ -152,7 +159,7 @@ module CloudMonkey
152
159
  # error or if it's just a generic message. Errors are raised as a
153
160
  # runtime exception, while generic messages are put into a hash
154
161
  # with a :message property.
155
- def handle_non_json_output(message)
162
+ def handle_non_json_output(message)
156
163
  # handle various error messages, otherwise simply return a hash
157
164
  # with the message
158
165
  if message.start_with?('[Errno') or message.start_with?('Unauthorized:')
@@ -172,7 +179,7 @@ module CloudMonkey
172
179
  def initialize(cm)
173
180
  @cm = cm
174
181
  end
175
-
182
+
176
183
  # Return a single network by name.
177
184
  def list_physical_network(name)
178
185
  networks = @cm.list_physicalnetworks(:name => name)
@@ -195,7 +202,7 @@ module CloudMonkey
195
202
  def enable_custom_vrouter_provider(provider, iface_id, zone_id)
196
203
  nsp = @cm.add_networkserviceprovider(:name => provider, :physicalnetworkid => iface_id)
197
204
  nsp = nsp[:networkserviceprovider]
198
-
205
+
199
206
  element = @cm.create_virtualrouterelement(:nspid => nsp[:id])[:virtualrouterelement]
200
207
  @cm.configure_virtualrouterelement(:enabled => true, :id => element[:id])
201
208
  new_nsp = @cm.update_networkserviceprovider(:state => 'Enabled', :id => nsp[:id])
@@ -214,4 +221,4 @@ module CloudMonkey
214
221
  end
215
222
 
216
223
  end
217
- end
224
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudmonkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - GreenQloud
@@ -23,26 +22,26 @@ files:
23
22
  homepage: https://github.com/greenqloud/cloudmonkey-ruby
24
23
  licenses:
25
24
  - Apache
25
+ metadata: {}
26
26
  post_install_message:
27
27
  rdoc_options: []
28
28
  require_paths:
29
29
  - lib
30
30
  required_ruby_version: !ruby/object:Gem::Requirement
31
- none: false
32
31
  requirements:
33
- - - ! '>='
32
+ - - ">="
34
33
  - !ruby/object:Gem::Version
35
34
  version: '0'
36
35
  required_rubygems_version: !ruby/object:Gem::Requirement
37
- none: false
38
36
  requirements:
39
- - - ! '>='
37
+ - - ">="
40
38
  - !ruby/object:Gem::Version
41
39
  version: '0'
42
40
  requirements: []
43
41
  rubyforge_project:
44
- rubygems_version: 1.8.23
42
+ rubygems_version: 2.4.5
45
43
  signing_key:
46
- specification_version: 3
44
+ specification_version: 4
47
45
  summary: CloudMonkey-Ruby
48
46
  test_files: []
47
+ has_rdoc: