diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-06-13 22:31:52 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-06-13 22:31:52 +0000 |
| commit | ef2698c316562172fc78eee45507acd603a06e70 (patch) | |
| tree | e0831415a82a4e1d6baa5927f964e1404a134574 | |
| parent | cb5bccc8bb6099ef7800837486638c1ce547cff3 (diff) | |
| download | puppet-ef2698c316562172fc78eee45507acd603a06e70.tar.gz puppet-ef2698c316562172fc78eee45507acd603a06e70.tar.xz puppet-ef2698c316562172fc78eee45507acd603a06e70.zip | |
Updating ralsh with more functionality: You can now perform work on the command line, with commands like "sudo ralsh file /etc/passwd ensure=absent". This makes ralsh a bit more interactive.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2573 980ebf18-57e1-0310-9a29-db15c13687c0
| -rwxr-xr-x | bin/ralsh | 75 |
1 files changed, 69 insertions, 6 deletions
@@ -7,7 +7,8 @@ # # = Usage # -# ralsh [-h|--help] [-e|--edit] [-H|--host <host>] [-p|--param <param>] [-t|--types] type <name> +# ralsh [-h|--help] [-d|--debug] [-v|--verbose] [-e|--edit] [-H|--host <host>] +# [-p|--param <param>] [-t|--types] type <name> # # = Description # @@ -27,6 +28,19 @@ # # = Options # +# Note that any configuration parameter that's valid in the configuration file +# is also a valid long argument. For example, 'ssldir' is a valid configuration +# parameter, so you can specify '--ssldir <directory>' as an argument. +# +# See the configuration file documentation at +# http://reductivelabs.com/projects/puppet/reference/configref.html for +# the full list of acceptable parameters. A commented list of all +# configuration options can also be generated by running puppet with +# '--genconfig'. +# +# debug:: +# Enable full debugging. +# # edit: # Write the results of the query to a file, open the file in an editor, # and read the file back in as an executable Puppet manifest. @@ -44,6 +58,9 @@ # types: # List all available types. # +# verbose:: +# Print extra information. +# # = Example # # $ ralsh user luke @@ -72,6 +89,8 @@ require 'getoptlong' require 'puppet' options = [ + [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], + [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], [ "--types", "-t", GetoptLong::NO_ARGUMENT ], [ "--param", "-p", GetoptLong::REQUIRED_ARGUMENT ], [ "--host", "-H", GetoptLong::REQUIRED_ARGUMENT ], @@ -84,6 +103,8 @@ Puppet.config.addargs(options) result = GetoptLong.new(*options) +debug = false +verbose = false edit = false extra_params = [] host = nil @@ -112,11 +133,28 @@ result.each { |opt,arg| puts "install RDoc:usage for help" end exit + when "--verbose" + verbose = true + when "--debug" + debug = true else # Anything else is handled by the config stuff + Puppet.config.handlearg(opt, arg) end } +Puppet::Util::Log.newdestination(:console) + +# Now parse the config +Puppet.parse_config + +if debug + Puppet::Util::Log.level = :debug +elsif verbose + Puppet::Util::Log.level = :info +end + + if ARGV.length > 0 type = ARGV.shift else @@ -124,17 +162,25 @@ else end name = nil +params = {} if ARGV.length > 0 name = ARGV.shift end +if ARGV.length > 0 + ARGV.each do |setting| + if setting =~ /^(\w+)=(.+)$/ + params[$1] = $2 + else + raise "Invalid parameter setting %s" % setting + end + end +end + if edit and host raise "You cannot edit a remote host" end -# Now parse the config -Puppet.parse_config - typeobj = nil unless typeobj = Puppet::Type.type(type) @@ -167,7 +213,7 @@ text = if host transbucket = [client.describe(type, name)] else # Else, list the whole thing out. - transbucket = client.list(type) + transbucket = client.instances(type) end rescue Puppet::Network::XMLRPCClientError => exc raise "client.list(#{type}) failed: #{exc.message}" @@ -177,9 +223,26 @@ else if name obj = typeobj.create(:name => name, :check => properties) vals = obj.retrieve + + unless params.empty? + params.each do |param, value| + obj[param] = value + end + comp = Puppet::Type.type(:component).create(:name => "ralsh") + comp.push(obj) + transaction = comp.evaluate + begin + transaction.evaluate + rescue => detail + if Puppet[:trace] + puts detail.backtrace + end + end + + end [format.call(obj.to_trans(true))] else - typeobj.list.collect do |obj| + typeobj.instances.collect do |obj| next if ARGV.length > 0 and ! ARGV.include? obj.name trans = obj.to_trans(true) format.call(trans) |
