lorj 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/prc-logging.rb CHANGED
@@ -26,13 +26,67 @@ require 'ansi/logger'
26
26
  #
27
27
  # PrcLib module
28
28
  #
29
+ # PrcLib Implements a Logging class based on logger.
30
+ #
31
+ # For details about this class capabilities, see PrcLib::Logging
32
+ #
33
+ # # To use the Prc::Logging system, do the following:
34
+ # require 'PrcLib'
35
+ #
36
+ # # To configure logging system:
37
+ # PrcLib.app_name = 'config/app' # Define application data path as ~/.<app_name>. Ex: 'config/app' will use ~/.config/app
38
+ # PrcLib.log_file = 'app.log' # Relative path to the log file name stored in the Application data path. Here, ~/.config/app/app.log
39
+ # PrcLib.level = Logger::FATAL # Define printout debug level. Can be any Logger predefined value.
40
+ #
41
+ # # To log some information:
42
+ # PrcLib.debug('My debug message')
43
+ # PrcLib.info('My info message')
44
+ # PrcLib.warning('my warning')
45
+ # PrcLib.error('my error')
46
+ # PrcLib.fatal(2, "Fatal error, with return code = 2)
47
+ # PrcLib.message('Only printout message')
48
+ #
49
+ # # You can printout some instant message to the terminal, not logged.
50
+ # # This is useful before any action that will take time to be executed.
51
+ # # It is inform the end user that something is still running, which means
52
+ # # the application is not frozen
53
+ # PrcLib.state("Running a long task")
54
+ # # The next message will replace the previous state message.
55
+ # sleep(10)
56
+ # PrcLib.info("The long task has been executed successfully.")
57
+ #
58
+ # # You can change the logger level with PrcLib.level
59
+ # PrcLib.level = Logger::DEBUG
60
+ #
61
+ # # You can just print high level message (print without \n) if PrcLib.level is not DEBUG or INFO.
62
+ # PrcLib.high_level_msg("Print a message, not logged, if level is not DEBUG or INFO")
63
+ #
64
+ # Enjoy!
29
65
  module PrcLib
30
66
 
67
+ # Class used to create 2 logger object, in order to keep track of error in a log file and change log output to OUTPUT on needs (option flags).
68
+ # The idea is that everytime, if you did not set the debug level mode, you can refer to the log file which is
69
+ # already configured with Logger::DEBUG level.
70
+ #
71
+ # As well, sometimes, you do not want to keep track on messages that are just to keep informed the end user about activity.
72
+ # So, this object implement 2 Logger objects.
73
+ # * One for log file
74
+ # * One for print out.
75
+ #
76
+ # Everytime you log a message with Logging, it is printed out if the level permits and stored everytime in the log file, never mind about Logger level set.
77
+ # In several cases, messages are printed out, but not stored in the log file.
78
+ #
79
+ # See Logging functions for details.
80
+ #
31
81
  class Logging
32
- # Class used to create 2 log object, in order to keep track of error in a log file and change log output to OUTPUT on needs (option flags).
33
82
 
34
83
  attr_reader :level
35
84
 
85
+ # Initialize Logging instance
86
+ # The log file name is defined by PrcLib.log_file
87
+ # The log path is defined by PrcLib.app_name and will be kept as ~/.<PrcLib.app_name>
88
+ # The log level is defined by PrcLib.level. It will update only log print out.
89
+ # Depending on levels, messages are prefixed by colored 'ERROR!!!', 'FATAL!!!', 'WARNING' or <LEVEL NAME>
36
90
  def initialize()
37
91
 
38
92
  if not PrcLib.app_name
@@ -71,53 +125,66 @@ module PrcLib
71
125
  PrcLib.log_file = sLogFile
72
126
  end
73
127
 
128
+ # Is Logging print out level is info?
74
129
  def info?
75
130
  return(@oOutLogger.info?)
76
131
  end
77
132
 
133
+ # Is Logging print out level is debug?
78
134
  def debug?
79
135
  return(@oOutLogger.debug?)
80
136
  end
81
137
 
138
+ # Is Logging print out level is error?
82
139
  def error?
83
140
  return(@oOutLogger.error?)
84
141
  end
85
142
 
143
+ # Is Logging print out level is fatal?
86
144
  def fatal?
