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 #10788 - add foreman-admin for admin tasks #2452
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env ruby | ||
# -*- encoding: utf-8 -*- | ||
|
||
require 'clamp' | ||
|
||
module ForemanAdmin | ||
class Command < ::Clamp::Command | ||
def self.command_name(name = nil) | ||
@command_name = name if name | ||
@command_name | ||
end | ||
|
||
def command_name | ||
self.class.command_name | ||
end | ||
|
||
def self.description(description = nil) | ||
@description = description if description | ||
@description | ||
end | ||
|
||
def description | ||
self.class.description | ||
end | ||
end | ||
|
||
class ExternalCommand < Command | ||
# The base command that will be executed externally. | ||
# Think of this as ARGV[0] of what we're running externally. | ||
def self.external_invocation(invocation = nil) | ||
@external_invocation = invocation if invocation | ||
@external_invocation | ||
end | ||
|
||
def external_invocation | ||
self.class.external_invocation | ||
end | ||
|
||
# The exact assembled command that will be executed externally. | ||
# Override this in a child class if you want it have logic. | ||
def external_command | ||
"#{external_invocation}" | ||
end | ||
|
||
def execute | ||
puts `#{external_command}` | ||
end | ||
end | ||
|
||
class DebugCommand < ForemanAdmin::ExternalCommand | ||
command_name 'generate-debug' | ||
description 'Create a foreman-debug tarball for debugging purposes' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lacking i18n support? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. foreman-debug is only in English? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, but Foreman is generally i18n capable, as is our existing main CLI, so I'd expect a new CLI to be i18n capable too. Especially if you're trying to make it more user-centric than the existing mix of tools. |
||
external_invocation '/usr/sbin/foreman-debug' | ||
|
||
parameter "[ARGS] ...", "args", :hidden => true | ||
|
||
def help | ||
`#{external_invocation} -h`.gsub(external_invocation, File.expand_path(__FILE__)) | ||
end | ||
|
||
def external_command | ||
"#{external_invocation} #{args_list}" | ||
end | ||
end | ||
|
||
class MainCommand < ForemanAdmin::Command | ||
subcommand(DebugCommand.command_name, DebugCommand.description, DebugCommand) | ||
|
||
preload_constants = ForemanAdmin.constants | ||
Dir.glob('/etc/foreman-admin.d/*.rb').each do |file| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be relative to Foreman's root, and definitely not in /etc for code. |
||
require file | ||
end | ||
plugin_commands = ForemanAdmin.constants - preload_constants | ||
|
||
plugin_commands.map { |c| ForemanAdmin.const_get(c) }.each do |com| | ||
subcommand(com.command_name, com.description, com) | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $0 | ||
ForemanAdmin::MainCommand.run | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clamp is not part of a foreman install as such
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's installed outside of the SCL because
hammer
uses it so this should be fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but one can still install foreman without hammer and clamp will not get pulled in as dependency then... At least clamp (for RH and friends in the non-SCL variant) has to get added as dependency in the packaging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The installer installs Foreman as well as Hammer, correct? Why would someone install Foreman without using the installer? Personally, I feel like that's on them to resolve dependencies if they don't use the installer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is not about using the installer or not. I can disable foreman_cli in the installer to have a Foreman server without hammer and everything will work just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installer's just a bit of extra configuration, packages still enforce dependencies. You can install from packages or source, works fine.
Perhaps add the dependency to our packages (in which case for RPMs, this would use SCL) or use the existing bundler configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, didn't realize. I'll see about adding
clamp
as a depenency.