Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36730 - Implement pruning of old TFTP files #9825

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/services/proxy_api/tftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,21 @@ def create_default(kind, args)
rescue => e
raise ProxyException.new(url, e, N_("Unable to create default TFTP boot menu"))
end

# Prune old TFTP entries
# [+age+] : The age of a file in seconds
# Returns : Integer the number of files pruned or nil if it's not
# implemented
def prune(age)
args = {
age: age,
}
parse(post(args, "prune"))
rescue RestClient::ResourceNotFound
# Not implemented
nil
rescue => e
raise ProxyException.new(url, e, N_("Unable to prune old TFTP files"))
end
end
end
24 changes: 24 additions & 0 deletions lib/tasks/orchestration.rake
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,28 @@ namespace :orchestration do
end
end
end

namespace :tftp do
task :prune => :environment do
duration = Setting['token_duration']
return if duration == 0

age = duration * 60

SmartProxy.unscoped.with_features('TFTP').sum do |smart_proxy|
tftp = ProxyAPI::TFTP.new(url: smart_proxy.url)
pruned = tftp.prune(age)

if pruned.nil?
puts "Smart Proxy #{smart_proxy} does not implement pruning"
0
else
puts "Smart Proxy #{smart_proxy} pruned #{pruned} files"
pruned
end
end

puts "Pruned #{pruned} files in total"
end
end
end