Created
June 18, 2016 18:16
-
-
Save webframp/f51ec268ebe838a7cc896d6de8dba3a4 to your computer and use it in GitHub Desktop.
A thing to make a graphite user, from some point in the past
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os,sys | |
sys.path.append("/opt/graphite/webapp/graphite") | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' | |
from django.contrib.auth.models import User | |
username = 'root' | |
password = 'change_me' | |
def get_user(username): | |
u = User.objects.get(username__exact=username) | |
def create_user(username, password): | |
u = User.objects.create_user(username, password=password) | |
u.save() | |
print "user created %s" % username | |
def set_password(username): | |
u = User.objects.get(username__exact=username) | |
u.set_password(password) | |
def set_passsword_or_create(username, password='changeme'): | |
u = get_user(username) | |
if u: | |
u.set_password(password) | |
else: | |
create_user(username, password) | |
def failed(username, error): | |
print "Could not create user: %s. Failed with %s" % username, error | |
try: | |
set_password_or_create(username, password) | |
except err: | |
failed(username, err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment