Permalink
Browse files

Turn YAML option data into Ruby code option data

This imports the YAML option definitions into Ruby code, avoiding the need to
parse and decode an external file before we can print option data.  This also
makes it harder - though, obviously, still entirely possible - to miss the
existence of that data when updating the code.

There is no behavioural change in the product from this.  The same data, in
the same form and order, is supplied to the rest of the system.  Only the
source is modified.

This closes #459, as the data now lives in Ruby.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
  • Loading branch information...
1 parent c4aa1f5 commit db26406812083abdc1dcd5aff03ccfeae8179352 @slippycheeze slippycheeze committed Apr 16, 2013
View
@@ -213,13 +213,21 @@ def list_help(return_hash = nil)
end
end
+ # Return a hash mapping symbolic command names to option data; this is the
+ # internal counterpart to `command_option_data`, which imposes the semantics
+ # around searching this map.
+ def all_command_option_data
+ fail "The #{slice_name} command has not defined any command options!"
+ end
+ private 'all_command_option_data'
+
def command_option_data(command)
- begin
- file = File.join(File.dirname(__FILE__), "slice/#{slice_name}/#{command}/option_items.yaml")
- return YAML.load_file(file)
- rescue => e
- raise ProjectRazor::Error::Slice::SliceCommandParsingFailed, "Slice #{slice_name} cannot parse option items file"
- end
+ # The original version of this would raise an exception (Errno::ENOENT)
+ # when the file didn't exist on disk; this roughly mirrors those semantics
+ # albeit without preserving the exact exception. I don't think anyone
+ # cares, since nothing in Razor catches it specifically. --daniel 2013-04-16
+ all_command_option_data[command.to_sym] or
+ fail "Unknown command #{command} was looked up in `command_option_data`"
end
# here, we define a Stack class that simply delegates the equivalent "push", "pop",
@@ -44,6 +44,49 @@ def slice_commands
commands
end
+ def all_command_option_data
+ {
+ :get => [
+ { :name => :query,
+ :default => nil,
+ :short_form => '-q',
+ :long_form => '--query IPMI_QUERY',
+ :description => 'The IPMI query to run against a BMC',
+ :uuid_is => 'required',
+ :required => false
+ }
+ ],
+ :register => [
+ { :name => :ip_address,
+ :default => false,
+ :short_form => '-i',
+ :long_form => '--ip_address IP_ADDR',
+ :description => 'IP address for BMC being registered',
+ :uuid_is => 'not_allowed',
+ :required => true
+ },
+ { :name => :mac_address,
+ :default => false,
+ :short_form => '-m',
+ :long_form => '--mac_address MAC_ADDR',
+ :description => 'MAC address for BMC being registered',
+ :uuid_is => 'not_allowed',
+ :required => true
+ }
+ ],
+ :update => [
+ { :name => :power_state,
+ :default => nil,
+ :short_form => "-p",
+ :long_form => "--power-state NEW_STATE",
+ :description => "Used to transition the power-state of a node",
+ :uuid_is => "required",
+ :required => true
+ }
+ ]
+ }.freeze
+ end
+
def bmc_help
if @prev_args.length > 1
command = @prev_args.peek(1)
@@ -1,8 +0,0 @@
----
-- :name: :query
- :default:
- :short_form: -q
- :long_form: --query IPMI_QUERY
- :description: The IPMI query to run against a BMC
- :uuid_is: required
- :required: false
@@ -1,15 +0,0 @@
----
-- :name: :ip_address
- :default: false
- :short_form: -i
- :long_form: --ip_address IP_ADDR
- :description: IP address for BMC being registered
- :uuid_is: not_allowed
- :required: true
-- :name: :mac_address
- :default: false
- :short_form: -m
- :long_form: --mac_address MAC_ADDR
- :description: MAC address for BMC being registered
- :uuid_is: not_allowed
- :required: true
@@ -1,8 +0,0 @@
----
-- :name: :power_state
- :default:
- :short_form: -p
- :long_form: --power-state NEW_STATE
- :description: Used to transition the power-state of a node
- :uuid_is: required
- :required: true
@@ -38,6 +38,63 @@ def slice_commands
commands
end
+ def all_command_option_data
+ {
+ :add => [
+ { :name => :plugin,
+ :default => false,
+ :short_form => '-p',
+ :long_form => '--plugin BROKER_PLUGIN',
+ :description => 'The broker plugin to use.',
+ :uuid_is => 'not_allowed',
+ :required => true
+ },
+ { :name => :name,
+ :default => false,
+ :short_form => '-n',
+ :long_form => '--name BROKER_NAME',
+ :description => 'The name for the broker target.',
+ :uuid_is => 'not_allowed',
+ :required => true
+ },
+ { :name => :description,
+ :default => false,
+ :short_form => '-d',
+ :long_form => '--description DESCRIPTION',
+ :description => 'A description for the broker target.',
+ :uuid_is => 'not_allowed',
+ :required => true
+ }
+ ],
+ :update => [
+ { :name => :name,
+ :default => false,
+ :short_form => '-n',
+ :long_form => '--name BROKER_NAME',
+ :description => 'New name for the broker target.',
+ :uuid_is => 'required',
+ :required => true
+ },
+ { :name => :description,
+ :default => false,
+ :short_form => '-d',
+ :long_form => '--description DESCRIPTION',
+ :description => 'New description for the broker target.',
+ :uuid_is => 'required',
+ :required => true
+ },
+ { :name => :change_metadata,
+ :default => false,
+ :short_form => '-c',
+ :long_form => '--change-metadata',
+ :description => 'Used to trigger a change in the broker\'s meta-data',
+ :uuid_is => 'required',
+ :required =>true
+ }
+ ]
+ }.freeze
+ end
+
def broker_help
if @prev_args.length > 1
command = @prev_args.peek(1)
@@ -1,22 +0,0 @@
----
-- :name: :plugin
- :default: false
- :short_form: -p
- :long_form: --plugin BROKER_PLUGIN
- :description: The broker plugin to use.
- :uuid_is: not_allowed
- :required: true
-- :name: :name
- :default: false
- :short_form: -n
- :long_form: --name BROKER_NAME
- :description: The name for the broker target.
- :uuid_is: not_allowed
- :required: true
-- :name: :description
- :default: false
- :short_form: -d
- :long_form: --description DESCRIPTION
- :description: A description for the broker target.
- :uuid_is: not_allowed
- :required: true
@@ -1,22 +0,0 @@
----
-- :name: :name
- :default: false
- :short_form: -n
- :long_form: --name BROKER_NAME
- :description: New name for the broker target.
- :uuid_is: required
- :required: true
-- :name: :description
- :default: false
- :short_form: -d
- :long_form: --description DESCRIPTION
- :description: New description for the broker target.
- :uuid_is: required
- :required: true
-- :name: :change_metadata
- :default: false
- :short_form: -c
- :long_form: --change-metadata
- :description: Used to trigger a change in the broker's meta-data
- :uuid_is: required
- :required: true
@@ -31,6 +31,45 @@ def slice_commands
"remove_image")
end
+ def all_command_option_data
+ {
+ :add => [
+ { :name => :type,
+ :default => nil,
+ :short_form => '-t',
+ :long_form => '--type TYPE',
+ :description => 'The type of image (mk, os, esxi, or xenserver)',
+ :uuid_is => 'not_allowed',
+ :required => true
+ },
+ { :name => :path,
+ :default => nil,
+ :short_form => '-p',
+ :long_form => '--path /path/to/iso',
+ :description => 'The local path to the image ISO',
+ :uuid_is => 'not_allowed',
+ :required => true
+ },
+ { :name => :name,
+ :default => nil,
+ :short_form => '-n',
+ :long_form => '--name IMAGE_NAME',
+ :description => 'The logical name to use (os images only)',
+ :uuid_is => 'not_allowed',
+ :required => false
+ },
+ { :name => :version,
+ :default => nil,
+ :short_form => '-v',
+ :long_form => '--version VERSION',
+ :description => 'The version to use (os images only)',
+ :uuid_is => 'not_allowed',
+ :required => false
+ }
+ ]
+ }.freeze
+ end
+
def image_help
if @prev_args.length > 1
command = @prev_args.peek(1)
@@ -1,29 +0,0 @@
----
-- :name: :type
- :default:
- :short_form: -t
- :long_form: --type TYPE
- :description: The type of image (mk, os, esxi, or xenserver)
- :uuid_is: not_allowed
- :required: true
-- :name: :path
- :default:
- :short_form: -p
- :long_form: --path /path/to/iso
- :description: The local path to the image ISO
- :uuid_is: not_allowed
- :required: true
-- :name: :name
- :default:
- :short_form: -n
- :long_form: --name IMAGE_NAME
- :description: The logical name to use (os images only)
- :uuid_is: not_allowed
- :required: false
-- :name: :version
- :default:
- :short_form: -v
- :long_form: --version VERSION
- :description: The version to use (os images only)
- :uuid_is: not_allowed
- :required: false
@@ -173,6 +173,77 @@ def slice_commands
}
end
+ def all_command_option_data
+ {
+ :get_razor_log => [
+ { :name => :tail,
+ :default => nil,
+ :short_form => '-t',
+ :long_form => '--tail NLINES',
+ :description => 'The number of lines to tail.',
+ :uuid_is => 'not_allowed',
+ :required => false
+ },
+ { :name => :log_level,
+ :default => nil,
+ :short_form => '-l',
+ :long_form => '--log-level LOG_LEVEL',
+ :description => 'The log level pattern/value.',
+ :uuid_is => 'not_allowed',
+ :required => false
+ },
+ { :name => :class_name,
+ :default => nil,
+ :short_form => '-c',
+ :long_form => '--class-name CLASS_NAME',
+ :description => 'The class name pattern/value.',
+ :uuid_is => 'not_allowed',
+ :required => false
+ },
+ { :name => :method_name,
+ :default => nil,
+ :short_form => '-m',
+ :long_form => '--method-name METHOD_NAME',
+ :description => 'The method name pattern/value.',
+ :uuid_is => 'not_allowed',
+ :required => false
+ },
+ { :name => :log_message,
+ :default => nil,
+ :short_form => '-g',
+ :long_form => '--log-message LOG_LEVEL',
+ :description => 'The log message pattern/value.',
+ :uuid_is => 'not_allowed',
+ :required => false
+ },
+ { :name => :elapsed_time,
+ :default => nil,
+ :short_form => '-e',
+ :long_form => '--elapsed-time ELAPSED_TIME',
+ :description => 'The elapsed time limit (for messages).',
+ :uuid_is => 'not_allowed',
+ :required => false
+ },
+ { :name => :filter_before_tail,
+ :default => false,
+ :short_form => '-n',
+ :long_form => '--filter-before-tail',
+ :description => 'Apply filter before tailing (default).',
+ :uuid_is => 'not_allowed',
+ :required => false
+ },
+ { :name => :tail_before_filter,
+ :default => false,
+ :short_form => '-r',
+ :long_form => '--tail-before-filter',
+ :description => 'Apply tail before filtering.',
+ :uuid_is => 'not_allowed',
+ :required => false
+ }
+ ]
+ }.freeze
+ end
+
# uses the location of the Razor configuration file to determine the path to the
# ${RAZOR_HOME}/log directory (which is where the logfiles for Razor are located)
def get_logfile_path
Oops, something went wrong.

0 comments on commit db26406

Please sign in to comment.