Sha256: 38320f7000742433b028585cc6ed91bfa7452984820789a683a0853ea3027a82

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'hammer_cli'
require 'foreman_api'

module HammerCLIForeman

  class CommonParameter < HammerCLI::AbstractCommand


    class ListCommand < HammerCLIForeman::ListCommand
      resource ForemanApi::Resources::CommonParameter, "index"

      output do
        from "common_parameter" do
          field :name, "Name"
          field :value, "Value"
        end
      end

      apipie_options
    end

    class SetCommand < HammerCLI::Apipie::WriteCommand

      command_name "set"
      desc "Set a global parameter."

      resource ForemanApi::Resources::CommonParameter

      option "--name", "NAME", "parameter name", :required => true
      option "--value", "VALUE", "parameter value", :required => true

      def execute
        if parameter_exist?
          self.class.action :update
        else
          self.class.action :create
        end
        super
      end

      def print_message
        if self.class.action == :create
          msg = "Global parameter created"
        else
          msg = "Global parameter updated"
        end
        output.print_message msg
      end

      def parameter_exist?
        params = resource.index(resource_config)[0]
        params.find { |p| p["common_parameter"]["name"] == name }
      end

      def request_params
        params = method_options
        params['id'] = name
        params
      end

    end


    class DeleteCommand < HammerCLIForeman::DeleteCommand

      identifiers :name

      success_message "Global parameter deleted"
      failure_message "Could not delete the global parameter"
      resource ForemanApi::Resources::CommonParameter, "destroy"

      apipie_options :without => :id
    end

    autoload_subcommands
  end
end

HammerCLI::MainCommand.subcommand 'global_parameter', "Manipulate Foreman's global parameters.", HammerCLIForeman::CommonParameter

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hammer_cli_foreman-0.0.5 lib/hammer_cli_foreman/common_parameter.rb