2015-08-30 00:13:07 +00:00
|
|
|
# encoding: utf-8
|
2015-09-04 07:59:30 +00:00
|
|
|
|
2015-09-01 09:48:50 +00:00
|
|
|
require 'shellwords'
|
2015-09-14 12:50:08 +00:00
|
|
|
require 'specinfra'
|
|
|
|
require 'specinfra/helper'
|
|
|
|
require 'specinfra/helper/set'
|
2015-08-30 00:13:07 +00:00
|
|
|
|
2015-09-14 14:36:54 +00:00
|
|
|
module Specinfra
|
|
|
|
module Helper
|
|
|
|
module Os
|
|
|
|
def os
|
2015-09-25 17:46:46 +00:00
|
|
|
property[:os] = {} if !property[:os]
|
|
|
|
if !property[:os].include?(:family)
|
2015-09-14 14:36:54 +00:00
|
|
|
property[:os] = detect_os
|
|
|
|
end
|
|
|
|
property[:os]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2015-09-25 17:46:46 +00:00
|
|
|
|
2015-09-14 14:36:54 +00:00
|
|
|
def detect_os
|
|
|
|
backend = Specinfra.configuration.backend
|
|
|
|
if backend == :cmd || backend == :winrm
|
2015-09-25 17:46:46 +00:00
|
|
|
return { family: 'windows', release: nil, arch: nil }
|
2015-09-14 14:36:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Specinfra::Helper::DetectOs.subclasses.each do |c|
|
|
|
|
res = c.detect
|
|
|
|
if res
|
|
|
|
res[:arch] ||= Specinfra.backend.run_command('uname -m').stdout.strip
|
|
|
|
return res
|
|
|
|
end
|
|
|
|
end
|
2015-09-25 17:46:46 +00:00
|
|
|
fail NotImplementedError, 'Specinfra failed os detection.'
|
2015-09-14 14:36:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-30 00:13:07 +00:00
|
|
|
module Vulcano::Backends
|
|
|
|
class SpecinfraHelper < Vulcano.backend(1)
|
|
|
|
name 'specinfra'
|
|
|
|
|
2015-09-29 13:10:45 +00:00
|
|
|
autoload :Docker, 'vulcano/backend/specinfra_docker'
|
|
|
|
autoload :Exec, 'vulcano/backend/specinfra_exec'
|
|
|
|
autoload :Ssh, 'vulcano/backend/specinfra_ssh'
|
|
|
|
autoload :Winrm, 'vulcano/backend/specinfra_winrm'
|
|
|
|
|
|
|
|
autoload :File, 'vulcano/backend/specinfra_file'
|
|
|
|
|
2015-08-30 00:13:07 +00:00
|
|
|
def initialize(conf)
|
|
|
|
@conf = conf
|
|
|
|
@files = {}
|
2015-08-30 02:46:46 +00:00
|
|
|
|
2015-08-30 00:13:07 +00:00
|
|
|
configure_shared_options
|
2015-08-30 02:46:46 +00:00
|
|
|
|
2015-09-29 13:10:45 +00:00
|
|
|
type = @conf['backend'].to_s
|
|
|
|
case type
|
|
|
|
when 'docker'
|
|
|
|
spec_backend = Specinfra::Backend::Docker
|
|
|
|
backend_helper = Docker
|
|
|
|
when 'exec'
|
|
|
|
spec_backend = Specinfra::Backend::Exec
|
|
|
|
backend_helper = Exec
|
|
|
|
when 'ssh'
|
|
|
|
spec_backend = Specinfra::Backend::Ssh
|
|
|
|
backend_helper = Ssh
|
|
|
|
when 'winrm'
|
|
|
|
spec_backend = Specinfra::Backend::Winrm
|
|
|
|
backend_helper = Winrm
|
2015-08-30 00:13:07 +00:00
|
|
|
else
|
2015-09-03 21:24:42 +00:00
|
|
|
fail "Cannot configure Specinfra backend #{type}: it isn't supported yet."
|
2015-08-30 00:13:07 +00:00
|
|
|
end
|
2015-09-29 13:10:45 +00:00
|
|
|
|
|
|
|
reset_backend(spec_backend)
|
|
|
|
backend_helper.configure(@conf)
|
2015-08-30 00:13:07 +00:00
|
|
|
end
|
|
|
|
|
2015-09-14 14:36:54 +00:00
|
|
|
def os
|
|
|
|
Specinfra::Helper::Os.os
|
|
|
|
end
|
|
|
|
|
2015-08-30 00:13:07 +00:00
|
|
|
def file(path)
|
2015-09-15 10:20:05 +00:00
|
|
|
@files[path] ||= File.new(self, path)
|
2015-08-30 00:13:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_command(cmd)
|
|
|
|
Specinfra::Runner.run_command(cmd)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
'SpecInfra Backend Runner'
|
|
|
|
end
|
|
|
|
|
|
|
|
def configure_shared_options
|
|
|
|
Specinfra::Backend::Cmd.send(:include, Specinfra::Helper::Set)
|
2015-09-14 20:10:02 +00:00
|
|
|
|
|
|
|
# Force specinfra to disregard any locally detected backend and instead
|
|
|
|
# retry backend detection.
|
|
|
|
Specinfra::Properties.instance.properties({})
|
|
|
|
|
2015-08-30 00:13:07 +00:00
|
|
|
si = Specinfra.configuration
|
|
|
|
if @conf['disable_sudo']
|
|
|
|
si.disable_sudo = true
|
|
|
|
else
|
|
|
|
si.sudo_password = @conf['sudo_password']
|
|
|
|
si.sudo_options = @conf['sudo_options']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-29 13:10:45 +00:00
|
|
|
def reset_backend(x)
|
|
|
|
x.instance_variable_set(:@instance, nil)
|
2015-08-30 00:13:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|