Class: Puppetfactory::Plugins::Example

Inherits:
Puppetfactory::Plugins show all
Defined in:
lib/puppetfactory/plugins/example.rb

Overview

inherit from Puppetfactory::Plugins

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Example

Returns a new instance of Example.



7
8
9
10
11
12
# 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

Instance Attribute Details

#weightObject (readonly)

Returns the value of attribute weight.



5
6
7
# File 'lib/puppetfactory/plugins/example.rb', line 5

def weight
  @weight
end

Instance Method Details

#create(username, password) ⇒ Object

include one or more of the following methods. Any method you implement will be called when the corresponding task is invoked.



17
18
19
20
21
22
23
24
25
# 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) ⇒ Object



27
28
29
30
31
32
# 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) ⇒ Object



46
47
48
49
50
51
52
# 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

#loginObject

hook called when users log in. Only one can be active at any time.



77
78
79
80
# File 'lib/puppetfactory/plugins/example.rb', line 77

def 
  $logger.info 'Logging in with the default system shell'
  exec('bash --login')
end

#redeploy(username) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object

used by container plugins to rebuild them



71
72
73
74
# File 'lib/puppetfactory/plugins/example.rb', line 71

def repair(username)
  $logger.info "Container #{username} repaired"
  true
end

#userinfo(username, extended = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# 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

#usersObject

returns an array of all user accounts. Only one can be active at any time.



83
84
85
86
# 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