87
145
  return(@oOutLogger.fatal?)
88
146
  end
89
147
 
148
+ # Log to STDOUT and Log file and INFO class message
90
149
  def info(message)
91
150
  @oOutLogger.info(message + ANSI.clear_line)
92
151
  @oFileLogger.info(message)
93
152
  end
94
153
 
154
+ # Log to STDOUT and Log file and DEBUG class message
95
155
  def debug(message)
96
156
  @oOutLogger.debug(message + ANSI.clear_line)
97
157
  @oFileLogger.debug(message)
98
158
  end
99
159
 
160
+ # Log to STDOUT and Log file and ERROR class message
100
161
  def error(message)
101
162
  @oOutLogger.error(message + ANSI.clear_line)
102
163
  @oFileLogger.error(message)
103
164
  end
104
165
 
166
+ # Log to STDOUT and Log file and FATAL class message
167
+ # fatal retrieve the caller list of functions and save it to the log file if the exception class is given.
168
+ # The exception class should provide message and backtrace.
105
169
  def fatal(message, e)
106
170
  @oOutLogger.fatal(message + ANSI.clear_line)
107
171
  @oFileLogger.fatal("%s\n%s\n%s" % [message, e.message, e.backtrace.join("\n")]) if e
108
172
  @oFileLogger.fatal(message)
109
173
  end
110
174
 
175
+ # Log to STDOUT and Log file and WARNING class message
111
176
  def warn(message)
112
177
  @oOutLogger.warn(message + ANSI.clear_line)
113
178
  @oFileLogger.warn(message)
114
179
  end
115
180
 
181
+ # set STDOUT logger level
116
182
  def set_level(level)
117
183
  @level = level
118
184
  @oOutLogger.level = level
119
185
  end
120
186
 
187
+ # Print out a message, not logged in the log file. This message is printed out systematically as not taking care of logger level.
121
188
  def unknown(message)
122
189
  @oOutLogger.unknown(message + ANSI.clear_line)
123
190
  end
@@ -126,6 +193,8 @@ module PrcLib
126
193
 
127
194
  module_function
128
195
 
196
+ # Create a Logging object if missing and return it.
197
+ # Used internally by other functions
129
198
  def log_object()
130
199
  if PrcLib.log.nil?
131
200
  PrcLib.log = PrcLib::Logging.new
@@ -134,30 +203,38 @@ module PrcLib
134
203
  end
135
204
  end
136
205
 
206
+ # Print out a message, not logged in the log file. This message is printed out systematically as not taking care of logger level.
137
207
  def message(message)
138
208
  log_object.unknown(message)
139
209
  end
140
210
 
211
+ # Log to STDOUT and Log file and INFO class message
141
212
  def info(message)
142
213
  log_object.info(message)
143
214
  nil
144
215
  end
145
216
 
217
+ # Log to STDOUT and Log file and DEBUG class message
146
218
  def debug(message)
147
219
  log_object.debug(message)
148
220
  nil
149
221
  end
150
222
 
223
+ # Log to STDOUT and Log file and WARNING class message
151
224
  def warning(message)
152
225
  log_object.warn(message)
153
226
  nil
154
227
  end
155
228
 
229
+ # Log to STDOUT and Log file and ERROR class message
156
230
  def error(message)
157
231
  log_object.error(message)
158
232
  nil
159
233
  end
160
234
 
235
+ # Log to STDOUT and Log file and FATAL class message then exit the application with a return code.
236
+ # fatal retrieve the caller list of functions and save it to the log file if the exception class is given.
237
+ # The exception class should provide message and backtrace.
161
238
  def fatal(rc, message, e = nil)
162
239
  log_object.fatal(message, e)
163
240
  puts 'Issues found. Please fix it and retry. Process aborted.'
@@ -174,8 +251,9 @@ module PrcLib
174
251
  nil
175
252
  end
176
253
 
254
+ # Not DEBUG and not INFO. Just printed to the output.
177
255
  def high_level_msg(message)
178
- # Not DEBUG and not INFO. Just printed to the output.
256
+
179
257
  print ("%s" % [message]) if log_object.level > 1
180
258
  nil
181
259
  end
data/lib/prc.rb CHANGED
@@ -105,4 +105,27 @@ module PrcLib
105
105
  @level
