summaryrefslogtreecommitdiffstats
path: root/lib/puppet/application
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2011-01-30 17:33:28 -0800
committerLuke Kanies <luke@puppetlabs.com>2011-01-30 17:33:28 -0800
commit809aebec7a54be90990b9ee5fea1f85204598f17 (patch)
tree9adc1e05d66fbec9772c7b379bbb52976b9b5753 /lib/puppet/application
downloadpuppet-809aebec7a54be90990b9ee5fea1f85204598f17.tar.gz
puppet-809aebec7a54be90990b9ee5fea1f85204598f17.tar.xz
puppet-809aebec7a54be90990b9ee5fea1f85204598f17.zip
Moving data executables to their own module
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet/application')
-rw-r--r--lib/puppet/application/catalog.rb4
-rw-r--r--lib/puppet/application/certificate.rb4
-rw-r--r--lib/puppet/application/certificate_request.rb4
-rw-r--r--lib/puppet/application/certificate_revocation_list.rb4
-rw-r--r--lib/puppet/application/data.rb84
-rw-r--r--lib/puppet/application/data_baseclass.rb80
-rw-r--r--lib/puppet/application/facts.rb4
-rw-r--r--lib/puppet/application/file_bucket_file.rb4
-rw-r--r--lib/puppet/application/inventory.rb4
-rw-r--r--lib/puppet/application/key.rb4
-rw-r--r--lib/puppet/application/node.rb4
-rw-r--r--lib/puppet/application/report.rb4
-rw-r--r--lib/puppet/application/resource_type.rb4
-rw-r--r--lib/puppet/application/status.rb4
14 files changed, 212 insertions, 0 deletions
diff --git a/lib/puppet/application/catalog.rb b/lib/puppet/application/catalog.rb
new file mode 100644
index 000000000..536d79c29
--- /dev/null
+++ b/lib/puppet/application/catalog.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Catalog < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/certificate.rb b/lib/puppet/application/certificate.rb
new file mode 100644
index 000000000..708de07bb
--- /dev/null
+++ b/lib/puppet/application/certificate.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Certificate < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/certificate_request.rb b/lib/puppet/application/certificate_request.rb
new file mode 100644
index 000000000..4363fc1ae
--- /dev/null
+++ b/lib/puppet/application/certificate_request.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Certificate_request < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/certificate_revocation_list.rb b/lib/puppet/application/certificate_revocation_list.rb
new file mode 100644
index 000000000..158ed7b20
--- /dev/null
+++ b/lib/puppet/application/certificate_revocation_list.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Certificate_revocation_list < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/data.rb b/lib/puppet/application/data.rb
new file mode 100644
index 000000000..cfbf4305a
--- /dev/null
+++ b/lib/puppet/application/data.rb
@@ -0,0 +1,84 @@
+require 'puppet/application'
+
+class Puppet::Application::Data < Puppet::Application
+
+ should_parse_config
+ run_mode :agent
+
+ option("--debug", "-d") do |arg|
+ Puppet::Util::Log.level = :debug
+ end
+
+ option("--verbose", "-v") do
+ Puppet::Util::Log.level = :info
+ end
+
+ def list(*arguments)
+ if arguments.empty?
+ arguments = %w{terminuses actions}
+ end
+ indirections.each do |ind|
+ str = "#{ind}:\n"
+ if arguments.include?("terminuses")
+ begin
+ terms = terminus_classes(ind.to_sym)
+ str << "\tTerminuses: #{terms.join(", ")}\n"
+ rescue => detail
+ $stderr.puts "Could not load terminuses for #{ind}: #{detail}"
+ end
+ end
+
+ if arguments.include?("actions")
+ begin
+ actions = actions(ind.to_sym)
+ str << "\tActions: #{actions.join(", ")}\n"
+ rescue => detail
+ $stderr.puts "Could not load actions for #{ind}: #{detail}"
+ end
+ end
+
+ print str
+ end
+ exit(0)
+ end
+
+ attr_accessor :verb, :name, :arguments
+
+ def main
+ # Call the method associated with the provided action (e.g., 'find').
+ send(verb, *arguments)
+ end
+
+ def setup
+ Puppet::Util::Log.newdestination :console
+
+ @verb, @arguments = command_line.args
+ @arguments ||= []
+
+ validate
+ end
+
+ def validate
+ unless verb
+ raise "You must specify 'find', 'search', 'save', or 'destroy' as a verb; 'save' probably does not work right now"
+ end
+
+ unless respond_to?(verb)
+ raise "Command '#{verb}' not found for 'data'"
+ end
+ end
+
+ def indirections
+ Puppet::Indirector::Indirection.instances.collect { |t| t.to_s }.sort
+ end
+
+ def terminus_classes(indirection)
+ Puppet::Indirector::Terminus.terminus_classes(indirection).collect { |t| t.to_s }.sort
+ end
+
+ def actions(indirection)
+ return [] unless app = Puppet::Application.find(indirection)
+ return app.actions.sort { |a,b| a.to_s <=> b.to_s }
+ end
+end
+
diff --git a/lib/puppet/application/data_baseclass.rb b/lib/puppet/application/data_baseclass.rb
new file mode 100644
index 000000000..95142b8ba
--- /dev/null
+++ b/lib/puppet/application/data_baseclass.rb
@@ -0,0 +1,80 @@
+require 'puppet/application'
+require 'puppet/interface'
+
+class Puppet::Application::DataBaseclass < Puppet::Application
+ should_parse_config
+ run_mode :agent
+
+ option("--debug", "-d") do |arg|
+ Puppet::Util::Log.level = :debug
+ end
+
+ option("--verbose", "-v") do
+ Puppet::Util::Log.level = :info
+ end
+
+ option("--from TERMINUS", "-f") do |arg|
+ @from = arg
+ end
+
+ option("--format FORMAT") do |arg|
+ @format = arg
+ end
+
+ # XXX this doesn't work, I think
+ option("--list") do
+ indirections.each do |ind|
+ begin
+ classes = terminus_classes(ind.to_sym)
+ rescue => detail
+ $stderr.puts "Could not load terminuses for #{ind}: #{detail}"
+ next
+ end
+ puts "%-30s: #{classes.join(", ")}" % ind
+ end
+ exit(0)
+ end
+
+ option("--mode RUNMODE", "-r") do |arg|
+ raise "Invalid run mode #{arg}; supported modes are user, agent, master" unless %w{user agent master}.include?(arg)
+ self.class.run_mode(arg.to_sym)
+ set_run_mode self.class.run_mode
+ end
+
+
+ attr_accessor :interface, :from, :type, :verb, :name, :arguments, :indirection, :format
+
+ def main
+ # Call the method associated with the provided action (e.g., 'find').
+ interface.send(verb, name, *arguments)
+ end
+
+ def setup
+ @format ||= :yaml
+
+ Puppet::Util::Log.newdestination :console
+
+ @verb, @name, @arguments = command_line.args
+ @arguments ||= []
+
+ @type = self.class.name.to_s.sub(/.+:/, '').downcase.to_sym
+
+ @interface = Puppet::Interface.interface(@type).new
+
+ validate
+
+ raise "Could not find data type #{type} for application #{self.class.name}" unless @indirection = Puppet::Indirector::Indirection.instance(type)
+
+ @interface.set_terminus(from) if from
+ end
+
+ def validate
+ unless verb
+ raise "You must specify #{interface.actions.join(", ")} as a verb; 'save' probably does not work right now"
+ end
+
+ unless interface.action?(verb)
+ raise "Command '#{verb}' not found for #{type}"
+ end
+ end
+end
diff --git a/lib/puppet/application/facts.rb b/lib/puppet/application/facts.rb
new file mode 100644
index 000000000..dd79a00d9
--- /dev/null
+++ b/lib/puppet/application/facts.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Facts < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/file_bucket_file.rb b/lib/puppet/application/file_bucket_file.rb
new file mode 100644
index 000000000..f08a37f90
--- /dev/null
+++ b/lib/puppet/application/file_bucket_file.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::File_bucket_file < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/inventory.rb b/lib/puppet/application/inventory.rb
new file mode 100644
index 000000000..f54708f24
--- /dev/null
+++ b/lib/puppet/application/inventory.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Inventory < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/key.rb b/lib/puppet/application/key.rb
new file mode 100644
index 000000000..1197ae026
--- /dev/null
+++ b/lib/puppet/application/key.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Key < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/node.rb b/lib/puppet/application/node.rb
new file mode 100644
index 000000000..4d7de1ab2
--- /dev/null
+++ b/lib/puppet/application/node.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Node < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/report.rb b/lib/puppet/application/report.rb
new file mode 100644
index 000000000..e4b5cf440
--- /dev/null
+++ b/lib/puppet/application/report.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Report < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/resource_type.rb b/lib/puppet/application/resource_type.rb
new file mode 100644
index 000000000..5bd001e88
--- /dev/null
+++ b/lib/puppet/application/resource_type.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Resource_type < Puppet::Application::DataBaseclass
+end
diff --git a/lib/puppet/application/status.rb b/lib/puppet/application/status.rb
new file mode 100644
index 000000000..382532f7f
--- /dev/null
+++ b/lib/puppet/application/status.rb
@@ -0,0 +1,4 @@
+require 'puppet/application/data_baseclass'
+
+class Puppet::Application::Status < Puppet::Application::DataBaseclass
+end