def initialize
super
- @nebula = $nebula
+ @nebula = Now::Nebula.new($config)
end
configure do
helpers do
def switch_user(user)
if user.nil?
- @nebula.switch_server()
+ nebula.switch_server()
else
- @nebula.switch_user(user)
+ nebula.switch_user(user)
end
end
end
cross_origin
begin
switch_user(params['user'])
- networks = @nebula.list_networks
+ networks = nebula.list_networks
JSON.pretty_generate(networks)
rescue NowError => e
logger.error "[HTTP #{e.code}] #{e.message}"
cross_origin
begin
switch_user(params['user'])
- network = @nebula.get(params['id'])
+ network = nebula.get(params['id'])
JSON.pretty_generate(network)
rescue NowError => e
logger.error "[HTTP #{e.code}] #{e.message}"
--- /dev/null
+require 'logger'
+require 'yaml'
+
+module Now
+
+ CONFIG_FILES = [
+ ::File.expand_path('~/.config/now.yml'),
+ '/etc/now.yml',
+ ::File.expand_path('../../etc/now.yml', __FILE__),
+ ]
+
+ # Config class for NOW
+ class Config < Hash
+ attr_accessor :logger
+
+ def load_config(file)
+ 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
+
+ def initialize
+ @logger = $logger
+ config = {}
+
+ CONFIG_FILES.each do |path|
+ if ::File.exist?(path)
+ config = load_config(path)
+ break
+ end
+ end
+ #logger.debug "[config] Configuration: #{config}"
+
+ replace config
+ end
+
+ end
+end
module Now
EXPIRE_LENGTH = 8 * 60 * 60
- CONFIG_FILES = [
- ::File.expand_path('~/.config/now.yml'),
- '/etc/now.yml',
- ::File.expand_path('../../etc/now.yml', __FILE__),
- ]
# NOW core class for communication with OpenNebula
class Nebula
- attr_accessor :logger
+ attr_accessor :logger, :config
@ctx = nil
@server_ctx = nil
@user_ctx = nil
- def load_config(file)
- 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
-
def one_connect(url, credentials)
logger.debug "Connecting to #{url} ..."
return OpenNebula::Client.new(credentials, url)
end
def switch_user(user)
- admin_user = @config['opennebula']['admin_user']
- admin_password = @config['opennebula']['admin_password']
+ admin_user = config['opennebula']['admin_user']
+ admin_password = config['opennebula']['admin_password']
logger.debug "Authentication from #{admin_user} to #{user}"
server_auth = ServerCipherAuth.new(admin_user, admin_password)
end
def switch_server
- admin_user = @config['opennebula']['admin_user']
- admin_password = @config['opennebula']['admin_password']
+ admin_user = config['opennebula']['admin_user']
+ admin_password = config['opennebula']['admin_password']
logger.debug "Authentication to #{admin_user}"
direct_token = "#{admin_user}:#{admin_password}"
@ctx = @server_ctx
end
- def initialize
+ def initialize(config)
@logger = $logger
logger.info "Starting Network Orchestrator Wrapper (NOW #{VERSION})"
- @config = {}
- CONFIG_FILES.each do |path|
- if ::File.exist?(path)
- @config = load_config(path)
- break
- end
- end
- logger.debug "Configuration: #{@config}"
+ @config = config
+ #logger.debug "[nebula] Configuration: #{config}"
- @url = @config['opennebula']['endpoint']
+ @url = config['opennebula']['endpoint']
end
def list_networks