106
106
  end
107
107
 
108
+ def lib_path=(v)
109
+ @lib_path = v if @lib_path.nil?
110
+ end
111
+
112
+ def lib_path()
113
+ @lib_path
114
+ end
115
+
116
+ def controller_path()
117
+ File.expand_path(File.join(@lib_path, "providers"))
118
+ end
119
+
120
+ def process_path()
121
+ File.join(@lib_path, "core_process")
122
+ end
123
+ end
124
+
125
+
126
+ class Object
127
+ # Simplify boolean test on objects
128
+ def boolean?
129
+ self.is_a?(TrueClass) || self.is_a?(FalseClass)
130
+ end
108
131
  end
@@ -27,7 +27,7 @@ require File.join($HPCLOUD_PATH, "network.rb")
27
27
  require File.join($HPCLOUD_PATH, "security_groups.rb")
28
28
 
29
29
  # Defines Meta HPCloud object
30
- class Hpcloud < BaseDefinition
30
+ class Hpcloud
31
31
 
32
32
  define_obj :services
33
33
  obj_needs :data, :account_id, :mapping => :hp_access_key
@@ -176,7 +176,7 @@ end
176
176
 
177
177
  # Following class describe how FORJ should handle HP Cloud objects.
178
178
  # Except Cloud connection, all HPCloud objects management are described/called in HP* modules.
179
- class HpcloudController < BaseController
179
+ class HpcloudController
180
180
 
181
181
  def connect(sObjectType, hParams)
182
182
  case sObjectType
@@ -187,7 +187,7 @@ class HpcloudController < BaseController
187
187
  when :network_connection
188
188
  Fog::HP::Network.new(hParams[:hdata])
189
189
  else
190
- forjError "'%s' is not a valid object for 'connect'" % sObjectType
190
+ Error "'%s' is not a valid object for 'connect'" % sObjectType
191
191
  end
192
192
  end
193
193
 
@@ -252,7 +252,7 @@ class HpcloudController < BaseController
252
252
  required?(hParams, :subnetwork)
253
253
  HPNetwork.add_interface(hParams[:router], hParams[:subnetwork])
254
254
  else
255
- forjError "'%s' is not a valid object for 'create'" % sObjectType
255
+ Error "'%s' is not a valid object for 'create'" % sObjectType
256
256
  end
257
257
  end
258
258
 
@@ -296,7 +296,7 @@ class HpcloudController < BaseController
296
296
  required?(hParams, :compute_connection)
297
297
  HPCompute.query_flavor(hParams[:compute_connection], sQuery)
298
298
  else
299
- forjError "'%s' is not a valid object for 'query'" % sObjectType
299
+ Error "'%s' is not a valid object for 'query'" % sObjectType
300
300
  end
301
301
  end
302
302
 
@@ -307,26 +307,33 @@ class HpcloudController < BaseController
307
307
  when :rule
308
308
  HPSecurityGroups.delete_rule(hParams[:network_connection], hParams[:id])
309
309
  hParams[:network_connection].security_group_rules.get(hParams[:id]).destroy
310
- else
310
+ when :server
311
+ required?(hParams, :compute_connection)
312
+ required?(hParams, :server)
313
+ HPCompute.delete_server(hParams[:compute_connection], hParams[:server] )
314
+ else
311
315
  nil
312
316
  end
313
317
  end
314
318
 
315
319
  def get(sObjectType, sUniqId, hParams)
316
320
  case sObjectType
317
- when :server_log
321
+ when :server_log
318
322
  required?(hParams, :server)
319
-
323
+
320
324
  hParams[:server].console_output(sUniqId)
321
- when :server
325
+ when :server
322
326
  required?(hParams, :compute_connection)
323
327
  HPCompute.get_server(hParams[:compute_connection], sUniqId)
324
- when :image
328
+ when :image
325
329
  required?(hParams, :compute_connection)
326
330
  HPCompute.get_image(hParams[:compute_connection], sUniqId)
327
331
  when :network
328
332
  required?(hParams, :network_connection)
329
333
  HPNetwork.get_network(hParams[:network_connection], sUniqId)
334
+ when :keypairs
335
+ required?(hParams, :compute_connection)
336
+ HPKeyPairs.get_keypair(hParams[:compute_connection], sUniqId)
330
337
  else
