Code Monkey home page Code Monkey logo

otree_virtual_machine_manager's Introduction

oTree Virtual Machine Manager

https://travis-ci.org/tobiasraabe/otree_virtual_machine_manager.svg?branch=master Documentation Status

oTree Virtual Machine Manager helps to manage user accounts.

Overview

oTree Virtual Machine Manager is a complement to the oTree Virtual Machine Image provided by Felix Albrecht and Holger Gerhardt.

Since doing research is time-consuming enough, this tool ensures that administrators of an oTree server do not waste their time on creating fully equipped user accounts and similar tedious tasks. Everything breaks down to a single commandline interface.

Managing an oTree server with multiple experiments running parallel has never been easier.

Features

Create users
Creates a fully equipped experimenter account (clear project structure, virtual environment, graphical or point-and-click solutions to many oTree-related commands, samba access).
Back up user
Creates a database and/or home folder backup for users upon account closure so that nothing gets lost.
Remove user
Removes otree-server user accounts.
Reroutes user
Depending on the network it might be necessary to assign the main port to a different user.
Behind the scenes
Handles port configuration for multiple parallel user accounts on a single virtual host.

Tutorials

You can find a series of tutorial videos on Youtube.

For administrators
For end users

Contributing

Contributions are welcome and they are greatly appreciated! Every little bit helps, and credit will always be given.

Credits

Thanks to all contributors who spent their time on making this project more helpful for everyone.

  • Jonas Radbruch (Contributions to the documentation)

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

otree_virtual_machine_manager's People

Contributors

cataclysmic avatar jradbruch avatar pyup-bot avatar tobiasraabe avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

otree_virtual_machine_manager's Issues

ovmm delete_user does not work

  • oTree Virtual Machine Manager version: latest
  • Python version: 3.5 / 3.6
  • Operating System: oTree Virtual Machine image, but also fresh osboxes.org Ubuntu image

Description

I wanted to add, and then delete a user. Adding works. When I try to delete a user, there are some errors, and the user does not get removed from the PG table and from the system. The file user_config/davidjk.txt is deleted after running the command, however, subsequent runs of the delete_user command still fail with reference to the pkill exit code.

Thanks for the great work on ovmm, it is really very helpful.

What I Did

sudo ovmm delete_user

------------------- Process: Delete User -------------------
Do you want to see a list of users? [Y/n]: n
Which user do you want to delete? [louis]: davidjk
Do you want a database backup? [Y/n]: n
ERROR: User could not be deleted.
Command line: ['/usr/bin/sudo', 'pkill', '-u', 'davidjk']
Exit code: 0
SUCCESS: nginx configuration works.
SUCCESS: nginx configuration works.
SUCCESS: Removed user from nginx configuration.
SUCCESS: smb.conf works.
SUCCESS: Created backup of smb.conf.
SUCCESS: Removed user from smb.conf.
ERROR: User configuration text file could not be deleted.
Command line: ['/usr/bin/sudo', 'rm', '/home/otreeadmin/ovmm_sources/user_configs/davidjk.txt']
Exit code: 0
ERROR: An exception was raised during the deletion process.
Please, fix the problem manually. After that, run the command
again, so that the user will also be deleted from database.

WARNING: The deletion process is completed. If an error
occurred, check it manually.

----------------------- Process: End -----------------------

different handling of statics

Instead of writing a replacement handler for each new file could we iterate over the statics folder structure and replace ALL standardized the replacements?

Create BaseCommand class

  • oTree Ubuntu Server Manager version: 0.1.0
  • Python version: 3.6
  • Operating System: Ubuntu

Description

A much more sophisticate approach regarding commands would be to build class BaseCommand which could look like this:

# commands/base.py
"""The base command"""

class BaseCommand(object):
    """A base command."""
 
    def __init__(self, options, *args, **kwargs):
        self.options = options
        self.args = args
        self.kwargs = kwargs

   def requirements_check():
        pass
 
    def run(self):
        raise NotImplementedError('You must implement the run() method yourself!')

Additional ressources:

