From 388a78c12deaef1f878a7062796c1a5c716bda9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Tue, 7 Jun 2016 15:28:01 +0200 Subject: [PATCH] Logging and skeleton for the NOW core. --- README.md | 2 +- config.ru | 10 +++++++--- etc/now.yaml | 3 +++ lib/api.rb | 7 ++++--- lib/nebula.rb | 30 ++++++++++++++++++++++++++++++ version.rb | 4 ++++ 6 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 etc/now.yaml create mode 100644 lib/nebula.rb create mode 100644 version.rb diff --git a/README.md b/README.md index 585314e..ae0b615 100644 --- 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 ``` diff --git a/config.ru b/config.ru index d1b8fbf..00f9f4b 100644 --- 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 index 0000000..3dc3048 --- /dev/null +++ b/etc/now.yaml @@ -0,0 +1,3 @@ +opennebula: + admin_user: oneadmin + admin_password: 'good-password' diff --git a/lib/api.rb b/lib/api.rb index 2a16ca0..0d9df51 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -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 index 0000000..4026c7f --- /dev/null +++ b/lib/nebula.rb @@ -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 index 0000000..7f4b2c4 --- /dev/null +++ b/version.rb @@ -0,0 +1,4 @@ +module Now + VERSION = '0.0.1' + API_VERSION = '0.0.0' +end -- 1.8.2.3