331
338
  forjError "'%s' is not a valid object for 'get'" % sObjectType
332
339
  end
@@ -339,21 +346,21 @@ class HpcloudController < BaseController
339
346
  yield(value)
340
347
  }
341
348
  else
342
- forjError "'%s' is not a valid list for 'each'" % oFogObject.class
349
+ Error "'%s' is not a valid list for 'each'" % oFogObject.class
343
350
  end
344
351
  end
345
352
 
346
353
  def get_attr(oControlerObject, key)
347
354
  begin
348
355
  if oControlerObject.is_a?(Excon::Response)
349
- rhGet(oControlerObject.data, :body, key)
356
+ Lorj::rhGet(oControlerObject.data, :body, key)
350
357
  else
351
358
  attributes = oControlerObject.attributes
352
359
  raise "attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, oControlerObject.class.attributes ] unless oControlerObject.class.attributes.include?(key[0])
353
- rhGet(attributes, key)
360
+ Lorj::rhGet(attributes, key)
354
361
  end
355
362
  rescue => e
356
- forjError "Unable to map '%s'. %s" % [key, e.message]
363
+ Error "Unable to map '%s'. %s" % [key, e.message]
357
364
  end
358
365
  end
359
366
 
@@ -364,7 +371,7 @@ class HpcloudController < BaseController
364
371
  raise "attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, oControlerObject.class.attributes ] unless oControlerObject.class.attributes.include?(key[0])
365
372
  Lorj::rhSet(attributes, value, key)
366
373
  rescue => e
367
- forjError "Unable to map '%s' on '%s'" % [key, sObjectType]
374
+ Error "Unable to map '%s' on '%s'" % [key, sObjectType]
368
375
  end
369
376
  end
370
377
 
@@ -372,11 +379,11 @@ class HpcloudController < BaseController
372
379
  def update(sObjectType, oObject, hParams)
373
380
  case sObjectType
374
381
  when :router
375
- forjError "Object to update is nil" if oObject.nil?
382
+ Error "Object to update is nil" if oObject.nil?
376
383
 
377
384
  HPNetwork.update_router(oObject[:object])
378
385
  else
379
- forjError "'%s' is not a valid list for 'update'" % oFogObject.class
386
+ Error "'%s' is not a valid list for 'update'" % oFogObject.class
380
387
  end
381
388
  end
382
389
 
@@ -396,7 +403,7 @@ class HpcloudController < BaseController
396
403
  hServiceToFind = oParams[:list_services]
397
404
  end
398
405
  # Search for service. Ex: Can be :Networking or network. I currently do not know why...
399
- hSearchServices= rhGet(hServices, :service_catalog)
406
+ hSearchServices= Lorj::rhGet(hServices, :service_catalog)
400
407
  sService = nil
401
408
  hServiceToFind.each { | sServiceElem |
402
409
  if hSearchServices.key?(sServiceElem)
@@ -405,15 +412,15 @@ class HpcloudController < BaseController
405
412
  end
406
413
  }
407
414
 
408
- forjError "Unable to find services %s" % hServiceToFind if sService.nil?
409
- result = rhGet(hServices, :service_catalog, sService).keys
415
+ Error "Unable to find services %s" % hServiceToFind if sService.nil?
416
+ result = Lorj::rhGet(hServices, :service_catalog, sService).keys
410
417
  result.delete("name")
411
418
  result.each_index { | iIndex |
412
419
  result[iIndex] = result[iIndex].to_s if result[iIndex].is_a?(Symbol)
413
420
  }
414
421
  return result
415
422
  else
416
- forjError "'%s' is not a valid object for 'get_services'" % sObjectType
423
+ Error "'%s' is not a valid object for 'get_services'" % sObjectType
417
424
  end
418
425
  end
419
426
  end
@@ -105,4 +105,9 @@ module HPCompute
105
105
  # This list must support the each function.
106
106
  oAddress
107
107
  end
108
+
109
+ def HPCompute.delete_server(oComputeConnect, oServer)
110
+ oComputeConnect.servers.get(oServer.id).destroy
111
+ end
112
+
108
113
  end
data/lorj.gemspec CHANGED
@@ -4,36 +4,39 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'lorj/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "lorj"
7
+ spec.name = 'lorj'
8
8
  spec.version = Lorj::VERSION
