Merge pull request #14 from chef/os-detection

Os detection
This commit is contained in:
Dominik Richter 2015-09-14 16:38:49 +02:00
commit d7e0f98ace
4 changed files with 39 additions and 3 deletions

View file

@ -8,7 +8,7 @@ class Mysql < Vulcano.resource(1)
attr_reader :package, :service, :conf_dir, :conf_path, :data_dir, :log_dir, :log_path, :log_group, :log_dir_group
def initialize
# set OS-dependent filenames and paths
case os[:family]
case vulcano.os[:family]
when 'ubuntu', 'debian'
init_ubuntu
when 'redhat', 'fedora'

View file

@ -16,7 +16,7 @@ class Package < Vulcano.resource(1)
# select package manager
@pkgman = nil
case os[:family]
case vulcano.os[:family]
when 'ubuntu', 'debian'
@pkgman = Deb.new(vulcano)
when 'redhat', 'fedora'

View file

@ -7,7 +7,7 @@ class Postgres < Vulcano.resource(1)
attr_reader :service, :data_dir, :conf_dir, :conf_path
def initialize
case os[:family]
case vulcano.os[:family]
when 'ubuntu', 'debian'
@service = 'postgresql'
@data_dir = '/var/lib/postgresql'

View file

@ -6,6 +6,37 @@ require 'specinfra/helper'
require 'specinfra/helper/set'
require 'winrm'
module Specinfra
module Helper
module Os
def os
property[:os] = {} if ! property[:os]
if ! property[:os].include?(:family)
property[:os] = detect_os
end
property[:os]
end
private
def detect_os
backend = Specinfra.configuration.backend
if backend == :cmd || backend == :winrm
return { :family => 'windows', :release => nil, :arch => nil }
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
raise NotImplementedError, "Specinfra failed os detection."
end
end
end
end
module Vulcano::Backends
class SpecinfraHelper < Vulcano.backend(1)
name 'specinfra'
@ -29,6 +60,10 @@ module Vulcano::Backends
end
end
def os
Specinfra::Helper::Os.os
end
def file(path)
@files[path] ||= File.new(path)
end
@ -58,6 +93,7 @@ module Vulcano::Backends
def configure_shared_options
Specinfra::Backend::Cmd.send(:include, Specinfra::Helper::Set)
si = Specinfra.configuration
si.os = nil
if @conf['disable_sudo']
si.disable_sudo = true
else