~charmers/charms/precise/haproxy/precise

« back to all changes in this revision

Viewing changes to formulas/mysql/hooks/common.py

  • Committer: Francis J. Lacoste
  • Date: 2011-05-27 15:21:03 UTC
  • Revision ID: francis.lacoste@canonical.com-20110527152103-a89th9opq6y2eual
Split out from principia-tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: syntax=python
2
 
 
3
 
import os
4
 
import MySQLdb
5
 
 
6
 
change_unit = os.environ.get("ENSEMBLE_REMOTE_UNIT")
7
 
# We'll name the database the same as the service.
8
 
database_name, _ = change_unit.split("/")
9
 
# A user per service unit so we can deny access quickly
10
 
user = change_unit.replace("/","-")
11
 
connection = None
12
 
 
13
 
def get_db_cursor():
14
 
    # Connect to mysql
15
 
    passwd = open("/var/lib/ensemble/mysql.passwd").read().strip()
16
 
    print passwd
17
 
    connection = MySQLdb.connect(user="root", host="localhost", passwd=passwd)
18
 
 
19
 
    return connection.cursor()
20