Skip to content

Commit 4cb3776

Browse files
author
Morgan Haskel
committed
Merge pull request #57 from cyberious/RenameComplete
Finish refactor to all methods as issue occurs while running against master
2 parents 6923fd9 + 0fee05b commit 4cb3776

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+298
-288
lines changed

examples/database_full.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
mssql::database{ 'testdb_full':
1+
sqlserver::config{ 'MSSQLSERVER':
2+
admin_user => 'sa',
3+
admin_pass => 'Pupp3t1@',
4+
}
5+
sqlserver::database{ 'testdb_full':
26
instance => 'MSSQLSERVER',
37
containment => 'PARTIAL',
48
compatibility => 110,

examples/init.pp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
$sapwd = 'Pupp3t1@'
1313
$instance_name = 'MSSQLSERVER'
1414

15-
mssql_instance{ $instance_name:
15+
sqlserver_instance{ $instance_name:
1616
source => 'E:/',
1717
security_mode => 'SQL',
1818
sa_pwd => $sapwd,
1919
features => ['SQL'],
2020
sql_sysadmin_accounts => ['vagrant'],
2121
}
2222

23-
mssql::config{ 'MSSQLSERVER':
23+
sqlserver::config{ 'MSSQLSERVER':
2424
admin_user => 'sa',
2525
admin_pass => 'Pupp3t1@',
2626
require => Mssql_instance[$instance_name],
2727
}
28-
mssql::login{ 'padmin':
28+
29+
sqlserver::login{ 'padmin':
2930
password => 'PadminP@ssw0rd1',
3031
instance => $instance_name,
31-
require => Mssql::Config[$instance_name],
3232
}

examples/sp_configure.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
sqlserver::config{ 'MSSQLSERVER':
2+
admin_user => 'sa',
3+
admin_pass => 'Pupp3t1@',
4+
require => Mssql_instance[$instance_name],
5+
}
16
#Enable Filestream access on server
27
mssql::sp_configure{ 'filestream access level':
38
value => 1,

files/install_dot_net_35.ps1

Lines changed: 0 additions & 15 deletions
This file was deleted.

files/run_discovery.ps1

Lines changed: 0 additions & 34 deletions
This file was deleted.

files/sqlserver_management.psm1

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/puppet/parser/functions/mssql_is_domain_user.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib/puppet_x/sqlserver/server_helper'))
2+
3+
module Puppet::Parser::Functions
4+
newfunction(:sqlserver_is_domain_or_local_user, :type => :rvalue) do |args|
5+
if args.length != 1
6+
raise Puppet::ParseError, ("is_domain_or_local_user(): requires exactly 1 argument, you provided #{args.length}")
7+
end
8+
PuppetX::Sqlserver::ServerHelper.is_domain_or_local_user?(args[0], Facter.value(:hostname))
9+
end
10+
end

lib/puppet/parser/functions/mssql_validate_instance_name.rb renamed to lib/puppet/parser/functions/sqlserver_validate_instance_name.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# @raise [Puppet::ParserError] Instance name can not start or end with underscore (_)
1212
#
1313
module Puppet::Parser::Functions
14-
newfunction(:mssql_validate_instance_name, :docs => <<DOC) do |args|
14+
newfunction(:sqlserver_validate_instance_name, :docs => <<DOC) do |args|
1515
Validate the MS SQL Instance name based on what Microsoft has set within the document located at
1616
http://msdn.microsoft.com/en-us/library/ms143531(v=sql.120).aspx
1717
DOC

lib/puppet/parser/functions/mssql_validate_on_off.rb renamed to lib/puppet/parser/functions/sqlserver_validate_on_off.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Puppet::Parser::Functions
2-
newfunction(:mssql_validate_on_off) do |args|
2+
newfunction(:sqlserver_validate_on_off) do |args|
33
if args.length != 1
44
raise Puppet::ParseError, ("validate_on_off(): requires exactly 1 argument, you provided #{args.length}")
55
end

lib/puppet/parser/functions/mssql_validate_range.rb renamed to lib/puppet/parser/functions/sqlserver_validate_range.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Puppet::Parser::Functions
2-
newfunction(:mssql_validate_range) do |args|
2+
newfunction(:sqlserver_validate_range) do |args|
33
if (args.length < 3) or (args.length > 4) then
44
raise Puppet::ParseError, ("validate_range(): wrong number of arguments (#{args.length}; must be 3)")
55
end

lib/puppet/parser/functions/mssql_validate_size.rb renamed to lib/puppet/parser/functions/sqlserver_validate_size.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Puppet::Parser::Functions
2-
newfunction(:mssql_validate_size) do |args|
2+
newfunction(:sqlserver_validate_size) do |args|
33
if args.length != 1
44
raise(Puppet::ParseError, "mssql_validate_size(): requires exactly 1 argument, you provided #{args.length}")
55
end

lib/puppet/parser/functions/mssql_validate_svrroles_hash.rb renamed to lib/puppet/parser/functions/sqlserver_validate_svrroles_hash.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Puppet::Parser::Functions
2-
newfunction(:mssql_validate_svrroles_hash) do |args|
2+
newfunction(:sqlserver_validate_svrroles_hash) do |args|
33
if args.length != 1 then
4-
raise Puppet::ParseError, ("mssql_validate_svcrole_hash(): wrong number of arguments (#{args.length}; must be 1)")
4+
raise Puppet::ParseError, ("sqlserver_validate_svcrole_hash(): wrong number of arguments (#{args.length}; must be 1)")
55
end
66

77
value = args[0]

lib/puppet/property/login.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'puppet/property'
22

3-
class Puppet::Property::MssqlLogin < Puppet::Property
3+
class Puppet::Property::SqlserverLogin < Puppet::Property
44
desc 'A MS SQL Login, possible to be domain or local account'
55
validate do |value|
66
# @todo

lib/puppet/provider/mssql.rb

Lines changed: 0 additions & 79 deletions
This file was deleted.

lib/puppet/provider/sqlserver.rb

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib/puppet_x/sqlserver/server_helper'))
2+
require File.expand_path(File.join(File.dirname(__FILE__), 'sqlserver'))
3+
require 'tempfile'
4+
5+
class Puppet::Provider::Sqlserver < Puppet::Provider
6+
confine :operatingsystem => :windows
7+
8+
initvars
9+
10+
commands :powershell =>
11+
if File.exists?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe")
12+
"#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe"
13+
elsif File.exists?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe")
14+
"#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe"
15+
else
16+
'powershell.exe'
17+
end
18+
19+
def try_execute(command, msg = nil)
20+
begin
21+
execute(command.compact)
22+
rescue Puppet::ExecutionFailure => error
23+
msg = "Failure occured when trying to install SQL Server #{@resource[:name]}" if msg.nil?
24+
raise Puppet::Error, "#{msg} \n #{error}"
25+
end
26+
end
27+
28+
##
29+
# Used by tsql provider
30+
##
31+
def self.run_authenticated_sqlcmd(query, opts)
32+
b = binding
33+
@sql_instance_config = "C:/Program Files/Microsoft SQL Server/.puppet/.#{opts[:instance_name]}.cfg"
34+
if File.exists?(@sql_instance_config)
35+
@sql_instance_config = native_path(@sql_instance_config)
36+
else
37+
raise Puppet::ParseError, "Config file does not exist"
38+
end
39+
temp = Tempfile.new(['puppet', '.sql'])
40+
begin
41+
temp.write(query)
42+
temp.flush
43+
temp.close
44+
#input file is used in the authenticated_query.ps1.erb template
45+
input_file = native_path(temp.path)
46+
@instance = opts[:instance_name]
47+
erb_template = File.join(template_path, 'authenticated_query.ps1.erb')
48+
ps1 = ERB.new(File.new(erb_template).read, nil, '-')
49+
temp_ps1 = Tempfile.new(['puppet', '.ps1'])
50+
begin
51+
temp_ps1.write(ps1.result(b))
52+
temp_ps1.flush
53+
temp_ps1.close
54+
result = Puppet::Util::Execution.execute(['powershell.exe', '-noprofile', '-executionpolicy', 'unrestricted', temp_ps1.path], {:failonfail => false}) #We expect some things to fail in order to run as an only if
55+
debug("Return result #{result.exitstatus}")
56+
return result
57+
ensure
58+
temp_ps1.close
59+
temp_ps1.unlink
60+
end
61+
ensure
62+
temp.close
63+
temp.unlink
64+
end
65+
return result
66+
end
67+
68+
private
69+
def self.native_path(path)
70+
path.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
71+
end
72+
73+
def self.template_path
74+
return File.expand_path(File.join(File.dirname(__FILE__), '../templates'))
75+
end
76+
77+
def not_nil_and_not_empty?(obj)
78+
!obj.nil? and !obj.empty?
79+
end
80+
81+
def self.run_discovery_script
82+
discovery = <<-DISCOVERY
83+
if(Test-Path 'C:\\Program Files\\Microsoft SQL Server\\120\\Setup Bootstrap\\SQLServer2014\\setup.exe'){
84+
pushd 'C:\\Program Files\\Microsoft SQL Server\\120\\Setup Bootstrap\\SQLServer2014\\'
85+
Start-Process -FilePath .\\setup.exe -ArgumentList @("/Action=RunDiscovery","/q") -Wait -WindowStyle Hidden
86+
popd
87+
}elseif(Test-Path 'C:\\Program Files\\Microsoft SQL Server\\110\\Setup Bootstrap\\SQLServer2012\\setup.exe'){
88+
pushd 'C:\\Program Files\\Microsoft SQL Server\\110\\Setup Bootstrap\\SQLServer2012\\'
89+
Start-Process -FilePath .\\setup.exe -ArgumentList @("/Action=RunDiscovery","/q") -Wait -WindowStyle Hidden
90+
popd
91+
}
92+
93+
$file = gci 'C:\\Program Files\\Microsoft SQL Server\\*\\Setup Bootstrap\\Log\\*\\SqlDiscoveryReport.xml' -ErrorAction Ignore | sort -Descending | select -First 1
94+
if($file -ne $null) {
95+
[xml] $xml = cat $file
96+
$json = $xml.ArrayOfDiscoveryInformation.DiscoveryInformation
97+
$hash = @{"instances" = @();"TimeStamp"= ("{0:yyyy-MM-dd HH:mm:ss}" -f $file.CreationTime)}
98+
foreach($instance in ($json | % { $_.Instance } | Get-Unique )){
99+
$features = @()
100+
$json | %{
101+
if($_.instance -eq $instance){
102+
$features += $_.feature
103+
}
104+
}
105+
if($instance -eq "" ){
106+
$hash.Add("Generic Features",$features)
107+
}else{
108+
$hash["instances"] += $instance
109+
$hash.Add($instance,@{"features"=$features})
110+
}
111+
}
112+
$file.Directory.Delete($true)
113+
Write-Host (ConvertTo-Json $hash)
114+
}else{
115+
Write-host ("{}")
116+
}
117+
DISCOVERY
118+
result = powershell([discovery])
119+
JSON.parse(result)
120+
end
121+
122+
def self.run_install_dot_net
123+
install_dot_net = <<-DOTNET
124+
Install-WindowsFeature NET-Framework-Core
125+
126+
Write-Host "Installing .Net Framework 3.5, do not close this prompt..."
127+
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:$LocalSource | Out-Null
128+
$Result = Dism /online /Get-featureinfo /featurename:NetFx3
129+
If($Result -contains "State : Enabled")
130+
{
131+
Write-Host "Install .Net Framework 3.5 successfully."
132+
}
133+
Else
134+
{
135+
Write-Host "Failed to install Install .Net Framework 3.5,please make sure the local source is correct."
136+
}
137+
DOTNET
138+
powershell([install_dot_net])
139+
end
140+
end

0 commit comments

Comments
 (0)