Class: PuppetX::Sqlserver::ServerHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/sqlserver/server_helper.rb

Class Method Summary collapse

Class Method Details

.get_sub_features(super_feature) ⇒ Object



9
10
11
# File 'lib/puppet_x/sqlserver/server_helper.rb', line 9

def self.get_sub_features(super_feature)
  @super_feature_hash[super_feature.to_sym]
end

.is_domain_or_local_user?(user, hostname) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/puppet_x/sqlserver/server_helper.rb', line 17

def self.is_domain_or_local_user?(user, hostname)
  if /(^(((nt (authority|service))|#{hostname})\\\w+)$)|^(\w+)$/i.match(user)
    false
  else
    true
  end
end

.is_super_feature(feature) ⇒ Object



13
14
15
# File 'lib/puppet_x/sqlserver/server_helper.rb', line 13

def self.is_super_feature(feature)
  @super_feature_hash.has_key?(feature.to_sym)
end

.sql_version_from_install_source(source_dir) ⇒ Object

Returns either SQL_2016, SQL_2014 or SQL_2012 if it can determine the SQL Version from the install source Returns nil if it can not be determined



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/puppet_x/sqlserver/server_helper.rb', line 27

def self.sql_version_from_install_source(source_dir)
  # Attempt to read the Mediainfo.xml file in the root of the install media
  media_file = File.expand_path("#{source_dir}/MediaInfo.xml")
  return nil unless File.exist?(media_file)
  # As we don't have a XML parser easily, just use simple text matching to find the following XML element. This
  # also means we can just ignore BOM markers etc.
  #     <Property Id="BaselineVersion" Value="xx.yyy.zz." />
  content = File.read(media_file)
  index1 = content.index('"BaselineVersion"')
  return nil if index1.nil?
  index2 = content.index('/>',index1) 
  return nil if index2.nil?
  content = content.slice(index1 + 18, index2 - index1 - 18)
  # Extract the version number from the text snippet
  #     Value="xx.yyy.zz."
  ver = content.match('"(.+)"')
  return nil if ver.nil?

  return SQL_2016 if ver[1].start_with?('13.')
  return SQL_2014 if ver[1].start_with?('12.')
  return SQL_2012 if ver[1].start_with?('11.')

  nil
end