Class: Puppetfactory::Plugins::UserEnvironment
- Inherits:
-
Puppetfactory::Plugins
- Object
- Puppetfactory::Plugins
- Puppetfactory::Plugins::UserEnvironment
- Defined in:
- lib/puppetfactory/plugins/user_environment.rb
Instance Attribute Summary
Attributes inherited from Puppetfactory::Plugins
Instance Method Summary collapse
- #create(username, password) ⇒ Object
- #delete(username) ⇒ Object
- #deploy(username) ⇒ Object
-
#initialize(options) ⇒ UserEnvironment
constructor
A new instance of UserEnvironment.
- #redeploy(username) ⇒ Object
Constructor Details
#initialize(options) ⇒ UserEnvironment
Returns a new instance of UserEnvironment.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/puppetfactory/plugins/user_environment.rb', line 7 def initialize() super() @master = [:master] @confdir = [:confdir] @codedir = [:codedir] @stagedir = [:stagedir] @puppetcode = [:puppetcode] @templatedir = [:templatedir] @environments = [:environments] @repomodel = [:repomodel] @codestage = "#{@stagedir}/environments" end |
Instance Method Details
#create(username, password) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puppetfactory/plugins/user_environment.rb', line 21 def create(username, password) environment = "#{@codestage}/#{Puppetfactory::Helpers.environment_name(username)}" begin # configure environment FileUtils.mkdir_p "#{environment}/manifests" FileUtils.mkdir_p "#{environment}/modules" File.open("#{environment}/manifests/site.pp", 'w') do |f| f.write ERB.new(File.read("#{@templatedir}/site.pp.erb")).result(binding) end # Copy userprefs module into user environment if Dir.exist?("#{@codedir}/modules/userprefs") then FileUtils.cp_r("#{@codedir}/modules/userprefs", "#{environment}/modules/") elsif Dir.exist?("#{@environments}/production/modules/userprefs") then FileUtils.cp_r("#{@environments}/production/modules/userprefs", "#{environment}/modules/") else $logger.warn "Module userprefs not found in global or production modulepath" end # make sure the user and pe-puppet can access all the needful FileUtils.chown_R(username, 'pe-puppet', environment) FileUtils.chmod_R(0750, environment) deploy(username) rescue => e $logger.error "Error creating user environment for #{username}" $logger.error e. return false end true end |
#delete(username) ⇒ Object
57 58 59 60 |
# File 'lib/puppetfactory/plugins/user_environment.rb', line 57 def delete(username) FileUtils.rm_rf "#{@codestage}/#{Puppetfactory::Helpers.environment_name(username)}" FileUtils.rm_rf "#{@environments}/#{Puppetfactory::Helpers.environment_name(username)}" end |
#deploy(username) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/puppetfactory/plugins/user_environment.rb', line 62 def deploy(username) # TODO: temporary hack to keep this from disrupting current deliveries. return if @codestage == @environments environment = Puppetfactory::Helpers.environment_name(username) begin FileUtils.cp_r("#{@codestage}/#{environment}/*", "#{@environments}/#{environment}/") FileUtils.chown_R('pe-puppet', 'pe-puppet', "#{@environments}/#{environment}") RestClient::Resource.new( "https://#{@master}:8140/puppet-admin-api/v1/environment-cache?environment=#{environment}", :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("#{@confdir}/ssl/certs/#{@master}.pem")), :ssl_client_key => OpenSSL::PKey::RSA.new(File.read("#{@confdir}/ssl/private_keys/#{@master}.pem")), :ssl_ca_file => "#{@confdir}/ssl/ca/ca_crt.pem", :verify_ssl => OpenSSL::SSL::VERIFY_PEER ).delete rescue => e $logger.error "Deploying environment #{environment} failed: #{e.}" $logger.debug e.backtrace raise "Error deploying environment #{environment}." end end |
#redeploy(username) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/puppetfactory/plugins/user_environment.rb', line 85 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.}" end end |