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

fixes #10788 - add foreman-admin for admin tasks #2452

wants to merge 1 commit into from

Conversation

komidore64
Copy link
Contributor

moving into foreman proper due to conversation in theforeman/foreman-packaging#672

still to do:

  • add clamp to foreman deps
  • man page

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • ec4e50d must be in the format Fixes/refs #redmine_number - brief description.

Guidelines are available on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@komidore64
Copy link
Contributor Author

renamed commit message

@komidore64 komidore64 changed the title add foreman-admin to foreman proper fixes #10788 - add foreman-admin for admin tasks Jun 11, 2015
@komidore64
Copy link
Contributor Author

fixed rubocop warnings

#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-

require 'rubygems'
Copy link
Contributor

Choose a reason for hiding this comment

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

should be fine without this line in Ruby 1.9, not sure about 1.8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this line is required for 1.8.

Copy link
Contributor

Choose a reason for hiding this comment

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

Foreman core doesn't support 1.8, it can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't ruby's version on el6 outside of the SCL 1.8 though?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but see below, if packaged in Foreman then we can simply depend on SCL and use 1.9+ on all platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

@domcleal
Copy link
Contributor

Needs fleshing out some more, removal of all of the TODOs.

@ShimShtein
Copy link
Member

@komidore64 Can you fix rubocop errors please?

@domcleal
Copy link
Contributor

TODO still needs doing, and how do you plan for this to be extended from plugins? It should also have a man page.

@komidore64
Copy link
Contributor Author

@domcleal haha, well yeah. they're TODOs because i'm still working on it :)

how do you plan for this to be extended from plugins?

As for plugins adding more commands, what they'd need to do is add a file to /etc/foreman-admin.d/ upon installation which would contain the command that foreman-admin would then slurp up and use whenever it runs.

Take foreman-tasks for example which needs to add a export-tasks command. foreman-tasks will install /etc/foreman-admin.d/export_tasks.rb that foreman-admin will then pull in whenever it runs. The command classes in plugin commands aren't complicated. There are two base command classes that you can choose to extend: ForemanAdmin::Command and ForemanAdmin::ExternalCommand. These two classes are wrappers on Clamp's Command class so all the usual clamping is applicable.

ForemanAdmin::Command is for actions that will be carried out in the ForemanAdmin ruby environment. A command name must be set (command_name 'my-new-command') and a description must be set (description 'a description of my-new-command'). Then override the execute method to carry out your desired logic.

example:

module ForemanAdmin
  class CountCommand < ForemanAdmin::ExternalCommand
    command_name 'countdown' # required
    description 'prints out numbers counting downward' # required

    # regular clamp-style parameters and options
    option ['--prefix', '-p'], 'PREFIX', 'String to prefix each count', :default => ''
    parameter 'COUNT', 'Number to start from' do |c|
      Integer(c)
    end

    # override is required otherwise command will simply exit
    def execute
      count.downto(1) { |c| puts "#{prefix}#{c}" }
    end
  end
end

ForemanAdmin::External command is for when an action is external to ForemanAdmin requiring the tool to shell out. Specifying the command name and description are required, as well as giving the external_invocation. This the external tool/script that will be called when shelling out. By default ExternalCommand only shells out with #{external_invocation} but you can override the external_command method to append options, arguments, etc into the command that is externally called.

example:

class DebugCommand < ForemanAdmin::ExternalCommand
  command_name 'generate-debug' # required
  description 'Create a foreman-debug tarball for debugging purposes' # required
  external_invocation '/usr/sbin/foreman-debug' # required

  parameter "[ARGS] ...", "args", :hidden => true

  # optional override (this is a clamp method)
  def help
    `#{external_invocation} -h`.gsub(external_invocation, File.expand_path(__FILE__))
  end

  # optional override (this is a ForemanAdmin::ExternalCommand method)
  def external_command
    "#{external_invocation} #{args_list}"
  end

end

@komidore64
Copy link
Contributor Author

It should also have a man page.

Most of what I just explained above will make it into foreman-admin's man page in one form or another.

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • 3678e7e must be in the format Fixes/refs #redmine_number - brief description.

Guidelines are available on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@komidore64
Copy link
Contributor Author

argh @theforeman-bot!

@ShimShtein addressed rubocop messages.

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.


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.

@domcleal
Copy link
Contributor

Seems that with stuff like extensions and locales that using the existing Hammer framework would be quite useful. Any reason this couldn't just be developed in its existing plugins in some way?

@komidore64
Copy link
Contributor Author

@domcleal hammer was considered, but as you stated earlier hammer is not part of Foreman core.

Since these actions take place on the filesystem (not inside of the rails environment), @mccun934 and I are wanting these actions to only be available to the system's root user which can best be achieved by operating outside of the Foreman/Rails environment entirely instead of using hammer with an API.

@domcleal
Copy link
Contributor

hammer was considered, but as you stated earlier hammer is not part of Foreman core.

Right, but at least we have an existing plugin distribution method for it, existing locale support etc. Reinventing that properly is work.

Since these actions take place on the filesystem (not inside of the rails environment), @mccun934 and I are wanting these actions to only be available to the system's root user which can best be achieved by operating outside of the Foreman/Rails environment entirely instead of using hammer with an API.

It doesn't need to operate over the API though, that's only what hammer_cli_foreman usually does, not hammer_cli.

@tbrisker
Copy link
Member

@komidore64,
Thank you very much for your efforts!
This PR has been open for a very long time with no activity.
Please indicate if you plan to continue working on it or not; if not, feel free to close it.
If you do not respond either way within a couple of weeks, I will assume this PR is abandoned and will go ahead and close it for you.

@komidore64
Copy link
Contributor Author

Portions of foreman-admin need more development, so I'm going to close this.

@komidore64 komidore64 closed this Mar 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants