2015-08-13 01:48:17 +00:00
|
|
|
# encoding: utf-8
|
2015-09-02 02:13:59 +00:00
|
|
|
require 'uri'
|
2015-08-29 23:11:23 +00:00
|
|
|
require 'vulcano/plugins'
|
|
|
|
|
|
|
|
module Vulcano
|
|
|
|
class Backend
|
2015-09-02 02:13:59 +00:00
|
|
|
# Expose all registered backends
|
2015-08-29 23:11:23 +00:00
|
|
|
def self.registry
|
|
|
|
@registry ||= {}
|
|
|
|
end
|
|
|
|
|
2015-09-02 02:13:59 +00:00
|
|
|
# Resolve target configuration in URI-scheme into
|
|
|
|
# all respective fields and merge with existing configuration.
|
|
|
|
# e.g. ssh://bob@remote => backend: ssh, user: bob, host: remote
|
2015-10-02 20:29:40 +00:00
|
|
|
def self.target_config(config = nil) # rubocop:disable Metrics/AbcSize
|
2015-09-28 11:03:05 +00:00
|
|
|
conf = config.nil? ? {} : config.dup
|
2015-08-30 02:46:46 +00:00
|
|
|
|
2015-10-02 20:29:40 +00:00
|
|
|
# in case the user specified a key-file, register it that way
|
2015-10-01 17:27:25 +00:00
|
|
|
key = conf['key']
|
2015-10-02 20:29:40 +00:00
|
|
|
if !key.nil? and File.file?(key)
|
|
|
|
conf['key_file'] = key
|
|
|
|
end
|
2015-10-01 17:27:25 +00:00
|
|
|
|
2015-09-03 12:56:08 +00:00
|
|
|
return conf if conf['target'].to_s.empty?
|
2015-08-30 02:46:46 +00:00
|
|
|
|
2015-09-05 14:07:54 +00:00
|
|
|
uri = URI.parse(conf['target'].to_s)
|
2015-10-03 21:39:09 +00:00
|
|
|
unless uri.host.nil? and uri.scheme.nil?
|
|
|
|
conf['backend'] ||= uri.scheme
|
|
|
|
conf['host'] ||= uri.host
|
|
|
|
conf['port'] ||= uri.port
|
|
|
|
conf['user'] ||= uri.user
|
|
|
|
conf['password'] ||= uri.password
|
|
|
|
conf['path'] ||= uri.path
|
|
|
|
end
|
2015-08-30 02:46:46 +00:00
|
|
|
|
|
|
|
# return the updated config
|
2015-08-29 23:11:23 +00:00
|
|
|
conf
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-02 02:13:59 +00:00
|
|
|
def self.backend(version = 1)
|
2015-08-29 23:11:23 +00:00
|
|
|
if version != 1
|
2015-09-03 21:18:28 +00:00
|
|
|
fail 'Only backend version 1 is supported!'
|
2015-08-29 23:11:23 +00:00
|
|
|
end
|
|
|
|
Vulcano::Plugins::Backend
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-08 15:58:32 +00:00
|
|
|
require 'vulcano/backend/docker'
|
2015-09-06 15:15:09 +00:00
|
|
|
require 'vulcano/backend/local'
|
2015-08-27 20:59:15 +00:00
|
|
|
require 'vulcano/backend/mock'
|
2015-08-30 00:13:07 +00:00
|
|
|
require 'vulcano/backend/specinfra'
|
2015-09-08 22:28:06 +00:00
|
|
|
require 'vulcano/backend/ssh'
|