Logging and skeleton for the NOW core.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 7 Jun 2016 13:28:01 +0000 (15:28 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Tue, 7 Jun 2016 13:31:56 +0000 (15:31 +0200)
README.md
config.ru
etc/now.yaml [new file with mode: 0644]
lib/api.rb
lib/nebula.rb [new file with mode: 0644]
version.rb [new file with mode: 0644]

index 585314e..ae0b615 100644 (file)
--- a/README.md
+++ b/README.md
@@ -5,5 +5,5 @@ This is the component to extend OpenNebula network orchestration capabilities.
 
 ## Launch
 ```
-rackup config.ru
+rackup
 ```
index d1b8fbf..00f9f4b 100644 (file)
--- a/config.ru
+++ b/config.ru
@@ -1,5 +1,9 @@
-Dir["./lib/*.rb"].each { |file|
-  require file
-}
+require 'logger'
 
+require './version.rb'
+require './lib/nebula.rb'
+require './lib/api.rb'
+
+$logger = Logger.new(STDOUT)
+$nebula = Now::Nebula.new()
 run Now::Application
diff --git a/etc/now.yaml b/etc/now.yaml
new file mode 100644 (file)
index 0000000..3dc3048
--- /dev/null
@@ -0,0 +1,3 @@
+opennebula:
+  admin_user: oneadmin
+  admin_password: 'good-password'
index 2a16ca0..0d9df51 100644 (file)
@@ -1,20 +1,21 @@
 require 'sinatra'
 require 'sinatra/cross_origin'
+require ::File.expand_path('../../version',  __FILE__)
 
 module Now
 
   class Application < Sinatra::Base
+    attr_accessor :nebula
     register Sinatra::CrossOrigin
-    attr_accessor :api_version
 
     def initialize
       super
-      @api_version = '0.0.0'
+      @nebula = $nebula
     end
 
     get // do
       cross_origin
-      @api_version
+      API_VERSION
     end
 
   end
diff --git a/lib/nebula.rb b/lib/nebula.rb
new file mode 100644 (file)
index 0000000..4026c7f
--- /dev/null
@@ -0,0 +1,30 @@
+require 'yaml'
+
+module Now
+
+  class Nebula
+    attr_accessor :config, :logger
+
+    def load_config(file)
+      begin
+        c = YAML.load_file(file)
+        @logger.debug "Config file '#{file}' loaded"
+        return c
+      rescue Errno::ENOENT
+        @logger.debug "Config file '#{file}' not found"
+        return {}
+      end
+    end
+
+    def initialize()
+      @logger = $logger
+      @logger.info "Starting Network Orchestrator Wrapper (NOW #{VERSION})"
+      @config = {}
+      @config.merge! load_config(::File.expand_path('../../etc/now.yaml', __FILE__))
+      @config.merge! load_config('/etc/now.yaml')
+      @logger.debug "Configuration: #{@config}"
+    end
+
+  end
+
+end
diff --git a/version.rb b/version.rb
new file mode 100644 (file)
index 0000000..7f4b2c4
--- /dev/null
@@ -0,0 +1,4 @@
+module Now
+  VERSION = '0.0.1'
+  API_VERSION = '0.0.0'
+end