"add_user" + sudo

  • oTree Virtual Machine Manager version: 0.2.2
  • Python version: 3.5
  • Operating System: Ubuntu 16.04.2

Description

  • add step to add user to "sudo" group to allow for installation of software

For highly trusted users.
Default: "No"

Error message despite 'sudo'

ovmmadmin@otreehost:~/otree_virtual_machine_manager$ sudo ovmm add_user
ERROR: Not all environment variables are specified.
Program does not work! Have you run ovmm initialise?

Adding sentry to the installation

I learned that sentry is a django based open source project and can be installed locally.
I will look into it and we will add it to the installation instructions and add the necessary stuff to the otree_environ_config.

Todo

  • pip install -U sentry on initialise (optional)
  • write sentry link to otree_environ_config for each user
  • on otree_startproject ask if local sentry should be activated (static)
    • run sed on settings.py, add SENTRY_DSN = environ.get('SENTRY_DSN')

ufw Nginx Full

Realized that we do not open the ports 80 and 443 by default.

Should happen on ovvm initialise
commands:
sudo ufw allow "Nginx Full"
sudo service ufw restart

User command to finalize experiment

  • oTree Virtual Machine Manager version: 0.2.2
  • Python version: 3.5
  • Operating System: Ubuntu 16.04.2

Description

  • make database dump
  • get otree version / django version / base linux system
  • compress including project folder using 7zip
  • kill running otree instance *optional

run_prodserver command in .profile

  • oTree Ubuntu Server Manager version: 0.1.0
  • Python version: 3.6
  • Operating System: Ubuntu

Description

Adding a new user account should also implement the shortcut run_prodserver.

What I Did

When logging in as a new user, changing the folder to <user>/oTree/, running run_prodserver produces the error Cannot open your terminal '/dev/pts/17' - please check. Running script /dev/null resolves the error of running screen, but now run_prodserver, the shortcut, is gone.

Additional resources:

nginx config to example

We need to move the 'original' preconfigured nginx_conf.py to, e.g., nginx_conf_example.py.

Admins then need to create an nginx_conf.py with their specific data. Otherwise nginx_conf.py get replaced every time the git is pulled or the pull fails because of local changes in the nginx_conf.py.

File exists error

If the PostgreSQL superuser exists, set password? [Y/n]:
--> The content folder will be created under /home/ovmmadmin/ovmm_sources
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/ovmm-0.2.2-py3.5.egg/ovmm/commands/initialise.py", line 107, in initialise
os.mkdir(os.path.join(HOME, OSF))
FileExistsError: [Errno 17] File exists: '/home/ovmmadmin/ovmm_sources'

During handling of the above exception, another exception occurred:

ufw rules cannot be added when ufw is active

I used the old-old-old implementation as the module failed on me.
But it appears to me that this is a ufw rather than a python issue.

Trying to connect to the database and user table
The connection to the PostgreSQL database was successful!
Number of user accounts: 2
Limit of additional accounts: 97
The nginx configuration is fine.
The user was successfully added to nginx configuration.
The nginx configuration is fine.
Traceback (most recent call last):
  File "admin_scripts/add_user.py", line 148, in <module>
    add_user()
  File "admin_scripts/add_user.py", line 105, in add_user
    sudo[ufw['allow', dict_user['http_port']]]()
  File "/usr/local/lib/python3.5/dist-packages/plumbum/commands/base.py", line 96, in __call__
    return self.run(args, **kwargs)[1]
  File "/usr/local/lib/python3.5/dist-packages/plumbum/commands/base.py", line 226, in run
    return p.run()
  File "/usr/local/lib/python3.5/dist-packages/plumbum/commands/base.py", line 188, in runner
    return run_proc(p, retcode, timeout)
  File "/usr/local/lib/python3.5/dist-packages/plumbum/commands/processes.py", line 206, in run_proc
    return _check_process(proc, retcode, timeout, stdout, stderr)
  File "/usr/local/lib/python3.5/dist-packages/plumbum/commands/processes.py", line 23, in _check_process
    proc.verify(retcode, timeout, stdout, stderr)
  File "/usr/local/lib/python3.5/dist-packages/plumbum/machines/base.py", line 22, in verify
    stdout, stderr)