9
- spec.authors = ["forj team"]
10
- spec.email = ["forj@forj.io"]
11
- spec.summary = %q{Process Controllers framework system}
12
- spec.description = %q{Framework to create/maintain uniform process, against any kind of controller.}
13
- spec.homepage = "https://github.com/forj-oss/lorj"
14
- spec.license = "Apache License, Version 2.0."
9
+ spec.authors = ['forj team']
10
+ spec.email = ['forj@forj.io']
11
+ spec.summary = 'Process Controllers framework system'
12
+ spec.description = <<-END
13
+ Framework to create/maintain uniform process, against any kind of controller.
14
+ This library is used by forj to become cloud agnostic.
15
+ END
16
+ spec.homepage = 'https://github.com/forj-oss/lorj'
17
+ spec.license = 'Apache License, Version 2.0.'
15
18
 
16
19
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
22
+ spec.require_paths = ['lib']
20
23
 
21
- spec.add_development_dependency "bundler"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec", "~> 3.1.0"
24
- spec.rdoc_options << '--title' << 'Lorj - The Process Controllers framework system' <<
25
- '--main' << 'README.md'
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.1.0'
27
+ spec.rdoc_options << \
28
+ '--title Lorj - The Process Controllers framework system' << \
29
+ '--main README.md'
26
30
 
27
- # spec.add_runtime_dependency 'thor', '~>0.16.0'
28
- # spec.add_runtime_dependency 'nokogiri', '~>1.5.11'
29
- # spec.add_runtime_dependency 'fog', '~>1.19.0'
30
- # spec.add_runtime_dependency 'hpcloud', '~>2.0.9'
31
- # spec.add_runtime_dependency 'git', '>=1.2.7'
32
- # spec.add_runtime_dependency 'rbx-require-relative', '~>0.0.7'
33
- # spec.add_runtime_dependency 'highline', '~> 1.6.21'
31
+ # spec.add_runtime_dependency 'thor', '~>0.16.0'
32
+ # spec.add_runtime_dependency 'nokogiri', '~>1.5.11'
33
+ # spec.add_runtime_dependency 'fog', '~>1.19.0'
34
+ # spec.add_runtime_dependency 'hpcloud', '~>2.0.9'
35
+ # spec.add_runtime_dependency 'git', '>=1.2.7'
36
+ # spec.add_runtime_dependency 'rbx-require-relative', '~>0.0.7'
37
+ spec.add_runtime_dependency 'highline', '~> 1.6.21'
34
38
  spec.add_runtime_dependency 'ansi', '>= 1.4.3'
35
- # spec.add_runtime_dependency 'bundler'
36
- # spec.add_runtime_dependency 'encryptor', '1.3.0'
37
- # spec.add_runtime_dependency 'json', '1.7.5'
38
-
39
+ # spec.add_runtime_dependency 'bundler'
40
+ spec.add_runtime_dependency 'encryptor', '1.3.0'
41
+ # spec.add_runtime_dependency 'json', '1.7.5'
39
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lorj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - forj team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-10 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: highline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.21
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.21
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: ansi
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +80,23 @@ dependencies:
66
80
  - - '>='
67
81
  - !ruby/object:Gem::Version
68
82
  version: 1.4.3
69
- description: Framework to create/maintain uniform process, against any kind of controller.
83
+ - !ruby/object:Gem::Dependency
84
+ name: encryptor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.0
97
+ description: |2
98
+ Framework to create/maintain uniform process, against any kind of controller.
99
+ This library is used by forj to become cloud agnostic.
70
100
  email:
71
101
  - forj@forj.io
72
102
  executables:
@@ -137,10 +167,8 @@ licenses:
137
167
  metadata: {}
138
168
  post_install_message:
139
169
  rdoc_options:
140
- - --title
141
- - Lorj - The Process Controllers framework system
142
- - --main
143
- - README.md
170
+ - --title Lorj - The Process Controllers framework system
171
+ - --main README.md
144
172
  require_paths:
145
173
  - lib
146
174
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -162,3 +190,4 @@ summary: Process Controllers framework system
162
190
  test_files:
163
191
  - spec/forj-account_spec.rb
164
192
  - spec/forj-config_spec.rb
193
+ has_rdoc: