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 #10788 - add foreman-admin for admin tasks #2452

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 83 additions & 0 deletions script/foreman-admin
@@ -0,0 +1,83 @@
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-

require 'clamp'
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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?

Copy link
Contributor Author

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.

ah, didn't realize. I'll see about adding clamp as a depenency.


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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lacking i18n support?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foreman-debug is only in English?

Copy link
Contributor

Choose a reason for hiding this comment

The 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|
Copy link
Contributor

Choose a reason for hiding this comment

The 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