plumbum.commands.processes.ProcessExecutionError: Command line: ['/usr/bin/sudo', '/usr/sbin/ufw', 'allow', '7902']
Exit code: 1
Stderr:  | ERROR: problem running
otree@sms:~/otree-ubuserver-config$ 

Change user otree_restart command to awk syntax

  • change broad range killall otree to user specific clean process termination

kill $(ps -axo user:20,pid,command | grep $USER | grep 'otree' | grep 'python' | awk '{if (NR==1) print $(2)}')

Add skip for nginx on initialise

  • oTree Virtual Machine Manager version:
  • Python version:
  • Operating System:

Description

Rerunning initialise deletes the current nginx config.

no module 'util'

Here is the traceback:

otree@sms:~$ ovmm list_user
Traceback (most recent call last):
  File "/usr/local/bin/ovmm", line 11, in <module>
    load_entry_point('ovmm==0.1.0', 'console_scripts', 'ovmm')()
  File "/usr/local/lib/python2.7/dist-packages/click-6.7-py2.7.egg/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click-6.7-py2.7.egg/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click-6.7-py2.7.egg/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click-6.7-py2.7.egg/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click-6.7-py2.7.egg/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/ovmm-0.1.0-py2.7.egg/ovmm/cli.py", line 64, in list_user
    from .commands.list_user import list_user as list_usr
  File "/usr/local/lib/python2.7/dist-packages/ovmm-0.1.0-py2.7.egg/ovmm/commands/__init__.py", line 18, in <module>
    raise e
AttributeError: 'module' object has no attribute 'util'


Plumbum imports

  • oTree Ubuntu Server Manager version: 0.1.0
  • Python version: 3.6
  • Operating System: Ubuntu

Description

Up to now, plumbum commands are used in different flavors. But since sudo is used for almost all commands, one could also call all other commands with sudo instead of importing them explicitly.

E.g.:

from plumbum.cmd import sudo
from plumbum.cmd import useradd

sudo[useradd[]]()

or

from plumbum.cmd import sudo

sudo['useradd', ...]()

user cron job - kill reminder

Check oTree instance for last worker action and send notification mail to user after long (48h) inactivity to close oTree.

  • create local cronjob on user_add ~ 1.00am
  • check if otree is active
    kill $(ps -axo user:20,pid,command | grep $USER | grep 'otree' | grep 'python' | awk '{if (NR==1) print $(2)}')
  • query database for last user every 24h
  • if last user activity > 48h, send reminder to experimenter to kill otree

Needs one script and one crontab entry.

User-specific cronjob:
https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job#2369

Upgrade of user static commands

Need a way to upgrade user statics without overwriting everything.
Probably relates to issue "different handling of statics".

  • upgrade command for admin

Replace command line wrapper with alternative

Description

Currently, we are using Plumbum which offers a way to execute shell commands in a python script but it is not very pythonic.

Sultan is more pythonic, the syntax is cleaner and offers context managers.

There is no current need for it, but we should consider this when we want to improve the program.

click 2.0 update causes legacy error

User name [louis_alexander]:
/usr/local/lib/python3.5/dist-packages/click/core.py:880: Warning: Invoked legacy parameter callback "<function validate_user_name at 0x7fc06dac9d08>". The new signature for such callbacks starting with click 2.0 is (ctx, param, value).
value, args = param.handle_parse_result(ctx, opts, args)
Traceback (most recent call last):

Creation of SSL certificates on initialisation

  • oTree Virtual Machine Manager version: 0.2.1
  • Python version: 3.6
  • Operating System: Ubuntu 16.04.2

Description

Add command to create personal certificate quickly.

Standard snakeoil already implemented, but with distribution online, private key is freely on the web.

readthedocs.org

Description

Up to now, there is no documentation online on readthedocs.org.

script to 'gutt' the DB by the user

Egon ran into the issue that a resetdb did NOT completely remove all existing tables.
After Egon renamed some fields otree kept throwing errors because it kept referencing old non-existent fields that didn't exist anymore.
Only a database removal and reinstallation of Egon DB solved the issue.

Suggestion, single user command to executes the following.
In the DB:
DROP SCHEMA public CASCADE; # removes all tables within the DB
CREATE SCHEMA public; # creates a schema that be filled by otree

Before executing a clear warning msg should show up. (in red)

Create BasePrompt class

  • oTree Ubuntu Server Manager version: 0.1.0
  • Python version: 3.6
  • Operating System: Ubuntu

Description

A much more sophisticate approach regarding prompts would be to build class BasePrompt which could look like this:

# prompts/base.py
"""The base prompt"""

class BasePrompt():
   """A base prompt."""

    def __init__(self, prompt_string):
        self.prompt_string = prompt_string
        self.input = None

   def input_validation(self):
       # check with regular expression, type conversion, escaping of command sequences
 
    def run(self):
        raise NotImplementedError('You must implement the run() method yourself!')

Up to know, I dropped the input validation and provided examples of inputs, so that users hopefully stick to them. But in the long run users will try everything and you do not want to have a user called "John ; DROP TABLE;".

Remarks

  • usernames should not include hyphens because of postgres

Additional ressources:

where to put enduser scripts

Where do you want the enduser scripts?

This would also solve the run_prodserver issue. We will replace the command alias with a script handling the resetdb and database backup, too.

Comments on the oTree Virtual Machine Image and OVMM

  • oTree Virtual Machine Manager version: DON’T KNOW — Maybe add command “ovmm version”? (addressed in #102 )

oTree Virtual Machine Image:

  • Set video RAM to at least 16 MByte to support higher resolutions. (Automatic resizing of the VM window worked when I set the VRAM to 32 MB.)
  • 2 CPU cores by default.
  • Conky positioning should be adjusted on-the-fly when the resolution/windows size is changed.
  • Font in Conky should be monospaced. Decimal period instead of comma.
  • Add “construction site” emblem to the “Projects” folder.
  • Relabel the buttons in the “collectstatic” message.
    • Change text.
  • Include an “empty app” to be shown on the oTree demo page.
  • Conky: use monospaced font; replace decimal comma by period; make position depend on CURRENT screen resolution.
    • not feasible.
  • Window regarding creation of a virtual environment: Add explanation that this would enable installation of several oTree versions in parallel, one per project.
  • “Link Experiment” script: Change text so that “project folder” is replaced by “project (which is usually a subfolder of /home/otreeadmin/Projects/)”.
  • 3 tabs/windows that open when Firefox/Chromium starts: otree.org, localhost, http://otree.readthedocs.io/en/latest/
  • export OTREE_PRODUCTION=0 or 1 should be set on the fly instead of hardcoded; same for OTREE_AUTH_LEVEL?
  • /home/otreeadmin/Templates/_rooms/econ101.txt should include leading zeros.

OVMM

ovmm add_user

is executed and at then end asks for the sudo password. The command fails, however. See attached screenshot. screen shot 2017-08-09 at 14 15 04

  • nginx_template: Rephrase the instructions on how to set up HTTPS instead of HTTP.

Port 80 switch

On ovvm initialise:

  • create folder query whether port change should be doable by user - default admin
  • create folder "/var/port_80_switch
  • set permissions according to 1 - group permissions writeable group either admin or users
  • copy default nginx config to /etc/nginx/sites-available that calls /var/port_80_switch/otree
  • write user command to switch port (not in static package)
  • make available to admin ?~/local/bin
  • copy to users' ~/local/bin is users are allowed to use

Felix: provides switch command and default nginx

Propose functionality:

*** TODO nginx default config setup [0%]

  • nginx default config - bot block
  • replace original setup default config with ours

*** TODO Make default port switchable [0%]

**** TODO decide whether only admin or user can switch ports

**** TODO if users are allowed

  • create linux usergroup otree on initialise
  • config folder creating with otree group permission
  • assign newly created users to group otree
  • create symlink otree_link in folder
  • shell script that deletes symlink otree_link and creates new one to HOME/.oTree

**** TODO if only admin

  • ovmm query for username to switch default port to
  • delete current otree_link replace with symlink to /home/username/.oTree

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.