Skip to content

Commit

Permalink
share SLP discovery with AutoYast
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Mar 24, 2014
1 parent ae09184 commit 4974509
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 24 deletions.
23 changes: 2 additions & 21 deletions src/clients/discover_registration_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@
require "registration/helpers"

module Yast
import 'SlpService'
import 'UI'
import 'Label'
import 'Report'

class DiscoverRegistrationServicesClient < Client
include Yast::Logger

REGISTRATION_SERVICES = {
'susemanager' => 'SUSE Manager'
}

SUPPORTED_SERVICES = REGISTRATION_SERVICES.keys

attr_reader :services

def initialize
Expand All @@ -25,16 +18,10 @@ def initialize
def main
textdomain "registration"

busy_box do
log.info "Searching for #{SUPPORTED_SERVICES.inspect} SLP services"
SUPPORTED_SERVICES.each do |service_name|
services.concat(SlpService.all(service_name))
end
::Registration::Helpers.slp_feedback do
@services = ::Registration::Helpers.slp_discovery
end

log.debug "Found services: #{services.inspect}"
log.info "Found #{services.size} services: #{services.map(&:slp_url).inspect}"

services.empty? ? nil : select_registration_service
end

Expand Down Expand Up @@ -108,12 +95,6 @@ def services_radio_buttons
end
end

def busy_box
Popup.ShowFeedback(_("Searching..."), _("Looking up local registration servers..."))
yield
ensure
Popup.ClearFeedback
end
end unless defined?(DiscoverRegistrationServicesClient)
DiscoverRegistrationServicesClient.new.main
end
30 changes: 28 additions & 2 deletions src/clients/scc_auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ def write
# set the registration URL
url = @config.reg_server if @config.reg_server && !@config.reg_server.empty?

# use SLP discovery
if @config.slp_discovery
# TODO FIXME: do SLP query
# url = ...
url = find_slp_server
return false unless url
end

@registration = ::Registration::Registration.new(url)
Expand Down Expand Up @@ -497,6 +498,31 @@ def configure_registration
ret
end

# find registration server via SLP
# @retun [String,nil] URL of the server, nil on error
def find_slp_server
# do SLP query
slp_services = ::Registration::Helpers.slp_discovery_feedback
slp_urls = slp_services.map(&:slp_url)

# remove possible duplicates
slp_urls.uniq!
log.info "Found #{slp_urls.size} SLP servers"

case slp_urls.size
when 0
Report.Error(_("SLP discovery failed, no server found"))
return nil
when 1
return slp_urls.first
else
# TODO FIXME: use first found or fail?
Report.Error(_("Found %s SLP servers, only one is supported.") % slp_urls.size)
return nil
end

end

# UI workflow definition
def start_workflow
aliases = {
Expand Down
34 changes: 33 additions & 1 deletion src/lib/registration/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@ class Helpers
include Yast::Logger
extend Yast::I18n

textdomain "registration"

Yast.import "Linuxrc"
Yast.import "Mode"
Yast.import "Popup"
Yast.import "Report"
Yast.import "SlpService"

# name of the boot parameter
BOOT_PARAM = "reg_url"

REGISTRATION_SERVICES = {
'susemanager' => 'SUSE Manager'
}

SUPPORTED_SERVICES = REGISTRATION_SERVICES.keys


# Get the language for using in HTTP requests (in "Accept-Language" header)
def self.language
lang = Yast::WFM.GetLanguage
Expand Down Expand Up @@ -122,7 +132,7 @@ def self.run_with_feedback(header, label, &block)

def self.run_network_configuration
log.info "Running network configuration..."
WFM.call("inst_lan")
Yast::WFM.call("inst_lan")
end

def self.catch_registration_errors(&block)
Expand Down Expand Up @@ -197,5 +207,27 @@ def self.slp_service_url
url
end

def self.slp_discovery
services = []

SUPPORTED_SERVICES.each do |service_name|
log.info "Searching for #{service_name} SLP services"
services.concat(Yast::SlpService.all(service_name))
end

log.debug "Found services: #{services.inspect}"
log.info "Found #{services.size} services: #{services.map(&:slp_url).inspect}"

services
end

def self.slp_discovery_feedback
Yast::Popup.ShowFeedback(_("Searching..."), _("Looking up local registration servers..."))
slp_discovery
ensure
Yast::Popup.ClearFeedback
end


end
end

0 comments on commit 4974509

Please sign in to comment.