Class: WdsServer
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- WdsServer
- Extended by:
- FriendlyId
- Includes:
- Encryptable, Parameterizable::ByIdName
- Defined in:
- app/models/wds_server.rb
Defined Under Namespace
Classes: Jail
Class Method Summary collapse
- .bootfile_path(architecture_name, loader = :bios, boot_type = :pxe) ⇒ Object
- .wdsify_architecture(architecture) ⇒ Object
Instance Method Summary collapse
- #all_images ⇒ Object
- #boot_image(name) ⇒ Object
- #boot_images ⇒ Object
- #client(host) ⇒ Object
- #clients ⇒ Object
- #create_client(host) ⇒ Object
- #delete_client(host) ⇒ Object
- #install_image(name) ⇒ Object
- #install_images ⇒ Object
- #next_server_ip ⇒ Object
- #refresh_cache ⇒ Object
- #shortname ⇒ Object
- #test_connection ⇒ Object
- #timezone ⇒ Object
Class Method Details
.bootfile_path(architecture_name, loader = :bios, boot_type = :pxe) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/wds_server.rb', line 122 def self.bootfile_path(architecture_name, loader = :bios, boot_type = :pxe) file_name = nil if boot_type == :local file_name = 'bootmgfw.efi' if loader == :uefi file_name = 'abortpxe.com' if loader == :bios elsif boot_type == :pxe file_name = 'wdsmgfw.efi' if loader == :uefi file_name = 'wdsnbp.com' if loader == :bios end raise ArgumentError, 'Invalid loader or boot type provided' if file_name.nil? "boot\\\\#{architecture_name}\\\\#{file_name}" end |
.wdsify_architecture(architecture) ⇒ Object
136 137 138 139 |
# File 'app/models/wds_server.rb', line 136 def self.wdsify_architecture(architecture) wds_arch = ForemanWds::WdsImage::WDS_IMAGE_ARCHES.find_index { |arch| arch =~ architecture.name } ForemanWds::WdsImage::WDS_ARCH_NAMES[wds_arch] end |
Instance Method Details
#all_images ⇒ Object
99 100 101 |
# File 'app/models/wds_server.rb', line 99 def all_images boot_images + install_images end |
#boot_image(name) ⇒ Object
40 41 42 |
# File 'app/models/wds_server.rb', line 40 def boot_image(name) images(:boot, name).first end |
#boot_images ⇒ Object
69 70 71 72 73 |
# File 'app/models/wds_server.rb', line 69 def boot_images cache.cache(:boot_images) do images(:boot) end.each { |i| i.wds_server = self } end |
#client(host) ⇒ Object
63 64 65 66 67 |
# File 'app/models/wds_server.rb', line 63 def client(host) clients.find do |c| [host.mac.upcase.tr(':', '-'), host.name].include?(c[:device_id]) || [host.name, host.shortname].include?(c[:device_name]) end end |
#clients ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/wds_server.rb', line 48 def clients objects = connection.run_wql('SELECT * FROM MSFT_WdsClient')[:msft_wdsclient] rescue nil objects = nil if objects.empty? objects ||= begin data = connection.shell(:powershell) do |s| s.run('Get-WdsClient | ConvertTo-Json -Compress') end.stdout data = '[]' if data.empty? underscore_result([JSON.parse(data)].flatten) end objects end |
#create_client(host) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'app/models/wds_server.rb', line 81 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 |
#delete_client(host) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'app/models/wds_server.rb', line 90 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 |
#install_image(name) ⇒ Object
44 45 46 |
# File 'app/models/wds_server.rb', line 44 def install_image(name) images(:install, name).first end |
#install_images ⇒ Object
75 76 77 78 79 |
# File 'app/models/wds_server.rb', line 75 def install_images cache.cache(:install_images) do images(:install) end.each { |i| i.wds_server = self } end |
#next_server_ip ⇒ Object
115 116 117 118 119 120 |
# File 'app/models/wds_server.rb', line 115 def next_server_ip IPSocket.getaddress URI(url).host rescue SocketError ::Rails.logger.info "Failed to look up IP of WDS server #{name}" nil end |
#refresh_cache ⇒ Object
147 148 149 |
# File 'app/models/wds_server.rb', line 147 def refresh_cache cache.refresh end |
#shortname ⇒ Object
109 110 111 112 113 |
# File 'app/models/wds_server.rb', line 109 def shortname cache.cache(:shortname) do connection.run_wql('SELECT Name FROM Win32_ComputerSystem')[:xml_fragment].first[:name] end end |
#test_connection ⇒ Object
141 142 143 144 145 |
# File 'app/models/wds_server.rb', line 141 def test_connection connection.run_wql('SELECT * FROM Win32_UTCTime').key? :win32_utc_time rescue StandardError false end |
#timezone ⇒ Object
103 104 105 106 107 |
# File 'app/models/wds_server.rb', line 103 def timezone cache.cache(:timezone) do connection.run_wql('SELECT Bias FROM Win32_TimeZone')[:xml_fragment].first[:bias].to_i * 60 end end |