Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Mar 4, 2014
1 parent 6c40892 commit 7849075
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions src/clients/inst_setup_dhcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ module SetupDHCPClient
include Yast

BASH_PATH = Path.new(".target.bash")
BASH_OUT_PATH = Path.new(".target.bash_output")

def self.network_cards
LanItems.Read
LanItems.GetNetcardNames
end

# Makes DHCP setup persistent
#
# instsys currently uses wicked as network services "manager" (including
# dhcp client). wicked is currently able to configure a card for dhcp leases
# only via loading config from file. All other ways are workarounds and
# needn't to work when wickedd* services are already running
def self.setup_dhcp card
index = LanItems.FindDeviceIndex(card)

Expand All @@ -36,18 +43,24 @@ def self.setup_dhcp card
LanItems.Commit
end

def self.get_lease?(card)
SCR.Execute(BASH_PATH, "dhcpcd-test '#{card}'") == 0
def self.reload_config(card)
SCR.Execute(BASH_PATH, "wicked ifreload '#{card}'") == 0
end

def self.start_dhcp(card)
SCR.Execute(BASH_PATH, "wicked ifreload '#{card}'") == 0
def self.delete_config(devname)
NetworkInterfaces.Delete2(devname)
end

def self.write_configuration
NetworkInterfaces.Write("")
end

def self.activate_changes(devnames)
return false if !write_configuration

devnames.map { |d| reload_config(d) }
end

def self.configured?(devname)
# TODO:
# one day there should be LanItems.IsItemConfigured, but we currently
Expand All @@ -58,18 +71,33 @@ def self.configured?(devname)
NetworkInterfaces.Check(devname)
end

# Checks if given device is active
#
# inactive device <=> a device which is not reported as "up" by wicked
def self.inactive_config?(devname)
wicked_query = "wicked ifstatus --brief #{devname} | grep -v 'up$'"
ret = SCR.Execute(BASH_OUT_PATH, wicked_query)["stdout"].to_s

return false if ret.empty?

ret.split(/\s+/, 2).first
end

include Logger

# TODO time consuming, some progress would be nice
dhcp_cards = network_cards.select { |c| !configured?(c) && get_lease?(c) }
dhcp_cards = network_cards.select { |c| !configured?(c) }
log.info "Candidates for enabling DHCP: #{dhcp_cards}"

dhcp_cards.each do |dcard|
setup_dhcp(dcard) # make DHCP setup persistent
start_dhcp(dcard)
end
# TODO time consuming, some progress would be nice
dhcp_cards.each { |d| setup_dhcp(d) }

activate_changes(dhcp_cards)

# drop devices without dhcp lease
inactive_devices = dhcp_cards.select { |c| inactive_config?(c) }
log.info "Inactive devices: #{inactive_devices}"

write_configuration
activate_changes(inactive_devices)
end

:next

0 comments on commit 7849075

Please sign in to comment.