Skip to content

Commit

Permalink
Add ComputerListener generator
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboyd committed Feb 3, 2012
1 parent 06a636f commit 77c8e09
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/jenkins/plugin/cli/generate.rb
Expand Up @@ -48,6 +48,12 @@ def run_listener(name)
@name = name
template('templates/run_listener.tt', "models/#{name.downcase}_listener.rb")
end

desc "computer_listener", "computer_listener NAME", :desc => "create a new computer listener"
def computer_listener(name)
@name = name
template('templates/computer_listener.tt', "models/#{name.downcase}_listener.rb")
end
end
end
end
Expand Down
61 changes: 61 additions & 0 deletions lib/jenkins/plugin/cli/templates/computer_listener.tt
@@ -0,0 +1,61 @@
class <%= name.capitalize %>Listener
include Jenkins::Slaves::ComputerListener

# Called before a {ComputerLauncher} is asked to launch a connection with {Computer}.
#
# This enables you to do some configurable checks to see if we
# want to bring this slave online or if there are considerations
# that would keep us from doing so.
#
# Calling Computer#abort would let you veto the launch operation. Other thrown exceptions
# will also have the same effect
#
# @param [Jenkins::Model::Computer] computer the computer about to be launched
# @param [Jenkins::Model::Listener] listener the listener connected to the slave console log.
def prelaunch(computer, listener)
end

# Called when a slave attempted to connect via {ComputerLauncher} but failed.
#
# @param [Jenkins::Model::Computer] computer the computer that was trying to launch
# @param [Jenkins::Model::Listener] listener the listener connected to the slave console log
def launchfailed(computer, listener)
end

# Called before a {Computer} is marked online.
#
# This enables you to do some work on all the slaves
# as they get connected. Unlike {#online},
# a failure to carry out this function normally will prevent
# a computer from marked as online.
#
# @param [Jenkins::Remote::Channel] channel the channel object to talk to the slave.
# @param [Jenkins::FilePath] root the directory where this slave stores files.
# @param [Jenkins::Model::Listener] listener connected to the launch log of the computer.
# @see {#online}
def preonline(computer, channel, root, listener)
end

# Called right after a {Computer} comes online.
#
# This enables you to do some work on all the slaves
# as they get connected.
#
#
# @param [Jenkins::Model::Computer] computer the computer that just came online
# @param [Jenkins::Model::Listener] listener connected to the launch log of the computer.
# @see {#preonline}
#
def online(computer, listener)
end

# Called right after a {@link Computer} went offline.
#
# @param [Jenkins::Model::Computer] computer the computer that just went offline
def offline(computer)
end

# Called when configuration of the node was changed, a node is added/removed, etc.
def configured()
end
end

0 comments on commit 77c8e09

Please sign in to comment.