-
Notifications
You must be signed in to change notification settings - Fork 897
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
Support setting var type with configure_server_settings.rb #17039
Changes from 4 commits
b55557b
b36583c
473bfc6
fcad45f
0d2d2ff
8a48156
64b11ce
b892264
d7c045f
c081bd2
ceccacc
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 |
---|---|---|
|
@@ -4,19 +4,26 @@ | |
|
||
opts = Trollop.options(ARGV) do | ||
banner "USAGE: #{__FILE__} -s <server id> -p <settings path separated by a /> -v <new value>\n" \ | ||
"Example: #{__FILE__} -d -s 1 -p reporting/history/keep_reports -v 42" | ||
"Example: #{__FILE__} -d -s 1 -p reporting/history/keep_reports -v 42\n" \ | ||
"Example: #{__FILE__} -s 1 -p workers/worker_base/queue_worker_base/ems_metrics_collector_worker/defaults/count -v 4 -i" | ||
|
||
opt :dry_run, "Dry Run", :short => "d" | ||
opt :serverid, "Server Id", :short => "s", :default => 0 | ||
opt :path, "Path within advanced settings hash", :short => "p", :default => "" | ||
opt :value, "New value for setting", :short => "v", :default => "" | ||
opt :serverid, "Server Id", :short => "s", :type => :integer, :required => true | ||
opt :path, "Path within advanced settings hash", :short => "p", :type => :string, :required => true | ||
opt :value, "New Value for setting", :short => "v", :type => :string, :required => true | ||
opt :integer, "Value Provided is an Integer", :short => "i", :type => :boolean, :default => false | ||
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. I didn't go this route in #17043 because it's not obvious it's required for some values... 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. See below @rvalente, I think warning the user they're changing an existing Integer value to a String and telling them to look at the help banner to specify an integer may make this option easier to use. 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. Agreed, I'll improve the output 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. @rvalente Was looking at #17043 with @jrafanie and we were thinking that this approach would be better if, instead of having the boolean option
an option that specifies the type of the value, defaulting to
I think it would still be good to warn if the new type of the new value is different than the old one. 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. I agree, this make sense to me. In this way, we're not forcing casting of strings to other types. We default to string and use the check mentioned below to detect when we're changing a sensible default from the correct type to a String type (count from 1,2,3, etc. to "1", "2", "3") and request the user to either allow this to happen or inform them they need to specify the type. 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. Note, integer was requested here, but boolean was also requested here so having a single flag that allows us to specify a type would help solve all of these at once. |
||
|
||
depends :path, :serverid, :value | ||
end | ||
|
||
puts opts.inspect | ||
|
||
Trollop.die :serverid, "is required" unless opts[:serverid_given] | ||
Trollop.die :path, "is required" unless opts[:path_given] | ||
Trollop.die :value, "is required" unless opts[:value_given] | ||
# Grab the value that we have set | ||
newval = if opts[:integer] | ||
opts[:value].to_i | ||
else | ||
opts[:value] | ||
end | ||
|
||
server = MiqServer.where(:id => opts[:serverid]).take | ||
unless server | ||
|
@@ -32,7 +39,7 @@ | |
keys.each { |p| path = path[p.to_sym] } | ||
|
||
puts "Setting [#{opts[:path]}], old value: [#{path[key]}], new value: [#{opts[:value]}]" | ||
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. Should we cherry-pick the first commit from #17043 so we can see the class? Or perhaps we don't need to care about telling the user about the string/integer class unless they don't match: # allow user to escape if the new value's class is not the same as the original,
# such as setting a String where it was previously an Integer
if path[key] && path[key].class != opts[:value].class
STDERR.puts "The new value's class #{opts[:value].class} does not match the prior one's #{path[key].class}. Do you want to continue? (Y/N)"
exit 1 if STDERR.gets.strip.downcase == "n"
end
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. Perhaps the above condition could advise the user to run 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. That is a good idea, essentially being able to tell the user that the input made is not valid. |
||
path[key] = opts[:value] | ||
path[key] = newval | ||
|
||
valid, errors = VMDB::Config::Validator.new(settings).validate | ||
unless valid | ||
|
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.
hmm, was this wrong previously? Perhaps this example should also specify a -i
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.
added new line because a 3rd example was added below with
-i