Permalink
Browse files

Add new cvsmgr plugin

  • Loading branch information...
ripienaar committed Sep 10, 2010
1 parent 42b9f28 commit 1d8137f115f4f48fc846bb4a162f6ac7aebd73be
Showing with 106 additions and 0 deletions.
  1. +47 −0 agent/vcsmgr/vcsmgr.ddl
  2. +59 −0 agent/vcsmgr/vcsmgr.rb
View
@@ -0,0 +1,47 @@
+metadata :name => "Version Control System Manager",
+ :description => "Manages checkouts of code managed by VCS tools",
+ :author => "R.I.Pienaar <rip@devco.net>",
+ :license => "Apache 2",
+ :version => "0.1",
+ :url => "http://mcollective-plugins.googlecode.com/",
+ :timeout => 90
+
+action "svn_update", :description => "Performs an SVN update on an existing checkout" do
+ display :always
+
+ input :path,
+ :prompt => "Path to update",
+ :description => "The directory containing the SVN checkout",
+ :type => :string,
+ :validation => '^.+$',
+ :optional => false,
+ :maxlength => 150
+
+ output :svnout,
+ :description => "Output from SVN",
+ :display_as => "Output"
+
+ output :author,
+ :description => "Latest Author",
+ :display_as => "Author"
+
+ output :url,
+ :description => "Repository URL",
+ :display_as => "URL"
+
+ output :root,
+ :description => "Repository root",
+ :display_as => "Root"
+
+ output :revision,
+ :description => "Current Revision",
+ :display_as => "Revision"
+
+ output :date,
+ :description => "Latest Date",
+ :display_as => "Date"
+
+ output :path,
+ :description => "Path to the repository",
+ :display_as => "Path"
+end
View
@@ -0,0 +1,59 @@
+module MCollective
+ module Agent
+ class Vcsmgr<RPC::Agent
+ require 'yaml'
+
+ metadata :name => "Version Control System Manager",
+ :description => "Manages checkouts of code managed by VCS tools",
+ :author => "R.I.Pienaar <rip@devco.net>",
+ :license => "Apache 2",
+ :version => "0.1",
+ :url => "http://mcollective-plugins.googlecode.com/",
+ :timeout => 90
+
+ def startup_hook
+ @svn = @config.pluginconf["vcsmgr.svn"] || "/usr/bin/svn"
+ end
+
+ action "svn_update" do
+ validate :path, :shellsafe
+
+ svn_validcheckout?(request[:path])
+
+ svnout = %x[#{@svn} up #{request[:path]}]
+ svnexit = $?.exitstatus
+
+ reply.fail "svn up failed with exit code #{svnexit}" unless svnexit == 0
+
+ reply[:svnout] = svnout
+
+ reply.data.merge!(svn_info(request[:path]))
+ end
+
+ private
+ def svn_validcheckout?(path)
+ raise "Path doesn't exist: #{path}" unless File.exist?(path)
+ raise "Path doesn't look like a svn checkout" unless File.exist?([path, ".svn"].join(File::SEPARATOR))
+ end
+
+ def svn_info(path)
+ svn_validcheckout?(path)
+
+ cmd = "#{@svn} info #{path}"
+ info = YAML.load(%x[#{@svn} info #{path}])
+ response = {}
+
+ {"Last Changed Author" => :author,
+ "URL" => :url,
+ "Repository Root" => :root,
+ "Revision" => :revision,
+ "Last Changed Date" => :date,
+ "Path" => :path}.each do |k,v|
+ response[v] = info[k] || ""
+ end
+
+ response
+ end
+ end
+ end
+end

0 comments on commit 1d8137f

Please sign in to comment.