|
from charms.reactive import when, when_not, set_state |
|
|
|
from subprocess import check_call |
|
|
|
from charmhelpers.core.hookenv import status_set |
|
from charmhelpers.core.host import add_group |
|
from charmhelpers.core.host import adduser |
|
|
|
from charmhelpers.fetch import apt_install |
|
from charmhelpers.fetch import apt_update |
|
|
|
# This is a comment, you can delete me |
|
# Layers also emmit states you can react to. Most states are prefixed with the name |
|
# So, apt.installed.cpanminus tells us that the apt layer has successfully installed |
|
# cpanm. We could also add decorators for things like `apt.installed.php5.6` or any |
|
# package we requested the apt layer to install in the `layer.yaml` or via |
|
# `charms.apt.queue_install` |
|
@when('apt.installed.cpanminus') |
|
@when_not('sme.installed') |
|
def install(): |
|
status_set('maintenance', 'Installing CPAN Packages') |
|
cpan_packages = [ |
|
'Test::Simple', |
|
'Test::Warn', |
|
'Class::Accessor', |
|
'XML::Parser::EasyTree', |
|
'CGI::Ajax', |
|
'Date::Format', |
|
'Date::Parse', |
|
'Date::Manip', |
|
'IO::Tty' |
|
] |
|
|
|
for i in cpan_packages: |
|
status_set('maintenance', 'Installing CPAN Package: {}'.format(i)) |
|
check_call(['cpanm', i]) |
|
|
|
set_state('sme.nstalled') |
|
status_set('maintenance', 'CPAN Packages installed') |
|
|
|
@when('sme.installed') |
|
@when_not('sme.groups_added') |
|
def add_groups(): |
|
status_set('maintenance', 'Creating system groups') |
|
|
|
groups = [ |
|
'smestorage', |
|
'smeconfiguser', |
|
'defaultstore', |
|
'sme' |
|
] |
|
|
|
# This is a comment, you can delete me |
|
# If you find yourself using subprocess a lot, odds are there is a helper method |
|
# in charmhelpers for that. The documentation can be a bit unwieldy, but check out |
|
# http://pythonhosted.org/charmhelpers/api/charmhelpers.html and use the search |
|
# to try to map to things you're subprocessing for |
|
for group in groups: |
|
add_group(group) |
|
status_set('maintenance', 'System groups created') |
|
set_state('sme.groups_added') |
|
|
|
|
|
@when('sme.groups_added') |
|
@when_not('sme.ready') |
|
def add_users(): |
|
status_set('maintenance', 'Creating user accounts') |
|
|
|
# This is a comment, you can delete me |
|
# There is a charmhelpers.core.host.adduser method however you can not set the HOME |
|
# For the created user. This needs to be requested / patched in the charmhelpers library |
|
# http://pythonhosted.org/charmhelpers/api/charmhelpers.core.host.html#charmhelpers.core.host.adduser |
|
check_call(['useradd', '-m', '-p', '$6$mQM0S5fe$01X38ZTeOBEHkVovBYJ2Qn2NQKHdVRkpQmHItCx/lkTfNUZ8ge2v/aYHIm9y8LcxvjeMmzcHdFd0Y48B25NSq/', '-g', '5000', '-d', '/var/www/smestorage' ]) |
|
#check_call(['useradd', '-m', '-p', '',]) |
|
#check_call(['useradd', '-m', '-p', '',]) |
|
#check_call(['useradd', '-m', '-p', '',]) |
|
set_state('sme.ready') |
|
status_set('active', 'Ready') |