Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
foreman_wds
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LiU IT - Infrastructure
foreman_wds
Commits
a55a42a1
Commit
a55a42a1
authored
6 years ago
by
Alexander Olofsson
Browse files
Options
Downloads
Patches
Plain Diff
Clean up install-image/client orchestration
parent
7a5191bf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/concerns/foreman_wds/host_extensions.rb
+1
-3
1 addition, 3 deletions
app/models/concerns/foreman_wds/host_extensions.rb
app/models/wds_server.rb
+66
-46
66 additions, 46 deletions
app/models/wds_server.rb
with
67 additions
and
49 deletions
app/models/concerns/foreman_wds/host_extensions.rb
+
1
−
3
View file @
a55a42a1
...
...
@@ -79,7 +79,6 @@ module ForemanWds
raise
NotImplementedError
,
'Not implemented yet'
return
unless
wds?
wds_server
.
ensure_unattend
(
self
)
client
=
wds_server
.
client
(
self
)
||
wds_server
.
create_client
(
self
)
Rails
.
logger
.
info
client
...
...
@@ -96,8 +95,7 @@ module ForemanWds
client
=
wds_server
.
client
(
self
)
return
unless
client
wds_server
.
delete_client
(
client
)
wds_server
.
delete_unattend
(
self
)
wds_server
.
delete_client
(
self
)
true
rescue
ScriptError
,
StandardError
=>
ex
Rails
.
logger
.
error
"Failed to remove WDS client,
#{
ex
}
"
...
...
This diff is collapsed.
Click to expand it.
app/models/wds_server.rb
+
66
−
46
View file @
a55a42a1
...
...
@@ -76,6 +76,20 @@ class WdsServer < ApplicationRecord
def
create_client
(
host
)
raise
NotImplementedError
,
'Not finished yet'
ensure_unattend
(
host
)
connection
.
shell
(
:powershell
)
do
|
sh
|
# New-WdsClient -DeviceID '#{host.mac.upcase.delete ':'}' -DeviceName '#{host.name}' -WdsClientUnattend '#{unattend_file(host)}' -BootImagePath 'boot\\#{wdsify_architecture(host.architecture)}\\images\\#{(host.wds_boot_image || boot_images.first).file_name}' -PxePromptPolicy 'NoPrompt'
end
end
def
delete_client
(
host
)
raise
NotImplementedError
,
'Not finished yet'
delete_unattend
(
host
)
connection
.
shell
(
:powershell
)
do
|
sh
|
sh
.
run
(
"Remove-WdsClient -DeviceID '
#{
host
.
mac
.
upcase
.
delete
':'
}
'"
)
end
end
def
all_images
...
...
@@ -101,52 +115,6 @@ class WdsServer < ApplicationRecord
nil
end
def
ensure_unattend
(
host
)
raise
NotImplementedException
,
'TODO: Not implemented yet'
connection
.
shell
(
:powershell
)
do
|
sh
|
unattend_path
=
''
# TODO: find or specify remoteinstall path as a parameter
unattend_file
=
"
#{
unattend_path
}
\\
#{
host
.
mac
.
tr
':'
,
'_'
}
.xml"
# TODO: render template, send as heredoc
# sh.run("$unattend_render = @'\n#{unattend_template}\n'@")
# sh.run("New-Item -Path '#{unattend_file}' -ItemType 'file' -Value $unattend_render")
if
SETTINGS
[
:wds_unattend_group
]
# New-WdsInstallImageGroup -Name #{SETTINGS[:wds_unattend_group]}
# Export-WdsInstallImage -ImageGroup <Group> ...
# Import-WdsInstallImage -ImageGroup #{SETTINGS[:wds_unattend_group]} -UnattendFile '#{unattend_file}' -OverwriteUnattend ...
else
source_image
=
host
.
wds_facet
.
install_image
target_image
=
ForemanWds
::
WdsInstallImage
.
new
(
wds_server:
self
,
file_name:
"install-
#{
host
.
mac
.
tr
':'
,
'_'
}
.wim"
,
image_group:
source_image
.
image_group
,
image_name:
"
#{
source_image
.
image_name
}
(for
#{
host
.
name
}
)"
)
sh
.
run
(
"Copy-WdsInstallImage -ImageGroup '
#{
source_image
.
image_group
}
' -FileName '
#{
source_image
.
file_name
}
' -ImageName '
#{
source_image
.
image_name
}
' -NewFileName '
#{
target_image
.
file_name
}
' -NewImageName '
#{
target_image
.
image_name
}
'"
)
sh
.
run
(
"Set-WdsInstallImage -ImageGroup '
#{
target_image
.
image_group
}
' -FileName '
#{
target_image
.
file_name
}
' -ImageName '
#{
target_image
.
image_name
}
' -DisplayOrder 99999 -UnattendFile '
#{
unattend_file
}
' -OverwriteUnattend"
)
end
end
end
def
delete_unattend
(
host
)
raise
NotImplementedException
,
'TODO: Not implemented yet'
image
=
host
.
wds_facet
.
install_image
group
=
SETTINGS
[
:wds_unattend_group
]
if
group
image
=
image
.
dup
.
tap
{
|
i
|
i
.
image_group
=
group
}
else
image
.
file_name
=
"install-
#{
host
.
mac
.
tr
':'
,
'_'
}
.wim"
image
.
image_name
=
"
#{
image
.
image_name
}
(for
#{
host
.
name
}
)"
end
unattend_path
=
''
# TODO: find or specify remoteinstall path as a parameter
unattend_file
=
"
#{
unattend_path
}
\\
#{
host
.
mac
.
tr
':'
,
'_'
}
.xml"
connection
.
shell
(
:powershell
)
do
|
sh
|
sh
.
run
(
"Remove-WdsInstallImage -ImageGroup '
#{
image
.
image_group
}
' -ImageName '
#{
image
.
image_name
}
' -FileName '
#{
image
.
file_name
}
'"
)
sh
.
run
(
"Remove-Item -Path '
#{
unattend_file
}
'"
)
end
end
def
self
.
bootfile_path
(
architecture_name
,
loader
=
:bios
,
boot_type
=
:pxe
)
file_name
=
nil
if
boot_type
==
:local
...
...
@@ -178,6 +146,58 @@ class WdsServer < ApplicationRecord
private
def
unattend_path
cache
.
cache
(
:unattend_path
)
do
JSON
.
parse
(
connection
.
shell
(
:powershell
)
do
|
sh
|
sh
.
run
(
'Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\WDSServer\Providers\WDSTFTP -Name RootFolder | select RootFolder | ConvertTo-Json -Compress'
)
end
,
symbolize_names:
true
)[
:RootFolder
]
end
end
def
unattend_file
(
host
)
"
#{
unattend_path
}
\\
#{
host
.
mac
.
tr
':'
,
'_'
}
.xml"
end
def
target_image_for
(
host
)
source_image
=
host
.
wds_install_image
ForemanWds
::
WdsInstallImage
.
new
(
wds_server:
self
,
file_name:
"install-
#{
host
.
mac
.
tr
':'
,
'_'
}
.wim"
,
image_group:
SETTINGS
[
:wds_unattend_group
]
||
source_image
.
image_group
,
image_name:
"
#{
source_image
.
image_name
}
(specialized for
#{
host
.
name
}
/
#{
host
.
mac
}
)"
)
end
def
ensure_unattend
(
host
)
raise
NotImplementedException
,
'TODO: Not implemented yet'
connection
.
shell
(
:powershell
)
do
|
sh
|
target_image
=
target_image_for
(
host
)
# TODO: render template, send as heredoc
# sh.run("$unattend_render = @'\n#{unattend_template}\n'@")
# sh.run("New-Item -Path '#{unattend_file(host)}' -ItemType 'file' -Value $unattend_render")
if
SETTINGS
[
:wds_unattend_group
]
# New-WdsInstallImageGroup -Name #{SETTINGS[:wds_unattend_group]}
# Export-WdsInstallImage -ImageGroup <Group> ...
# Import-WdsInstallImage -ImageGroup #{SETTINGS[:wds_unattend_group]} -UnattendFile '#{unattend_file(host)}' -OverwriteUnattend ...
else
source_image
=
host
.
wds_facet
.
install_image
sh
.
run
(
"Copy-WdsInstallImage -ImageGroup '
#{
source_image
.
image_group
}
' -FileName '
#{
source_image
.
file_name
}
' -ImageName '
#{
source_image
.
image_name
}
' -NewFileName '
#{
target_image
.
file_name
}
' -NewImageName '
#{
target_image
.
image_name
}
'"
)
sh
.
run
(
"Set-WdsInstallImage -ImageGroup '
#{
target_image
.
image_group
}
' -FileName '
#{
target_image
.
file_name
}
' -ImageName '
#{
target_image
.
image_name
}
' -DisplayOrder 99999 -UnattendFile '
#{
unattend_file
(
host
)
}
' -OverwriteUnattend"
)
end
end
end
def
delete_unattend
(
host
)
image
=
target_image_for
(
host
)
connection
.
shell
(
:powershell
)
do
|
sh
|
sh
.
run
(
"Remove-WdsInstallImage -ImageGroup '
#{
image
.
image_group
}
' -ImageName '
#{
image
.
image_name
}
' -FileName '
#{
image
.
file_name
}
'"
)
sh
.
run
(
"Remove-Item -Path '
#{
unattend_file
(
host
)
}
'"
)
end
.
errcode
.
zero?
end
def
images
(
type
,
name
=
nil
)
raise
ArgumentError
,
'Type must be :boot or :install'
unless
%i[boot install]
.
include?
type
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment