class Puppetfactory::Plugins::Example
inherit from Puppetfactory::Plugins
Attributes
weight[R]
Public Class Methods
new(options)
click to toggle source
Calls superclass method
Puppetfactory::Plugins::new
# File lib/puppetfactory/plugins/example.rb, line 7 def initialize(options) super(options) # call the superclass to initialize it @weight = 1 @example = options[:example] || '/tmp/example' end
Public Instance Methods
create(username, password)
click to toggle source
include one or more of the following methods. Any method you implement will be called when the corresponding task is invoked.
# File lib/puppetfactory/plugins/example.rb, line 17 def create(username, password) $logger.info "User #{username} created." # Log an error with $logger.error # fail user creation with a fatal error by raising an exception # return true if our action succeeded true end
delete(username)
click to toggle source
# File lib/puppetfactory/plugins/example.rb, line 27 def delete(username) $logger.info "User #{username} deleted." # return true if our action succeeded true end
deploy(username)
click to toggle source
# File lib/puppetfactory/plugins/example.rb, line 46 def deploy(username) environment = Puppetfactory::Helpers.environment_name(username) $logger.info "Deployed environment #{environment} for #{username}" # return true if our action succeeded true end
login()
click to toggle source
hook called when users log in. Only one can be active at any time.
# File lib/puppetfactory/plugins/example.rb, line 77 def login $logger.info 'Logging in with the default system shell' exec('bash --login') end
redeploy(username)
click to toggle source
# File lib/puppetfactory/plugins/example.rb, line 54 def redeploy(username) begin if username == 'production' raise "Can't redeploy production environment" end delete(username) deploy(username) rescue => e raise "Error redeploying environment #{username}: #{e.message}" end # return true if our action succeeded true end
repair(username)
click to toggle source
used by container plugins to rebuild them
# File lib/puppetfactory/plugins/example.rb, line 71 def repair(username) $logger.info "Container #{username} repaired" true end
userinfo(username, extended = false)
click to toggle source
# File lib/puppetfactory/plugins/example.rb, line 34 def userinfo(username, extended = false) # we can bail if we don't want to add to the basic user object. # for example, if these are heavy operations. return unless extended # return a hash with the :username key { :username => username, :example => username.upcase, } end
users()
click to toggle source
returns an array of all user accounts. Only one can be active at any time.
# File lib/puppetfactory/plugins/example.rb, line 83 def users usernames = Dir.glob('/home/*').map { |path| File.basename path } usernames.reject { |username| ['centos', 'training', 'showoff'].include? username } end